TTK
Loading...
Searching...
No Matches
ttkSphereFromPoint.cpp
Go to the documentation of this file.
2
3#include <vtkAppendPolyData.h>
4#include <vtkDataSet.h>
5#include <vtkInformation.h>
6#include <vtkPointData.h>
7#include <vtkSphereSource.h>
8
9#include <ttkMacros.h>
10#include <ttkUtils.h>
11
12using namespace std;
13using namespace ttk;
14
16
18
19 masterAppender_ = nullptr;
20
21 this->SetNumberOfInputPorts(1);
22 this->SetNumberOfOutputPorts(1);
23 setDebugMsgPrefix("SphereFromPoint");
24
25 vtkWarningMacro("`TTK SphereFromPoint' is now deprecated. Please use "
26 "`TTK IcospheresFromPoint' instead.");
27}
28
30
31 if(masterAppender_)
32 masterAppender_->Delete();
33
34 for(SimplexId i = 0; i < (SimplexId)appenderList_.size(); i++) {
35 appenderList_[i]->Delete();
36 }
37
38 for(SimplexId i = 0; i < (SimplexId)sphereList_.size(); i++) {
39 sphereList_[i]->Delete();
40 }
41
42 for(SimplexId i = 0; i < (SimplexId)dataArrayList_.size(); i++) {
43 for(SimplexId j = 0; j < (SimplexId)dataArrayList_[i].size(); j++) {
44 dataArrayList_[i][j]->Delete();
45 }
46 }
47}
48
50 vtkInformation *info) {
51 if(port == 0) {
52 info->Set(vtkAlgorithm::INPUT_REQUIRED_DATA_TYPE(), "vtkDataSet");
53 return 1;
54 }
55 return 0;
56}
57
59 vtkInformation *info) {
60 if(port == 0) {
61 info->Set(vtkDataObject::DATA_TYPE_NAME(), "vtkPolyData");
62 return 1;
63 }
64 return 0;
65}
66
67int ttkSphereFromPoint::RequestData(vtkInformation *ttkNotUsed(request),
68 vtkInformationVector **inputVector,
69 vtkInformationVector *outputVector) {
70
71 Timer t;
72
73 vtkDataSet *input = vtkDataSet::GetData(inputVector[0]);
74 vtkDataSet *output = vtkDataSet::GetData(outputVector);
75
76 if(masterAppender_) {
77 masterAppender_->Delete();
78 masterAppender_ = nullptr;
79 }
80
81 for(SimplexId i = 0; i < (SimplexId)appenderList_.size(); i++) {
82 appenderList_[i]->Delete();
83 }
84
85 masterAppender_ = vtkAppendPolyData::New();
86 appenderList_.resize(threadNumber_);
87 for(SimplexId i = 0; i < (SimplexId)appenderList_.size(); i++) {
88 appenderList_[i] = vtkAppendPolyData::New();
89 }
90
91 if((SimplexId)sphereList_.size() > input->GetNumberOfPoints()) {
92 for(SimplexId i = input->GetNumberOfPoints();
93 i < (SimplexId)sphereList_.size(); i++) {
94 sphereList_[i]->Delete();
95 }
96
97 sphereList_.resize(input->GetNumberOfPoints());
98 } else if((SimplexId)sphereList_.size() < input->GetNumberOfPoints()) {
99 SimplexId const oldSize = sphereList_.size();
100
101 sphereList_.resize(input->GetNumberOfPoints());
102
103 for(SimplexId i = oldSize; i < (SimplexId)sphereList_.size(); i++) {
104 sphereList_[i] = vtkSphereSource::New();
105 }
106 }
107
108 if(dataArrayList_.size()) {
109 for(SimplexId i = 0; i < (SimplexId)dataArrayList_.size(); i++) {
110 for(SimplexId j = 0; j < (SimplexId)dataArrayList_[i].size(); j++) {
111 dataArrayList_[i][j]->Delete();
112 }
113 dataArrayList_[i].clear();
114 }
115 }
116 dataArrayList_.resize(threadNumber_);
117
118 vector<vector<double>> p(threadNumber_);
119
120 for(SimplexId i = 0; i < (SimplexId)p.size(); i++) {
121 p[i].resize(3);
122 }
123
124 if(!input->GetNumberOfPoints())
125 return -1;
126 // make this function thread-safe
127 input->GetPoint(0, p[0].data());
128
129#ifdef TTK_ENABLE_OPENMP
130#pragma omp parallel for num_threads(threadNumber_)
131#endif
132 for(SimplexId i = 0; i < input->GetNumberOfPoints(); i++) {
133
134 ThreadId threadId = 0;
135
136#ifdef TTK_ENABLE_OPENMP
137 threadId = omp_get_thread_num();
138#endif
139
140 input->GetPoint(i, p[threadId].data());
141
142 sphereList_[i]->SetCenter(p[threadId][0], p[threadId][1], p[threadId][2]);
143
144 sphereList_[i]->SetRadius(Radius);
145
146 sphereList_[i]->SetThetaResolution(ThetaResolution);
147 sphereList_[i]->SetStartTheta(StartTheta);
148 sphereList_[i]->SetEndTheta(EndTheta);
149
150 sphereList_[i]->SetPhiResolution(PhiResolution);
151 sphereList_[i]->SetStartPhi(StartPhi);
152 sphereList_[i]->SetEndPhi(EndPhi);
153
154 sphereList_[i]->Update();
155
156 vtkPolyData *sphereSurface = sphereList_[i]->GetOutput();
157
158 // copy the data values
159 for(SimplexId j = 0; j < input->GetPointData()->GetNumberOfArrays(); j++) {
160
161 vtkDataArray *array = input->GetPointData()->GetArray(j);
162
163 if(array != nullptr && array->GetNumberOfComponents() == 1) {
164
165 double value = 0;
166 array->GetTuple(i, &value);
167
168 vtkDataArray *dataArray = array->NewInstance();
169 if(dataArray != nullptr) {
170 dataArray->SetName(array->GetName());
171 dataArray->SetNumberOfTuples(sphereSurface->GetNumberOfPoints());
172 for(SimplexId k = 0; k < sphereSurface->GetNumberOfPoints(); k++) {
173 dataArray->SetTuple(k, &value);
174 }
175 }
176 sphereSurface->GetPointData()->AddArray(dataArray);
177 dataArrayList_[threadId].emplace_back(dataArray);
178 } else {
179 printMsg(
180 "Unsupported number of components :(", debug::Priority::DETAIL);
181 }
182 }
183
184 appenderList_[threadId]->AddInputConnection(
185 sphereList_[i]->GetOutputPort());
186 }
187
188 for(SimplexId i = 0; i < (SimplexId)appenderList_.size(); i++) {
189 if(appenderList_[i]->GetInput())
190 masterAppender_->AddInputConnection(appenderList_[i]->GetOutputPort());
191 }
192 masterAppender_->Update();
193
194 output->ShallowCopy(masterAppender_->GetOutput());
195
196 printMsg(std::to_string(input->GetNumberOfPoints()) + " spheres generated", 1,
198
200
201 return 1;
202}
#define ttkNotUsed(x)
Mark function/method parameters that are not used in the function body at all.
Definition BaseClass.h:47
TTK VTK-filter that produces sphere-only glyphs.
int RequestData(vtkInformation *request, vtkInformationVector **inputVector, vtkInformationVector *outputVector) override
int FillInputPortInformation(int port, vtkInformation *info) override
int FillOutputPortInformation(int port, vtkInformation *info) override
void setDebugMsgPrefix(const std::string &prefix)
Definition Debug.h:364
double getElapsedTime()
Definition Timer.h:15
std::string to_string(__int128)
Definition ripserpy.cpp:99
The Topology ToolKit.
int ThreadId
Identifier type for threads (i.e. with OpenMP).
Definition DataTypes.h:26
int SimplexId
Identifier type for simplices of any dimension.
Definition DataTypes.h:22
vtkStandardNewMacro(ttkSphereFromPoint)
printMsg(debug::output::BOLD+" | | | | | . \\ | | (__| | / __/| |_| / __/|__ _|"+debug::output::ENDCOLOR, debug::Priority::PERFORMANCE, debug::LineMode::NEW, stream)