TTK
Loading...
Searching...
No Matches
ttkTableDataSelector.cpp
Go to the documentation of this file.
1#include <ttkMacros.h>
3#include <ttkUtils.h>
4
5#include <vtkObjectFactory.h>
6
7#include <regex>
8
9using namespace std;
10using namespace ttk;
11
13
15 vtkInformation *info) {
16 if(port == 0) {
17 info->Set(vtkAlgorithm::INPUT_REQUIRED_DATA_TYPE(), "vtkTable");
18 return 1;
19 }
20 return 0;
21}
22
24 vtkInformation *info) {
25 if(port == 0) {
27 return 1;
28 }
29 return 0;
30}
31
33 vtkInformation *request,
34 vtkInformationVector **inputVector,
35 vtkInformationVector *outputVector) {
36
37 vtkTable *input = vtkTable::GetData(inputVector[0]);
38 FillAvailableCols(input);
39 return ttkAlgorithm::RequestInformation(request, inputVector, outputVector);
40}
41
42int ttkTableDataSelector::RequestData(vtkInformation *ttkNotUsed(request),
43 vtkInformationVector **inputVector,
44 vtkInformationVector *outputVector) {
45 vtkTable *input = vtkTable::GetData(inputVector[0]);
46 vtkTable *output = vtkTable::GetData(outputVector);
47
48 Timer timer;
49
50 output->ShallowCopy(input);
51
52 vtkDataSetAttributes *inputRowData = input->GetRowData();
53#ifndef TTK_ENABLE_KAMIKAZE
54 if(!inputRowData) {
55 this->printErr("Input has no row data.");
56 return -1;
57 }
58#endif
59
62#ifndef TTK_ENABLE_KAMIKAZE
63 if(!outputRowData) {
64 this->printErr("vtkFieldData memory allocation problem.");
65 return -1;
66 }
67#endif
68
69 if(AvailableCols.empty()) {
70 // loading from states
71 FillAvailableCols(input);
72 }
73
74 for(auto &col : SelectedCols) {
75 // check valid col
76 if(col.empty()) {
77 continue;
78 }
79 // check bounds in the range
80 ptrdiff_t const pos = find(AvailableCols.begin(), AvailableCols.end(), col)
81 - AvailableCols.begin();
82 if(pos < RangeId[0] || pos > RangeId[1]) {
83 continue;
84 }
85 // filter by regex
86 if(!regex_match(col, regex(RegexpString))) {
87 continue;
88 }
89 // add the array
90 vtkDataArray *arr = inputRowData->GetArray(col.c_str());
91 if(arr)
92 outputRowData->AddArray(arr);
93 }
94
95 output->GetRowData()->ShallowCopy(outputRowData);
96
97 {
99 this->printMsg("Complete", 1, timer.getElapsedTime());
101 }
102
103 return 1;
104}
105
107 int const nbColumns = input->GetNumberOfColumns();
108 AvailableCols.clear();
109 AvailableCols.resize(nbColumns);
110 for(int i = 0; i < nbColumns; ++i) {
111 AvailableCols[i] = input->GetColumnName(i);
112 }
113}
#define ttkNotUsed(x)
Mark function/method parameters that are not used in the function body at all.
Definition BaseClass.h:47
static vtkInformationIntegerKey * SAME_DATA_TYPE_AS_INPUT_PORT()
virtual int RequestInformation(vtkInformation *ttkNotUsed(request), vtkInformationVector **ttkNotUsed(inputVectors), vtkInformationVector *ttkNotUsed(outputVector))
TTK VTK-filter that selects scalar fields on input with shallow copy.
int RequestData(vtkInformation *request, vtkInformationVector **inputVector, vtkInformationVector *outputVector) override
int FillInputPortInformation(int port, vtkInformation *info) override
int RequestInformation(vtkInformation *request, vtkInformationVector **inputVector, vtkInformationVector *outputVector) override
int FillOutputPortInformation(int port, vtkInformation *info) override
void FillAvailableCols(vtkTable *input)
int printErr(const std::string &msg, const debug::LineMode &lineMode=debug::LineMode::NEW, std::ostream &stream=std::cerr) const
Definition Debug.h:149
double getElapsedTime()
Definition Timer.h:15
The Topology ToolKit.
vtkStandardNewMacro(ttkTableDataSelector)
printMsg(debug::output::BOLD+" | | | | | . \\ | | (__| | / __/| |_| / __/|__ _|"+debug::output::ENDCOLOR, debug::Priority::PERFORMANCE, debug::LineMode::NEW, stream)