TTK
Loading...
Searching...
No Matches
ttkImportEmbeddingFromTable.cpp
Go to the documentation of this file.
1#include <regex>
3
4#include <ttkMacros.h>
5#include <ttkUtils.h>
6
7// VTK includes
8#include <vtkIdTypeArray.h>
9#include <vtkInformation.h>
10#include <vtkPointSet.h>
11#include <vtkTable.h>
12
13using namespace std;
14using namespace ttk;
15
17
19 int port, vtkInformation *info) {
20 if(port == 0) {
21 info->Set(vtkAlgorithm::INPUT_REQUIRED_DATA_TYPE(), "vtkPointSet");
22 return 1;
23 }
24 if(port == 1) {
25 info->Set(vtkAlgorithm::INPUT_REQUIRED_DATA_TYPE(), "vtkTable");
26 return 1;
27 }
28
29 return 0;
30}
31
33 int port, vtkInformation *info) {
34 if(port == 0) {
36 return 1;
37 }
38 return 0;
39}
40
41template <typename VTK_TT>
43 VTK_TT *xdata,
44 VTK_TT *ydata,
45 VTK_TT *zdata,
46 const bool Embedding2D) {
47 for(SimplexId i = 0; i < points->GetNumberOfPoints(); ++i) {
48 double p[3];
49 p[0] = xdata[i];
50 p[1] = ydata[i];
51 p[2] = Embedding2D ? 0 : zdata[i];
52 points->SetPoint(i, p);
53 }
54}
55
57 vtkInformation *ttkNotUsed(request),
58 vtkInformationVector **inputVector,
59 vtkInformationVector *outputVector) {
60
61 vtkPointSet *inputDataSet = vtkPointSet::GetData(inputVector[0]);
62 vtkTable *inputTable = vtkTable::GetData(inputVector[1]);
63 vtkPointSet *output = vtkPointSet::GetData(outputVector);
64
65 const SimplexId numberOfPoints = inputDataSet->GetNumberOfPoints();
66#ifndef TTK_ENABLE_KAMIKAZE
67 if(numberOfPoints <= 0) {
68 printErr("input has no point.");
69 return -1;
70 }
71#endif
72
73 vtkDataArray *xarr = XColumn.empty()
74 ? nullptr
75 : vtkDataArray::SafeDownCast(
76 inputTable->GetColumnByName(XColumn.data()));
77 vtkDataArray *yarr = YColumn.empty()
78 ? nullptr
79 : vtkDataArray::SafeDownCast(
80 inputTable->GetColumnByName(YColumn.data()));
81 vtkDataArray *zarr = ZColumn.empty()
82 ? nullptr
83 : vtkDataArray::SafeDownCast(
84 inputTable->GetColumnByName(ZColumn.data()));
85
86#ifndef TTK_ENABLE_KAMIKAZE
87 if(xarr == nullptr or yarr == nullptr or zarr == nullptr) {
88 printErr("invalid input columns.");
89 return -1;
90 }
91 if(xarr->GetNumberOfTuples() != numberOfPoints
92 or yarr->GetNumberOfTuples() != numberOfPoints
93 or zarr->GetNumberOfTuples() != numberOfPoints) {
94 printErr("number of points on inputs mismatch.");
95 return -1;
96 }
97 if(xarr->GetDataType() != yarr->GetDataType()
98 or xarr->GetDataType() != zarr->GetDataType()) {
99 printErr("input columns has different data types.");
100 return -1;
101 }
102#endif
103
105 points->SetNumberOfPoints(numberOfPoints);
106
107 switch(xarr->GetDataType()) {
108 vtkTemplateMacro(setPointFromData(
109 points, static_cast<VTK_TT *>(ttkUtils::GetVoidPointer(xarr)),
110 static_cast<VTK_TT *>(ttkUtils::GetVoidPointer(yarr)),
111 static_cast<VTK_TT *>(ttkUtils::GetVoidPointer(zarr)), Embedding2D));
112 }
113
114 output->ShallowCopy(inputDataSet);
115 output->SetPoints(points);
116
117 return 1;
118}
#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()
TTK VTK-filter that embeds a vtkPointSet with the data of a vtkTable.
int FillOutputPortInformation(int port, vtkInformation *info) override
int RequestData(vtkInformation *request, vtkInformationVector **inputVector, vtkInformationVector *outputVector) override
int FillInputPortInformation(int port, vtkInformation *info) override
static void * GetVoidPointer(vtkDataArray *array, vtkIdType start=0)
Definition: ttkUtils.cpp:225
int printErr(const std::string &msg, const debug::LineMode &lineMode=debug::LineMode::NEW, std::ostream &stream=std::cerr) const
Definition: Debug.h:149
The Topology ToolKit.
int SimplexId
Identifier type for simplices of any dimension.
Definition: DataTypes.h:22
vtkStandardNewMacro(ttkImportEmbeddingFromTable) int ttkImportEmbeddingFromTable
void setPointFromData(const vtkSmartPointer< vtkPoints > &points, VTK_TT *xdata, VTK_TT *ydata, VTK_TT *zdata, const bool Embedding2D)