TTK
Loading...
Searching...
No Matches
ttkMergeBlockTables.cpp
Go to the documentation of this file.
2
3#include <vtkFieldData.h>
4#include <vtkInformation.h>
5#include <vtkInformationVector.h>
6#include <vtkMultiBlockDataSet.h>
7#include <vtkNew.h>
8#include <vtkObjectFactory.h>
9#include <vtkTable.h>
10
12
14 this->setDebugMsgPrefix("MergeBlockTables");
15 this->SetNumberOfInputPorts(1);
16 this->SetNumberOfOutputPorts(1);
17}
18
20 vtkInformation *info) {
21 if(port == 0) {
22 info->Set(vtkAlgorithm::INPUT_REQUIRED_DATA_TYPE(), "vtkMultiBlockDataSet");
23 return 1;
24 }
25 return 0;
26}
27
29 vtkInformation *info) {
30 if(port == 0) {
31 info->Set(vtkDataObject::DATA_TYPE_NAME(), "vtkTable");
32 return 1;
33 }
34 return 0;
35}
36
37int ttkMergeBlockTables::RequestData(vtkInformation *ttkNotUsed(request),
38 vtkInformationVector **inputVector,
39 vtkInformationVector *outputVector) {
40 // Get input data
41 std::vector<vtkTable *> inputTables;
42
43 auto blocks = vtkMultiBlockDataSet::GetData(inputVector[0], 0);
44
45 // Number of input tables
46 size_t nInputs{};
47
48 if(blocks != nullptr) {
49 nInputs = blocks->GetNumberOfBlocks();
50 for(size_t i = 0; i < nInputs; ++i) {
51 inputTables.emplace_back(vtkTable::SafeDownCast(blocks->GetBlock(i)));
52 }
53 }
54
55 // Sanity check
56 for(const auto table : inputTables) {
57 if(table == nullptr) {
58 this->printErr("Input tables are not all vtkTables");
59 return 0;
60 }
61 }
62
63 // Sanity check
64 if(nInputs == 0) {
65 this->printErr("No input table");
66 return 0;
67 }
68
69 // Set output
70 auto outputTable = vtkTable::GetData(outputVector);
71
72 // Copy first table to output
73 // (deep copy leaves the input untouched)
74 outputTable->DeepCopy(inputTables[0]);
75
76 // Clear out the FieldData that may have been copied
77 const auto fd = outputTable->GetFieldData();
78 if(fd != nullptr) {
79 fd->Reset();
80 }
81
82 // Insert row of every other table into output
83 for(size_t i = 1; i < nInputs; ++i) {
84 const auto currTable{inputTables[i]};
85 for(vtkIdType j = 0; j < currTable->GetNumberOfRows(); ++j) {
86 outputTable->InsertNextRow(currTable->GetRow(j));
87 }
88 }
89
90 return 1;
91}
#define ttkNotUsed(x)
Mark function/method parameters that are not used in the function body at all.
Definition: BaseClass.h:47
TTK processing package for merging vtkTables from a vtkMultiBlockDataSet.
int RequestData(vtkInformation *request, vtkInformationVector **inputVector, vtkInformationVector *outputVector) override
int FillOutputPortInformation(int port, vtkInformation *info) override
int FillInputPortInformation(int port, vtkInformation *info) override
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
vtkStandardNewMacro(ttkMergeBlockTables)