3#include <vtkFieldData.h>
4#include <vtkInformation.h>
5#include <vtkInformationVector.h>
6#include <vtkMultiBlockDataSet.h>
8#include <vtkObjectFactory.h>
9#include <vtkUnsignedIntArray.h>
15 this->SetNumberOfInputPorts(1);
16 this->SetNumberOfOutputPorts(1);
20 vtkInformation *info) {
22 info->Set(vtkAlgorithm::INPUT_REQUIRED_DATA_TYPE(),
"vtkMultiBlockDataSet");
29 vtkInformation *info) {
31 info->Set(vtkDataObject::DATA_TYPE_NAME(),
"vtkMultiBlockDataSet");
38 vtkInformationVector **inputVector,
39 vtkInformationVector *outputVector) {
42 std::vector<std::pair<vtkDataObject *, size_t>> blocks{};
44 auto input = vtkMultiBlockDataSet::GetData(inputVector[0], 0);
47 if(input ==
nullptr || input->GetNumberOfBlocks() == 0) {
52 for(
size_t i = 0; i < input->GetNumberOfBlocks(); ++i) {
53 const auto topLvlBlock
54 = vtkMultiBlockDataSet::SafeDownCast(input->GetBlock(i));
55 if(topLvlBlock ==
nullptr) {
58 for(
size_t j = 0; j < topLvlBlock->GetNumberOfBlocks(); ++j) {
59 blocks.emplace_back(topLvlBlock->GetBlock(j), i);
63 auto outputFlatBlocks = vtkMultiBlockDataSet::GetData(outputVector);
67 this->
printWrn(
"Not a hierarchy of vtkMultiBlockDataSet");
68 outputFlatBlocks->ShallowCopy(input);
73 outputFlatBlocks->SetNumberOfBlocks(blocks.size());
75 for(
size_t i = 0; i < blocks.size(); ++i) {
77 outputFlatBlocks->SetBlock(i, blocks[i].first);
80 vtkNew<vtkUnsignedIntArray> blockId{};
81 blockId->SetName(
"ParentBlockId");
82 blockId->SetNumberOfTuples(1);
83 blockId->SetTuple1(0, blocks[i].second);
85 blocks[i].first->GetFieldData()->AddArray(blockId);
#define ttkNotUsed(x)
Mark function/method parameters that are not used in the function body at all.
TTK processing package for flattening the top-level hierarchy of a tree vtkMultiBlockDataSet structur...
int FillOutputPortInformation(int port, vtkInformation *info) override
int RequestData(vtkInformation *request, vtkInformationVector **inputVector, vtkInformationVector *outputVector) override
int FillInputPortInformation(int port, vtkInformation *info) override
int printWrn(const std::string &msg, const debug::LineMode &lineMode=debug::LineMode::NEW, std::ostream &stream=std::cerr) const
void setDebugMsgPrefix(const std::string &prefix)
int printErr(const std::string &msg, const debug::LineMode &lineMode=debug::LineMode::NEW, std::ostream &stream=std::cerr) const
vtkStandardNewMacro(ttkFlattenMultiBlock)