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 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164
|
/*=========================================================================
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 "vtkCellData.h"
#include "vtkHierarchicalBoxDataSet.h"
#include "vtkInformation.h"
#include "vtkInformationVector.h"
#include "vtkMultiBlockDataSet.h"
#include "vtkMultiPieceDataSet.h"
#include "vtkObjectFactory.h"
#include "vtkUniformGrid.h"
#include "vtkUnsignedCharArray.h"
#include <cassert>
#include <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 std::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::FillInputPortInformation(
int vtkNotUsed(port), vtkInformation* info )
{
info->Set(
vtkAlgorithm::INPUT_REQUIRED_DATA_TYPE(),"vtkUniformGridAMR");
return 1;
}
//------------------------------------------------------------------------------
int vtkExtractDataSets::FillOutputPortInformation(
int vtkNotUsed(port), vtkInformation *info )
{
info->Set(vtkDataObject::DATA_TYPE_NAME(),"vtkMultiBlockDataSet");
return 1;
}
//------------------------------------------------------------------------------
int vtkExtractDataSets::RequestData(
vtkInformation *vtkNotUsed(request),
vtkInformationVector **inputVector,
vtkInformationVector *outputVector)
{
// STEP 0: Get input
vtkInformation *inInfo = inputVector[0]->GetInformationObject(0);
assert( "pre: input information object is NULL!" && (inInfo != NULL) );
vtkUniformGridAMR *input =
vtkUniformGridAMR::SafeDownCast(
inInfo->Get( vtkDataObject::DATA_OBJECT() ) );
assert( "pre: input dataset is NULL!" && (input != NULL) );
// STEP 1: Get output
vtkInformation* info = outputVector->GetInformationObject(0);
assert( "pre: output information object is NULL!" && (info != NULL) );
vtkMultiBlockDataSet *output =
vtkMultiBlockDataSet::SafeDownCast(info->Get(vtkDataObject::DATA_OBJECT()));
assert( "pre: output dataset is NULL!" && (output != NULL) );
// STEP 2: Initialize structure
output->SetNumberOfBlocks( input->GetNumberOfLevels() );
unsigned int blk = 0;
for( ; blk < output->GetNumberOfBlocks(); ++blk )
{
vtkMultiPieceDataSet *mpds = vtkMultiPieceDataSet::New();
// mpds->SetNumberOfPieces( input->GetNumberOfDataSets( blk ) );
output->SetBlock( blk, mpds );
mpds->Delete();
} // END for all blocks/levels
// STEP 3: Loop over sected blocks
vtkInternals::DatasetsType::iterator iter = this->Internals->Datasets.begin();
for (;iter != this->Internals->Datasets.end(); ++iter)
{
vtkUniformGrid* inUG = input->GetDataSet(iter->Level, iter->Index);
if( inUG )
{
vtkMultiPieceDataSet *mpds =
vtkMultiPieceDataSet::SafeDownCast( output->GetBlock(iter->Level) );
assert( "pre: mpds is NULL!" && (mpds!=NULL) );
unsigned int out_index = mpds->GetNumberOfPieces();
vtkUniformGrid* clone = inUG->NewInstance();
clone->ShallowCopy(inUG);
// Remove blanking from output datasets.
clone->GetCellData()->RemoveArray(vtkDataSetAttributes::GhostArrayName());
mpds->SetPiece( out_index, clone );
clone->Delete();
}
} // END for all selected items
return 1;
}
//----------------------------------------------------------------------------
void vtkExtractDataSets::PrintSelf(ostream& os, vtkIndent indent)
{
this->Superclass::PrintSelf(os, indent);
}
|