TTK
Loading...
Searching...
No Matches
ttkMorseSmaleQuadrangulation.cpp
Go to the documentation of this file.
1#include <ttkMacros.h>
3#include <ttkUtils.h>
4
5#include <vtkIdTypeArray.h>
6#include <vtkInformation.h>
7#include <vtkPointData.h>
8#include <vtkPolyData.h>
9
11
13 // critical points + 1-separatrices + segmentation
14 SetNumberOfInputPorts(3);
15 // quad mesh (containing ttkVertexIdentifiers of critical points)
16 SetNumberOfOutputPorts(1);
17}
18
20 int port, vtkInformation *info) {
21 if(port == 0) { // critical points
22 info->Set(vtkAlgorithm::INPUT_REQUIRED_DATA_TYPE(), "vtkPointSet");
23 return 1;
24 } else if(port == 1) { // MSC separatrices
25 info->Set(vtkAlgorithm::INPUT_REQUIRED_DATA_TYPE(), "vtkPolyData");
26 return 1;
27 } else if(port == 2) { // triangulated domain
28 info->Set(vtkAlgorithm::INPUT_REQUIRED_DATA_TYPE(), "vtkDataSet");
29 return 1;
30 }
31 return 0;
32}
33
35 int port, vtkInformation *info) {
36 if(port == 0) {
37 info->Set(vtkDataObject::DATA_TYPE_NAME(), "vtkPolyData");
38 return 1;
39 }
40 return 0;
41}
42
44 vtkInformation *ttkNotUsed(request),
45 vtkInformationVector **inputVector,
46 vtkInformationVector *outputVector) {
47
48 auto critpoints = vtkPointSet::GetData(inputVector[0]);
49 auto seprs = vtkPolyData::GetData(inputVector[1]);
50 auto domain = vtkDataSet::GetData(inputVector[2]);
51 auto output = vtkPolyData::GetData(outputVector);
52
53 auto triangulation = ttkAlgorithm::GetTriangulation(domain);
54 if(triangulation == nullptr) {
55 return 0;
56 }
57 this->preconditionTriangulation(triangulation);
58
59 auto cpPoints = critpoints->GetPoints();
60 auto cpData = critpoints->GetPointData();
61 auto seprsPoints = seprs->GetPoints();
62 auto seprsData = seprs->GetPointData();
63
64 if(seprsPoints == nullptr || seprsData == nullptr || cpPoints == nullptr
65 || cpData == nullptr) {
66 this->printErr("Invalid input");
67 return 0;
68 }
69
70 auto cpci = cpData->GetArray("CellId");
71 auto cpcd = cpData->GetArray("CellDimension");
72 auto cpid = cpData->GetArray(ttk::VertexScalarFieldName);
73 auto sepid = seprsData->GetArray("CellId");
74 auto sepdim = seprsData->GetArray("CellDimension");
75 auto sepmask = seprsData->GetArray(ttk::MaskScalarFieldName);
76
77 if(cpci == nullptr || cpcd == nullptr || cpid == nullptr || sepid == nullptr
78 || sepdim == nullptr || sepmask == nullptr) {
79 this->printErr("Missing data arrays");
80 return 0;
81 }
82
84 cpPoints->GetNumberOfPoints(), ttkUtils::GetVoidPointer(cpPoints),
87
88 this->setSeparatrices(
89 sepid->GetNumberOfTuples(), ttkUtils::GetVoidPointer(sepid),
91 ttkUtils::GetVoidPointer(seprsPoints));
92
93 int res{-1};
95 triangulation->getType(),
96 res = this->execute(*static_cast<TTK_TT *>(triangulation->getData())););
97
98 if(res != 0) {
99 this->printWrn("Consider another (eigen) function, persistence threshold "
100 "or refine your input triangulation");
101 if(!ShowResError) {
102 return 0;
103 }
104 }
105
106 // output points: critical points + generated separatrices middles
107 vtkNew<vtkPoints> outQuadPoints{};
108 for(size_t i = 0; i < outputPoints_.size() / 3; i++) {
109 outQuadPoints->InsertNextPoint(&outputPoints_[3 * i]);
110 }
111 output->SetPoints(outQuadPoints);
112
113 // quad vertices identifiers
114 vtkNew<ttkSimplexIdTypeArray> identifiers{};
115 identifiers->SetName(ttk::VertexScalarFieldName);
117 identifiers, outputPointsIds_.data(), outputPointsIds_.size(), 1);
118 output->GetPointData()->AddArray(identifiers);
119
120 // quad vertices type
121 vtkNew<ttkSimplexIdTypeArray> type{};
122 type->SetName("QuadVertType");
124 type, outputPointsTypes_.data(), outputPointsTypes_.size(), 1);
125 output->GetPointData()->AddArray(type);
126
127 // quad vertices cells
128 vtkNew<ttkSimplexIdTypeArray> cellid{};
129 cellid->SetName("QuadCellId");
131 cellid, outputPointsCells_.data(), outputPointsCells_.size(), 1);
132 output->GetPointData()->AddArray(cellid);
133
134 // vtkCellArray of quadrangle values containing outArray
135 vtkNew<vtkCellArray> cells{};
136 for(size_t i = 0; i < outputCells_.size(); i++) {
137 cells->InsertNextCell(4, outputCells_[i].data());
138 }
139
140 // update output: get quadrangle values
141 output->SetPolys(cells);
142
143 // shallow copy input field data
144 output->GetFieldData()->ShallowCopy(domain->GetFieldData());
145
146 return 1;
147}
#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
ttk::Triangulation * GetTriangulation(vtkDataSet *dataSet)
TTK VTK-filter for surface quadrangulation.
int FillInputPortInformation(int port, vtkInformation *info) override
int FillOutputPortInformation(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
static void SetVoidArray(vtkDataArray *array, void *data, vtkIdType size, int save)
Definition ttkUtils.cpp:280
int printWrn(const std::string &msg, const debug::LineMode &lineMode=debug::LineMode::NEW, std::ostream &stream=std::cerr) const
Definition Debug.h:159
int printErr(const std::string &msg, const debug::LineMode &lineMode=debug::LineMode::NEW, std::ostream &stream=std::cerr) const
Definition Debug.h:149
std::vector< SimplexId > outputPointsCells_
std::vector< SimplexId > outputPointsTypes_
void setSeparatrices(const unsigned int number, void *const cellIds, void *const cellDims, void *const mask, void *const points)
void preconditionTriangulation(AbstractTriangulation *const triangl)
void setCriticalPoints(const unsigned int number, void *const points, void *const ids, void *const cellIds, void *const type)
const char VertexScalarFieldName[]
default name for vertex scalar field
Definition DataTypes.h:35
const char MaskScalarFieldName[]
default name for mask scalar field
Definition DataTypes.h:32
vtkStandardNewMacro(ttkMorseSmaleQuadrangulation)