3#include <vtkInformation.h>
4#include <vtkInformationVector.h>
5#include <vtkSmartPointer.h>
7#include <vtkDoubleArray.h>
8#include <vtkFieldData.h>
9#include <vtkMultiBlockDataSet.h>
18 this->SetNumberOfInputPorts(1);
19 this->SetNumberOfOutputPorts(1);
25 vtkInformation *info) {
27 info->Set(vtkAlgorithm::INPUT_REQUIRED_DATA_TYPE(),
"vtkDataObject");
28 info->Set(vtkAlgorithm::INPUT_IS_REPEATABLE(), 1);
35 vtkInformation *info) {
37 info->Set(vtkDataObject::DATA_TYPE_NAME(),
"vtkMultiBlockDataSet");
44 this->AggregatedMultiBlockDataSet
49static int copyObjects(vtkDataObject *source, vtkDataObject *copy) {
50 if(source->IsA(
"vtkMultiBlockDataSet")) {
51 auto sourceAsMB = vtkMultiBlockDataSet::SafeDownCast(source);
52 auto copyAsMB = vtkMultiBlockDataSet::SafeDownCast(copy);
54 if(sourceAsMB ==
nullptr || copyAsMB ==
nullptr) {
58 const auto sourceFD = sourceAsMB->GetFieldData();
59 auto copyFD = copyAsMB->GetFieldData();
61 if(sourceFD ==
nullptr || copyFD ==
nullptr) {
65 copyFD->ShallowCopy(sourceFD);
67 for(
size_t i = 0; i < sourceAsMB->GetNumberOfBlocks(); i++) {
68 auto block = sourceAsMB->GetBlock(i);
72 copyObjects(block, blockCopy);
73 copyAsMB->SetBlock(i, blockCopy);
76 copy->ShallowCopy(source);
84 size_t const nBlocks = this->AggregatedMultiBlockDataSet->GetNumberOfBlocks();
85 this->
printMsg(
"Adding object add index " + std::to_string(nBlocks), 0,
89 copyObjects(dataObject, copy);
91 this->AggregatedMultiBlockDataSet->SetBlock(nBlocks, copy);
93 this->
printMsg(
"Adding object at block index " + std::to_string(nBlocks), 1,
100 vtkInformationVector **inputVector,
101 vtkInformationVector *outputVector) {
103 double iterationIndex = 0;
104 this->SetInputArrayToProcess(0, 0, 0, 2,
"_ttk_IterationInfo");
105 auto iterationInformation = vtkDoubleArray::SafeDownCast(
106 this->GetInputArrayToProcess(0, inputVector));
107 if(iterationInformation) {
108 iterationIndex = iterationInformation->GetValue(0);
109 this->AggregatedMultiBlockDataSet->GetFieldData()->AddArray(
110 iterationInformation);
114 if(!iterationInformation || this->
GetForceReset() || iterationIndex == 0)
118 size_t const nInputs = inputVector[0]->GetNumberOfInformationObjects();
119 for(
size_t i = 0; i < nInputs; i++) {
120 auto input = vtkDataObject::GetData(inputVector[0], i);
123 auto inputAsMB = (vtkMultiBlockDataSet *)input;
124 auto nBlocks = inputAsMB->GetNumberOfBlocks();
125 for(
size_t j = 0; j < nBlocks; j++)
132 auto output = vtkMultiBlockDataSet::GetData(outputVector);
133 output->ShallowCopy(this->AggregatedMultiBlockDataSet);
#define ttkNotUsed(x)
Mark function/method parameters that are not used in the function body at all.
TTK VTK-filter that appends every input vtkDataObject as a block to an output vtkMultiBlockDataSet.
int FillOutputPortInformation(int port, vtkInformation *info) override
~ttkBlockAggregator() override
int RequestData(vtkInformation *request, vtkInformationVector **inputVector, vtkInformationVector *outputVector) override
int AggregateBlock(vtkDataObject *dataObject)
virtual bool GetForceReset()
virtual bool GetFlattenInput()
int FillInputPortInformation(int port, vtkInformation *info) override
void setDebugMsgPrefix(const std::string &prefix)
vtkStandardNewMacro(ttkBlockAggregator)
printMsg(debug::output::BOLD+" | | | | | . \\ | | (__| | / __/| |_| / __/|__ _|"+debug::output::ENDCOLOR, debug::Priority::PERFORMANCE, debug::LineMode::NEW, stream)