TTK
Loading...
Searching...
No Matches
ttkBlockAggregator.cpp
Go to the documentation of this file.
2
3#include <vtkInformation.h>
4#include <vtkInformationVector.h>
5#include <vtkSmartPointer.h>
6
7#include <vtkDoubleArray.h>
8#include <vtkFieldData.h>
9#include <vtkMultiBlockDataSet.h>
10
12
14 this->setDebugMsgPrefix("BlockAggregator");
15
16 this->Reset();
17
18 this->SetNumberOfInputPorts(1);
19 this->SetNumberOfOutputPorts(1);
20}
21
23
25 vtkInformation *info) {
26 if(port == 0) {
27 info->Set(vtkAlgorithm::INPUT_REQUIRED_DATA_TYPE(), "vtkDataObject");
28 info->Set(vtkAlgorithm::INPUT_IS_REPEATABLE(), 1);
29 return 1;
30 }
31 return 0;
32}
33
35 vtkInformation *info) {
36 if(port == 0) {
37 info->Set(vtkDataObject::DATA_TYPE_NAME(), "vtkMultiBlockDataSet");
38 return 1;
39 }
40 return 0;
41}
42
44 this->AggregatedMultiBlockDataSet
46 return 1;
47}
48
49static int copyObjects(vtkDataObject *source, vtkDataObject *copy) {
50 if(source->IsA("vtkMultiBlockDataSet")) {
51 auto sourceAsMB = vtkMultiBlockDataSet::SafeDownCast(source);
52 auto copyAsMB = vtkMultiBlockDataSet::SafeDownCast(copy);
53
54 if(sourceAsMB == nullptr || copyAsMB == nullptr) {
55 return 0;
56 }
57
58 const auto sourceFD = sourceAsMB->GetFieldData();
59 auto copyFD = copyAsMB->GetFieldData();
60
61 if(sourceFD == nullptr || copyFD == nullptr) {
62 return 0;
63 }
64
65 copyFD->ShallowCopy(sourceFD);
66
67 for(size_t i = 0; i < sourceAsMB->GetNumberOfBlocks(); i++) {
68 auto block = sourceAsMB->GetBlock(i);
69 auto blockCopy
70 = vtkSmartPointer<vtkDataObject>::Take(block->NewInstance());
71
72 copyObjects(block, blockCopy);
73 copyAsMB->SetBlock(i, blockCopy);
74 }
75 } else {
76 copy->ShallowCopy(source);
77 }
78
79 return 1;
80}
81
82int ttkBlockAggregator::AggregateBlock(vtkDataObject *dataObject) {
83 ttk::Timer t;
84 size_t const nBlocks = this->AggregatedMultiBlockDataSet->GetNumberOfBlocks();
85 this->printMsg("Adding object add index " + std::to_string(nBlocks), 0,
87
88 auto copy = vtkSmartPointer<vtkDataObject>::Take(dataObject->NewInstance());
89 copyObjects(dataObject, copy);
90
91 this->AggregatedMultiBlockDataSet->SetBlock(nBlocks, copy);
92
93 this->printMsg("Adding object at block index " + std::to_string(nBlocks), 1,
94 t.getElapsedTime());
95
96 return 1;
97}
98
99int ttkBlockAggregator::RequestData(vtkInformation *ttkNotUsed(request),
100 vtkInformationVector **inputVector,
101 vtkInformationVector *outputVector) {
102 // Get iteration information
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);
111 }
112
113 // Check if AggregatedMultiBlockDataSet needs to be reset
114 if(!iterationInformation || this->GetForceReset() || iterationIndex == 0)
115 this->Reset();
116
117 // Add all inputs
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);
121
122 if(this->GetFlattenInput() && input->IsA("vtkMultiBlockDataSet")) {
123 auto inputAsMB = (vtkMultiBlockDataSet *)input;
124 auto nBlocks = inputAsMB->GetNumberOfBlocks();
125 for(size_t j = 0; j < nBlocks; j++)
126 this->AggregateBlock(inputAsMB->GetBlock(j));
127 } else
128 this->AggregateBlock(input);
129 }
130
131 // Prepare output
132 auto output = vtkMultiBlockDataSet::GetData(outputVector);
133 output->ShallowCopy(this->AggregatedMultiBlockDataSet);
134
135 return 1;
136}
#define ttkNotUsed(x)
Mark function/method parameters that are not used in the function body at all.
Definition BaseClass.h:47
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)
Definition Debug.h:364
double getElapsedTime()
Definition Timer.h:15
vtkStandardNewMacro(ttkBlockAggregator)
printMsg(debug::output::BOLD+" | | | | | . \\ | | (__| | / __/| |_| / __/|__ _|"+debug::output::ENDCOLOR, debug::Priority::PERFORMANCE, debug::LineMode::NEW, stream)