VMTK
Loading...
Searching...
No Matches
vtkvmtkPolyDataBifurcationProfiles.cxx
Go to the documentation of this file.
1/*=========================================================================
2
3Program: VMTK
4Module: $RCSfile: vtkvmtkPolyDataBifurcationProfiles.cxx,v $
5Language: C++
6Date: $Date: 2006/10/17 15:16:16 $
7Version: $Revision: 1.1 $
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 "vtkPolyData.h"
24#include "vtkPointData.h"
25#include "vtkCellData.h"
26#include "vtkCellArray.h"
27#include "vtkDoubleArray.h"
28#include "vtkIntArray.h"
29#include "vtkMath.h"
30#include "vtkInformation.h"
31#include "vtkInformationVector.h"
32#include "vtkObjectFactory.h"
33#include "vtkVersion.h"
34
35#include "vtkvmtkConstants.h"
39
42
43
45
62
64{
65 if (this->GroupIdsArrayName)
66 {
67 delete[] this->GroupIdsArrayName;
68 this->GroupIdsArrayName = NULL;
69 }
70
71 if (this->Centerlines)
72 {
73 this->Centerlines->Delete();
74 this->Centerlines = NULL;
75 }
76
78 {
79 delete[] this->CenterlineRadiusArrayName;
80 this->CenterlineRadiusArrayName = NULL;
81 }
82
84 {
85 delete[] this->CenterlineGroupIdsArrayName;
86 this->CenterlineGroupIdsArrayName = NULL;
87 }
88
89 if (this->CenterlineIdsArrayName)
90 {
91 delete[] this->CenterlineIdsArrayName;
92 this->CenterlineIdsArrayName = NULL;
93 }
94
96 {
97 delete[] this->CenterlineTractIdsArrayName;
98 this->CenterlineTractIdsArrayName = NULL;
99 }
100
101 if (this->BlankingArrayName)
102 {
103 delete[] this->BlankingArrayName;
104 this->BlankingArrayName = NULL;
105 }
106
108 {
111 }
112
114 {
117 }
118
120 {
123 }
124}
125
127 vtkInformation *vtkNotUsed(request),
128 vtkInformationVector **inputVector,
129 vtkInformationVector *outputVector)
130{
131 vtkInformation *inInfo = inputVector[0]->GetInformationObject(0);
132 vtkInformation *outInfo = outputVector->GetInformationObject(0);
133
134 vtkPolyData *input = vtkPolyData::SafeDownCast(
135 inInfo->Get(vtkDataObject::DATA_OBJECT()));
136 vtkPolyData *output = vtkPolyData::SafeDownCast(
137 outInfo->Get(vtkDataObject::DATA_OBJECT()));
138
139 if (!this->GroupIdsArrayName)
140 {
141 vtkErrorMacro(<<"GroupIdsArrayName not specified");
142 return 1;
143 }
144
145 vtkDataArray* groupIdsArray = input->GetPointData()->GetArray(this->GroupIdsArrayName);
146
147 if (!groupIdsArray)
148 {
149 vtkErrorMacro(<<"GroupIdsArray with name specified does not exist");
150 return 1;
151 }
152
153 if (!this->Centerlines)
154 {
155 vtkErrorMacro(<<"Centerlines not set");
156 return 1;
157 }
158
159 if (!this->CenterlineRadiusArrayName)
160 {
161 vtkErrorMacro(<<"CenterlineRadiusArrayName not specified");
162 return 1;
163 }
164
165 vtkDataArray* centerlineRadiusArray = this->Centerlines->GetPointData()->GetArray(this->CenterlineRadiusArrayName);
166
167 if (!centerlineRadiusArray)
168 {
169 vtkErrorMacro(<<"CenterlineRadiusArray with name specified does not exist");
170 return 1;
171 }
172
174 {
175 vtkErrorMacro(<<"CenterlineGroupIdsArrayName not specified");
176 return 1;
177 }
178
179 vtkDataArray* centerlineGroupIdsArray = this->Centerlines->GetCellData()->GetArray(this->CenterlineGroupIdsArrayName);
180
181 if (!centerlineGroupIdsArray)
182 {
183 vtkErrorMacro(<<"CenterlineGroupIdsArray with name specified does not exist");
184 return 1;
185 }
186
187 if (!this->CenterlineIdsArrayName)
188 {
189 vtkErrorMacro(<<"CenterlineIdsArrayName not specified");
190 return 1;
191 }
192
193 vtkDataArray* centerlineIdsArray = this->Centerlines->GetCellData()->GetArray(this->CenterlineIdsArrayName);
194
195 if (!centerlineIdsArray)
196 {
197 vtkErrorMacro(<<"CenterlineIdsArray with name specified does not exist");
198 return 1;
199 }
200
202 {
203 vtkErrorMacro(<<"CenterlineTractIdsArrayName not specified");
204 return 1;
205 }
206
207 vtkDataArray* centerlineTractIdsArray = this->Centerlines->GetCellData()->GetArray(this->CenterlineTractIdsArrayName);
208
209 if (!centerlineTractIdsArray)
210 {
211 vtkErrorMacro(<<"CenterlineTractIdsArray with name specified does not exist");
212 return 1;
213 }
214
215 if (!this->BlankingArrayName)
216 {
217 vtkErrorMacro(<<"BlankingArrayName not specified");
218 return 1;
219 }
220
221 vtkDataArray* blankingArray = this->Centerlines->GetCellData()->GetArray(this->BlankingArrayName);
222
223 if (!blankingArray)
224 {
225 vtkErrorMacro(<<"BlankingArray with name specified does not exist");
226 return 1;
227 }
228
230 {
231 vtkErrorMacro(<<"BifurcationProfileGroupIdsArrayName not specified");
232 return 1;
233 }
234
236 {
237 vtkErrorMacro(<<"BifurcationProfileBifurcationGroupIdsArrayName not specified");
238 return 1;
239 }
240
242 {
243 vtkErrorMacro(<<"BifurcationProfileOrientationArrayName not specified");
244 return 1;
245 }
246
247 vtkIntArray* bifurcationProfileGroupIdsArray = vtkIntArray::New();
248 bifurcationProfileGroupIdsArray->SetName(this->BifurcationProfileGroupIdsArrayName);
249
250 vtkIntArray* bifurcationProfileBifurcationGroupIdsArray = vtkIntArray::New();
251 bifurcationProfileBifurcationGroupIdsArray->SetName(this->BifurcationProfileBifurcationGroupIdsArrayName);
252
253 vtkIntArray* bifurcationProfileOrientationArray = vtkIntArray::New();
254 bifurcationProfileOrientationArray->SetName(this->BifurcationProfileOrientationArrayName);
255
256 output->GetCellData()->AddArray(bifurcationProfileGroupIdsArray);
257 output->GetCellData()->AddArray(bifurcationProfileBifurcationGroupIdsArray);
258 output->GetCellData()->AddArray(bifurcationProfileOrientationArray);
259
260 vtkPoints* outputPoints = vtkPoints::New();
261 vtkCellArray* outputLines = vtkCellArray::New();
262
263 output->SetPoints(outputPoints);
264 output->SetLines(outputLines);
265
266 vtkIdList* blankedGroupIds = vtkIdList::New();
268 int i;
269 for (i=0; i<blankedGroupIds->GetNumberOfIds(); i++)
270 {
271 vtkIdType bifurcationGroupId = blankedGroupIds->GetId(i);
272
273 //compute quantities and insert proper values in arrays
274 vtkIdList* upStreamGroupIds = vtkIdList::New();
275 vtkIdList* downStreamGroupIds = vtkIdList::New();
276
278
279 this->ComputeBifurcationProfiles(input,bifurcationGroupId,upStreamGroupIds,downStreamGroupIds,output);
280
281 upStreamGroupIds->Delete();
282 downStreamGroupIds->Delete();
283 }
284
285 blankedGroupIds->Delete();
286
287 outputPoints->Delete();
288 outputLines->Delete();
289
290 bifurcationProfileGroupIdsArray->Delete();
291 bifurcationProfileBifurcationGroupIdsArray->Delete();
292 bifurcationProfileOrientationArray->Delete();
293
294 return 1;
295}
296
297void vtkvmtkPolyDataBifurcationProfiles::ComputeBifurcationProfiles(vtkPolyData* input, int bifurcationGroupId, vtkIdList* upStreamGroupIds, vtkIdList* downStreamGroupIds, vtkPolyData* output)
298{
299 vtkDataArray* radiusArray = this->Centerlines->GetPointData()->GetArray(this->CenterlineRadiusArrayName);
300 vtkPoints* outputPoints = output->GetPoints();
301 vtkCellArray* outputLines = output->GetLines();
302 vtkIntArray* bifurcationProfileOrientationArray = vtkIntArray::SafeDownCast(output->GetCellData()->GetArray(this->BifurcationProfileOrientationArrayName));
303 vtkIntArray* bifurcationProfileGroupIdsArray = vtkIntArray::SafeDownCast(output->GetCellData()->GetArray(this->BifurcationProfileGroupIdsArrayName));
304 vtkIntArray* bifurcationProfileBifurcationGroupIdsArray = vtkIntArray::SafeDownCast(output->GetCellData()->GetArray(this->BifurcationProfileBifurcationGroupIdsArrayName));
305
306 vtkIdList* bifurcationProfileGroupIds = vtkIdList::New();
307 vtkIntArray* bifurcationProfileOrientations = vtkIntArray::New();
308
309 int numberOfUpStreamGroupIds = upStreamGroupIds->GetNumberOfIds();
310 int numberOfDownStreamGroupIds = downStreamGroupIds->GetNumberOfIds();
311 int i;
312 for (i=0; i<numberOfUpStreamGroupIds; i++)
313 {
314 bifurcationProfileGroupIds->InsertNextId(upStreamGroupIds->GetId(i));
315 bifurcationProfileOrientations->InsertNextValue(vtkvmtkCenterlineBifurcationVectors::VTK_VMTK_UPSTREAM_ORIENTATION);
316 }
317 for (i=0; i<numberOfDownStreamGroupIds; i++)
318 {
319 bifurcationProfileGroupIds->InsertNextId(downStreamGroupIds->GetId(i));
320 bifurcationProfileOrientations->InsertNextValue(vtkvmtkCenterlineBifurcationVectors::VTK_VMTK_DOWNSTREAM_ORIENTATION);
321 }
322
323 int numberOfBifurcationProfiles = bifurcationProfileGroupIds->GetNumberOfIds();
324
325 for (i=0; i<numberOfBifurcationProfiles; i++)
326 {
327 int bifurcationProfileGroupId = bifurcationProfileGroupIds->GetId(i);
328 int bifurcationProfileOrientation = bifurcationProfileOrientations->GetValue(i);
329
330 double averagePoint[3];
331 averagePoint[0] = averagePoint[1] = averagePoint[2] = 0.0;
332
333 double weightSum = 0.0;
334
335 int j;
336 vtkIdList* groupCellIds = vtkIdList::New();
337 vtkvmtkCenterlineUtilities::GetGroupUniqueCellIds(this->Centerlines,this->CenterlineGroupIdsArrayName,bifurcationProfileGroupId,groupCellIds);
338 for (j=0; j<groupCellIds->GetNumberOfIds(); j++)
339 {
340 vtkIdType cellId = groupCellIds->GetId(j);
341 vtkCell* cell = this->Centerlines->GetCell(cellId);
342 int numberOfCellPoints = cell->GetNumberOfPoints();
343
344 double lastPoint[3];
345 double lastPointRadius = 0.0;
346
348 {
349 cell->GetPoints()->GetPoint(numberOfCellPoints-1,lastPoint);
350 lastPointRadius = radiusArray->GetComponent(cell->GetPointId(numberOfCellPoints-1),0);
351 }
352 else if (bifurcationProfileOrientation == vtkvmtkCenterlineBifurcationVectors::VTK_VMTK_DOWNSTREAM_ORIENTATION)
353 {
354 cell->GetPoints()->GetPoint(0,lastPoint);
355 lastPointRadius = radiusArray->GetComponent(cell->GetPointId(0),0);
356 }
357 else
358 {
359 vtkErrorMacro("Error: invalid BifurcationVectorOrientation");
360 return;
361 }
362
363 averagePoint[0] += lastPointRadius * lastPointRadius * lastPoint[0];
364 averagePoint[1] += lastPointRadius * lastPointRadius * lastPoint[1];
365 averagePoint[2] += lastPointRadius * lastPointRadius * lastPoint[2];
366
367 weightSum += lastPointRadius * lastPointRadius;
368 }
369
370 averagePoint[0] /= weightSum;
371 averagePoint[1] /= weightSum;
372 averagePoint[2] /= weightSum;
373
374 vtkPolyData* cylinder = vtkPolyData::New();
375 vtkvmtkPolyDataBranchUtilities::ExtractGroup(input,this->GroupIdsArrayName,bifurcationProfileGroupId,false,cylinder);
376
378 boundaryExtractor->SetInputData(cylinder);
379 boundaryExtractor->Update();
380
381 vtkPolyData* profile = boundaryExtractor->GetOutput();
382
383 int numberOfCells = profile->GetNumberOfCells();
384 int closestCellId = -1;
385 double minDistance = VTK_VMTK_LARGE_DOUBLE;
386 for (j=0; j<numberOfCells; j++)
387 {
388 double barycenter[3];
389 vtkvmtkBoundaryReferenceSystems::ComputeBoundaryBarycenter(profile->GetCell(j)->GetPoints(),barycenter);
390 double barycenterDistance = vtkMath::Distance2BetweenPoints(barycenter,averagePoint);
391 if (barycenterDistance < minDistance)
392 {
393 closestCellId = j;
394 minDistance = barycenterDistance;
395 }
396 }
397
398 vtkPoints* profileCellPoints = profile->GetCell(closestCellId)->GetPoints();
399 int numberOfProfileCellPoints = profileCellPoints->GetNumberOfPoints();
400 outputLines->InsertNextCell(numberOfProfileCellPoints);
401 for (j=0; j<numberOfProfileCellPoints; j++)
402 {
403 vtkIdType pointId = outputPoints->InsertNextPoint(profileCellPoints->GetPoint(j));
404 outputLines->InsertCellPoint(pointId);
405 }
406
407 bifurcationProfileGroupIdsArray->InsertNextValue(bifurcationProfileGroupId);
408 bifurcationProfileBifurcationGroupIdsArray->InsertNextValue(bifurcationGroupId);
409 bifurcationProfileOrientationArray->InsertNextValue(bifurcationProfileOrientation);
410
411 groupCellIds->Delete();
412 cylinder->Delete();
413 boundaryExtractor->Delete();
414 }
415
416 bifurcationProfileGroupIds->Delete();
417 bifurcationProfileOrientations->Delete();
418}
419
420void vtkvmtkPolyDataBifurcationProfiles::PrintSelf(std::ostream& os, vtkIndent indent)
421{
422 this->Superclass::PrintSelf(os,indent);
423}
static void ComputeBoundaryBarycenter(vtkPoints *points, double barycenter[3])
static void GetBlankedGroupsIdList(vtkPolyData *centerlines, const char *groupIdsArrayName, const char *blankingArrayName, vtkIdList *groupIds)
static void GetGroupUniqueCellIds(vtkPolyData *centerlines, const char *groupIdsArrayName, vtkIdType groupId, vtkIdList *groupCellIds)
static void FindAdjacentCenterlineGroupIds(vtkPolyData *centerlines, const char *groupIdsArrayName, const char *centerlineIdsArrayName, const char *tractIdsArrayName, vtkIdType groupId, vtkIdList *upStreamGroupIds, vtkIdList *downStreamGroupIds)
Compute bifurcation profiles (the bifurcation splitting lines) from an input surface and grouped and ...
virtual int RequestData(vtkInformation *, vtkInformationVector **, vtkInformationVector *) override
void PrintSelf(std::ostream &os, vtkIndent indent) override
void ComputeBifurcationProfiles(vtkPolyData *input, int bifurcationGroupId, vtkIdList *upStreamGroupIds, vtkIdList *downStreamGroupIds, vtkPolyData *output)
Extract boundary edges as poly lines.
static vtkvmtkPolyDataBoundaryExtractor * New()
static void ExtractGroup(vtkPolyData *surface, const char *groupIdsArrayName, vtkIdType groupId, bool cleanGroupSurface, vtkPolyData *groupSurface)
#define VTK_VMTK_LARGE_DOUBLE
vtkStandardNewMacro(vtkvmtkPolyDataBifurcationProfiles)