VMTK
Loading...
Searching...
No Matches
vtkvmtkPolyDataCenterlineGroupsClipper.cxx
Go to the documentation of this file.
1/*=========================================================================
2
3Program: VMTK
4Module: $RCSfile: vtkvmtkPolyDataCenterlineGroupsClipper.cxx,v $
5Language: C++
6Date: $Date: 2006/04/06 16:46:43 $
7Version: $Revision: 1.9 $
8
9 Copyright (c) Luca Antiga, David Steinman. All rights reserved.
10 See LICENSE file for details.
11
12 Portions of this code are covered under the VTK copyright.
13 See VTKCopyright.txt or http://www.kitware.com/VTKCopyright.htm
14 for details.
15
16 This software is distributed WITHOUT ANY WARRANTY; without even
17 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
18 PURPOSE. See the above copyright notices for more information.
19
20=========================================================================*/
21
23#include "vtkExecutive.h"
24#include "vtkPointData.h"
25#include "vtkCellData.h"
26#include "vtkIntArray.h"
27#include "vtkDoubleArray.h"
28#include "vtkClipPolyData.h"
29#include "vtkAppendPolyData.h"
30#include "vtkvmtkPolyBallLine.h"
31#include "vtkMath.h"
32#include "vtkInformation.h"
33#include "vtkInformationVector.h"
34#include "vtkObjectFactory.h"
35#include "vtkVersion.h"
36
37#include "vtkvmtkConstants.h"
38
39
41
43{
44 this->Centerlines = NULL;
45 this->CenterlineGroupIdsArrayName = NULL;
46 this->CenterlineRadiusArrayName = NULL;
47 this->GroupIdsArrayName = NULL;
48 this->BlankingArrayName = NULL;
49 this->CenterlineGroupIds = NULL;
52 this->ClipValue = 0.0;
53 this->UseRadiusInformation = 1;
54
55 this->SetNumberOfOutputPorts(2);
56 this->GenerateClippedOutput = 0;
57 vtkPolyData *output2 = vtkPolyData::New();
58 this->GetExecutive()->SetOutputData(1, output2);
59 output2->Delete();
60}
61
63{
64 if (this->Centerlines)
65 {
66 this->Centerlines->Delete();
67 this->Centerlines = NULL;
68 }
69
70 if (this->CenterlineGroupIds)
71 {
72 this->CenterlineGroupIds->Delete();
73 this->CenterlineGroupIds = NULL;
74 }
75
77 {
78 delete[] this->CenterlineGroupIdsArrayName;
79 this->CenterlineGroupIdsArrayName = NULL;
80 }
81
83 {
84 delete[] this->CenterlineRadiusArrayName;
85 this->CenterlineRadiusArrayName = NULL;
86 }
87
88 if (this->GroupIdsArrayName)
89 {
90 delete[] this->GroupIdsArrayName;
91 this->GroupIdsArrayName = NULL;
92 }
93
94 if (this->BlankingArrayName)
95 {
96 delete[] this->BlankingArrayName;
97 this->BlankingArrayName = NULL;
98 }
99}
100
102{
103 if (this->GetNumberOfOutputPorts() < 2)
104 {
105 return NULL;
106 }
107
108 return vtkPolyData::SafeDownCast(this->GetExecutive()->GetOutputData(1));
109}
110
112 vtkInformation *vtkNotUsed(request),
113 vtkInformationVector **inputVector,
114 vtkInformationVector *outputVector)
115{
116 vtkInformation *inInfo = inputVector[0]->GetInformationObject(0);
117 vtkInformation *outInfo = outputVector->GetInformationObject(0);
118
119 vtkPolyData *input = vtkPolyData::SafeDownCast(
120 inInfo->Get(vtkDataObject::DATA_OBJECT()));
121 vtkPolyData *output = vtkPolyData::SafeDownCast(
122 outInfo->Get(vtkDataObject::DATA_OBJECT()));
123
124 vtkDataArray* centerlineGroupIdsArray;
125 vtkIntArray* blankingArray;
126 vtkIntArray* groupIdsArray;
127
128 if (!this->Centerlines)
129 {
130 vtkErrorMacro(<< "Centerlines not set.");
131 return 1;
132 }
133
135 {
136 vtkErrorMacro(<< "CenterlineGroupIds not set.");
137 return 1;
138 }
139
141 {
142 vtkErrorMacro(<< "CenterlineGroupIdsArrayName not set.");
143 return 1;
144 }
145
146 if (!this->GroupIdsArrayName)
147 {
148 vtkErrorMacro(<< "GroupIdsArrayName not set.");
149 return 1;
150 }
151
152 centerlineGroupIdsArray = this->Centerlines->GetCellData()->GetArray(this->CenterlineGroupIdsArrayName);
153
154 if (!centerlineGroupIdsArray)
155 {
156 vtkErrorMacro(<< "CenterlineGroupIdsArray with name specified does not exist");
157 return 1;
158 }
159
160 if (!this->BlankingArrayName)
161 {
162 vtkErrorMacro(<< "BlankingArrayName not set.");
163 return 1;
164 }
165
166 blankingArray = vtkIntArray::SafeDownCast(this->Centerlines->GetCellData()->GetArray(this->BlankingArrayName));
167
168 if (!blankingArray)
169 {
170 vtkErrorMacro(<< "BlankingArrayName with name specified does not exist");
171 return 1;
172 }
173
174 if (!this->CenterlineRadiusArrayName)
175 {
176 vtkErrorMacro(<< "CenterlineRadiusArrayName not set.");
177 return 1;
178 }
179
180 if (!this->Centerlines->GetPointData()->GetArray(this->CenterlineRadiusArrayName))
181 {
182 vtkErrorMacro(<< "CenterlineRadiusArray with name specified does not exist");
183 return 1;
184 }
185
186 if (this->Centerlines->GetNumberOfCells() == 1)
187 {
188 output->DeepCopy(input);
189 groupIdsArray = vtkIntArray::New();
190 groupIdsArray->SetName(this->GroupIdsArrayName);
191 groupIdsArray->SetNumberOfTuples(output->GetNumberOfPoints());
192 groupIdsArray->FillComponent(0,centerlineGroupIdsArray->GetComponent(0,0));
193 output->GetPointData()->AddArray(groupIdsArray);
194 groupIdsArray->Delete();
195 return 1;
196 }
197
198 vtkAppendPolyData* appendBranches = vtkAppendPolyData::New();
199 vtkAppendPolyData* appendClippedOutput = NULL;
200 if (this->GenerateClippedOutput)
201 {
202 appendClippedOutput = vtkAppendPolyData::New();
203 }
204
205 // for each group, compute the clipping array, clip, add group ids array and append.
206
208 groupTubes->SetInput(this->Centerlines);
211
213 nonGroupTubes->SetInput(this->Centerlines);
215 nonGroupTubes->SetUseRadiusInformation(this->UseRadiusInformation);
216
217 int numberOfPoints = input->GetNumberOfPoints();
218
219 const char clippingArrayName[] = "ClippingArray";
220
221 vtkDoubleArray* clippingArray = vtkDoubleArray::New();
222 clippingArray->SetNumberOfComponents(1);
223 clippingArray->SetNumberOfTuples(numberOfPoints);
224 clippingArray->FillComponent(0,0.0);
225 clippingArray->SetName(clippingArrayName);
226
227 vtkPolyData* clippingInput = vtkPolyData::New();
228 clippingInput->DeepCopy(input);
229 clippingInput->GetPointData()->AddArray(clippingArray);
230 clippingInput->GetPointData()->SetActiveScalars(clippingArrayName);
231
232 vtkIdList* groupTubesGroupIds = vtkIdList::New();
233 vtkIdList* nonGroupTubesGroupIds = vtkIdList::New();
234
235 double point[3];
236 double groupTubeValue, nonGroupTubeValue, tubeDifferenceValue;
237
238 vtkIdType groupId;
239
240 vtkIdList* centerlineGroupIds = vtkIdList::New();
241
242 int i;
244 {
245 for (i=0; i<centerlineGroupIdsArray->GetNumberOfTuples(); i++)
246 {
247 if (blankingArray->GetValue(i) == 1)
248 {
249 continue;
250 }
251 centerlineGroupIds->InsertUniqueId(static_cast<vtkIdType>(vtkMath::Round(centerlineGroupIdsArray->GetComponent(i,0))));
252 }
253 }
254 else
255 {
256 centerlineGroupIds->DeepCopy(this->CenterlineGroupIds);
257 }
258
259 for (i=0; i<centerlineGroupIds->GetNumberOfIds(); i++)
260 {
261 groupId = centerlineGroupIds->GetId(i);
262
263 groupTubesGroupIds->Initialize();
264 nonGroupTubesGroupIds->Initialize();
265
266 for (int j=0; j<this->Centerlines->GetNumberOfCells(); j++)
267 {
268 if (blankingArray->GetValue(j) == 1)
269 {
270 continue;
271 }
272 if (static_cast<vtkIdType>(vtkMath::Round(centerlineGroupIdsArray->GetComponent(j,0))) == groupId)
273 {
274 groupTubesGroupIds->InsertNextId(j);
275 }
276 else
277 {
278 nonGroupTubesGroupIds->InsertNextId(j);
279 }
280 }
281
282 if ((groupTubesGroupIds->GetNumberOfIds() == 0) || (nonGroupTubesGroupIds->GetNumberOfIds() == 0))
283 {
284 continue;
285 }
286
287 groupTubes->SetInputCellIds(groupTubesGroupIds);
288 nonGroupTubes->SetInputCellIds(nonGroupTubesGroupIds);
289
290 for (int k=0; k<numberOfPoints; k++)
291 {
292 input->GetPoint(k,point);
293 groupTubeValue = groupTubes->EvaluateFunction(point);
294 if (groupTubeValue > this->CutoffRadiusFactor * this->CutoffRadiusFactor - 1)
295 {
296 groupTubeValue = VTK_VMTK_LARGE_DOUBLE;
297 }
298 nonGroupTubeValue = nonGroupTubes->EvaluateFunction(point);
299 tubeDifferenceValue = nonGroupTubeValue - groupTubeValue;
300 clippingArray->SetValue(k,tubeDifferenceValue);
301 }
302
303 vtkClipPolyData* clipper = vtkClipPolyData::New();
304 clipper->SetInputData(clippingInput);
305 clipper->SetValue(this->ClipValue);
306 clipper->GenerateClipScalarsOff();
307 clipper->SetGenerateClippedOutput(this->GenerateClippedOutput);
308 clipper->Update();
309
310 if (clipper->GetOutput()->GetNumberOfPoints()==0)
311 {
312 clipper->Delete();
313 continue;
314 }
315
316 vtkPolyData* clippedBranch = vtkPolyData::New();
317 clippedBranch->DeepCopy(clipper->GetOutput());
318
319 if (this->GenerateClippedOutput)
320 {
321 vtkPolyData* clippedOutputBranch = vtkPolyData::New();
322 clippedOutputBranch->DeepCopy(clipper->GetClippedOutput());
323 appendClippedOutput->AddInputData(clippedOutputBranch);
324 clippedOutputBranch->Delete();
325 }
326
327 groupIdsArray = vtkIntArray::New();
328 groupIdsArray->SetName(this->GroupIdsArrayName);
329 groupIdsArray->SetNumberOfTuples(clippedBranch->GetNumberOfPoints());
330 groupIdsArray->FillComponent(0,groupId);
331
332 clippedBranch->GetPointData()->AddArray(groupIdsArray);
333 appendBranches->AddInputData(clippedBranch);
334 groupIdsArray->Delete();
335 clippedBranch->Delete();
336 clipper->Delete();
337 }
338
339 appendBranches->Update();
340
341 output->DeepCopy(appendBranches->GetOutput());
342
343 if (this->GenerateClippedOutput)
344 {
345 appendClippedOutput->Update();
346 this->GetClippedOutput()->DeepCopy(appendClippedOutput->GetOutput());
347 appendClippedOutput->Delete();
348 }
349
350 clippingArray->Delete();
351 clippingInput->Delete();
352 appendBranches->Delete();
353 groupTubes->Delete();
354 nonGroupTubes->Delete();
355 groupTubesGroupIds->Delete();
356 nonGroupTubesGroupIds->Delete();
357 centerlineGroupIds->Delete();
358
359 return 1;
360}
361
362void vtkvmtkPolyDataCenterlineGroupsClipper::PrintSelf(std::ostream& os, vtkIndent indent)
363{
364 this->Superclass::PrintSelf(os,indent);
365}
Implements vtkImplicitFunction to evaluate the minimum sphere function for an envelope created by an ...
virtual void SetInput(vtkPolyData *)
virtual void SetPolyBallRadiusArrayName(const char *)
virtual void SetInputCellIds(vtkIdList *)
virtual void SetUseRadiusInformation(int)
static vtkvmtkPolyBallLine * New()
double EvaluateFunction(double x[3]) override
Split a surface into groups/branches corresponding to their proximity to the polyball line of a branc...
virtual int RequestData(vtkInformation *, vtkInformationVector **, vtkInformationVector *) override
void PrintSelf(std::ostream &os, vtkIndent indent) override
#define VTK_VMTK_LARGE_DOUBLE
vtkStandardNewMacro(vtkvmtkPolyDataCenterlineGroupsClipper)