VMTK
Loading...
Searching...
No Matches
vtkvmtkUnstructuredGridCenterlineGroupsClipper.cxx
Go to the documentation of this file.
1/*=========================================================================
2
3Program: VMTK
4Module: $RCSfile: vtkvmtkUnstructuredGridCenterlineGroupsClipper.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 "vtkClipDataSet.h"
29#include "vtkvmtkAppendFilter.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 vtkUnstructuredGrid *output2 = vtkUnstructuredGrid::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 vtkUnstructuredGrid::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 vtkUnstructuredGrid *input = vtkUnstructuredGrid::SafeDownCast(
120 inInfo->Get(vtkDataObject::DATA_OBJECT()));
121 vtkUnstructuredGrid *output = vtkUnstructuredGrid::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
199 appendBranches->MergeDuplicatePointsOff();
200 vtkvmtkAppendFilter* appendClippedOutput = NULL;
201 if (this->GenerateClippedOutput)
202 {
203 appendClippedOutput = vtkvmtkAppendFilter::New();
204 appendClippedOutput->MergeDuplicatePointsOff();
205 }
206
207 // for each group, compute the clipping array, clip, add group ids array and append.
208
210 groupTubes->SetInput(this->Centerlines);
213
215 nonGroupTubes->SetInput(this->Centerlines);
217 nonGroupTubes->SetUseRadiusInformation(this->UseRadiusInformation);
218
219 int numberOfPoints = input->GetNumberOfPoints();
220
221 const char clippingArrayName[] = "ClippingArray";
222
223 vtkDoubleArray* clippingArray = vtkDoubleArray::New();
224 clippingArray->SetNumberOfComponents(1);
225 clippingArray->SetNumberOfTuples(numberOfPoints);
226 clippingArray->FillComponent(0,0.0);
227 clippingArray->SetName(clippingArrayName);
228
229 vtkUnstructuredGrid* clippingInput = vtkUnstructuredGrid::New();
230 clippingInput->DeepCopy(input);
231 clippingInput->GetPointData()->AddArray(clippingArray);
232 clippingInput->GetPointData()->SetActiveScalars(clippingArrayName);
233
234 vtkIdList* groupTubesGroupIds = vtkIdList::New();
235 vtkIdList* nonGroupTubesGroupIds = vtkIdList::New();
236
237 double point[3];
238 double groupTubeValue, nonGroupTubeValue, tubeDifferenceValue;
239
240 vtkIdType groupId;
241
242 vtkIdList* centerlineGroupIds = vtkIdList::New();
243
244 int i;
246 {
247 for (i=0; i<centerlineGroupIdsArray->GetNumberOfTuples(); i++)
248 {
249 if (blankingArray->GetValue(i) == 1)
250 {
251 continue;
252 }
253 centerlineGroupIds->InsertUniqueId(static_cast<vtkIdType>(vtkMath::Round(centerlineGroupIdsArray->GetComponent(i,0))));
254 }
255 }
256 else
257 {
258 centerlineGroupIds->DeepCopy(this->CenterlineGroupIds);
259 }
260
261 for (i=0; i<centerlineGroupIds->GetNumberOfIds(); i++)
262 {
263 groupId = centerlineGroupIds->GetId(i);
264
265 groupTubesGroupIds->Initialize();
266 nonGroupTubesGroupIds->Initialize();
267
268 for (int j=0; j<this->Centerlines->GetNumberOfCells(); j++)
269 {
270 if (blankingArray->GetValue(j) == 1)
271 {
272 continue;
273 }
274 if (static_cast<vtkIdType>(vtkMath::Round(centerlineGroupIdsArray->GetComponent(j,0))) == groupId)
275 {
276 groupTubesGroupIds->InsertNextId(j);
277 }
278 else
279 {
280 nonGroupTubesGroupIds->InsertNextId(j);
281 }
282 }
283
284 if ((groupTubesGroupIds->GetNumberOfIds() == 0) || (nonGroupTubesGroupIds->GetNumberOfIds() == 0))
285 {
286 continue;
287 }
288
289 groupTubes->SetInputCellIds(groupTubesGroupIds);
290 nonGroupTubes->SetInputCellIds(nonGroupTubesGroupIds);
291
292 for (int k=0; k<numberOfPoints; k++)
293 {
294 input->GetPoint(k,point);
295 groupTubeValue = groupTubes->EvaluateFunction(point);
296 if (groupTubeValue > this->CutoffRadiusFactor * this->CutoffRadiusFactor - 1)
297 {
298 groupTubeValue = VTK_VMTK_LARGE_DOUBLE;
299 }
300 nonGroupTubeValue = nonGroupTubes->EvaluateFunction(point);
301 tubeDifferenceValue = nonGroupTubeValue - groupTubeValue;
302 clippingArray->SetValue(k,tubeDifferenceValue);
303 }
304
305 vtkClipDataSet* clipper = vtkClipDataSet::New();
306 clipper->SetInputData(clippingInput);
307 clipper->SetValue(this->ClipValue);
308 clipper->GenerateClipScalarsOff();
309 clipper->SetGenerateClippedOutput(this->GenerateClippedOutput);
310 clipper->Update();
311
312 if (clipper->GetOutput()->GetNumberOfPoints()==0)
313 {
314 clipper->Delete();
315 continue;
316 }
317
318 vtkUnstructuredGrid* clippedBranch = vtkUnstructuredGrid::New();
319 clippedBranch->DeepCopy(clipper->GetOutput());
320
321 if (this->GenerateClippedOutput)
322 {
323 vtkUnstructuredGrid* clippedOutputBranch = vtkUnstructuredGrid::New();
324 clippedOutputBranch->DeepCopy(clipper->GetClippedOutput());
325 appendClippedOutput->AddInputData(clippedOutputBranch);
326 clippedOutputBranch->Delete();
327 }
328
329 groupIdsArray = vtkIntArray::New();
330 groupIdsArray->SetName(this->GroupIdsArrayName);
331 groupIdsArray->SetNumberOfTuples(clippedBranch->GetNumberOfPoints());
332 groupIdsArray->FillComponent(0,groupId);
333
334 clippedBranch->GetPointData()->AddArray(groupIdsArray);
335 appendBranches->AddInputData(clippedBranch);
336 groupIdsArray->Delete();
337 clippedBranch->Delete();
338 clipper->Delete();
339 }
340
341 appendBranches->Update();
342
343 output->DeepCopy(appendBranches->GetOutput());
344
345 if (this->GenerateClippedOutput)
346 {
347 appendClippedOutput->Update();
348 this->GetClippedOutput()->DeepCopy(appendClippedOutput->GetOutput());
349 appendClippedOutput->Delete();
350 }
351
352 clippingArray->Delete();
353 clippingInput->Delete();
354 appendBranches->Delete();
355 groupTubes->Delete();
356 nonGroupTubes->Delete();
357 groupTubesGroupIds->Delete();
358 nonGroupTubesGroupIds->Delete();
359 centerlineGroupIds->Delete();
360
361 return 1;
362}
363
364void vtkvmtkUnstructuredGridCenterlineGroupsClipper::PrintSelf(std::ostream& os, vtkIndent indent)
365{
366 this->Superclass::PrintSelf(os,indent);
367}
Merges points, point data, and cell data.
static vtkvmtkAppendFilter * New()
virtual void MergeDuplicatePointsOff()
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 an unstructured grid into groups/branches corresponding to their proximity to the polyball line...
virtual int RequestData(vtkInformation *, vtkInformationVector **, vtkInformationVector *) override
#define VTK_VMTK_LARGE_DOUBLE
vtkStandardNewMacro(vtkvmtkUnstructuredGridCenterlineGroupsClipper)