VMTK
Loading...
Searching...
No Matches
vtkvmtkPolyDataCenterlines.cxx
Go to the documentation of this file.
1/*=========================================================================
2
3Program: VMTK
4Module: $RCSfile: vtkvmtkPolyDataCenterlines.cxx,v $
5Language: C++
6Date: $Date: 2006/04/06 16:46:43 $
7Version: $Revision: 1.6 $
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 "vtkvmtkConstants.h"
24#include "vtkPolyDataNormals.h"
25#include "vtkDelaunay3D.h"
29#include "vtkArrayCalculator.h"
32#include "vtkMath.h"
33#include "vtkPolyData.h"
34#include "vtkUnstructuredGrid.h"
35#include "vtkTetra.h"
36#include "vtkPointData.h"
37#include "vtkCellData.h"
38#include "vtkIdList.h"
39#include "vtkInformation.h"
40#include "vtkInformationVector.h"
41#include "vtkObjectFactory.h"
42#include "vtkVersion.h"
43
45
49
51{
52 this->SourceSeedIds = NULL;
53 this->TargetSeedIds = NULL;
54 this->CapCenterIds = NULL;
55
56 this->RadiusArrayName = NULL;
57 this->CostFunction = new char[16];
58 strcpy(this->CostFunction,"1/R");
59
60 this->CostFunctionArrayName = new char[256];
61 strcpy(this->CostFunctionArrayName,"CostFunctionArray");
62
63 this->EikonalSolutionArrayName = new char[256];
64 strcpy(this->EikonalSolutionArrayName,"EikonalSolutionArray");
65
66 this->EdgeArrayName = new char[256];
67 strcpy(this->EdgeArrayName,"EdgeArray");
68
69 this->EdgePCoordArrayName = new char[256];
70 strcpy(this->EdgePCoordArrayName,"EdgePCoordArray");
71
72 this->FlipNormals = 0;
73 this->SimplifyVoronoi = 0;
74 this->CenterlineResampling = 0;
76
77 this->ResamplingStepLength = 1.0;
78
80
81 this->DelaunayTessellation = NULL;
82 this->DelaunayTolerance = 1E-3;
83
84 this->GenerateVoronoiDiagram = 1;
86 this->VoronoiDiagram = NULL;
87 this->PoleIds = NULL;
88}
89
91{
92 if (this->SourceSeedIds)
93 {
94 this->SourceSeedIds->Delete();
95 this->SourceSeedIds = NULL;
96 }
97
98 if (this->TargetSeedIds)
99 {
100 this->TargetSeedIds->Delete();
101 this->TargetSeedIds = NULL;
102 }
103
104 if (this->CapCenterIds)
105 {
106 this->CapCenterIds->Delete();
107 this->CapCenterIds = NULL;
108 }
109
110 if (this->CostFunction)
111 {
112 delete[] this->CostFunction;
113 this->CostFunction = NULL;
114 }
115
116 if (this->CostFunctionArrayName)
117 {
118 delete[] this->CostFunctionArrayName;
119 this->CostFunctionArrayName = NULL;
120 }
121
122 if (this->EikonalSolutionArrayName)
123 {
124 delete[] this->EikonalSolutionArrayName;
125 this->EikonalSolutionArrayName = NULL;
126 }
127
128 if (this->EdgeArrayName)
129 {
130 delete[] this->EdgeArrayName;
131 this->EdgeArrayName = NULL;
132 }
133
134 if (this->EdgePCoordArrayName)
135 {
136 delete[] this->EdgePCoordArrayName;
137 this->EdgePCoordArrayName = NULL;
138 }
139
140 if (this->RadiusArrayName)
141 {
142 delete[] this->RadiusArrayName;
143 this->RadiusArrayName = NULL;
144 }
145
146 if (this->DelaunayTessellation)
147 {
148 this->DelaunayTessellation->Delete();
149 this->DelaunayTessellation = NULL;
150 }
151
152 if (this->VoronoiDiagram)
153 {
154 this->VoronoiDiagram->Delete();
155 this->VoronoiDiagram = NULL;
156 }
157
158 if (this->PoleIds)
159 {
160 this->PoleIds->Delete();
161 this->PoleIds = NULL;
162 }
163
164}
165
167 vtkInformation *vtkNotUsed(request),
168 vtkInformationVector **inputVector,
169 vtkInformationVector *outputVector)
170{
171 vtkInformation *inInfo = inputVector[0]->GetInformationObject(0);
172 vtkInformation *outInfo = outputVector->GetInformationObject(0);
173
174 vtkPolyData *input = vtkPolyData::SafeDownCast(
175 inInfo->Get(vtkDataObject::DATA_OBJECT()));
176 vtkPolyData *output = vtkPolyData::SafeDownCast(
177 outInfo->Get(vtkDataObject::DATA_OBJECT()));
178
179 if (!this->SourceSeedIds)
180 {
181 vtkErrorMacro(<< "No SourceSeedIds set.");
182 return 1;
183 }
184
185 if (!this->TargetSeedIds)
186 {
187 vtkErrorMacro(<< "No TargetSeedIds set.");
188 return 1;
189 }
190
191 if (!this->RadiusArrayName)
192 {
193 vtkErrorMacro(<< "No RadiusArrayName set.");
194 return 1;
195 }
196
198 {
199 vtkErrorMacro(<< "GenerateDelaunayTessellation is off but a DelaunayTessellation has not been set.");
200 return 1;
201 }
202
203 if (!this->GenerateVoronoiDiagram && !this->VoronoiDiagram)
204 {
205 vtkErrorMacro(<< "GenerateVoronoiDiagram is off but a VoronoiDiagram has not been set.");
206 return 1;
207 }
208
209 if (!this->GenerateVoronoiDiagram && !this->PoleIds)
210 {
211 vtkErrorMacro(<< "GenerateVoronoiDiagram is off but Voronoi PoleIds have not been set.");
212 return 1;
213 }
214
215 // Since VTK 9.4, vtkPolyDataNormals passes pre-existing normals through
216 // unchanged instead of recomputing them, so inherited input normals would
217 // bypass AutoOrientNormals and feed arbitrarily oriented normals to the
218 // internal tetrahedra classification below, breaking the Voronoi diagram
219 // and centerline backtracing. Strip them so outward-oriented normals are
220 // always recomputed.
221 vtkPolyData* inputWithoutNormals = vtkPolyData::New();
222 inputWithoutNormals->ShallowCopy(input);
223 inputWithoutNormals->GetPointData()->SetNormals(NULL);
224 inputWithoutNormals->GetCellData()->SetNormals(NULL);
225
226 vtkPolyDataNormals* surfaceNormals = vtkPolyDataNormals::New();
227 surfaceNormals->SetInputData(inputWithoutNormals);
228 inputWithoutNormals->Delete();
229 surfaceNormals->SplittingOff();
230 surfaceNormals->AutoOrientNormalsOn();
231 surfaceNormals->SetFlipNormals(this->FlipNormals);
232 surfaceNormals->ComputePointNormalsOn();
233 surfaceNormals->ConsistencyOn();
234 surfaceNormals->Update();
235
237 {
238 vtkDelaunay3D* delaunayTessellator = vtkDelaunay3D::New();
239 delaunayTessellator->CreateDefaultLocator();
240 delaunayTessellator->SetInputConnection(surfaceNormals->GetOutputPort());
241 delaunayTessellator->SetTolerance(this->DelaunayTolerance);
242 delaunayTessellator->Update();
243
244 vtkUnstructuredGrid* delaunay = delaunayTessellator->GetOutput();
245 delaunay->GetPointData()->AddArray(surfaceNormals->GetOutput()->GetPointData()->GetNormals());
246
248 internalTetrahedraExtractor->SetInputConnection(delaunayTessellator->GetOutputPort());
249 if (!surfaceNormals
250 || !surfaceNormals->GetOutput()
251 || !surfaceNormals->GetOutput()->GetPointData()
252 || !surfaceNormals->GetOutput()->GetPointData()->GetNormals()
253 || !surfaceNormals->GetOutput()->GetPointData()->GetNormals()->GetName())
254 {
255 vtkErrorMacro(<< "Centerline extraction failed: could not compute surface normals");
256 return 1;
257 }
258
259 internalTetrahedraExtractor->SetOutwardNormalsArrayName(surfaceNormals->GetOutput()->GetPointData()->GetNormals()->GetName());
260
261 if (this->CapCenterIds)
262 {
263 internalTetrahedraExtractor->UseCapsOn();
264 internalTetrahedraExtractor->SetCapCenterIds(this->CapCenterIds);
265 }
266
267 internalTetrahedraExtractor->Update();
268
269 this->DelaunayTessellation = internalTetrahedraExtractor->GetOutput();
270 this->DelaunayTessellation->Register(this);
271
272 delaunayTessellator->Delete();
273 internalTetrahedraExtractor->Delete();
274 }
275
276 if (this->GenerateVoronoiDiagram)
277 {
279 voronoiDiagramFilter->SetInputData(this->DelaunayTessellation);
280 voronoiDiagramFilter->SetRadiusArrayName(this->RadiusArrayName);
281 voronoiDiagramFilter->Update();
282
283 this->PoleIds = vtkIdList::New();
284 this->PoleIds->DeepCopy(voronoiDiagramFilter->GetPoleIds());
285
286 vtkPolyData* voronoiDiagram = voronoiDiagramFilter->GetOutput();
287
288 if (this->SimplifyVoronoi)
289 {
291 voronoiDiagramSimplifier->SetInputConnection(voronoiDiagramFilter->GetOutputPort());
292 voronoiDiagramSimplifier->SetUnremovablePointIds(voronoiDiagramFilter->GetPoleIds());
293 voronoiDiagramSimplifier->Update();
294 voronoiDiagram = voronoiDiagramSimplifier->GetOutput();
295 voronoiDiagram->Register(this);
296 voronoiDiagramSimplifier->Delete();
297 }
298 this->VoronoiDiagram = vtkPolyData::New();
299 this->VoronoiDiagram->DeepCopy(voronoiDiagram);
300 voronoiDiagramFilter->Delete();
301 }
302
303 #if defined(__EMSCRIPTEN__)
304 vtkNew<vtkDoubleArray> array;
305 array->SetName(this->CostFunctionArrayName);
306 auto outputArray = dynamic_cast<vtkDoubleArray *>(
307 this->VoronoiDiagram->GetPointData()->GetArray(this->RadiusArrayName));
308
309 for (int i = 0; i < outputArray->GetNumberOfTuples(); i++)
310 {
311 array->InsertNextValue(1 / outputArray->GetValue(i));
312 }
313 this->VoronoiDiagram->GetPointData()->AddArray(array);
314 #else
315 vtkArrayCalculator *voronoiCostFunctionCalculator = vtkArrayCalculator::New();
316 voronoiCostFunctionCalculator->SetInputData(this->VoronoiDiagram);
317 voronoiCostFunctionCalculator->SetAttributeTypeToPointData();
318 voronoiCostFunctionCalculator->AddScalarVariable("R", this->RadiusArrayName, 0);
319 voronoiCostFunctionCalculator->SetFunction(this->CostFunction);
320 voronoiCostFunctionCalculator->SetResultArrayName(this->CostFunctionArrayName);
321 voronoiCostFunctionCalculator->Update();
322 #endif
323
324 vtkIdList* voronoiSourceSeedIds = vtkIdList::New();
325 vtkIdList* voronoiTargetSeedIds = vtkIdList::New();
326
327 vtkIdList* voronoiSeeds = vtkIdList::New();
328
329 int i;
330 if (this->CapCenterIds)
331 {
332 this->FindVoronoiSeeds(this->DelaunayTessellation,this->CapCenterIds,surfaceNormals->GetOutput()->GetPointData()->GetNormals(),voronoiSeeds);
333 for (i=0; i<this->SourceSeedIds->GetNumberOfIds(); i++)
334 {
335 voronoiSourceSeedIds->InsertNextId(voronoiSeeds->GetId(this->SourceSeedIds->GetId(i)));
336 }
337 for (i=0; i<this->TargetSeedIds->GetNumberOfIds(); i++)
338 {
339 voronoiTargetSeedIds->InsertNextId(voronoiSeeds->GetId(this->TargetSeedIds->GetId(i)));
340 }
341 }
342 else
343 {
344 for (i=0; i<this->SourceSeedIds->GetNumberOfIds(); i++)
345 {
346 voronoiSourceSeedIds->InsertNextId(this->PoleIds->GetId(this->SourceSeedIds->GetId(i)));
347 }
348 for (i=0; i<this->TargetSeedIds->GetNumberOfIds(); i++)
349 {
350 voronoiTargetSeedIds->InsertNextId(this->PoleIds->GetId(this->TargetSeedIds->GetId(i)));
351 }
352 }
353
355 #if defined(__EMSCRIPTEN__)
356 voronoiFastMarching->SetInputData(this->VoronoiDiagram);
357 #else
358 voronoiFastMarching->SetInputConnection(voronoiCostFunctionCalculator->GetOutputPort());
359 #endif
360 voronoiFastMarching->SetCostFunctionArrayName(this->CostFunctionArrayName);
361 voronoiFastMarching->SetSolutionArrayName(this->EikonalSolutionArrayName);
363 {
364 voronoiFastMarching->SetStopSeedId(voronoiTargetSeedIds);
365 }
366 voronoiFastMarching->SeedsBoundaryConditionsOn();
367 voronoiFastMarching->SetSeeds(voronoiSourceSeedIds);
368 voronoiFastMarching->Update();
369
370 this->VoronoiDiagram->ShallowCopy(voronoiFastMarching->GetOutput());
371
373 centerlineBacktracing->SetInputConnection(voronoiFastMarching->GetOutputPort());
374 centerlineBacktracing->SetDataArrayName(this->RadiusArrayName);
375 centerlineBacktracing->SetDescentArrayName(this->EikonalSolutionArrayName);
376 centerlineBacktracing->SetEdgeArrayName(this->EdgeArrayName);
377 centerlineBacktracing->SetEdgePCoordArrayName(this->EdgePCoordArrayName);
378 centerlineBacktracing->SetSeeds(voronoiTargetSeedIds);
379 centerlineBacktracing->MergePathsOff();
380 centerlineBacktracing->StopOnTargetsOn();
381 centerlineBacktracing->SetTargets(voronoiSourceSeedIds);
382 centerlineBacktracing->Update();
383
384 output->ShallowCopy(centerlineBacktracing->GetOutput());
385
386 vtkIdList* hitTargets = centerlineBacktracing->GetHitTargets();
387
388 vtkPoints* endPointPairs = vtkPoints::New();
389
390 const vtkIdType numTargetSeedIds = this->TargetSeedIds->GetNumberOfIds();
391 const vtkIdType numHitTargets = hitTargets->GetNumberOfIds();
392 if(numHitTargets == numTargetSeedIds) {
394 {
395 for (i=0; i<numTargetSeedIds; i++)
396 {
397 if (this->CapCenterIds)
398 {
399 vtkIdType endPointId1 = this->CapCenterIds->GetId(this->TargetSeedIds->GetId(i));
400 vtkIdType hitTargetPointId = hitTargets->GetId(i);
401 vtkIdType targetId = voronoiSourceSeedIds->IsId(hitTargetPointId);
402 vtkIdType endPointId2 = this->CapCenterIds->GetId(this->SourceSeedIds->GetId(targetId));
403 endPointPairs->InsertNextPoint(input->GetPoint(endPointId1));
404 endPointPairs->InsertNextPoint(input->GetPoint(endPointId2));
405 }
406 else
407 {
408 vtkIdType endPointId1 = this->TargetSeedIds->GetId(i);
409 vtkIdType hitTargetPointId = hitTargets->GetId(i);
410 vtkIdType targetId = voronoiSourceSeedIds->IsId(hitTargetPointId);
411 vtkIdType endPointId2 = this->SourceSeedIds->GetId(targetId);
412 endPointPairs->InsertNextPoint(input->GetPoint(endPointId1));
413 endPointPairs->InsertNextPoint(input->GetPoint(endPointId2));
414 }
415 }
416
417 this->AppendEndPoints(endPointPairs);
418 }
419 }
420
421 if (this->CenterlineResampling)
422 {
423 this->ResampleCenterlines();
424 }
425 this->ReverseCenterlines();
426
427 surfaceNormals->Delete();
428 #if !defined(__EMSCRIPTEN__)
429 voronoiCostFunctionCalculator->Delete();
430 #endif
431 voronoiSeeds->Delete();
432 voronoiSourceSeedIds->Delete();
433 voronoiTargetSeedIds->Delete();
434 voronoiFastMarching->Delete();
435 centerlineBacktracing->Delete();
436 endPointPairs->Delete();
437
438 return 1;
439}
440
441void vtkvmtkPolyDataCenterlines::FindVoronoiSeeds(vtkUnstructuredGrid *delaunay, vtkIdList *boundaryBaricenterIds, vtkDataArray *normals, vtkIdList *seedIds)
442{
443 vtkIdType i, j;
444 vtkIdList *pointCells;
445 vtkIdType baricenterId;
446 double baricenter[3], normal[3];
447 double maxRadius, secondMaxRadius;
448 vtkTetra* tetra;
449 double p0[3], p1[3], p2[3], p3[3];
450 double circumcenter[3], circumradius, tetraRadius;
451 double referenceVector[3];
452 double pole[3], poleVector[3], secondPole[3], secondPoleVector[3];
453 pole[0] = pole[1] = pole[2] = 0.0;
454 vtkIdType maxRadiusCellId, secondMaxRadiusCellId;
455
456 pointCells = vtkIdList::New();
457
458 for (i=0; i<boundaryBaricenterIds->GetNumberOfIds(); i++)
459 {
460 baricenterId = boundaryBaricenterIds->GetId(i);
461 delaunay->GetPoint(baricenterId,baricenter);
462 normals->GetTuple(baricenterId,normal);
463 pointCells->Initialize();
464 delaunay->GetPointCells(baricenterId,pointCells);
465 maxRadius = 0.0;
466 maxRadiusCellId = -1;
467 secondMaxRadiusCellId = -1;
468
469 for (j=0; j<pointCells->GetNumberOfIds(); j++)
470 {
471 tetra = vtkTetra::SafeDownCast(delaunay->GetCell(pointCells->GetId(j)));
472 tetra->GetPoints()->GetPoint(0,p0);
473 tetra->GetPoints()->GetPoint(1,p1);
474 tetra->GetPoints()->GetPoint(2,p2);
475 tetra->GetPoints()->GetPoint(3,p3);
476
477 circumradius = vtkTetra::Circumsphere(p0,p1,p2,p3,circumcenter);
478 tetraRadius = sqrt(circumradius);
479
480 if (tetraRadius - maxRadius > VTK_VMTK_DOUBLE_TOL)
481 {
482 maxRadius = tetraRadius;
483 maxRadiusCellId = pointCells->GetId(j);
484 pole[0] = circumcenter[0];
485 pole[1] = circumcenter[1];
486 pole[2] = circumcenter[2];
487 }
488 }
489
490 poleVector[0] = pole[0] - baricenter[0];
491 poleVector[1] = pole[1] - baricenter[1];
492 poleVector[2] = pole[2] - baricenter[2];
493
494 secondMaxRadius = 0.0;
495
496 for (j=0; j<pointCells->GetNumberOfIds(); j++)
497 {
498 tetra = vtkTetra::SafeDownCast(delaunay->GetCell(pointCells->GetId(j)));
499 tetra->GetPoints()->GetPoint(0,p0);
500 tetra->GetPoints()->GetPoint(1,p1);
501 tetra->GetPoints()->GetPoint(2,p2);
502 tetra->GetPoints()->GetPoint(3,p3);
503
504 circumradius = vtkTetra::Circumsphere(p0,p1,p2,p3,circumcenter);
505 tetraRadius = sqrt(circumradius);
506
507 referenceVector[0] = circumcenter[0] - baricenter[0];
508 referenceVector[1] = circumcenter[1] - baricenter[1];
509 referenceVector[2] = circumcenter[2] - baricenter[2];
510
511 if ((tetraRadius - secondMaxRadius > VTK_VMTK_DOUBLE_TOL) && (vtkMath::Dot(poleVector,referenceVector) < VTK_VMTK_DOUBLE_TOL))
512 {
513 secondMaxRadius = tetraRadius;
514 secondMaxRadiusCellId = pointCells->GetId(j);
515 secondPole[0] = circumcenter[0];
516 secondPole[1] = circumcenter[1];
517 secondPole[2] = circumcenter[2];
518 }
519 }
520
521 secondPoleVector[0] = secondPole[0] - baricenter[0];
522 secondPoleVector[1] = secondPole[1] - baricenter[1];
523 secondPoleVector[2] = secondPole[2] - baricenter[2];
524
525 if (vtkMath::Dot(poleVector,normal) < VTK_VMTK_DOUBLE_TOL)
526 {
527 seedIds->InsertNextId(maxRadiusCellId);
528 }
529 else
530 {
531 seedIds->InsertNextId(secondMaxRadiusCellId);
532 }
533 }
534
535 pointCells->Delete();
536}
537
539{
540 vtkIdType endPointId1, endPointId2;
541 vtkPolyData* output = this->GetOutput();
542 vtkPolyData* completeCenterlines = vtkPolyData::New();
543 vtkPoints* completeCenterlinesPoints = vtkPoints::New();
544 vtkCellArray* completeCenterlinesCellArray = vtkCellArray::New();
545 vtkDoubleArray* completeCenterlinesRadiusArray = vtkDoubleArray::New();
546 completeCenterlinesRadiusArray->SetName(this->RadiusArrayName);
547 vtkIdList* completeCell = vtkIdList::New();
548
549 vtkDoubleArray* centerlinesRadiusArray = vtkDoubleArray::SafeDownCast(output->GetPointData()->GetArray(this->RadiusArrayName));
550
551 completeCenterlinesPoints->DeepCopy(output->GetPoints());
552 completeCenterlinesRadiusArray->DeepCopy(centerlinesRadiusArray);
553
554 for (int k=0; k<output->GetNumberOfCells(); k++)
555 {
556 vtkCell* cell = output->GetCell(k);
557
558 endPointId1 = completeCenterlinesPoints->InsertNextPoint(endPointPairs->GetPoint(2*k));
559 endPointId2 = completeCenterlinesPoints->InsertNextPoint(endPointPairs->GetPoint(2*k+1));
560
561 completeCell->Initialize();
562 completeCell->SetNumberOfIds(cell->GetNumberOfPoints()+2);
563
564 completeCell->SetId(0,endPointId1);
565
566 for (int i=0; i<cell->GetNumberOfPoints(); i++)
567 {
568 completeCell->SetId(i+1,cell->GetPointId(i));
569 }
570 completeCell->SetId(cell->GetNumberOfPoints()+1,endPointId2);
571
572 completeCenterlinesCellArray->InsertNextCell(completeCell);
573
574 completeCenterlinesRadiusArray->InsertNextValue(centerlinesRadiusArray->GetValue(cell->GetPointId(0)));
575 completeCenterlinesRadiusArray->InsertNextValue(centerlinesRadiusArray->GetValue(cell->GetPointId(cell->GetNumberOfPoints()-1)));
576 }
577
578 completeCenterlines->SetPoints(completeCenterlinesPoints);
579 completeCenterlines->SetLines(completeCenterlinesCellArray);
580 completeCenterlines->GetPointData()->AddArray(completeCenterlinesRadiusArray);
581
582 output->ShallowCopy(completeCenterlines);
583
584 completeCell->Delete();
585 completeCenterlines->Delete();
586 completeCenterlinesPoints->Delete();
587 completeCenterlinesCellArray->Delete();
588 completeCenterlinesRadiusArray->Delete();
589}
590
592{
593 vtkPolyData* output = this->GetOutput();
594 vtkPolyData* resampledCenterlines = vtkPolyData::New();
595 vtkPoints* resampledCenterlinesPoints = vtkPoints::New();
596 vtkCellArray* resampledCenterlinesCellArray = vtkCellArray::New();
597 vtkDoubleArray* resampledCenterlinesRadiusArray = vtkDoubleArray::New();
598 resampledCenterlinesRadiusArray->SetName(this->RadiusArrayName);
599 vtkIdList* resampledCell = vtkIdList::New();
600
601 vtkDoubleArray* centerlinesRadiusArray = vtkDoubleArray::SafeDownCast(output->GetPointData()->GetArray(this->RadiusArrayName));
602
603 for (int k=0; k<output->GetNumberOfCells(); k++)
604 {
605 vtkCell* cell = output->GetCell(k);
606
607 resampledCell->Initialize();
608
609 vtkIdType id = resampledCenterlinesPoints->InsertNextPoint(cell->GetPoints()->GetPoint(0));
610 resampledCell->InsertNextId(id);
611 resampledCenterlinesRadiusArray->InsertNextValue(centerlinesRadiusArray->GetValue(cell->GetPointId(0)));
612
613 double point0[3], point1[3], point[3];
614 double abscissa, lineAbscissa, lineLength, stepAbscissa;
615
616 abscissa = 0.0;
617 lineAbscissa = 0.0;
618 lineLength = 0.0;
619 stepAbscissa = 0.0;
620
621 for (int i=0; i<cell->GetNumberOfPoints()-1; i++)
622 {
623 cell->GetPoints()->GetPoint(i,point0);
624 cell->GetPoints()->GetPoint(i+1,point1);
625
626 double scalar0 = centerlinesRadiusArray->GetValue(cell->GetPointId(i));
627 double scalar1 = centerlinesRadiusArray->GetValue(cell->GetPointId(i+1));
628
629 double length = sqrt(vtkMath::Distance2BetweenPoints(point0,point1));
630
631 if (length < this->ResamplingStepLength - stepAbscissa)
632 {
633 stepAbscissa = stepAbscissa + length;
634 continue;
635 }
636
637 double pcoord = 0.0;
638 double pcoordStep = this->ResamplingStepLength / length;
639 while (pcoord < 1.0)
640 {
641 point[0] = point0[0] + (point1[0] - point0[0]) * pcoord;
642 point[1] = point0[1] + (point1[1] - point0[1]) * pcoord;
643 point[2] = point0[2] + (point1[2] - point0[2]) * pcoord;
644
645 double scalar = scalar0 + (scalar1 - scalar0) * pcoord;
646
647 vtkIdType id = resampledCenterlinesPoints->InsertNextPoint(point);
648 resampledCell->InsertNextId(id);
649 resampledCenterlinesRadiusArray->InsertNextValue(scalar);
650
651 if (pcoord + pcoordStep > 1.0)
652 {
653 break;
654 }
655 pcoord = pcoord + pcoordStep;
656 }
657 stepAbscissa = (1.0 - pcoord) * length;
658 }
659
660 id = resampledCenterlinesPoints->InsertNextPoint(cell->GetPoints()->GetPoint(cell->GetNumberOfPoints()-1));
661 resampledCell->InsertNextId(id);
662 resampledCenterlinesRadiusArray->InsertNextValue(centerlinesRadiusArray->GetValue(cell->GetPointId(cell->GetNumberOfPoints()-1)));
663
664 resampledCenterlinesCellArray->InsertNextCell(resampledCell);
665 }
666 resampledCenterlines->SetPoints(resampledCenterlinesPoints);
667 resampledCenterlines->SetLines(resampledCenterlinesCellArray);
668 resampledCenterlines->GetPointData()->AddArray(resampledCenterlinesRadiusArray);
669
670 output->ShallowCopy(resampledCenterlines);
671
672 resampledCenterlines->Delete();
673 resampledCenterlinesPoints->Delete();
674 resampledCenterlinesCellArray->Delete();
675 resampledCenterlinesRadiusArray->Delete();
676 resampledCell->Delete();
677}
678
680{
681 vtkPolyData* output = this->GetOutput();
682
683 vtkCellArray* reversedCenterlinesCellArray = vtkCellArray::New();
684 vtkIdList* reversedCell = vtkIdList::New();
685
686 for (int k=0; k<output->GetNumberOfCells(); k++)
687 {
688 vtkCell* cell = output->GetCell(k);
689
690 reversedCell->Initialize();
691
692 vtkIdType numberOfCellPoints = cell->GetNumberOfPoints();
693
694 for (int i=0; i<numberOfCellPoints; i++)
695 {
696 vtkIdType id = cell->GetPointId(numberOfCellPoints-1-i);
697 reversedCell->InsertNextId(id);
698 }
699 reversedCenterlinesCellArray->InsertNextCell(reversedCell);
700 }
701
702 output->SetLines(reversedCenterlinesCellArray);
703
704 reversedCell->Delete();
705 reversedCenterlinesCellArray->Delete();
706}
707
708void vtkvmtkPolyDataCenterlines::PrintSelf(std::ostream& os, vtkIndent indent)
709{
710 this->Superclass::PrintSelf(os,indent);
711}
Extract internal tetrahedra from a Delaunay tessellation of a surface.
static vtkvmtkInternalTetrahedraExtractor * New()
virtual void SetCapCenterIds(vtkIdList *)
virtual void SetOutwardNormalsArrayName(const char *)
Implements the Fast Marching Method on polygonal non-manifolds.
virtual void SeedsBoundaryConditionsOn()
virtual void SetSeeds(vtkIdList *)
static vtkvmtkNonManifoldFastMarching * New()
virtual void SetStopSeedId(vtkIdList *)
virtual void SetCostFunctionArrayName(const char *)
virtual void SetSolutionArrayName(const char *)
virtual void SetDescentArrayName(const char *)
Compute centerlines from surface.
void AppendEndPoints(vtkPoints *endPointPairs)
void FindVoronoiSeeds(vtkUnstructuredGrid *delaunay, vtkIdList *boundaryBaricenterIds, vtkDataArray *normals, vtkIdList *seedIds)
void PrintSelf(std::ostream &os, vtkIndent indent) override
virtual int RequestData(vtkInformation *, vtkInformationVector **, vtkInformationVector *) override
Remove non essential Voronoi polygon points (little spikes).
static vtkvmtkSimplifyVoronoiDiagram * New()
virtual void SetUnremovablePointIds(vtkIdList *)
Trace the steepest descent line over a polygonal non-manifold.
virtual void SetDataArrayName(const char *)
virtual void SetSeeds(vtkIdList *)
static vtkvmtkSteepestDescentLineTracer * New()
virtual vtkIdList * GetHitTargets()
virtual void SetTargets(vtkIdList *)
virtual void SetEdgeArrayName(const char *)
virtual void SetEdgePCoordArrayName(const char *)
Compute the Voronoi diagram from a Delaunay tessellation or an internal Delaunay tessellation.
static vtkvmtkVoronoiDiagram3D * New()
virtual void SetRadiusArrayName(const char *)
virtual vtkIdList * GetPoleIds()
#define VTK_VMTK_DOUBLE_TOL
vtkCxxSetObjectMacro(vtkvmtkPolyDataCenterlines, SourceSeedIds, vtkIdList)
vtkStandardNewMacro(vtkvmtkPolyDataCenterlines)