167 vtkInformation *vtkNotUsed(request),
168 vtkInformationVector **inputVector,
169 vtkInformationVector *outputVector)
171 vtkInformation *inInfo = inputVector[0]->GetInformationObject(0);
172 vtkInformation *outInfo = outputVector->GetInformationObject(0);
174 vtkPolyData *input = vtkPolyData::SafeDownCast(
175 inInfo->Get(vtkDataObject::DATA_OBJECT()));
176 vtkPolyData *output = vtkPolyData::SafeDownCast(
177 outInfo->Get(vtkDataObject::DATA_OBJECT()));
181 vtkErrorMacro(<<
"No SourceSeedIds set.");
187 vtkErrorMacro(<<
"No TargetSeedIds set.");
193 vtkErrorMacro(<<
"No RadiusArrayName set.");
199 vtkErrorMacro(<<
"GenerateDelaunayTessellation is off but a DelaunayTessellation has not been set.");
205 vtkErrorMacro(<<
"GenerateVoronoiDiagram is off but a VoronoiDiagram has not been set.");
211 vtkErrorMacro(<<
"GenerateVoronoiDiagram is off but Voronoi PoleIds have not been set.");
221 vtkPolyData* inputWithoutNormals = vtkPolyData::New();
222 inputWithoutNormals->ShallowCopy(input);
223 inputWithoutNormals->GetPointData()->SetNormals(NULL);
224 inputWithoutNormals->GetCellData()->SetNormals(NULL);
226 vtkPolyDataNormals* surfaceNormals = vtkPolyDataNormals::New();
227 surfaceNormals->SetInputData(inputWithoutNormals);
228 inputWithoutNormals->Delete();
229 surfaceNormals->SplittingOff();
230 surfaceNormals->AutoOrientNormalsOn();
232 surfaceNormals->ComputePointNormalsOn();
233 surfaceNormals->ConsistencyOn();
234 surfaceNormals->Update();
238 vtkDelaunay3D* delaunayTessellator = vtkDelaunay3D::New();
239 delaunayTessellator->CreateDefaultLocator();
240 delaunayTessellator->SetInputConnection(surfaceNormals->GetOutputPort());
242 delaunayTessellator->Update();
244 vtkUnstructuredGrid* delaunay = delaunayTessellator->GetOutput();
245 delaunay->GetPointData()->AddArray(surfaceNormals->GetOutput()->GetPointData()->GetNormals());
248 internalTetrahedraExtractor->SetInputConnection(delaunayTessellator->GetOutputPort());
250 || !surfaceNormals->GetOutput()
251 || !surfaceNormals->GetOutput()->GetPointData()
252 || !surfaceNormals->GetOutput()->GetPointData()->GetNormals()
253 || !surfaceNormals->GetOutput()->GetPointData()->GetNormals()->GetName())
255 vtkErrorMacro(<<
"Centerline extraction failed: could not compute surface normals");
259 internalTetrahedraExtractor->
SetOutwardNormalsArrayName(surfaceNormals->GetOutput()->GetPointData()->GetNormals()->GetName());
263 internalTetrahedraExtractor->
UseCapsOn();
267 internalTetrahedraExtractor->Update();
272 delaunayTessellator->Delete();
273 internalTetrahedraExtractor->Delete();
281 voronoiDiagramFilter->Update();
283 this->
PoleIds = vtkIdList::New();
286 vtkPolyData* voronoiDiagram = voronoiDiagramFilter->GetOutput();
291 voronoiDiagramSimplifier->SetInputConnection(voronoiDiagramFilter->GetOutputPort());
293 voronoiDiagramSimplifier->Update();
294 voronoiDiagram = voronoiDiagramSimplifier->GetOutput();
295 voronoiDiagram->Register(
this);
296 voronoiDiagramSimplifier->Delete();
300 voronoiDiagramFilter->Delete();
303 #if defined(__EMSCRIPTEN__)
304 vtkNew<vtkDoubleArray> array;
306 auto outputArray =
dynamic_cast<vtkDoubleArray *
>(
309 for (
int i = 0; i < outputArray->GetNumberOfTuples(); i++)
311 array->InsertNextValue(1 / outputArray->GetValue(i));
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);
321 voronoiCostFunctionCalculator->Update();
324 vtkIdList* voronoiSourceSeedIds = vtkIdList::New();
325 vtkIdList* voronoiTargetSeedIds = vtkIdList::New();
327 vtkIdList* voronoiSeeds = vtkIdList::New();
335 voronoiSourceSeedIds->InsertNextId(voronoiSeeds->GetId(this->SourceSeedIds->GetId(i)));
339 voronoiTargetSeedIds->InsertNextId(voronoiSeeds->GetId(this->TargetSeedIds->GetId(i)));
346 voronoiSourceSeedIds->InsertNextId(this->
PoleIds->GetId(this->SourceSeedIds->GetId(i)));
350 voronoiTargetSeedIds->InsertNextId(this->
PoleIds->GetId(this->TargetSeedIds->GetId(i)));
355 #if defined(__EMSCRIPTEN__)
358 voronoiFastMarching->SetInputConnection(voronoiCostFunctionCalculator->GetOutputPort());
367 voronoiFastMarching->
SetSeeds(voronoiSourceSeedIds);
368 voronoiFastMarching->Update();
370 this->
VoronoiDiagram->ShallowCopy(voronoiFastMarching->GetOutput());
373 centerlineBacktracing->SetInputConnection(voronoiFastMarching->GetOutputPort());
378 centerlineBacktracing->
SetSeeds(voronoiTargetSeedIds);
381 centerlineBacktracing->
SetTargets(voronoiSourceSeedIds);
382 centerlineBacktracing->Update();
384 output->ShallowCopy(centerlineBacktracing->GetOutput());
386 vtkIdList* hitTargets = centerlineBacktracing->
GetHitTargets();
388 vtkPoints* endPointPairs = vtkPoints::New();
390 const vtkIdType numTargetSeedIds = this->
TargetSeedIds->GetNumberOfIds();
391 const vtkIdType numHitTargets = hitTargets->GetNumberOfIds();
392 if(numHitTargets == numTargetSeedIds) {
395 for (i=0; i<numTargetSeedIds; i++)
400 vtkIdType hitTargetPointId = hitTargets->GetId(i);
401 vtkIdType targetId = voronoiSourceSeedIds->IsId(hitTargetPointId);
403 endPointPairs->InsertNextPoint(input->GetPoint(endPointId1));
404 endPointPairs->InsertNextPoint(input->GetPoint(endPointId2));
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));
427 surfaceNormals->Delete();
428 #if !defined(__EMSCRIPTEN__)
429 voronoiCostFunctionCalculator->Delete();
431 voronoiSeeds->Delete();
432 voronoiSourceSeedIds->Delete();
433 voronoiTargetSeedIds->Delete();
434 voronoiFastMarching->Delete();
435 centerlineBacktracing->Delete();
436 endPointPairs->Delete();
444 vtkIdList *pointCells;
445 vtkIdType baricenterId;
446 double baricenter[3], normal[3];
447 double maxRadius, secondMaxRadius;
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;
456 pointCells = vtkIdList::New();
458 for (i=0; i<boundaryBaricenterIds->GetNumberOfIds(); i++)
460 baricenterId = boundaryBaricenterIds->GetId(i);
461 delaunay->GetPoint(baricenterId,baricenter);
462 normals->GetTuple(baricenterId,normal);
463 pointCells->Initialize();
464 delaunay->GetPointCells(baricenterId,pointCells);
466 maxRadiusCellId = -1;
467 secondMaxRadiusCellId = -1;
469 for (j=0; j<pointCells->GetNumberOfIds(); j++)
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);
477 circumradius = vtkTetra::Circumsphere(p0,p1,p2,p3,circumcenter);
478 tetraRadius = sqrt(circumradius);
482 maxRadius = tetraRadius;
483 maxRadiusCellId = pointCells->GetId(j);
484 pole[0] = circumcenter[0];
485 pole[1] = circumcenter[1];
486 pole[2] = circumcenter[2];
490 poleVector[0] = pole[0] - baricenter[0];
491 poleVector[1] = pole[1] - baricenter[1];
492 poleVector[2] = pole[2] - baricenter[2];
494 secondMaxRadius = 0.0;
496 for (j=0; j<pointCells->GetNumberOfIds(); j++)
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);
504 circumradius = vtkTetra::Circumsphere(p0,p1,p2,p3,circumcenter);
505 tetraRadius = sqrt(circumradius);
507 referenceVector[0] = circumcenter[0] - baricenter[0];
508 referenceVector[1] = circumcenter[1] - baricenter[1];
509 referenceVector[2] = circumcenter[2] - baricenter[2];
513 secondMaxRadius = tetraRadius;
514 secondMaxRadiusCellId = pointCells->GetId(j);
515 secondPole[0] = circumcenter[0];
516 secondPole[1] = circumcenter[1];
517 secondPole[2] = circumcenter[2];
521 secondPoleVector[0] = secondPole[0] - baricenter[0];
522 secondPoleVector[1] = secondPole[1] - baricenter[1];
523 secondPoleVector[2] = secondPole[2] - baricenter[2];
527 seedIds->InsertNextId(maxRadiusCellId);
531 seedIds->InsertNextId(secondMaxRadiusCellId);
535 pointCells->Delete();
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();
547 vtkIdList* completeCell = vtkIdList::New();
549 vtkDoubleArray* centerlinesRadiusArray = vtkDoubleArray::SafeDownCast(output->GetPointData()->GetArray(this->RadiusArrayName));
551 completeCenterlinesPoints->DeepCopy(output->GetPoints());
552 completeCenterlinesRadiusArray->DeepCopy(centerlinesRadiusArray);
554 for (
int k=0; k<output->GetNumberOfCells(); k++)
556 vtkCell* cell = output->GetCell(k);
558 endPointId1 = completeCenterlinesPoints->InsertNextPoint(endPointPairs->GetPoint(2*k));
559 endPointId2 = completeCenterlinesPoints->InsertNextPoint(endPointPairs->GetPoint(2*k+1));
561 completeCell->Initialize();
562 completeCell->SetNumberOfIds(cell->GetNumberOfPoints()+2);
564 completeCell->SetId(0,endPointId1);
566 for (
int i=0; i<cell->GetNumberOfPoints(); i++)
568 completeCell->SetId(i+1,cell->GetPointId(i));
570 completeCell->SetId(cell->GetNumberOfPoints()+1,endPointId2);
572 completeCenterlinesCellArray->InsertNextCell(completeCell);
574 completeCenterlinesRadiusArray->InsertNextValue(centerlinesRadiusArray->GetValue(cell->GetPointId(0)));
575 completeCenterlinesRadiusArray->InsertNextValue(centerlinesRadiusArray->GetValue(cell->GetPointId(cell->GetNumberOfPoints()-1)));
578 completeCenterlines->SetPoints(completeCenterlinesPoints);
579 completeCenterlines->SetLines(completeCenterlinesCellArray);
580 completeCenterlines->GetPointData()->AddArray(completeCenterlinesRadiusArray);
582 output->ShallowCopy(completeCenterlines);
584 completeCell->Delete();
585 completeCenterlines->Delete();
586 completeCenterlinesPoints->Delete();
587 completeCenterlinesCellArray->Delete();
588 completeCenterlinesRadiusArray->Delete();
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();
599 vtkIdList* resampledCell = vtkIdList::New();
601 vtkDoubleArray* centerlinesRadiusArray = vtkDoubleArray::SafeDownCast(output->GetPointData()->GetArray(this->RadiusArrayName));
603 for (
int k=0; k<output->GetNumberOfCells(); k++)
605 vtkCell* cell = output->GetCell(k);
607 resampledCell->Initialize();
609 vtkIdType
id = resampledCenterlinesPoints->InsertNextPoint(cell->GetPoints()->GetPoint(0));
610 resampledCell->InsertNextId(
id);
611 resampledCenterlinesRadiusArray->InsertNextValue(centerlinesRadiusArray->GetValue(cell->GetPointId(0)));
613 double point0[3], point1[3], point[3];
614 double abscissa, lineAbscissa, lineLength, stepAbscissa;
621 for (
int i=0; i<cell->GetNumberOfPoints()-1; i++)
623 cell->GetPoints()->GetPoint(i,point0);
624 cell->GetPoints()->GetPoint(i+1,point1);
626 double scalar0 = centerlinesRadiusArray->GetValue(cell->GetPointId(i));
627 double scalar1 = centerlinesRadiusArray->GetValue(cell->GetPointId(i+1));
629 double length = sqrt(vtkMath::Distance2BetweenPoints(point0,point1));
633 stepAbscissa = stepAbscissa + length;
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;
645 double scalar = scalar0 + (scalar1 - scalar0) * pcoord;
647 vtkIdType
id = resampledCenterlinesPoints->InsertNextPoint(point);
648 resampledCell->InsertNextId(
id);
649 resampledCenterlinesRadiusArray->InsertNextValue(scalar);
651 if (pcoord + pcoordStep > 1.0)
655 pcoord = pcoord + pcoordStep;
657 stepAbscissa = (1.0 - pcoord) * length;
660 id = resampledCenterlinesPoints->InsertNextPoint(cell->GetPoints()->GetPoint(cell->GetNumberOfPoints()-1));
661 resampledCell->InsertNextId(
id);
662 resampledCenterlinesRadiusArray->InsertNextValue(centerlinesRadiusArray->GetValue(cell->GetPointId(cell->GetNumberOfPoints()-1)));
664 resampledCenterlinesCellArray->InsertNextCell(resampledCell);
666 resampledCenterlines->SetPoints(resampledCenterlinesPoints);
667 resampledCenterlines->SetLines(resampledCenterlinesCellArray);
668 resampledCenterlines->GetPointData()->AddArray(resampledCenterlinesRadiusArray);
670 output->ShallowCopy(resampledCenterlines);
672 resampledCenterlines->Delete();
673 resampledCenterlinesPoints->Delete();
674 resampledCenterlinesCellArray->Delete();
675 resampledCenterlinesRadiusArray->Delete();
676 resampledCell->Delete();