TTK
Loading...
Searching...
No Matches
ttkHarmonicField.cpp
Go to the documentation of this file.
1#include <ttkHarmonicField.h>
2#include <ttkMacros.h>
3#include <ttkUtils.h>
4
5// VTK includes
6#include <vtkDoubleArray.h>
7#include <vtkFloatArray.h>
8#include <vtkInformation.h>
9#include <vtkPointData.h>
10#include <vtkPointSet.h>
11#include <vtkSmartPointer.h>
12
14
16 SetNumberOfInputPorts(2);
17 SetNumberOfOutputPorts(1);
18}
19
20int ttkHarmonicField::FillInputPortInformation(int port, vtkInformation *info) {
21 if(port == 0) {
22 info->Set(vtkAlgorithm::INPUT_REQUIRED_DATA_TYPE(), "vtkDataSet");
23 return 1;
24 } else if(port == 1) {
25 info->Set(vtkAlgorithm::INPUT_REQUIRED_DATA_TYPE(), "vtkPointSet");
26 return 1;
27 }
28 return 0;
29}
30
32 vtkInformation *info) {
33 if(port == 0) {
35 return 1;
36 }
37 return 0;
38}
39
40int ttkHarmonicField::RequestData(vtkInformation *ttkNotUsed(request),
41 vtkInformationVector **inputVector,
42 vtkInformationVector *outputVector) {
43
44 const auto domain = vtkDataSet::GetData(inputVector[0]);
45 const auto identifiers = vtkPointSet::GetData(inputVector[1]);
46 auto output = vtkDataSet::GetData(outputVector);
47 auto triangulation = ttkAlgorithm::GetTriangulation(domain);
48
49 if(triangulation == nullptr) {
50 this->printErr("No triangulation");
51 return 0;
52 }
53 this->preconditionTriangulation(*triangulation);
54
55 vtkDataArray *inputField = this->GetInputArrayToProcess(0, identifiers);
56 std::vector<ttk::SimplexId> idSpareStorage{};
57 const auto *vertsid = this->GetIdentifierArrayPtr(
58 ForceConstraintIdentifiers, 1, ttk::VertexScalarFieldName, identifiers,
59 idSpareStorage);
60
61 if(vertsid == nullptr || inputField == nullptr) {
62 this->printErr("Input fields are NULL");
63 return 0;
64 }
65
66 if(inputField->IsA("vtkDoubleArray")) {
67 OutputScalarFieldType = FieldType::DOUBLE;
68 } else if(inputField->IsA("vtkFloatArray")) {
69 OutputScalarFieldType = FieldType::FLOAT;
70 } else {
71 this->printErr("Filter only supports floating point scalar fields");
72 this->printErr(
73 "Please select a floating point input scalar field or convert an "
74 "existing one with TTKPointDataConverter or TTKArrayEditor");
75 return -2;
76 }
77
78 const auto nVerts = domain->GetNumberOfPoints();
79 const auto nSources = identifiers->GetNumberOfPoints();
80
82
83 switch(OutputScalarFieldType) {
84 case FieldType::FLOAT:
86 break;
87 case FieldType::DOUBLE:
89 break;
90 default:
91 this->printErr("Unknown scalar field type");
92 return -7;
93 break;
94 }
95
96 if(outputField == nullptr) {
97 this->printErr("vtkArray allocation problem");
98 return 0;
99 }
100
101 outputField->SetNumberOfComponents(1);
102 outputField->SetNumberOfTuples(nVerts);
103 outputField->SetName(OutputScalarFieldName.data());
104 int res{};
105
106 switch(OutputScalarFieldType) {
107 case FieldType::FLOAT:
108 res = this->execute<float>(
109 *triangulation, nSources, vertsid,
110 static_cast<float *>(ttkUtils::GetVoidPointer(inputField)),
111 static_cast<float *>(ttkUtils::GetVoidPointer(outputField)),
112 UseCotanWeights, SolvingMethod, LogAlpha);
113 break;
114 case FieldType::DOUBLE:
115 res = this->execute<double>(
116 *triangulation, nSources, vertsid,
117 static_cast<double *>(ttkUtils::GetVoidPointer(inputField)),
118 static_cast<double *>(ttkUtils::GetVoidPointer(outputField)),
119 UseCotanWeights, SolvingMethod, LogAlpha);
120 break;
121 default:
122 break;
123 }
124
125 if(res != 0) {
126 this->printErr("HarmonicField execute() error code: "
127 + std::to_string(res));
128 return 0;
129 }
130
131 // update result
132 output->ShallowCopy(domain);
133 output->GetPointData()->AddArray(outputField);
134
135 return 1;
136}
#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::SimplexId * GetIdentifierArrayPtr(const bool &enforceArrayIndex, const int &arrayIndex, const std::string &arrayName, vtkDataSet *const inputData, std::vector< ttk::SimplexId > &spareStorage, const int inputPort=0, const bool printErr=true)
ttk::Triangulation * GetTriangulation(vtkDataSet *dataSet)
TTK VTK-filter for harmonic field computations.
int FillInputPortInformation(int port, vtkInformation *info) override
int RequestData(vtkInformation *request, vtkInformationVector **inputVector, vtkInformationVector *outputVector) override
int FillOutputPortInformation(int port, vtkInformation *info) override
static void * GetVoidPointer(vtkDataArray *array, vtkIdType start=0)
Definition: ttkUtils.cpp:225
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 &triangulation) const
Definition: HarmonicField.h:38
const char VertexScalarFieldName[]
default name for vertex scalar field
Definition: DataTypes.h:35
vtkStandardNewMacro(ttkHarmonicField)