1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148
|
/*=========================================================================
Program: Visualization Toolkit
Module: vtkExtractDataSets.cxx
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
#include "vtkExtractDataSets.h"
#include "vtkObjectFactory.h"
#include "vtkInformation.h"
#include "vtkInformationVector.h"
#include "vtkHierarchicalBoxDataSet.h"
#include "vtkUniformGrid.h"
#include "vtkAMRBox.h"
#include "vtkUnsignedCharArray.h"
#include <vtkstd/set>
class vtkExtractDataSets::vtkInternals
{
public:
struct Node
{
unsigned int Level;
unsigned int Index;
bool operator() (const Node& n1, const Node& n2) const
{
if (n1.Level == n2.Level)
{
return (n1.Index < n2.Index);
}
return (n1.Level < n2.Level);
}
};
typedef vtkstd::set<Node, Node> DatasetsType;
DatasetsType Datasets;
};
vtkStandardNewMacro(vtkExtractDataSets);
//----------------------------------------------------------------------------
vtkExtractDataSets::vtkExtractDataSets()
{
this->Internals = new vtkInternals();
}
//----------------------------------------------------------------------------
vtkExtractDataSets::~vtkExtractDataSets()
{
delete this->Internals;
}
//----------------------------------------------------------------------------
void vtkExtractDataSets::AddDataSet(
unsigned int level, unsigned int idx)
{
vtkInternals::Node node;
node.Level = level;
node.Index = idx;
this->Internals->Datasets.insert(node);
this->Modified();
}
//----------------------------------------------------------------------------
void vtkExtractDataSets::ClearDataSetList()
{
this->Internals->Datasets.clear();
this->Modified();
}
//----------------------------------------------------------------------------
int vtkExtractDataSets::RequestData(
vtkInformation *vtkNotUsed(request),
vtkInformationVector **inputVector,
vtkInformationVector *outputVector)
{
vtkInformation* inInfo = inputVector[0]->GetInformationObject(0);
vtkHierarchicalBoxDataSet *input = vtkHierarchicalBoxDataSet::SafeDownCast(
inInfo->Get(vtkDataObject::DATA_OBJECT()));
vtkInformation* info = outputVector->GetInformationObject(0);
vtkHierarchicalBoxDataSet *output = vtkHierarchicalBoxDataSet::SafeDownCast(
info->Get(vtkDataObject::DATA_OBJECT()));
unsigned int numLevels = input->GetNumberOfLevels();
output->SetNumberOfLevels(numLevels);
// copy levels meta-data.
for (unsigned int cc=0; cc < numLevels; cc++)
{
if (input->HasLevelMetaData(cc))
{
output->GetLevelMetaData(cc)->Copy(input->GetLevelMetaData(cc));
}
}
// Note that we need to ensure that all processess have the same tree
// structure in the output.
vtkInternals::DatasetsType::iterator iter;
for (iter = this->Internals->Datasets.begin();
iter != this->Internals->Datasets.end(); ++iter)
{
vtkAMRBox box;
vtkUniformGrid* inUG = input->GetDataSet(
iter->Level, iter->Index, box);
unsigned int out_index = output->GetNumberOfDataSets(iter->Level);
output->SetNumberOfDataSets(iter->Level, out_index+1);
if (input->HasMetaData(iter->Level, iter->Index))
{
output->GetMetaData(iter->Level, out_index)->Copy(
input->GetMetaData(iter->Level, iter->Index));
}
if (inUG)
{
vtkUniformGrid* clone = inUG->NewInstance();
clone->ShallowCopy(inUG);
// Remove blanking from output datasets.
clone->SetCellVisibilityArray(0);
output->SetDataSet(iter->Level,
out_index, box, clone);
clone->Delete();
}
}
// regenerate blanking.
output->GenerateVisibilityArrays();
return 1;
}
//----------------------------------------------------------------------------
void vtkExtractDataSets::PrintSelf(ostream& os, vtkIndent indent)
{
this->Superclass::PrintSelf(os, indent);
}
|