TTK
Loading...
Searching...
No Matches
ttkIcosphere.cpp
Go to the documentation of this file.
1#include <ttkIcosphere.h>
2
3#include <ttkUtils.h>
4
5#include <vtkInformation.h>
6#include <vtkObjectFactory.h>
7
8#include <vtkCellArray.h>
9#include <vtkDoubleArray.h>
10#include <vtkFloatArray.h>
11#include <vtkIdTypeArray.h>
12#include <vtkPointData.h>
13#include <vtkPolyData.h>
14#include <vtkSmartPointer.h>
15
17
19 this->SetNumberOfInputPorts(0);
20 this->SetNumberOfOutputPorts(1);
21}
23
25 vtkInformation *ttkNotUsed(info)) {
26 return 0;
27}
28
29int ttkIcosphere::FillOutputPortInformation(int port, vtkInformation *info) {
30 if(port == 0)
31 info->Set(vtkDataObject::DATA_TYPE_NAME(), "vtkPolyData");
32 else
33 return 0;
34 return 1;
35}
36
37int ttkIcosphere::RequestData(vtkInformation *ttkNotUsed(request),
38 vtkInformationVector **ttkNotUsed(inputVector),
39 vtkInformationVector *outputVector) {
40 // get parameter
41 size_t nSpheres = this->Centers ? this->Centers->GetNumberOfTuples() : 1;
42 size_t nSubdivisions = this->GetNumberOfSubdivisions();
43 double radius = this->GetRadius();
44
45 bool useDoublePrecision
46 = this->Centers ? this->Centers->GetDataType() == VTK_DOUBLE : false;
47
48 // prepare the output buffers
49 size_t nVertices = 0;
50 size_t nTriangles = 0;
52 nVertices, nTriangles, nSubdivisions);
53
54 const size_t nTotalVertices = nSpheres * nVertices;
55 const size_t nTotalTriangles = nSpheres * nTriangles;
56
57 auto points = vtkSmartPointer<vtkPoints>::New();
58 points->SetDataType(useDoublePrecision ? VTK_DOUBLE : VTK_FLOAT);
59 points->SetNumberOfPoints(nTotalVertices);
60
62 if(this->ComputeNormals) {
63 if(useDoublePrecision)
65 else
67
68 normals->SetName("Normals");
69 normals->SetNumberOfComponents(3);
70 normals->SetNumberOfTuples(nTotalVertices);
71 }
72
74 offsets->SetNumberOfTuples(nTotalTriangles + 1);
75 auto offsetsData
76 = static_cast<vtkIdType *>(ttkUtils::GetVoidPointer(offsets));
77 for(size_t i = 0; i <= nTotalTriangles; i++)
78 offsetsData[i] = i * 3;
79
80 auto connectivity = vtkSmartPointer<vtkIdTypeArray>::New();
81 connectivity->SetNumberOfTuples(nTotalTriangles * 3);
82
83 int status = 0;
84 if(useDoublePrecision) {
85 using DT = double;
86 status = this->computeIcospheres<DT, vtkIdType>(
87 ttkUtils::GetPointer<DT>(points->GetData()),
88 ttkUtils::GetPointer<vtkIdType>(connectivity),
89
90 nSpheres, nSubdivisions, radius,
91 this->Centers ? ttkUtils::GetPointer<DT>(this->Centers) : this->Center,
92 this->ComputeNormals ? ttkUtils::GetPointer<DT>(normals) : nullptr);
93 } else {
94 using DT = float;
95 DT centerFloat[3]{
96 (DT)this->Center[0], (DT)this->Center[1], (DT)this->Center[2]};
97 status = this->computeIcospheres<DT, vtkIdType>(
98 ttkUtils::GetPointer<DT>(points->GetData()),
99 ttkUtils::GetPointer<vtkIdType>(connectivity),
100
101 nSpheres, nSubdivisions, radius,
102 this->Centers ? ttkUtils::GetPointer<DT>(this->Centers) : centerFloat,
103 this->ComputeNormals ? ttkUtils::GetPointer<DT>(normals) : nullptr);
104 }
105
106 if(!status)
107 return 0;
108
109 // finalize output
110 {
111 auto output = vtkPolyData::GetData(outputVector);
112 output->SetPoints(points);
113
115 cells->SetData(offsets, connectivity);
116 output->SetPolys(cells);
117
118 if(this->ComputeNormals)
119 output->GetPointData()->SetNormals(normals);
120 }
121
122 return 1;
123}
#define ttkNotUsed(x)
Mark function/method parameters that are not used in the function body at all.
Definition: BaseClass.h:47
int RequestData(vtkInformation *request, vtkInformationVector **inputVector, vtkInformationVector *outputVector) override
~ttkIcosphere() override
int FillInputPortInformation(int port, vtkInformation *info) override
virtual double GetRadius()
virtual int GetNumberOfSubdivisions()
int FillOutputPortInformation(int port, vtkInformation *info) override
static void * GetVoidPointer(vtkDataArray *array, vtkIdType start=0)
Definition: ttkUtils.cpp:225
int computeNumberOfVerticesAndTriangles(size_t &nVertices, size_t &nTriangles, const size_t nSubdivisions) const
Definition: Icosphere.h:33
vtkStandardNewMacro(ttkIcosphere)