252{
253 vtkInformation *inInfo = inputVector[0]->GetInformationObject(0);
254 vtkInformation *outInfo = outputVector->GetInformationObject(0);
255
256 vtkPolyData *input = vtkPolyData::SafeDownCast(
257 inInfo->Get(vtkDataObject::DATA_OBJECT()));
258 vtkPolyData *output = vtkPolyData::SafeDownCast(
259 outInfo->Get(vtkDataObject::DATA_OBJECT()));
260
262 {
264 {
265 vtkErrorMacro(<< "Centerlines not set.");
266 return 1;
267 }
268 }
269
270 vtkNew<vtkPoints> outputPoints;
271 vtkNew<vtkCellArray> outputPolys;
272
273 outputPoints->DeepCopy(input->GetPoints());
274 outputPolys->DeepCopy(input->GetPolys());
275
276
277
278
279
280 bool useBoundaryLabels = false;
281
282
283
284 vtkNew<vtkIdList> boundaryLabels;
285 vtkSmartPointer<vtkPolyData> boundaries;
288 {
289 vtkNew<vtkPolyData> labeledBoundaries;
292 labeledBoundaries, boundaryLabels);
293 if (useBoundaryLabels)
294 {
295 boundaries = labeledBoundaries;
296 }
297 else
298 {
299 vtkWarningMacro(<<"The boundary label arrays are missing from the input surface or no longer describe it; "
300 <<"extracting its boundaries instead, and leaving the output unlabeled.");
301 }
302 }
303 if (!boundaries)
304 {
305 vtkNew<vtkvmtkPolyDataBoundaryExtractor> boundaryExtractor;
306 boundaryExtractor->SetInputData(input);
307 boundaryExtractor->Update();
308 boundaries = boundaryExtractor->GetOutput();
309 }
310
311 vtkNew<vtkPolyData> centerlines;
312 vtkNew<vtkvmtkPolyBallLine> tube;
313 vtkNew<vtkDoubleArray> zeroRadiusArray;
314
316 {
318
319 const char zeroRadiusArrayName[] = "ZeroRadiusArray";
320
321 zeroRadiusArray->SetName(zeroRadiusArrayName);
322 zeroRadiusArray->SetNumberOfTuples(centerlines->GetNumberOfPoints());
323 zeroRadiusArray->FillComponent(0,0.0);
324
325 centerlines->GetPointData()->AddArray(zeroRadiusArray);
326
327 tube->SetInput(centerlines);
328 tube->SetPolyBallRadiusArrayName(zeroRadiusArrayName);
329 }
330
331 input->BuildCells();
332 input->BuildLinks();
333
334
335
336
337 std::vector<std::vector<vtkIdType> > originalRingByBoundary(boundaries->GetNumberOfCells());
338 std::vector<std::vector<vtkIdType> > tipRingByBoundary(boundaries->GetNumberOfCells());
339
340 int i, k;
341 for (i=0; i<boundaries->GetNumberOfCells(); i++)
342 {
344 {
345
346
347 if (this->
BoundaryIds->IsId(useBoundaryLabels ? boundaryLabels->GetId(i) : i) == -1)
348 {
349 continue;
350 }
351 }
352
353 vtkPolyLine* boundary = vtkPolyLine::SafeDownCast(boundaries->GetCell(i));
354
355 if (!boundary)
356 {
357 vtkErrorMacro(<<"Boundary not a vtkPolyLine");
358 continue;
359 }
360
361 int numberOfBoundaryPoints = boundary->GetNumberOfPoints();
362
363 vtkNew<vtkIdList> boundaryIds;
364 int j;
365 for (j=0; j<numberOfBoundaryPoints; j++)
366 {
367 boundaryIds->InsertNextId(static_cast<vtkIdType>(vtkMath::Round(boundaries->GetPointData()->GetScalars()->GetComponent(boundary->GetPointId(j),0))));
368 }
369
370 double barycenter[3];
371 double normal[3], outwardNormal[3];
372 double meanRadius;
373
378
379 double flowExtensionNormal[3];
380 flowExtensionNormal[0] = flowExtensionNormal[1] = flowExtensionNormal[2] = 0.0;
381
383 {
384 tube->EvaluateFunction(barycenter);
385
386 double centerlinePoint[3];
387 vtkIdType cellId, subId;
388 double pcoord;
389 tube->GetLastPolyBallCenter(centerlinePoint);
390 cellId = tube->GetLastPolyBallCellId();
391 subId = tube->GetLastPolyBallCellSubId();
392 pcoord = tube->GetLastPolyBallCellPCoord();
393
394 vtkCell* centerline = centerlines->GetCell(cellId);
395
396 vtkIdType pointId0, pointId1;
397 double abscissa;
398
399 double point0[3], point1[3];
400
401 pointId0 = 0;
402 abscissa = sqrt(vtkMath::Distance2BetweenPoints(centerlinePoint,centerline->GetPoints()->GetPoint(subId)));
403 for (j=subId-1; j>=0; j--)
404 {
405 centerline->GetPoints()->GetPoint(j,point0);
406 centerline->GetPoints()->GetPoint(j+1,point1);
407 abscissa += sqrt(vtkMath::Distance2BetweenPoints(point0,point1));
409 {
410 pointId0 = j;
411 break;
412 }
413 }
414
415 pointId1 = centerline->GetNumberOfPoints()-1;
416 abscissa = sqrt(vtkMath::Distance2BetweenPoints(centerlinePoint,centerline->GetPoints()->GetPoint(subId+1)));
417 for (j=subId+1; j<centerline->GetNumberOfPoints()-2; j++)
418 {
419 centerline->GetPoints()->GetPoint(j,point0);
420 centerline->GetPoints()->GetPoint(j+1,point1);
421 abscissa += sqrt(vtkMath::Distance2BetweenPoints(point0,point1));
423 {
424 pointId1 = j+1;
425 break;
426 }
427 }
428
429
430
431 double centerlineNormal[3];
432
433 centerline->GetPoints()->GetPoint(pointId0,point0);
434 centerline->GetPoints()->GetPoint(pointId1,point1);
435
436 double toleranceFactor = 1E-4;
437
438 for (k=0; k<3; k++)
439 {
440 centerlineNormal[k] = 0.0;
441 }
442 if (sqrt(vtkMath::Distance2BetweenPoints(point1,centerlinePoint)) > toleranceFactor*meanRadius)
443 {
444 for (k=0; k<3; k++)
445 {
446 centerlineNormal[k] += point1[k] - centerlinePoint[k];
447 }
448 }
449 if (sqrt(vtkMath::Distance2BetweenPoints(centerlinePoint,point0)) > toleranceFactor*meanRadius)
450 {
451 for (k=0; k<3; k++)
452 {
453 centerlineNormal[k] += centerlinePoint[k] - point0[k];
454 }
455 }
456
457 vtkMath::Normalize(centerlineNormal);
458
459 for (k=0; k<3; k++)
460 {
461 flowExtensionNormal[k] = centerlineNormal[k];
462 }
463
464 if (vtkMath::Dot(outwardNormal,centerlineNormal) < 0.0)
465 {
466 for (k=0; k<3; k++)
467 {
468 flowExtensionNormal[k] *= -1.0;
469 }
470 }
471 }
473 {
474 for (k=0; k<3; k++)
475 {
476 flowExtensionNormal[k] = outwardNormal[k];
477 }
478 }
479 else
480 {
481 vtkErrorMacro(<< "Invalid ExtensionMode.");
482 return 1;
483 }
484
485 double extensionLength;
486
488 {
490 }
491 else
492 {
494 }
495
497 {
498 vtkIdType boundaryId = useBoundaryLabels ? boundaryLabels->GetId(i) : i;
500 {
502 }
503 }
504
505 double point[3], extensionPoint[3];
506
507
508
509
510 vtkNew<vtkPoints> projectedBoundaryPoints;
511 double meanProjectedRadius = 0.0;
512
513 double barycenterToPoint[3];
514 double outOfPlaneDistance;
515 double projectedPoint[3];
516 for (j=0; j<numberOfBoundaryPoints; j++)
517 {
518 boundary->GetPoints()->GetPoint(j,point);
519 for (k=0; k<3; k++)
520 {
521 barycenterToPoint[k] = point[k] - barycenter[k];
522 }
523 outOfPlaneDistance = vtkMath::Dot(barycenterToPoint,flowExtensionNormal);
524 for (k=0; k<3; k++)
525 {
526 barycenterToPoint[k] -= outOfPlaneDistance*flowExtensionNormal[k];
527 projectedPoint[k] = barycenter[k] + barycenterToPoint[k];
528 }
529 projectedBoundaryPoints->InsertNextPoint(projectedPoint);
530 meanProjectedRadius += vtkMath::Norm(barycenterToPoint);
531 }
532 meanProjectedRadius /= numberOfBoundaryPoints;
533
534 double targetRadius = 0.0;
535
537 {
538 targetRadius = meanProjectedRadius;
539 }
540 else
541 {
543 }
544
546 {
547 vtkWarningMacro(<<"Degenerate boundary outline, skipping flow extension for boundary "<<i);
548 continue;
549 }
550
551 vtkNew<vtkIdList> newBoundaryIds;
552 vtkNew<vtkIdList> previousBoundaryIds;
553 vtkIdType pointId;
554
555 previousBoundaryIds->DeepCopy(boundaryIds);
556
557
558
561 {
562 targetNumberOfBoundaryPoints = numberOfBoundaryPoints;
563 }
564
565 double targetDistanceBetweenPoints = 0.0;
566
567 vtkNew<vtkThinPlateSplineTransform> thinPlateSplineTransform;
568 thinPlateSplineTransform->SetSigma(this->
Sigma);
569 thinPlateSplineTransform->SetBasisToR2LogR();
570
571
572 vtkNew<vtkPoints> sourceLandmarks;
573 vtkNew<vtkPoints> targetLandmarks;
574
575 vtkNew<vtkPoints> targetBoundaryPoints;
576 vtkNew<vtkPoints> targetStaggeredBoundaryPoints;
577
578
579
580
582 vtkNew<vtkPoints> rimBoundaryPoints;
583 vtkNew<vtkPoints> rimStaggeredBoundaryPoints;
584
585 int startNumberOfBoundaryPoints = numberOfBoundaryPoints;
586
588 {
589
590
591
592
593
594 vtkPoints* rimPoints = useRampInterpolation ? rimBoundaryPoints.GetPointer() : nullptr;
595 vtkPoints* rimStaggeredPoints = useRampInterpolation ? rimStaggeredBoundaryPoints.GetPointer() : nullptr;
596 double perimeter = ResampleClosedPolygon(projectedBoundaryPoints,targetNumberOfBoundaryPoints,0.0,targetBoundaryPoints,boundary->GetPoints(),rimPoints);
597 ResampleClosedPolygon(projectedBoundaryPoints,targetNumberOfBoundaryPoints,0.5,targetStaggeredBoundaryPoints,boundary->GetPoints(),rimStaggeredPoints);
598
599 double targetPoint[3];
600 double scale = 1.0;
601
603 {
604
605
606 double meanResampledRadius = 0.0;
607 for (j=0; j<targetNumberOfBoundaryPoints; j++)
608 {
609 targetBoundaryPoints->GetPoint(j,targetPoint);
610 for (k=0; k<3; k++)
611 {
612 targetPoint[k] -= barycenter[k];
613 }
614 meanResampledRadius += vtkMath::Norm(targetPoint);
615 }
616 meanResampledRadius /= targetNumberOfBoundaryPoints;
617 scale = targetRadius / meanResampledRadius;
618
619 for (j=0; j<targetNumberOfBoundaryPoints; j++)
620 {
621 targetBoundaryPoints->GetPoint(j,targetPoint);
622 for (k=0; k<3; k++)
623 {
624 targetPoint[k] = barycenter[k] + scale * (targetPoint[k] - barycenter[k]);
625 }
626 targetBoundaryPoints->SetPoint(j,targetPoint);
627 targetStaggeredBoundaryPoints->GetPoint(j,targetPoint);
628 for (k=0; k<3; k++)
629 {
630 targetPoint[k] = barycenter[k] + scale * (targetPoint[k] - barycenter[k]);
631 }
632 targetStaggeredBoundaryPoints->SetPoint(j,targetPoint);
633 }
634 }
635
636 targetDistanceBetweenPoints = scale * perimeter / targetNumberOfBoundaryPoints;
637 }
638 else
639 {
640 targetDistanceBetweenPoints = 2.0 * sin (vtkMath::Pi() / targetNumberOfBoundaryPoints) * targetRadius;
641
642 double baseRadialNormal[3];
643 input->GetPoint(previousBoundaryIds->GetId(0),point);
644 for (k=0; k<3; k++)
645 {
646 baseRadialNormal[k] = point[k] - barycenter[k];
647 }
648 double outOfPlaneComponent = vtkMath::Dot(baseRadialNormal,flowExtensionNormal);
649 for (k=0; k<3; k++)
650 {
651 baseRadialNormal[k] -= outOfPlaneComponent * flowExtensionNormal[k];
652 }
653 vtkMath::Normalize(baseRadialNormal);
654 double angle = 360.0 / targetNumberOfBoundaryPoints;
655 vtkNew<vtkTransform> transform;
656 transform->RotateWXYZ(0.5*angle,flowExtensionNormal);
657 double testRadialNormal[3];
658 transform->TransformPoint(baseRadialNormal,testRadialNormal);
659 double cross[3], testCross[3], point1[3];
660 vtkMath::Cross(baseRadialNormal,testRadialNormal,testCross);
661 double dist = 0.0;
662 int testId = 1;
663 int numberOfPreviousBoundaryIds = previousBoundaryIds->GetNumberOfIds();
664 while (dist < 1E-8 && testId < numberOfPreviousBoundaryIds)
665 {
666 input->GetPoint(previousBoundaryIds->GetId(testId),point1);
667 dist = sqrt(vtkMath::Distance2BetweenPoints(point,point1));
668 testId++;
669 }
670 double testRadialVector[3];
671 for (k=0; k<3; k++)
672 {
673 testRadialVector[k] = point1[k] - barycenter[k];
674 }
675 vtkMath::Cross(baseRadialNormal,testRadialVector,cross);
676 if (vtkMath::Dot(cross,testCross) < 0.0)
677 {
678 angle *= -1.0;
679 transform->Identity();
680 transform->RotateWXYZ(0.5*angle,flowExtensionNormal);
681 }
682 double radialVector[3];
683 for (k=0; k<3; k++)
684 {
685 radialVector[k] = targetRadius * baseRadialNormal[k];
686 }
687 double targetPoint[3];
688 for (j=0; j<targetNumberOfBoundaryPoints; j++)
689 {
690 for (k=0; k<3; k++)
691 {
692 targetPoint[k] = barycenter[k] + radialVector[k];
693 }
694 targetBoundaryPoints->InsertNextPoint(targetPoint);
695 transform->TransformPoint(radialVector,radialVector);
696 for (k=0; k<3; k++)
697 {
698 targetPoint[k] = barycenter[k] + radialVector[k];
699 }
700 targetStaggeredBoundaryPoints->InsertNextPoint(targetPoint);
701 transform->TransformPoint(radialVector,radialVector);
702 }
703
704 if (useRampInterpolation)
705 {
706
707
708
709
710
711 if (!SampleClosedPolygonByAngle(projectedBoundaryPoints,boundary->GetPoints(),barycenter,flowExtensionNormal,baseRadialNormal,angle,0.0,targetNumberOfBoundaryPoints,rimBoundaryPoints)
712 || !SampleClosedPolygonByAngle(projectedBoundaryPoints,boundary->GetPoints(),barycenter,flowExtensionNormal,baseRadialNormal,angle,0.5,targetNumberOfBoundaryPoints,rimStaggeredBoundaryPoints))
713 {
714 vtkWarningMacro(<<"Boundary "<<i<<" is not star-shaped about its barycenter, pairing it with the extension by arc length instead of by angle");
715 rimBoundaryPoints->Initialize();
716 rimStaggeredBoundaryPoints->Initialize();
717 vtkNew<vtkPoints> discardedPoints;
718 ResampleClosedPolygon(projectedBoundaryPoints,targetNumberOfBoundaryPoints,0.0,discardedPoints,boundary->GetPoints(),rimBoundaryPoints);
719 discardedPoints->Initialize();
720 ResampleClosedPolygon(projectedBoundaryPoints,targetNumberOfBoundaryPoints,0.5,discardedPoints,boundary->GetPoints(),rimStaggeredBoundaryPoints);
721 }
722 }
723 }
724
725
726
727
728
729 std::vector<double> displacement, staggeredDisplacement;
730
731 if (useRampInterpolation)
732 {
733 displacement.resize(3*targetNumberOfBoundaryPoints);
734 staggeredDisplacement.resize(3*targetNumberOfBoundaryPoints);
735 double targetPoint[3], rimPoint[3];
736 for (j=0; j<targetNumberOfBoundaryPoints; j++)
737 {
738 targetBoundaryPoints->GetPoint(j,targetPoint);
739 rimBoundaryPoints->GetPoint(j,rimPoint);
740 for (k=0; k<3; k++)
741 {
742 displacement[3*j+k] = rimPoint[k] - targetPoint[k];
743 }
744 targetStaggeredBoundaryPoints->GetPoint(j,targetPoint);
745 rimStaggeredBoundaryPoints->GetPoint(j,rimPoint);
746 for (k=0; k<3; k++)
747 {
748 staggeredDisplacement[3*j+k] = rimPoint[k] - targetPoint[k];
749 }
750 }
751 }
752
754 {
755 for (j=0; j<targetNumberOfBoundaryPoints; j++)
756 {
757 double firstBoundaryPoint[3], lastBoundaryPoint[3];
758 targetBoundaryPoints->GetPoint(j,firstBoundaryPoint);
759 double distance = 1E20;
760 double currentPoint[3];
761 for (int j2=0; j2<startNumberOfBoundaryPoints; j2++)
762 {
763 input->GetPoint(previousBoundaryIds->GetId(j2),currentPoint);
764 double currentDistance = vtkMath::Distance2BetweenPoints(currentPoint,firstBoundaryPoint);
765 if (currentDistance < distance)
766 {
767 distance = currentDistance;
768 for (k=0; k<3; k++)
769 {
770 point[k] = currentPoint[k];
771 }
772 }
773 }
774 sourceLandmarks->InsertNextPoint(firstBoundaryPoint);
775 targetLandmarks->InsertNextPoint(point);
776 for (k=0; k<3; k++)
777 {
778 lastBoundaryPoint[k] = firstBoundaryPoint[k] + extensionLength * this->
TransitionRatio * flowExtensionNormal[k];
779 }
780 sourceLandmarks->InsertNextPoint(lastBoundaryPoint);
781 targetLandmarks->InsertNextPoint(lastBoundaryPoint);
782 }
783 thinPlateSplineTransform->SetSourceLandmarks(sourceLandmarks);
784 thinPlateSplineTransform->SetTargetLandmarks(targetLandmarks);
785 }
786
788 int numberOfLayers = extensionLength / targetDistanceBetweenPoints;
789 int numberOfTransitionLayers = transitionLength / targetDistanceBetweenPoints;
790 int l;
791 for (l=0; l<numberOfLayers; l++)
792 {
793 newBoundaryIds->Initialize();
794 for (j=0; j<targetNumberOfBoundaryPoints; j++)
795 {
796 if (l%2 != 0)
797 {
798 targetBoundaryPoints->GetPoint(j,extensionPoint);
799 }
800 else
801 {
802 targetStaggeredBoundaryPoints->GetPoint(j,extensionPoint);
803 }
804 for (k=0; k<3; k++)
805 {
806 extensionPoint[k] += (l+1) * targetDistanceBetweenPoints * flowExtensionNormal[k];
807 }
808 if (l<numberOfTransitionLayers)
809 {
811 {
812 thinPlateSplineTransform->TransformPoint(extensionPoint,extensionPoint);
813 }
814 else
815 {
816
817
818
819
820 double parametricHeight = (l+1) * targetDistanceBetweenPoints / transitionLength;
821 parametricHeight = parametricHeight > 1.0 ? 1.0 : parametricHeight;
822 double weight = 0.0;
824 {
825 weight = 1.0 - parametricHeight;
826 }
827 else
828 {
829
830
831 weight = 1.0 - parametricHeight * parametricHeight * (3.0 - 2.0 * parametricHeight);
832 }
833 const std::vector<double>& layerDisplacement = (l%2 != 0) ? displacement : staggeredDisplacement;
834 for (k=0; k<3; k++)
835 {
836 extensionPoint[k] += weight * layerDisplacement[3*j+k];
837 }
838 }
839 }
840 pointId = outputPoints->InsertNextPoint(extensionPoint);
841 newBoundaryIds->InsertNextId(pointId);
842 }
843
844 if (l==0)
845 {
846 vtkIdType pts[3];
847 int j2 = 0;
848 for (j=0; j<targetNumberOfBoundaryPoints; j++)
849 {
850 double point0[3], point1[3], point2[3], point3[3];
851 outputPoints->GetPoint(previousBoundaryIds->GetId(j2%startNumberOfBoundaryPoints),point0);
852 outputPoints->GetPoint(previousBoundaryIds->GetId((j2+1)%startNumberOfBoundaryPoints),point1);
853 outputPoints->GetPoint(newBoundaryIds->GetId(j),point2);
854 outputPoints->GetPoint(newBoundaryIds->GetId((j+1)%targetNumberOfBoundaryPoints),point3);
855
856 bool advance = false;
857 if ((j==0) || (j==targetNumberOfBoundaryPoints-1) || (vtkMath::Distance2BetweenPoints(point0,point3) > vtkMath::Distance2BetweenPoints(point1,point2)))
858 {
859 advance = true;
860 }
861 if (j2 == startNumberOfBoundaryPoints)
862 {
863 advance = false;
864 }
865 while(advance)
866 {
867 pts[0] = previousBoundaryIds->GetId(j2%startNumberOfBoundaryPoints);
868 pts[1] = newBoundaryIds->GetId(j);
869 pts[2] = previousBoundaryIds->GetId((j2+1)%startNumberOfBoundaryPoints);
870 outputPolys->InsertNextCell(3,pts);
871 j2 += 1;
872
873 outputPoints->GetPoint(previousBoundaryIds->GetId(j2%startNumberOfBoundaryPoints),point0);
874 outputPoints->GetPoint(previousBoundaryIds->GetId((j2+1)%startNumberOfBoundaryPoints),point1);
875 outputPoints->GetPoint(newBoundaryIds->GetId(j),point2);
876 outputPoints->GetPoint(newBoundaryIds->GetId((j+1)%targetNumberOfBoundaryPoints),point3);
877
878 if (j2 == startNumberOfBoundaryPoints || vtkMath::Distance2BetweenPoints(point0,point3) < vtkMath::Distance2BetweenPoints(point1,point2))
879 {
880 advance = false;
881 if (j2 < startNumberOfBoundaryPoints && j == targetNumberOfBoundaryPoints-1)
882 {
883 advance = true;
884 }
885 }
886 }
887 pts[0] = newBoundaryIds->GetId(j);
888 pts[1] = newBoundaryIds->GetId((j+1)%targetNumberOfBoundaryPoints);
889 pts[2] = previousBoundaryIds->GetId(j2%startNumberOfBoundaryPoints);
890 outputPolys->InsertNextCell(3,pts);
891 }
892 }
893 else
894 {
895 vtkIdType pts[3];
896 for (j=0; j<targetNumberOfBoundaryPoints; j++)
897 {
898 if (l%2 != 0)
899 {
900 pts[0] = newBoundaryIds->GetId(j);
901 pts[1] = newBoundaryIds->GetId((j-1+targetNumberOfBoundaryPoints)%targetNumberOfBoundaryPoints);
902 pts[2] = previousBoundaryIds->GetId((j-1+targetNumberOfBoundaryPoints)%targetNumberOfBoundaryPoints);
903 outputPolys->InsertNextCell(3,pts);
904
905 pts[0] = previousBoundaryIds->GetId(j);
906 pts[1] = newBoundaryIds->GetId(j);
907 pts[2] = previousBoundaryIds->GetId((j-1+targetNumberOfBoundaryPoints)%targetNumberOfBoundaryPoints);
908 outputPolys->InsertNextCell(3,pts);
909 }
910 else
911 {
912 pts[0] = newBoundaryIds->GetId(j);
913 pts[1] = newBoundaryIds->GetId((j-1+targetNumberOfBoundaryPoints)%targetNumberOfBoundaryPoints);
914 pts[2] = previousBoundaryIds->GetId(j);
915 outputPolys->InsertNextCell(3,pts);
916
917 pts[0] = previousBoundaryIds->GetId(j);
918 pts[1] = newBoundaryIds->GetId((j-1+targetNumberOfBoundaryPoints)%targetNumberOfBoundaryPoints);
919 pts[2] = previousBoundaryIds->GetId((j-1+targetNumberOfBoundaryPoints)%targetNumberOfBoundaryPoints);
920 outputPolys->InsertNextCell(3,pts);
921 }
922 }
923 }
924
925 previousBoundaryIds->DeepCopy(newBoundaryIds);
926 }
927
928
929
930
931 if (useBoundaryLabels)
932 {
933 for (j=0; j<boundaryIds->GetNumberOfIds(); j++)
934 {
935 originalRingByBoundary[i].push_back(boundaryIds->GetId(j));
936 }
937 for (j=0; j<previousBoundaryIds->GetNumberOfIds(); j++)
938 {
939 tipRingByBoundary[i].push_back(previousBoundaryIds->GetId(j));
940 }
941 }
942
943 }
944
945 output->SetPoints(outputPoints);
946 output->SetPolys(outputPolys);
947
948 if (useBoundaryLabels)
949 {
950
951
952
953
954
956 vtkIdType numberOfInputPoints = input->GetNumberOfPoints();
957 vtkIdType numberOfOutputPoints = outputPoints->GetNumberOfPoints();
958
961
962 vtkNew<vtkIntArray> outputLabels;
964 outputLabels->SetNumberOfTuples(numberOfOutputPoints);
965 outputLabels->FillComponent(0,static_cast<double>(invalidLabel));
966
967 vtkNew<vtkIntArray> outputOrder;
969 outputOrder->SetNumberOfTuples(numberOfOutputPoints);
970 outputOrder->FillComponent(0,static_cast<double>(invalidLabel));
971
972 for (vtkIdType pointId=0; pointId<numberOfInputPoints; pointId++)
973 {
974 outputLabels->SetValue(pointId,static_cast<int>(vtkMath::Round(inputLabels->GetComponent(pointId,0))));
975 outputOrder->SetValue(pointId,static_cast<int>(vtkMath::Round(inputOrder->GetComponent(pointId,0))));
976 }
977
978 for (size_t boundaryIndex=0; boundaryIndex<tipRingByBoundary.size(); boundaryIndex++)
979 {
980 if (tipRingByBoundary[boundaryIndex].empty())
981 {
982 continue;
983 }
984 vtkIdType boundaryLabel = boundaryLabels->GetId(static_cast<vtkIdType>(boundaryIndex));
985 for (size_t j2=0; j2<originalRingByBoundary[boundaryIndex].size(); j2++)
986 {
987 outputLabels->SetValue(originalRingByBoundary[boundaryIndex][j2],static_cast<int>(invalidLabel));
988 outputOrder->SetValue(originalRingByBoundary[boundaryIndex][j2],static_cast<int>(invalidLabel));
989 }
990 for (size_t j2=0; j2<tipRingByBoundary[boundaryIndex].size(); j2++)
991 {
992 outputLabels->SetValue(tipRingByBoundary[boundaryIndex][j2],static_cast<int>(boundaryLabel));
993 outputOrder->SetValue(tipRingByBoundary[boundaryIndex][j2],static_cast<int>(j2));
994 }
995 }
996
997 output->GetPointData()->AddArray(outputLabels);
998 output->GetPointData()->AddArray(outputOrder);
999 }
1000
1001 return 1;
1002}
static bool GetBoundaries(vtkPolyData *surface, const char *boundaryLabelsArrayName, const char *boundaryPointOrderArrayName, vtkPolyData *boundaries, vtkIdList *boundaryLabels)
static vtkIdType GetInvalidBoundaryLabel()
static void ComputeBoundaryBarycenter(vtkPoints *points, double barycenter[3])
static void OrientBoundaryNormalOutwards(vtkPolyData *surface, vtkPolyData *boundaries, vtkIdType boundaryCellId, double normal[3], double outwardNormal[3])
static void ComputeBoundaryNormal(vtkPoints *points, double barycenter[3], double normal[3])
static double ComputeBoundaryMeanRadius(vtkPoints *points, double barycenter[3])