VMTK
Loading...
Searching...
No Matches
vtkvmtkPolyDataReferenceSystemBoundaryMetricFilter.cxx
Go to the documentation of this file.
1/*=========================================================================
2
3 Program: VMTK
4 Module: $RCSfile: vtkvmtkPolyDataReferenceSystemBoundaryMetricFilter.cxx,v $
5 Language: C++
6 Date: $Date: 2006/04/06 16:46:43 $
7 Version: $Revision: 1.7 $
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 "vtkPointData.h"
24#include "vtkCellData.h"
25#include "vtkDoubleArray.h"
26#include "vtkvmtkPolyBallLine.h"
27#include "vtkPolyLine.h"
28#include "vtkCellArray.h"
29#include "vtkObjectFactory.h"
31#include "vtkInformation.h"
32#include "vtkInformationVector.h"
33#include "vtkVersion.h"
34
35#include "vtkvmtkPolyBallLine.h"
36
40
41
43
60
62{
64 {
65 delete[] this->BoundaryMetricArrayName;
66 this->BoundaryMetricArrayName = NULL;
67 }
68
69 if (this->GroupIdsArrayName)
70 {
71 delete[] this->GroupIdsArrayName;
72 this->GroupIdsArrayName = NULL;
73 }
74
75 if (this->Centerlines)
76 {
77 this->Centerlines->Delete();
78 this->Centerlines = NULL;
79 }
80
82 {
83 delete[] this->CenterlineAbscissasArrayName;
85 }
86
88 {
89 delete[] this->CenterlineRadiusArrayName;
90 this->CenterlineRadiusArrayName = NULL;
91 }
92
94 {
95 delete[] this->CenterlineGroupIdsArrayName;
96 this->CenterlineGroupIdsArrayName = NULL;
97 }
98
99 if (this->CenterlineIdsArrayName)
100 {
101 delete[] this->CenterlineIdsArrayName;
102 this->CenterlineIdsArrayName = NULL;
103 }
104
106 {
107 delete[] this->CenterlineTractIdsArrayName;
108 this->CenterlineTractIdsArrayName = NULL;
109 }
110
111 if (this->ReferenceSystems)
112 {
113 this->ReferenceSystems->Delete();
114 this->ReferenceSystems = NULL;
115 }
116
118 {
121 }
122}
123
125 vtkInformation *vtkNotUsed(request),
126 vtkInformationVector **inputVector,
127 vtkInformationVector *outputVector)
128{
129 vtkInformation *inInfo = inputVector[0]->GetInformationObject(0);
130 vtkInformation *outInfo = outputVector->GetInformationObject(0);
131
132 vtkPolyData *input = vtkPolyData::SafeDownCast(
133 inInfo->Get(vtkDataObject::DATA_OBJECT()));
134 vtkPolyData *output = vtkPolyData::SafeDownCast(
135 outInfo->Get(vtkDataObject::DATA_OBJECT()));
136
137 if (!this->BoundaryMetricArrayName)
138 {
139 vtkErrorMacro(<<"BoundaryMetricArrayName not set.");
140 return 1;
141 }
142
143 if (!this->GroupIdsArrayName)
144 {
145 vtkErrorMacro(<<"GroupIdsArrayName not set.");
146 return 1;
147 }
148
149 vtkDataArray* groupIdsArray = input->GetPointData()->GetArray(this->GroupIdsArrayName);
150
151 if (!groupIdsArray)
152 {
153 vtkErrorMacro(<<"GroupIdsArray with name specified does not exist.");
154 return 1;
155 }
156
157 if (!this->Centerlines)
158 {
159 vtkErrorMacro(<<"Centerlines not set");
160 return 1;
161 }
162
164 {
165 vtkErrorMacro(<<"CenterlineAbscissasArrayName not set.");
166 return 1;
167 }
168
169 vtkDataArray* centerlineAbscissasArray = this->Centerlines->GetPointData()->GetArray(this->CenterlineAbscissasArrayName);
170
171 if (!centerlineAbscissasArray)
172 {
173 vtkErrorMacro(<<"CenterlineAbscissasArray with name specified does not exist.");
174 return 1;
175 }
176
177 if (!this->CenterlineRadiusArrayName)
178 {
179 vtkErrorMacro(<<"CenterlineRadiusArrayName not set.");
180 return 1;
181 }
182
183 vtkDataArray* centerlineRadiusArray = this->Centerlines->GetPointData()->GetArray(this->CenterlineRadiusArrayName);
184
185 if (!centerlineRadiusArray)
186 {
187 vtkErrorMacro(<<"CenterlineRadiusArray with name specified does not exist.");
188 return 1;
189 }
190
192 {
193 vtkErrorMacro(<<"CenterlineGroupIdsArrayName not set.");
194 return 1;
195 }
196
197 vtkDataArray* centerlineGroupIdsArray = this->Centerlines->GetCellData()->GetArray(this->CenterlineGroupIdsArrayName);
198
199 if (!centerlineGroupIdsArray)
200 {
201 vtkErrorMacro(<<"CenterlineGroupIdsArrayName with name specified does not exist.");
202 return 1;
203 }
204
205 if (!this->CenterlineIdsArrayName)
206 {
207 vtkErrorMacro(<<"CenterlineIdsArrayName not set.");
208 return 1;
209 }
210
211 vtkDataArray* centerlineIdsArray = this->Centerlines->GetCellData()->GetArray(this->CenterlineIdsArrayName);
212
213 if (!centerlineIdsArray)
214 {
215 vtkErrorMacro(<<"CenterlineIdsArrayName with name specified does not exist.");
216 return 1;
217 }
218
220 {
221 vtkErrorMacro(<<"CenterlineTractIdsArrayName not set.");
222 return 1;
223 }
224
225 vtkDataArray* centerlineTractIdsArray = this->Centerlines->GetCellData()->GetArray(this->CenterlineTractIdsArrayName);
226
227 if (!centerlineTractIdsArray)
228 {
229 vtkErrorMacro(<<"CenterlineTractIdsArrayName with name specified does not exist.");
230 return 1;
231 }
232
233 if (!this->ReferenceSystems)
234 {
235 vtkErrorMacro(<<"ReferenceSystems not set");
236 return 1;
237 }
238
240 {
241 vtkErrorMacro(<<"ReferenceSystemGroupIdsArrayName not set.");
242 return 1;
243 }
244
245 vtkDataArray* referenceSystemGroupIdsArray = this->ReferenceSystems->GetPointData()->GetArray(this->ReferenceSystemGroupIdsArrayName);
246
247 if (!referenceSystemGroupIdsArray)
248 {
249 vtkErrorMacro(<<"ReferenceSystemGroupIdsArrayName with name specified does not exist.");
250 return 1;
251 }
252
253 int numberOfInputPoints = input->GetNumberOfPoints();
254
255 output->DeepCopy(input);
256
257 vtkDoubleArray* boundaryMetricArray = vtkDoubleArray::New();
258 boundaryMetricArray->SetName(this->BoundaryMetricArrayName);
259 boundaryMetricArray->SetNumberOfComponents(1);
260 boundaryMetricArray->SetNumberOfTuples(numberOfInputPoints);
261 boundaryMetricArray->FillComponent(0,0.0);
262
263 output->GetPointData()->AddArray(boundaryMetricArray);
264
265 // for each group, find boundaries, find centerline group, see if it's adjacent to a bifurcation, get correspondent reference system origin, evaluate mean abscissa and put value on right boundary; if not adjacent to bifucation, just put extremal centerline abscissa.
266
267 vtkIdList* groupIds = vtkIdList::New();
269 int i;
270 for (i=0; i<groupIds->GetNumberOfIds(); i++)
271 {
272 vtkIdType groupId = groupIds->GetId(i);
273 vtkPolyData* cylinder = vtkPolyData::New();
274 vtkvmtkPolyDataBranchUtilities::ExtractGroup(input,this->GroupIdsArrayName,groupId,false,cylinder);
275
277 boundaryExtractor->SetInputData(cylinder);
278 boundaryExtractor->Update();
279
280 int numberOfBoundaries = boundaryExtractor->GetOutput()->GetNumberOfCells();
281
282 if (numberOfBoundaries != 2)
283 {
284 vtkErrorMacro(<<"Branch is not topologically a cylinder");
285 return 1;
286 }
287
288 vtkIdList* centerlineGroupCellIds = vtkIdList::New();
290
292 tube->SetInput(this->Centerlines);
293 tube->SetInputCellIds(centerlineGroupCellIds);
296
297 double boundaryAbscissa[2];
298
299 int j;
300 for (j=0; j<numberOfBoundaries; j++)
301 {
302 vtkPolyLine* boundary = vtkPolyLine::SafeDownCast(boundaryExtractor->GetOutput()->GetCell(j));
303
304 if (boundary->GetNumberOfPoints() == 0)
305 {
306 vtkErrorMacro(<<"Zero-length boundary found");
307 return 1;
308 }
309
310 tube->EvaluateFunction(boundary->GetPoints()->GetPoint(0));
311
312 vtkIdType centerlineCellId = tube->GetLastPolyBallCellId();
313 vtkIdType centerlineSubId = tube->GetLastPolyBallCellSubId();
314 double centerlinePCoord = tube->GetLastPolyBallCellPCoord();
315 double abscissa = 0.0;
316 vtkvmtkCenterlineUtilities::InterpolateTuple1(this->Centerlines,this->CenterlineAbscissasArrayName,centerlineCellId,centerlineSubId,centerlinePCoord,abscissa);
317
318 boundaryAbscissa[j] = abscissa;
319 }
320
321 int boundaryOrderedIds[2];
322 boundaryOrderedIds[0] = 0;
323 boundaryOrderedIds[1] = 1;
324 if (boundaryAbscissa[0] > boundaryAbscissa[1])
325 {
326 boundaryOrderedIds[0] = 1;
327 boundaryOrderedIds[1] = 0;
328 }
329
330 // see if centerline group is adjacent to a bifurcation, get correspondent reference system origin, evaluate mean abscissa and put value on boundary; if not adjacent to bifucation, just put extremal centerline abscissa.
331
332 vtkIdList* upStreamGroupIds = vtkIdList::New();
333 vtkIdList* downStreamGroupIds = vtkIdList::New();
334
336
337 if ((upStreamGroupIds->GetNumberOfIds() > 1) || (downStreamGroupIds->GetNumberOfIds() > 1))
338 {
339 vtkErrorMacro(<<"More than one adjacent group found for current group. Not topologically a cylinder.");
340 return 1;
341 }
342
343 vtkIdType referenceSystemGroupIds[2];
344 referenceSystemGroupIds[0] = -1;
345 referenceSystemGroupIds[1] = -1;
346 vtkIdType referenceSystemPointIds[2];
347 referenceSystemPointIds[0] = -1;
348 referenceSystemPointIds[1] = -1;
349
350 if (upStreamGroupIds->GetNumberOfIds() > 0)
351 {
352 referenceSystemGroupIds[0] = upStreamGroupIds->GetId(0);
353 }
354
355 if (downStreamGroupIds->GetNumberOfIds() > 0)
356 {
357 referenceSystemGroupIds[1] = downStreamGroupIds->GetId(0);
358 }
359
360 int n;
361 for (n=0; n<2; n++)
362 {
363 if (referenceSystemGroupIds[n] == -1)
364 {
365 continue;
366 }
367 referenceSystemPointIds[n] = vtkvmtkReferenceSystemUtilities::GetReferenceSystemPointId(this->ReferenceSystems,this->ReferenceSystemGroupIdsArrayName,referenceSystemGroupIds[n]);
368 if (referenceSystemPointIds[n] == -1)
369 {
370 vtkErrorMacro(<<"Centerline group ids and reference system group ids are inconsistent.");
371 return 1;
372 }
373 }
374
375 // now, we have the origins and the corresponding boundaries. Compute average origin abscissa and put it in on the right boundary.
376 // if no boundary, put minimal abscissa in group
377
378 double referenceSystemAbscissas[2];
379 referenceSystemAbscissas[0] = 0.0;
380 referenceSystemAbscissas[1] = 0.0;
381
382 for (n=0; n<2; n++)
383 {
384 if (referenceSystemGroupIds[n] != -1)
385 {
386// Compute average origin abscissa and store it in referenceSystemAbscissas[n]. TODO: this one could be stored in ReferenceSystems as Abscissas array
387
389
390 double weightSum = 0.0;
391
392 vtkIdList* centerlineGroupAllCellIds = vtkIdList::New();
393 vtkvmtkCenterlineUtilities::GetGroupUniqueCellIds(this->Centerlines,this->CenterlineGroupIdsArrayName,referenceSystemGroupIds[n],centerlineGroupAllCellIds);
394 for (j=0; j<centerlineGroupAllCellIds->GetNumberOfIds(); j++)
395 {
396 centerlineGroupCellIds->Initialize();
397 centerlineGroupCellIds->InsertNextId(centerlineGroupAllCellIds->GetId(j));
398
399 tube->SetInputCellIds(centerlineGroupCellIds);
400 tube->EvaluateFunction(this->ReferenceSystems->GetPoint(referenceSystemPointIds[n]));
401
402 vtkIdType centerlineCellId = tube->GetLastPolyBallCellId();
403 vtkIdType centerlineSubId = tube->GetLastPolyBallCellSubId();
404 double centerlinePCoord = tube->GetLastPolyBallCellPCoord();
405
406 double radius = 0.0;
407 vtkvmtkCenterlineUtilities::InterpolateTuple1(this->Centerlines,this->CenterlineRadiusArrayName,centerlineCellId,centerlineSubId,centerlinePCoord,radius);
408 double weight = radius * radius;
409 double abscissa = 0.0;
410 vtkvmtkCenterlineUtilities::InterpolateTuple1(this->Centerlines,this->CenterlineAbscissasArrayName,centerlineCellId,centerlineSubId,centerlinePCoord,abscissa);
411
412 referenceSystemAbscissas[n] += weight * abscissa;
413 weightSum += weight;
414 }
415 referenceSystemAbscissas[n] /= weightSum;
416 }
417 else
418 {
419// Compute extremal abscissa in group and store it in referenceSystemAbscissas[n]
420 if (n==0)
421 {
422 referenceSystemAbscissas[n] = VTK_DOUBLE_MAX;
423
424 vtkIdList* centerlineGroupCellIds = vtkIdList::New();
426 for (j=0; j<centerlineGroupCellIds->GetNumberOfIds(); j++)
427 {
428 vtkIdType centerlineCellId = centerlineGroupCellIds->GetId(j);
429 double abscissa = centerlineAbscissasArray->GetComponent(this->Centerlines->GetCell(centerlineCellId)->GetPointId(0),0);
430 if (abscissa < referenceSystemAbscissas[n])
431 {
432 referenceSystemAbscissas[n] = abscissa;
433 }
434 }
435 centerlineGroupCellIds->Delete();
436 }
437 else if (n==1)
438 {
439 referenceSystemAbscissas[n] = VTK_DOUBLE_MIN;
440
441 vtkIdList* centerlineGroupCellIds = vtkIdList::New();
443 for (j=0; j<centerlineGroupCellIds->GetNumberOfIds(); j++)
444 {
445 vtkIdType centerlineCellId = centerlineGroupCellIds->GetId(j);
446
447 int numberOfCellPoints = this->Centerlines->GetCell(centerlineCellId)->GetNumberOfPoints();
448 double abscissa = centerlineAbscissasArray->GetComponent(this->Centerlines->GetCell(centerlineCellId)->GetPointId(numberOfCellPoints-1),0);
449 if (abscissa > referenceSystemAbscissas[n])
450 {
451 referenceSystemAbscissas[n] = abscissa;
452 }
453 }
454 }
455 }
456 }
457
458// put abscissas in the right place
459
460 for (n=0; n<2; n++)
461 {
462 vtkCell* boundary = boundaryExtractor->GetOutput()->GetCell(boundaryOrderedIds[n]);
463 vtkDataArray* boundaryPointIds = boundaryExtractor->GetOutput()->GetPointData()->GetScalars();
464 int numberOfBoundaryPoints = boundary->GetNumberOfPoints();
465 for (j=0; j<numberOfBoundaryPoints; j++)
466 {
467 vtkIdType boundaryPointId = static_cast<int>(boundaryPointIds->GetComponent(boundary->GetPointId(j),0));
468 boundaryMetricArray->SetComponent(boundaryPointId,0,referenceSystemAbscissas[n]);
469 }
470 }
471
472 tube->Delete();
473 centerlineGroupCellIds->Delete();
474 boundaryExtractor->Delete();
475 cylinder->Delete();
476 upStreamGroupIds->Delete();
477 downStreamGroupIds->Delete();
478 }
479
480 groupIds->Delete();
481 boundaryMetricArray->Delete();
482
483 return 1;
484}
485
static void GetGroupCellIds(vtkPolyData *centerlines, const char *groupIdsArrayName, vtkIdType groupId, vtkIdList *groupCellIds)
static void GetGroupUniqueCellIds(vtkPolyData *centerlines, const char *groupIdsArrayName, vtkIdType groupId, vtkIdList *groupCellIds)
static void InterpolateTuple1(vtkPolyData *centerlines, const char *arrayName, int cellId, int subId, double pcoord, double &interpolatedTuple1)
static void FindAdjacentCenterlineGroupIds(vtkPolyData *centerlines, const char *groupIdsArrayName, const char *centerlineIdsArrayName, const char *tractIdsArrayName, vtkIdType groupId, vtkIdList *upStreamGroupIds, vtkIdList *downStreamGroupIds)
Implements vtkImplicitFunction to evaluate the minimum sphere function for an envelope created by an ...
virtual double GetLastPolyBallCellPCoord()
virtual void SetInput(vtkPolyData *)
virtual void SetPolyBallRadiusArrayName(const char *)
virtual void SetInputCellIds(vtkIdList *)
virtual vtkIdType GetLastPolyBallCellId()
static vtkvmtkPolyBallLine * New()
double EvaluateFunction(double x[3]) override
virtual vtkIdType GetLastPolyBallCellSubId()
virtual void UseRadiusInformationOn()
virtual void UseRadiusInformationOff()
Extract boundary edges as poly lines.
static vtkvmtkPolyDataBoundaryExtractor * New()
static void ExtractGroup(vtkPolyData *surface, const char *groupIdsArrayName, vtkIdType groupId, bool cleanGroupSurface, vtkPolyData *groupSurface)
static void GetGroupsIdList(vtkPolyData *surface, const char *groupIdsArrayName, vtkIdList *groupIds)
Compute a per-branch-boundary longitudinal (abscissa) Dirichlet condition, expressed in the reference...
virtual int RequestData(vtkInformation *, vtkInformationVector **, vtkInformationVector *) override
static vtkIdType GetReferenceSystemPointId(vtkPolyData *referenceSystems, const char *groupIdsArrayName, vtkIdType groupId)
vtkStandardNewMacro(vtkvmtkPolyDataReferenceSystemBoundaryMetricFilter)