TTK
Loading...
Searching...
No Matches
ttkEndFor.cpp
Go to the documentation of this file.
1#include <ttkEndFor.h>
2
3#include <vtkCompositeDataPipeline.h>
4#include <vtkDoubleArray.h>
5#include <vtkFieldData.h>
6#include <vtkInformation.h>
7#include <vtkInformationVector.h>
8#include <vtkMultiBlockDataSet.h>
9
10#include <ttkForEach.h>
11
13
15 this->setDebugMsgPrefix("EndFor");
16
17 SetNumberOfInputPorts(2);
18 SetNumberOfOutputPorts(1);
19}
20
21ttkEndFor::~ttkEndFor() = default;
22
23int ttkEndFor::FillInputPortInformation(int port, vtkInformation *info) {
24 if(port == 0 || port == 1) {
25 info->Set(vtkAlgorithm::INPUT_REQUIRED_DATA_TYPE(), "vtkDataObject", 1);
26 return 1;
27 }
28 return 0;
29}
30
31int ttkEndFor::FillOutputPortInformation(int port, vtkInformation *info) {
32 if(port == 0) {
34 return 1;
35 }
36 return 0;
37}
38
39static int removeFieldDataRecursively(vtkDataObject *object) {
40 object->GetFieldData()->RemoveArray("_ttk_IterationInfo");
41 if(object->IsA("vtkMultiBlockDataSet")) {
42 auto objectAsMB = static_cast<vtkMultiBlockDataSet *>(object);
43 for(size_t i = 0; i < objectAsMB->GetNumberOfBlocks(); i++)
44 removeFieldDataRecursively(objectAsMB->GetBlock(i));
45 }
46 return 1;
47}
48
49int ttkEndFor::RequestData(vtkInformation *request,
50 vtkInformationVector **inputVector,
51 vtkInformationVector *outputVector) {
52
53 // find for each head
54 ttkForEach *forEach = nullptr;
55 {
56 auto inputAlgorithm = this->GetInputAlgorithm(1, 0);
57 while(inputAlgorithm && !inputAlgorithm->IsA("ttkForEach")) {
58 inputAlgorithm = inputAlgorithm->GetInputAlgorithm();
59 }
60 forEach = ttkForEach::SafeDownCast(inputAlgorithm);
61 }
62
63 if(!forEach) {
64 this->printErr("Second input not connected to a ttkForEach filter.");
65 return 0;
66 }
67
68 // get iteration info
69 int const i = forEach->GetIterationIdx() - 1;
70 int const n = forEach->GetIterationNumber();
71
72 bool const isRepeatedIteration = this->LastIterationIdx == i && i > 0;
73 this->LastIterationIdx = i;
74
75 if(isRepeatedIteration)
76 this->printMsg("For Loop Modified -> Restarting Iterations",
78 else
79 this->printMsg("Iteration ( " + std::to_string(i) + " / "
80 + std::to_string(n - 1) + " ) complete ",
82
83 if(i >= n - 1 && !isRepeatedIteration) {
84 // if this is the last iteration
85 auto input = vtkDataObject::GetData(inputVector[0]);
86 auto output = vtkDataObject::GetData(outputVector);
87 output->ShallowCopy(input);
88 removeFieldDataRecursively(output);
89 request->Remove(vtkStreamingDemandDrivenPipeline::CONTINUE_EXECUTING());
90 } else {
91 // if this is an intermediate iteration
92 forEach->Modified();
93 this->GetInputAlgorithm(0, 0)->Update();
94
95 request->Set(vtkStreamingDemandDrivenPipeline::CONTINUE_EXECUTING(), 1);
96 }
97
98 return 1;
99}
static vtkInformationIntegerKey * SAME_DATA_TYPE_AS_INPUT_PORT()
TTK VTK-filter that requests data as long as it is available.
Definition ttkEndFor.h:32
int FillInputPortInformation(int port, vtkInformation *info) override
Definition ttkEndFor.cpp:23
~ttkEndFor() override
int FillOutputPortInformation(int port, vtkInformation *info) override
Definition ttkEndFor.cpp:31
int RequestData(vtkInformation *request, vtkInformationVector **inputVector, vtkInformationVector *outputVector) override
Definition ttkEndFor.cpp:49
TTK VTK-filter that works in conjunction with the ttkEndFor filter to iterate over blocks,...
Definition ttkForEach.h:33
virtual int GetIterationNumber()
static ttkForEach * SafeDownCast(vtkObject *o)
virtual int GetIterationIdx()
void setDebugMsgPrefix(const std::string &prefix)
Definition Debug.h:364
int printErr(const std::string &msg, const debug::LineMode &lineMode=debug::LineMode::NEW, std::ostream &stream=std::cerr) const
Definition Debug.h:149
std::string to_string(__int128)
Definition ripserpy.cpp:99
vtkStandardNewMacro(ttkEndFor)
printMsg(debug::output::BOLD+" | | | | | . \\ | | (__| | / __/| |_| / __/|__ _|"+debug::output::ENDCOLOR, debug::Priority::PERFORMANCE, debug::LineMode::NEW, stream)