5#include <vtkCellData.h>
6#include <vtkDataArray.h>
7#include <vtkDataObject.h>
9#include <vtkDoubleArray.h>
10#include <vtkFloatArray.h>
11#include <vtkIdTypeArray.h>
12#include <vtkInformation.h>
14#include <vtkPointData.h>
15#include <vtkPolyData.h>
16#include <vtkSignedCharArray.h>
17#include <vtkUnsignedCharArray.h>
21ttkPathCompression::ttkPathCompression() {
22 this->setDebugMsgPrefix(
"PathCompression");
23 SetNumberOfInputPorts(1);
24 SetNumberOfOutputPorts(1);
27int ttkPathCompression::FillInputPortInformation(
int port,
28 vtkInformation *info) {
30 info->Set(vtkAlgorithm::INPUT_REQUIRED_DATA_TYPE(),
"vtkDataSet");
36int ttkPathCompression::FillOutputPortInformation(
int port,
37 vtkInformation *info) {
45template <
typename triangulationType>
46int ttkPathCompression::dispatch(
const SimplexId *
const inputOrderArray,
47 const triangulationType &triangulation) {
49 const int ret = this->execute<triangulationType>(
50 segmentations_, inputOrderArray, triangulation);
53 return !this->printErr(
"PathCompression.execute() error");
58int ttkPathCompression::RequestData(vtkInformation *
ttkNotUsed(request),
59 vtkInformationVector **inputVector,
60 vtkInformationVector *outputVector) {
62 const auto input = vtkDataSet::GetData(inputVector[0]);
63 auto outputMorseComplexes = vtkDataSet::GetData(outputVector, 0);
66 return !this->printErr(
"Input pointer is NULL.");
68 if(input->GetNumberOfPoints() == 0)
69 return !this->printErr(
"Input has no point.");
71 if(!outputMorseComplexes)
72 return !this->printErr(
"Output pointers are NULL.");
76 if(triangulation ==
nullptr)
77 return !this->printErr(
"Triangulation is null");
81 const auto inputScalars = this->GetInputArrayToProcess(0, inputVector);
83 if(inputScalars ==
nullptr)
84 return !this->printErr(
"No input scalars");
87 input, 0, triangulation,
false, 1, this->ForceInputOffsetScalarField);
89 if(inputOrderArray ==
nullptr)
90 return !this->printErr(
"No order array");
92 if(inputOrderArray->GetDataType() != VTK_INT
93 && inputOrderArray->GetDataType() != VTK_ID_TYPE)
94 return !this->printErr(
"input offset field type not supported.");
96 this->
printMsg(
"Launching computation on field `"
97 + std::string(inputScalars->GetName()) +
"'...");
99 const SimplexId numberOfVertices = triangulation->getNumberOfVertices();
101 if(!numberOfVertices)
102 return !this->printErr(
"Input has no vertices.");
104 vtkNew<ttkSimplexIdTypeArray> ascendingSegmentation{};
105 vtkNew<ttkSimplexIdTypeArray> descendingSegmentation{};
106 vtkNew<ttkSimplexIdTypeArray> morseSmaleSegmentation{};
108 if(!ascendingSegmentation || !descendingSegmentation
109 || !morseSmaleSegmentation)
110 return !this->printErr(
"Segmentation vtkDataArray allocation problem.");
112 ascendingSegmentation->SetNumberOfComponents(1);
113 ascendingSegmentation->SetNumberOfTuples(numberOfVertices);
114 ascendingSegmentation->SetName((std::string(inputScalars->GetName()) +
"_"
118 descendingSegmentation->SetNumberOfComponents(1);
119 descendingSegmentation->SetNumberOfTuples(numberOfVertices);
120 descendingSegmentation->SetName((std::string(inputScalars->GetName()) +
"_"
124 morseSmaleSegmentation->SetNumberOfComponents(1);
125 morseSmaleSegmentation->SetNumberOfTuples(numberOfVertices);
126 morseSmaleSegmentation->SetName((std::string(inputScalars->GetName()) +
"_"
138 triangulation->getType(),
140 *
static_cast<TTK_TT *
>(triangulation->getData()))));
145 outputMorseComplexes->ShallowCopy(input);
147 if(ComputeAscendingSegmentation || ComputeDescendingSegmentation
148 || ComputeMSSegmentationHash) {
149 vtkPointData *pointData = outputMorseComplexes->GetPointData();
152 return !this->printErr(
"outputMorseComplexes has no point data.");
154 if(ComputeDescendingSegmentation || ComputeMSSegmentationHash)
155 pointData->AddArray(descendingSegmentation);
156 if(ComputeAscendingSegmentation || ComputeMSSegmentationHash)
157 pointData->AddArray(ascendingSegmentation);
158 if(ComputeMSSegmentationHash)
159 pointData->AddArray(morseSmaleSegmentation);
#define ttkTemplateMacro(triangulationType, call)
#define ttkNotUsed(x)
Mark function/method parameters that are not used in the function body at all.
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)
static DT * GetPointer(vtkDataArray *array, vtkIdType start=0)
void preconditionTriangulation(AbstractTriangulation &triangulation)
Triangulation precondition function.
const char MorseSmaleManifoldName[]
int SimplexId
Identifier type for simplices of any dimension.
const char MorseSmaleAscendingName[]
const char MorseSmaleDescendingName[]
vtkStandardNewMacro(ttkPathCompression)
printMsg(debug::output::BOLD+" | | | | | . \\ | | (__| | / __/| |_| / __/| (_) |"+debug::output::ENDCOLOR, debug::Priority::PERFORMANCE, debug::LineMode::NEW, stream)