TTK
Loading...
Searching...
No Matches
ttkVectorWeightCurve.cpp
Go to the documentation of this file.
2#include <ttkMacros.h>
3#include <ttkUtils.h>
5
6#include <vtkDoubleArray.h>
7#include <vtkUnstructuredGrid.h>
8
10
12 this->SetNumberOfInputPorts(1);
13 this->SetNumberOfOutputPorts(1);
14}
15
17 return this->GetOutput(0);
18}
19
21 return vtkTable::SafeDownCast(this->GetOutputDataObject(port));
22}
23
25 vtkInformation *info) {
26 if(port == 0) {
27 info->Set(vtkAlgorithm::INPUT_REQUIRED_DATA_TYPE(), "vtkDataSet");
28 return 1;
29 }
30 return 0;
31}
32
34 vtkInformation *info) {
35 if(port == 0) {
36 info->Set(vtkDataObject::DATA_TYPE_NAME(), "vtkTable");
37 return 1;
38 }
39 return 0;
40}
41
42static void getVectorWeightCurve(
43 vtkTable *outputCurve,
44 std::vector<ttk::VectorSimplification::PlotPoint> &plotPoints,
45 bool displayCycles,
46 bool displayCancelTypes) {
47
48 if(plotPoints.empty()) {
49 return;
50 }
51
52 vtkNew<vtkDoubleArray> persistenceScalars{};
53 persistenceScalars->SetName("Weight Value");
54 persistenceScalars->SetNumberOfTuples(plotPoints.size());
55
56 vtkNew<ttkSimplexIdTypeArray> numberOfCPScalars{};
57 numberOfCPScalars->SetName("Number of Critical Points");
58 numberOfCPScalars->SetNumberOfTuples(plotPoints.size());
59
60 vtkNew<ttkSimplexIdTypeArray> numberOfSinksScalars{};
61 vtkNew<ttkSimplexIdTypeArray> numberOfSourcesScalars{};
62 if(displayCancelTypes) {
63 numberOfSinksScalars->SetName("Number of Sinks");
64 numberOfSinksScalars->SetNumberOfTuples(plotPoints.size());
65
66 numberOfSourcesScalars->SetName("Number of Sources");
67 numberOfSourcesScalars->SetNumberOfTuples(plotPoints.size());
68 }
69
70 vtkNew<ttkSimplexIdTypeArray> numberOfOrbitsAdded{};
71 vtkNew<ttkSimplexIdTypeArray> numberOfOrbitsRemoved{};
72 if(displayCycles) {
73 numberOfOrbitsAdded->SetName("Number of Orbits Generated");
74 numberOfOrbitsAdded->SetNumberOfTuples(plotPoints.size());
75
76 numberOfOrbitsRemoved->SetName("Number of Orbits Cancelled");
77 numberOfOrbitsRemoved->SetNumberOfTuples(plotPoints.size());
78 }
79
80 for(size_t i = 0; i < plotPoints.size(); ++i) {
81 persistenceScalars->SetTuple1(i, plotPoints[i].weight);
82 numberOfCPScalars->SetTuple1(i, plotPoints[i].numCP);
83 if(displayCancelTypes) {
84 numberOfSinksScalars->SetTuple1(i, plotPoints[i].numSinks);
85 numberOfSourcesScalars->SetTuple1(i, plotPoints[i].numSources);
86 }
87 if(displayCycles) {
88 numberOfOrbitsAdded->SetTuple1(i, plotPoints[i].orbitsAdded);
89 numberOfOrbitsRemoved->SetTuple1(i, plotPoints[i].orbitsRemoved);
90 }
91 }
92
93 vtkNew<vtkTable> vectorWeightCurve{};
94 vectorWeightCurve->AddColumn(persistenceScalars);
95 vectorWeightCurve->AddColumn(numberOfCPScalars);
96 if(displayCancelTypes) {
97 vectorWeightCurve->AddColumn(numberOfSinksScalars);
98 vectorWeightCurve->AddColumn(numberOfSourcesScalars);
99 }
100 if(displayCycles) {
101 vectorWeightCurve->AddColumn(numberOfOrbitsAdded);
102 vectorWeightCurve->AddColumn(numberOfOrbitsRemoved);
103 }
104
105 outputCurve->ShallowCopy(vectorWeightCurve);
106}
107
109 vtkInformationVector **inputVector,
110 vtkInformationVector *outputVector) {
111
112 ttk::Timer timer;
113
114 auto input = vtkDataSet::GetData(inputVector[0]);
115
116 auto triangulation = ttkAlgorithm::GetTriangulation(input);
117
118#ifndef TTK_ENABLE_KAMIKAZE
119 if(!input) {
120 this->printErr("Input pointer is NULL.");
121 return -1;
122 }
123 if(!input->GetNumberOfPoints()) {
124 this->printErr("Input has no point.");
125 return -1;
126 }
127#endif
128
129 this->vs_.preconditionTriangulation(triangulation);
130
131 const auto inputVectors = this->GetInputArrayToProcess(0, input);
132
133 if(inputVectors == nullptr) {
134 this->printErr("Input vector array is NULL");
135 return 0;
136 }
137 if(this->GetInputArrayAssociation(0, inputVector) != 0) {
138 this->printErr("Input array needs to be a point data array.");
139 return 0;
140 }
141 if(inputVectors->GetNumberOfComponents() != 3) {
142 this->printErr("Input array needs to be a vector array(3D).");
143 return 0;
144 }
145
146 auto *allPairsTable = vtkTable::GetData(outputVector, 0);
147
148 int ret{};
149
150 // Generate and simplify the discrete field
152 inputVectors->GetDataType(), triangulation->getType(),
153 (ret = this->vs_.buildField<VTK_TT, TTK_TT>(
154 ttkUtils::GetVoidPointer(inputVectors), inputVectors->GetMTime(),
155 *static_cast<TTK_TT *>(triangulation->getData()))));
156 if(ret != 0) {
157 this->printErr("Could not generate field");
158 return -1;
159 }
160 this->printMsg("Generated the discrete field");
161 std::vector<ttk::VectorSimplification::PlotPoint> vs_pairs;
162 this->UpdateTraceFullOrbits();
163
165 inputVectors->GetDataType(), triangulation->getType(),
166 (ret = this->vs_.performSimplification<VTK_TT, TTK_TT>(
167 0, true, vs_pairs, *static_cast<TTK_TT *>(triangulation->getData()))));
168 if(ret != 0) {
169 this->printErr("Could not simplify field");
170 return -1;
171 }
172 this->printMsg("Simplified the discete field");
173
174 getVectorWeightCurve(
175 allPairsTable, vs_pairs, this->DisplayOrbits, this->DisplayExtrema);
176
177 this->printMsg("Completed", 1, timer.getElapsedTime(), threadNumber_);
179
180 return 1;
181}
#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)
static void * GetVoidPointer(vtkDataArray *array, vtkIdType start=0)
Definition ttkUtils.cpp:226
TTK VTK-filter for the computation of vector field weight curves.
int FillOutputPortInformation(int port, vtkInformation *info) override
int RequestData(vtkInformation *request, vtkInformationVector **inputVector, vtkInformationVector *outputVector) override
int FillInputPortInformation(int port, vtkInformation *info) override
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
VectorSimplification vs_
#define ttkVtkTemplateMacro(dataType, triangulationType, call)
Definition ttkMacros.h:69
vtkStandardNewMacro(ttkVectorWeightCurve)
printMsg(debug::output::BOLD+" | | | | | . \\ | | (__| | / __/| |_| / __/| (_) |"+debug::output::ENDCOLOR, debug::Priority::PERFORMANCE, debug::LineMode::NEW, stream)