TTK
Loading...
Searching...
No Matches
ttkEigenField.cpp
Go to the documentation of this file.
1#include <ttkEigenField.h>
2#include <ttkMacros.h>
3#include <ttkUtils.h>
4
5// VTK includes
6#include <vtkDataSet.h>
7#include <vtkDoubleArray.h>
8#include <vtkFloatArray.h>
9#include <vtkInformation.h>
10#include <vtkObjectFactory.h>
11#include <vtkPointData.h>
12#include <vtkSmartPointer.h>
13
15
17 SetNumberOfInputPorts(1);
18 SetNumberOfOutputPorts(1);
19}
20
21int ttkEigenField::FillInputPortInformation(int port, vtkInformation *info) {
22 if(port == 0) {
23 info->Set(vtkAlgorithm::INPUT_REQUIRED_DATA_TYPE(), "vtkDataSet");
24 return 1;
25 }
26 return 0;
27}
28
29int ttkEigenField::FillOutputPortInformation(int port, vtkInformation *info) {
30 if(port == 0) {
32 return 1;
33 }
34 return 0;
35}
36
37int ttkEigenField::RequestData(vtkInformation *ttkNotUsed(request),
38 vtkInformationVector **inputVector,
39 vtkInformationVector *outputVector) {
40
41 const auto domain = vtkDataSet::GetData(inputVector[0]);
42 auto output = vtkDataSet::GetData(outputVector);
43 auto triangulation = ttkAlgorithm::GetTriangulation(domain);
44
45 if(triangulation == nullptr) {
46 this->printErr("Triangulation is NULL");
47 return 0;
48 }
49
50 this->preconditionTriangulation(*triangulation);
51
52 int res = 0;
53
54 // array of eigenfunctions
55 vtkSmartPointer<vtkDataArray> eigenFunctions{};
56 // statistics
58
59 switch(OutputFieldType) {
60 case FieldType::FLOAT:
61 eigenFunctions = vtkSmartPointer<vtkFloatArray>::New();
63 break;
64 case FieldType::DOUBLE:
65 eigenFunctions = vtkSmartPointer<vtkDoubleArray>::New();
67 break;
68 default:
69 this->printErr("Unknown field type");
70 return 0;
71 }
72
73 if(eigenFunctions == nullptr) {
74 this->printErr("vtkDataArray allocation problem");
75 return 0;
76 }
77
78 const auto vertexNumber = triangulation->getNumberOfVertices();
79
80 eigenFunctions->SetNumberOfComponents(EigenNumber);
81 eigenFunctions->SetNumberOfTuples(vertexNumber);
82 eigenFunctions->SetName(OutputFieldName.data());
83
84 if(ComputeStatistics) {
85 stats->SetName("Statistics");
86 const int statsComp = 4;
87 stats->SetNumberOfComponents(statsComp);
88 stats->SetNumberOfTuples(vertexNumber);
89 stats->SetComponentName(0, "Min");
90 stats->SetComponentName(1, "Max");
91 stats->SetComponentName(2, "Sum");
92 stats->SetComponentName(3, "EigenMagnitude");
93 }
94
95 switch(OutputFieldType) {
96 case FieldType::FLOAT:
97 res += this->execute<float>(
98 *triangulation,
99 static_cast<float *>(ttkUtils::GetVoidPointer(eigenFunctions)),
100 EigenNumber, ComputeStatistics,
101 static_cast<float *>(ttkUtils::GetVoidPointer(stats)));
102 break;
103 case FieldType::DOUBLE:
104 res += this->execute<double>(
105 *triangulation,
106 static_cast<double *>(ttkUtils::GetVoidPointer(eigenFunctions)),
107 EigenNumber, ComputeStatistics,
108 static_cast<double *>(ttkUtils::GetVoidPointer(stats)));
109 break;
110 default:
111 break;
112 }
113
114 if(res != 0) {
115 this->printErr("EigenField execute error code " + std::to_string(res));
116 return 0;
117 }
118
119 // update result
120 output->ShallowCopy(domain);
121 output->GetPointData()->AddArray(eigenFunctions);
122
123 if(ComputeStatistics) {
124 output->GetPointData()->AddArray(stats);
125 }
126
127 return 1;
128}
#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::Triangulation * GetTriangulation(vtkDataSet *dataSet)
TTK VTK-filter for eigenfunctions computation.
int FillOutputPortInformation(int port, vtkInformation *info) override
int FillInputPortInformation(int port, vtkInformation *info) override
int RequestData(vtkInformation *request, vtkInformationVector **inputVector, vtkInformationVector *outputVector) override
static void * GetVoidPointer(vtkDataArray *array, vtkIdType start=0)
Definition ttkUtils.cpp:226
int printErr(const std::string &msg, const debug::LineMode &lineMode=debug::LineMode::NEW, std::ostream &stream=std::cerr) const
Definition Debug.h:149
void preconditionTriangulation(AbstractTriangulation &triangulation) const
Definition EigenField.h:43
vtkStandardNewMacro(ttkEigenField)