TTK
Loading...
Searching...
No Matches
ttkMarchingTetrahedra.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#include <vtkUnsignedLongLongArray.h>
19
20namespace {
21 template <typename vtkArrayType, typename vectorType>
22 void setArray(vtkArrayType &vtkArray, vectorType &vector) {
23 ttkUtils::SetVoidArray(vtkArray, vector.data(), vector.size(), 1);
24 }
25} // namespace
26
28
30 this->setDebugMsgPrefix("MarchingTetrahedra");
31 this->SetNumberOfInputPorts(1);
32 this->SetNumberOfOutputPorts(1);
33}
34
36 vtkInformation *info) {
37 if(port == 0) {
38 info->Set(vtkAlgorithm::INPUT_REQUIRED_DATA_TYPE(), "vtkDataSet");
39 return 1;
40 }
41 return 0;
42}
43
45 vtkInformation *info) {
46 if(port == 0) {
47 info->Set(vtkDataObject::DATA_TYPE_NAME(), "vtkPolyData");
48 return 1;
49 }
50 return 0;
51}
52
53template <typename scalarType, typename triangulationType>
54int ttkMarchingTetrahedra::dispatch(vtkDataArray *const inputScalars,
55 vtkPolyData *const outputSeparators,
56 const triangulationType &triangulation) {
57
58 const auto scalars = ttkUtils::GetPointer<scalarType>(inputScalars);
59 const int dim = triangulation.getDimensionality();
60
61 output_points_.clear();
64
65 const int status
66 = this->execute<scalarType, triangulationType>(scalars, triangulation);
67
68 if(status != 0)
69 return !this->printErr("MarchingTetrahedra.execute() error");
70
71 vtkNew<vtkFloatArray> pointsCoords{};
72 pointsCoords->SetNumberOfComponents(3);
73 setArray(pointsCoords, output_points_);
74
75 vtkNew<ttkSimplexIdTypeArray> offsets{}, connectivity{};
76 offsets->SetNumberOfComponents(1);
77 offsets->SetNumberOfTuples(output_numberOfCells_ + 1);
78 connectivity->SetNumberOfComponents(1);
80
81 vtkNew<vtkUnsignedLongLongArray> hashArr{};
82 hashArr->SetNumberOfComponents(1);
83 hashArr->SetName("Hash");
85
86 if(dim == 2 || dim == 3) {
87#ifdef TTK_ENABLE_OPENMP
88#pragma omp parallel for num_threads(this->threadNumber_)
89#endif // TTK_ENABLE_OPENMP
90 for(SimplexId i = 0; i < output_numberOfCells_ + 1; ++i) {
91 offsets->SetTuple1(i, dim * i);
92 }
93 }
94
95 vtkNew<vtkPoints> points{};
96 points->SetData(pointsCoords);
97 outputSeparators->SetPoints(points);
98
99 vtkNew<vtkCellArray> cells{};
100#ifndef TTK_ENABLE_64BIT_IDS
101 cells->Use32BitStorage();
102#endif // TTK_ENABLE_64BIT_IDS
103 cells->SetData(offsets, connectivity);
104 if(dim == 3) {
105 outputSeparators->SetPolys(cells);
106 } else {
107 outputSeparators->SetLines(cells);
108 }
109
110 auto cellData = outputSeparators->GetCellData();
111 cellData->AddArray(hashArr);
112
113 return 1;
114}
115
117 vtkInformationVector **inputVector,
118 vtkInformationVector *outputVector) {
119
120 const auto input = vtkDataSet::GetData(inputVector[0]);
121 auto outputSeparators = vtkPolyData::GetData(outputVector, 0);
122
123 if(!input)
124 return !this->printErr("Input pointer is NULL.");
125
126 if(input->GetNumberOfPoints() == 0)
127 return !this->printErr("Input has no point.");
128
129 if(!outputSeparators)
130 return !this->printErr("Output pointers are NULL.");
131
132 const auto triangulation = ttkAlgorithm::GetTriangulation(input);
133
134 if(triangulation == nullptr)
135 return !this->printErr("Triangulation is null");
136
137 const auto inputScalars = this->GetInputArrayToProcess(0, inputVector);
138
139 if(inputScalars == nullptr)
140 return !this->printErr("wrong scalars.");
141
142 this->printMsg("Launching computation on field `"
143 + std::string(inputScalars->GetName()) + "'...");
144
145 const SimplexId numberOfVertices = triangulation->getNumberOfVertices();
146
147 if(!numberOfVertices)
148 return !this->printErr("Input has no vertices.");
149
150 int status{};
151
152 ttkVtkTemplateMacro(inputScalars->GetDataType(), triangulation->getType(),
153 (status = dispatch<VTK_TT, TTK_TT>(
154 inputScalars, outputSeparators,
155 *static_cast<TTK_TT *>(triangulation->getData()))));
156
157 return status;
158}
#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 that wraps the ttk::MarchingTetrahedra module.
int RequestData(vtkInformation *request, vtkInformationVector **inputVector, vtkInformationVector *outputVector) override
int FillOutputPortInformation(int port, vtkInformation *info) override
int FillInputPortInformation(int port, vtkInformation *info) override
int dispatch(vtkDataArray *const inputScalars, vtkPolyData *const outputSeparators, const triangulationType &triangulation)
static void SetVoidArray(vtkDataArray *array, void *data, vtkIdType size, int save)
Definition ttkUtils.cpp:280
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
std::vector< float > output_points_
std::vector< unsigned long long > output_cells_labels_
std::vector< SimplexId > output_cells_connectivity_
#define ttkVtkTemplateMacro(dataType, triangulationType, call)
Definition ttkMacros.h:69
vtkStandardNewMacro(ttkMarchingTetrahedra)
void setArray(vtkArrayType &vtkArray, vectorType &vector)
printMsg(debug::output::BOLD+" | | | | | . \\ | | (__| | / __/| |_| / __/|__ _|"+debug::output::ENDCOLOR, debug::Priority::PERFORMANCE, debug::LineMode::NEW, stream)