TTK
Loading...
Searching...
No Matches
ttkProjectionFromField.cpp
Go to the documentation of this file.
3
4#include <vtkFloatArray.h>
5#include <vtkInformation.h>
6#include <vtkNew.h>
7#include <vtkPointData.h>
8#include <vtkUnstructuredGrid.h>
9
10#include <array>
11
13
15 this->SetNumberOfInputPorts(1);
16 this->SetNumberOfOutputPorts(1);
17
18 this->setDebugMsgPrefix("ProjectionFromField");
19}
20
22 vtkInformation *info) {
23 if(port == 0) {
24 info->Set(vtkAlgorithm::INPUT_REQUIRED_DATA_TYPE(), "vtkPointSet");
25 return 1;
26 }
27 return 0;
28}
29
31 vtkInformation *info) {
32 if(port == 0) {
34 return 1;
35 }
36 return 0;
37}
38
40 vtkUnstructuredGrid *const inputDiagram,
41 vtkUnstructuredGrid *const outputDiagram) {
42
43 auto pointData = inputDiagram->GetPointData();
44
45 // ensure we have the right arrays
46 const auto critCoordinates = vtkFloatArray::SafeDownCast(
47 pointData->GetAbstractArray(ttk::PersistenceCoordinatesName));
48 bool const embed = critCoordinates == nullptr;
49 int ret{0};
50
51 if(embed) {
52 ret = ProjectDiagramIn2D(inputDiagram, outputDiagram, *this);
53 } else {
54 if(critCoordinates == nullptr) {
55 this->printErr("Missing `Coordinates' vtkPointData array");
56 return 0;
57 }
58 if(critCoordinates->GetNumberOfComponents() != 3) {
59 this->printErr("`Coordinates' array should have 3 components");
60 return 0;
61 }
62 ret = ProjectDiagramInsideDomain(inputDiagram, outputDiagram, *this);
63 }
64
65 return ret == 0 ? 1 : 0;
66}
67
69 vtkInformationVector **inputVector,
70 vtkInformationVector *outputVector) {
71
72 ttk::Timer t;
73
74 vtkPointSet *input = vtkPointSet::GetData(inputVector[0]);
75 vtkPointSet *output = vtkPointSet::GetData(outputVector, 0);
76
77 if(this->ProjectPersistenceDiagram) {
78 auto inputGrid = vtkUnstructuredGrid::SafeDownCast(input);
79 auto outputGrid = vtkUnstructuredGrid::SafeDownCast(output);
80 if(inputGrid != nullptr && outputGrid != nullptr) {
81 return projectPersistenceDiagram(inputGrid, outputGrid);
82 }
83 this->printErr("Input should be a vtkUnstructuredGrid");
84 return 0;
85 }
86
87 output->ShallowCopy(input);
88
89 vtkNew<vtkPoints> pointSet{};
90 pointSet->SetNumberOfPoints(input->GetNumberOfPoints());
91
92 if(UseTextureCoordinates) {
93
94 const auto textureCoordinates = input->GetPointData()->GetTCoords();
95 if(textureCoordinates == nullptr) {
96 return 0;
97 }
98 printMsg("Starting computation with texture coordinates...");
99
100#ifdef TTK_ENABLE_OPENMP
101#pragma omp parallel for num_threads(threadNumber_)
102#endif
103 for(int i = 0; i < input->GetNumberOfPoints(); i++) {
104 std::array<double, 3> pt{};
105 textureCoordinates->GetTuple(i, pt.data());
106 pointSet->SetPoint(i, pt[0], pt[1], pt[2]);
107 }
108
109 } else if(this->Use3DCoordinatesArray) {
110
111 const auto inputCoordsArray = this->GetInputArrayToProcess(2, inputVector);
112 if(inputCoordsArray == nullptr) {
113 return 0;
114 }
115 printMsg("Starting computation...");
116 printMsg(std::vector<std::vector<std::string>>{
117 {" Coordinates Array", inputCoordsArray->GetName()}});
118
119#ifdef TTK_ENABLE_OPENMP
120#pragma omp parallel for num_threads(threadNumber_)
121#endif
122 for(int i = 0; i < input->GetNumberOfPoints(); i++) {
123 std::array<double, 3> pt{};
124 inputCoordsArray->GetTuple(i, pt.data());
125 pointSet->SetPoint(i, pt[0], pt[1], pt[2]);
126 }
127
128 } else {
129
130 const auto inputScalarFieldU = this->GetInputArrayToProcess(0, inputVector);
131 const auto inputScalarFieldV = this->GetInputArrayToProcess(1, inputVector);
132
133 if(inputScalarFieldU == nullptr || inputScalarFieldV == nullptr) {
134 return 0;
135 }
136
137 printMsg("Starting computation...");
138 printMsg({{" U-component", inputScalarFieldU->GetName()},
139 {" V-component", inputScalarFieldV->GetName()}});
140
141#ifdef TTK_ENABLE_OPENMP
142#pragma omp parallel for num_threads(threadNumber_)
143#endif
144 for(int i = 0; i < input->GetNumberOfPoints(); i++) {
145 pointSet->SetPoint(i, inputScalarFieldU->GetComponent(i, 0),
146 inputScalarFieldV->GetComponent(i, 0), 0);
147 }
148 }
149
150 output->SetPoints(pointSet);
151
152 printMsg(std::to_string(input->GetNumberOfPoints()) + " points projected", 1,
154
156
157 return 1;
158}
#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 which projects a data-set to 2D given two point-data scalar fields to be used as 2D co...
int projectPersistenceDiagram(vtkUnstructuredGrid *const inputDiagram, vtkUnstructuredGrid *const outputDiagram)
Switch a given Persistence Diagram representation.
int FillOutputPortInformation(int port, vtkInformation *info) override
int FillInputPortInformation(int port, vtkInformation *info) override
int RequestData(vtkInformation *request, vtkInformationVector **inputVector, vtkInformationVector *outputVector) 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
double getElapsedTime()
Definition Timer.h:15
const char PersistenceCoordinatesName[]
Definition DataTypes.h:70
int ProjectDiagramInsideDomain(vtkUnstructuredGrid *const inputDiagram, vtkUnstructuredGrid *const outputDiagram, const ttk::Debug &dbg)
Generate the spatial embedding of a given Persistence Diagram.
int ProjectDiagramIn2D(vtkUnstructuredGrid *const inputDiagram, vtkUnstructuredGrid *const outputDiagram, const ttk::Debug &dbg)
Generate the 2D embedding of a given Persistence Diagram.
vtkStandardNewMacro(ttkProjectionFromField)
printMsg(debug::output::BOLD+" | | | | | . \\ | | (__| | / __/| |_| / __/|__ _|"+debug::output::ENDCOLOR, debug::Priority::PERFORMANCE, debug::LineMode::NEW, stream)