TTK
Loading...
Searching...
No Matches
ttkIcospheresFromPoints.cpp
Go to the documentation of this file.
2
3#include <vtkInformation.h>
4#include <vtkObjectFactory.h>
5
6#include <vtkPointData.h>
7#include <vtkPointSet.h>
8
9#include <ttkUtils.h>
10
12
14 this->setDebugMsgPrefix("IcospheresFromPoints");
15 this->SetNumberOfInputPorts(1);
16}
18
20 vtkInformation *info) {
21 if(port == 0)
22 info->Set(vtkAlgorithm::INPUT_REQUIRED_DATA_TYPE(), "vtkPointSet");
23 else
24 return 0;
25 return 1;
26}
27
28template <typename VTK_TT>
29int copyArrayData(vtkDataArray *oldArray,
30 vtkDataArray *newArray,
31 const size_t &nSpheres,
32 const size_t &nVerticesPerSphere,
33 const size_t &nComponents) {
34 auto oldData = ttkUtils::GetPointer<VTK_TT>(oldArray);
35 auto newData = ttkUtils::GetPointer<VTK_TT>(newArray);
36
37 for(size_t i = 0; i < nSpheres; i++) {
38 size_t sphereIndex = i * nVerticesPerSphere * nComponents;
39 for(size_t j = 0; j < nComponents; j++) {
40 const auto &value = oldData[i * nComponents + j];
41 size_t newIndex = sphereIndex + j;
42 for(size_t k = 0; k < nVerticesPerSphere; k++) {
43 newData[newIndex] = value;
44 newIndex += nComponents;
45 }
46 }
47 }
48 return 1;
49}
50
51int ttkIcospheresFromPoints::RequestData(vtkInformation *request,
52 vtkInformationVector **inputVector,
53 vtkInformationVector *outputVector) {
54 auto input = vtkPointSet::GetData(inputVector[0], 0);
55 if(!input)
56 return 1;
57 size_t nPoints = input->GetNumberOfPoints();
58 if(nPoints < 1)
59 return 1;
60
61 this->SetCenters(input->GetPoints()->GetData());
62
63 // compute spheres
64 int status
65 = this->ttkIcosphere::RequestData(request, inputVector, outputVector);
66 if(!status)
67 return 0;
68
69 size_t nVertices = 0;
70 size_t nTriangles = 0;
72 nVertices, nTriangles, this->GetNumberOfSubdivisions());
73
74 auto output = vtkDataSet::GetData(outputVector);
75 auto outputPD = output->GetPointData();
76
77 // copy point data
78 if(this->CopyPointData) {
79
80 auto inputPD = input->GetPointData();
81 for(size_t i = 0, n = inputPD->GetNumberOfArrays(); i < n; i++) {
82 auto oldArray = vtkDataArray::SafeDownCast(inputPD->GetAbstractArray(i));
83 if(!oldArray || oldArray->GetName() == nullptr) {
84 continue;
85 }
86 std::string oldArrayName(oldArray->GetName());
87 if(this->GetComputeNormals() && oldArrayName.compare("Normals") == 0) {
88 continue;
89 }
90 auto newArray
91 = vtkSmartPointer<vtkDataArray>::Take(oldArray->NewInstance());
92 size_t nComponents = oldArray->GetNumberOfComponents();
93 newArray->SetName(oldArray->GetName());
94 newArray->SetNumberOfComponents(nComponents);
95 newArray->SetNumberOfTuples(nVertices * nPoints);
96
97 switch(newArray->GetDataType()) {
98 vtkTemplateMacro((copyArrayData<VTK_TT>(
99 oldArray, newArray, nPoints, nVertices, nComponents)));
100 }
101 outputPD->AddArray(newArray);
102 }
103 }
104
105 return 1;
106}
int RequestData(vtkInformation *request, vtkInformationVector **inputVector, vtkInformationVector *outputVector) override
virtual void SetCenters(vtkDataArray *)
virtual int GetNumberOfSubdivisions()
virtual bool GetComputeNormals()
int FillInputPortInformation(int port, vtkInformation *info) override
int RequestData(vtkInformation *request, vtkInformationVector **inputVector, vtkInformationVector *outputVector) override
~ttkIcospheresFromPoints() override
void setDebugMsgPrefix(const std::string &prefix)
Definition: Debug.h:364
int computeNumberOfVerticesAndTriangles(size_t &nVertices, size_t &nTriangles, const size_t nSubdivisions) const
Definition: Icosphere.h:33
int copyArrayData(vtkDataArray *oldArray, vtkDataArray *newArray, const size_t &nSpheres, const size_t &nVerticesPerSphere, const size_t &nComponents)
vtkStandardNewMacro(ttkIcospheresFromPoints)