TTK
Loading...
Searching...
No Matches
ttkPathCompression.cpp
Go to the documentation of this file.
1#include <ttkMacros.h>
3#include <ttkUtils.h>
4
5#include <vtkCellData.h>
6#include <vtkDataArray.h>
7#include <vtkDataObject.h>
8#include <vtkDataSet.h>
9#include <vtkDoubleArray.h>
10#include <vtkFloatArray.h>
11#include <vtkIdTypeArray.h>
12#include <vtkInformation.h>
13#include <vtkNew.h>
14#include <vtkPointData.h>
15#include <vtkPolyData.h>
16#include <vtkSignedCharArray.h>
17#include <vtkUnsignedCharArray.h>
18
20
22 this->setDebugMsgPrefix("PathCompression");
23 SetNumberOfInputPorts(1);
24 SetNumberOfOutputPorts(1);
25}
26
28 vtkInformation *info) {
29 if(port == 0) {
30 info->Set(vtkAlgorithm::INPUT_REQUIRED_DATA_TYPE(), "vtkDataSet");
31 return 1;
32 }
33 return 0;
34}
35
37 vtkInformation *info) {
38 if(port == 0) {
40 return 1;
41 }
42 return 0;
43}
44
45template <typename triangulationType>
46int ttkPathCompression::dispatch(const SimplexId *const inputOrderArray,
47 const triangulationType &triangulation) {
48
49 const int ret = this->execute<triangulationType>(
50 segmentations_, inputOrderArray, triangulation);
51
52 if(ret != 0)
53 return !this->printErr("PathCompression.execute() error");
54
55 return ret;
56}
57
58int ttkPathCompression::RequestData(vtkInformation *ttkNotUsed(request),
59 vtkInformationVector **inputVector,
60 vtkInformationVector *outputVector) {
61
62 const auto input = vtkDataSet::GetData(inputVector[0]);
63 auto outputMorseComplexes = vtkDataSet::GetData(outputVector, 0);
64
65 if(!input)
66 return !this->printErr("Input pointer is NULL.");
67
68 if(input->GetNumberOfPoints() == 0)
69 return !this->printErr("Input has no point.");
70
71 if(!outputMorseComplexes)
72 return !this->printErr("Output pointers are NULL.");
73
74 const auto triangulation = ttkAlgorithm::GetTriangulation(input);
75
76 if(triangulation == nullptr)
77 return !this->printErr("Triangulation is null");
78
79 this->preconditionTriangulation(triangulation);
80
81 const auto inputScalars = this->GetInputArrayToProcess(0, inputVector);
82
83 if(inputScalars == nullptr)
84 return !this->printErr("No input scalars");
85
86 auto inputOrderArray = ttkAlgorithm::GetOrderArray(
87 input, 0, triangulation, false, 1, this->ForceInputOffsetScalarField);
88
89 if(inputOrderArray == nullptr)
90 return !this->printErr("No order array");
91
92 if(inputOrderArray->GetDataType() != VTK_INT
93 && inputOrderArray->GetDataType() != VTK_ID_TYPE)
94 return !this->printErr("input offset field type not supported.");
95
96 this->printMsg("Launching computation on field `"
97 + std::string(inputScalars->GetName()) + "'...");
98
99 const SimplexId numberOfVertices = triangulation->getNumberOfVertices();
100
101 if(!numberOfVertices)
102 return !this->printErr("Input has no vertices.");
103
104 vtkNew<ttkSimplexIdTypeArray> ascendingSegmentation{};
105 vtkNew<ttkSimplexIdTypeArray> descendingSegmentation{};
106 vtkNew<ttkSimplexIdTypeArray> morseSmaleSegmentation{};
107
108 if(!ascendingSegmentation || !descendingSegmentation
109 || !morseSmaleSegmentation)
110 return !this->printErr("Segmentation vtkDataArray allocation problem.");
111
112 ascendingSegmentation->SetNumberOfComponents(1);
113 ascendingSegmentation->SetNumberOfTuples(numberOfVertices);
114 ascendingSegmentation->SetName((std::string(inputScalars->GetName()) + "_"
115 + std::string(ttk::MorseSmaleAscendingName))
116 .data());
117
118 descendingSegmentation->SetNumberOfComponents(1);
119 descendingSegmentation->SetNumberOfTuples(numberOfVertices);
120 descendingSegmentation->SetName((std::string(inputScalars->GetName()) + "_"
121 + std::string(ttk::MorseSmaleDescendingName))
122 .data());
123
124 morseSmaleSegmentation->SetNumberOfComponents(1);
125 morseSmaleSegmentation->SetNumberOfTuples(numberOfVertices);
126 morseSmaleSegmentation->SetName((std::string(inputScalars->GetName()) + "_"
127 + std::string(ttk::MorseSmaleManifoldName))
128 .data());
129
130 this->segmentations_
131 = {ttkUtils::GetPointer<SimplexId>(ascendingSegmentation),
132 ttkUtils::GetPointer<SimplexId>(descendingSegmentation),
133 ttkUtils::GetPointer<SimplexId>(morseSmaleSegmentation)};
134
135 int ret{};
136
138 triangulation->getType(),
139 (ret = dispatch<TTK_TT>(ttkUtils::GetPointer<SimplexId>(inputOrderArray),
140 *static_cast<TTK_TT *>(triangulation->getData()))));
141
142 if(ret != 0)
143 return -1;
144
145 outputMorseComplexes->ShallowCopy(input);
146
149 vtkPointData *pointData = outputMorseComplexes->GetPointData();
150
151 if(!pointData)
152 return !this->printErr("outputMorseComplexes has no point data.");
153
155 pointData->AddArray(descendingSegmentation);
157 pointData->AddArray(ascendingSegmentation);
159 pointData->AddArray(morseSmaleSegmentation);
160 }
161
162 return 1;
163}
#define ttkTemplateMacro(triangulationType, call)
#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)
vtkDataArray * GetOrderArray(vtkDataSet *const inputData, const int scalarArrayIdx, ttk::Triangulation *triangulation, const bool getGlobalOrder=false, const int orderArrayIdx=0, const bool enforceOrderArrayIdx=false)
TTK VTK-filter that wraps the ttk::PathCompression module.
int FillOutputPortInformation(int port, vtkInformation *info) override
int RequestData(vtkInformation *request, vtkInformationVector **inputVector, vtkInformationVector *outputVector) override
int dispatch(const SimplexId *const inputOffsets, const triangulationType &triangulation)
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
void preconditionTriangulation(AbstractTriangulation *const data)
const char MorseSmaleManifoldName[]
Definition DataTypes.h:64
const char MorseSmaleAscendingName[]
Definition DataTypes.h:62
const char MorseSmaleDescendingName[]
Definition DataTypes.h:63
vtkStandardNewMacro(ttkPathCompression)
printMsg(debug::output::BOLD+" | | | | | . \\ | | (__| | / __/| |_| / __/|__ _|"+debug::output::ENDCOLOR, debug::Priority::PERFORMANCE, debug::LineMode::NEW, stream)