635{
636 vtkPointData* inputPD = input->GetPointData();
637 vtkCell* centerline = input->GetCell(cellId);
638
639 if (centerline->GetCellType() != VTK_POLY_LINE && centerline->GetCellType() != VTK_LINE)
640 {
641 return;
642 }
643
644 vtkIdType numberOfCenterlinePoints = centerline->GetNumberOfPoints();
645
646 int numberOfTractPoints;
647
648 splitCenterline->Initialize();
649 vtkPoints* splitCenterlinePoints = vtkPoints::New();
650 vtkCellArray* splitCenterlineCellArray = vtkCellArray::New();
651 vtkIdList* splitCenterlineCellPointIds = vtkIdList::New();
652 vtkPointData* splitCenterlinePD = splitCenterline->GetPointData();
653
654 vtkIntArray* centerlineIdsArray = vtkIntArray::New();
655 centerlineIdsArray->SetNumberOfComponents(1);
657
658 vtkIntArray* tractIdsArray = vtkIntArray::New();
659 tractIdsArray->SetNumberOfComponents(1);
661
662 vtkIntArray* blankingArray = vtkIntArray::New();
663 blankingArray->SetNumberOfComponents(1);
665
666 int i;
667 if (numberOfSplittingPoints == 0)
668 {
669 splitCenterlinePoints->DeepCopy(centerline->GetPoints());
670 splitCenterlineCellArray->InsertNextCell(numberOfCenterlinePoints);
671 splitCenterlinePD->CopyAllocate(inputPD,numberOfCenterlinePoints);
672 for (i=0; i<numberOfCenterlinePoints; i++)
673 {
674 splitCenterlinePD->CopyData(inputPD,centerline->GetPointId(i),i);
675 splitCenterlineCellArray->InsertCellPoint(i);
676 }
677 centerlineIdsArray->InsertNextValue(cellId);
678 tractIdsArray->InsertNextValue(0);
679 blankingArray->InsertNextValue(0);
680
681 splitCenterline->SetPoints(splitCenterlinePoints);
682 splitCenterline->SetLines(splitCenterlineCellArray);
683 splitCenterline->GetCellData()->CopyAllocate(input->GetCellData(),1);
684 splitCenterline->GetCellData()->CopyData(input->GetCellData(),cellId,0);
685 splitCenterline->GetCellData()->AddArray(centerlineIdsArray);
686 splitCenterline->GetCellData()->AddArray(tractIdsArray);
687 splitCenterline->GetCellData()->AddArray(blankingArray);
688
689 splitCenterlinePoints->Delete();
690 splitCenterlineCellArray->Delete();
691 splitCenterlineCellPointIds->Delete();
692 centerlineIdsArray->Delete();
693 tractIdsArray->Delete();
694 blankingArray->Delete();
695 return;
696 }
697
698 int numberOfSplitCenterlinePoints = 0;
699 for (i=0; i<=numberOfSplittingPoints; i++)
700 {
701 if (tractBlanking[i] == 1)
702 {
703 continue;
704 }
705 vtkIdType lowerId, higherId;
706
707 numberOfTractPoints = 0;
708
709 if (i==0)
710 {
711 lowerId = 0;
712 }
713 else
714 {
715 lowerId = subIds[i-1]+1;
716 numberOfTractPoints += 1;
717 }
718 if (i==numberOfSplittingPoints)
719 {
720 higherId = numberOfCenterlinePoints-1;
721 }
722 else
723 {
724 higherId = subIds[i];
725 numberOfTractPoints += 1;
726 }
727 if (higherId - lowerId > 0)
728 {
729 numberOfTractPoints += higherId - lowerId;
730 }
731 numberOfSplitCenterlinePoints += numberOfTractPoints;
732 }
733
734 splitCenterlinePD->InterpolateAllocate(inputPD,numberOfSplitCenterlinePoints);
735 splitCenterline->GetCellData()->CopyAllocate(input->GetCellData(),numberOfSplittingPoints+1);
736
737 for (i=0; i<=numberOfSplittingPoints; i++)
738 {
739
740
741
742
743
744
745 splitCenterlineCellPointIds->Initialize();
746
747 vtkIdType lowerId, higherId;
748
749 lowerId = (i == 0) ? 0 : subIds[i-1]+1;
750 higherId = (i == numberOfSplittingPoints) ? numberOfCenterlinePoints-1 : subIds[i];
751
752 double point[3], point0[3], point1[3];
753 vtkIdType pointId;
754
755
756 int j, k;
757 if (i>0)
758 {
759 centerline->GetPoints()->GetPoint(subIds[i-1],point0);
760 centerline->GetPoints()->GetPoint(subIds[i-1]+1,point1);
761 for (k=0; k<3; k++)
762 {
763 point[k] = point0[k] + pcoords[i-1]*(point1[k] - point0[k]);
764 }
765 if (vtkMath::Distance2BetweenPoints(point,centerline->GetPoints()->GetPoint(lowerId))>
VTK_VMTK_FLOAT_TOL)
766 {
767 pointId = splitCenterlinePoints->InsertNextPoint(point);
768 splitCenterlineCellPointIds->InsertNextId(pointId);
769 splitCenterlinePD->InterpolateEdge(inputPD,pointId,centerline->GetPointId(subIds[i-1]),centerline->GetPointId(subIds[i-1]+1),pcoords[i-1]);
770 }
771 }
772
773 for (j=lowerId; j<=higherId; j++)
774 {
775 pointId = splitCenterlinePoints->InsertNextPoint(centerline->GetPoints()->GetPoint(j));
776 splitCenterlineCellPointIds->InsertNextId(pointId);
777 splitCenterlinePD->CopyData(inputPD,centerline->GetPointId(j),pointId);
778 }
779
780
781 if (i<numberOfSplittingPoints)
782 {
783 centerline->GetPoints()->GetPoint(subIds[i],point0);
784 centerline->GetPoints()->GetPoint(subIds[i]+1,point1);
785 for (k=0; k<3; k++)
786 {
787 point[k] = point0[k] + pcoords[i]*(point1[k] - point0[k]);
788 }
789 if (vtkMath::Distance2BetweenPoints(point,centerline->GetPoints()->GetPoint(higherId))>
VTK_VMTK_FLOAT_TOL)
790 {
791 pointId = splitCenterlinePoints->InsertNextPoint(point);
792 splitCenterlineCellPointIds->InsertNextId(pointId);
793 splitCenterlinePD->InterpolateEdge(inputPD,pointId,centerline->GetPointId(subIds[i]),centerline->GetPointId(subIds[i]+1),pcoords[i]);
794 }
795 }
796
797 splitCenterlineCellArray->InsertNextCell(splitCenterlineCellPointIds);
798 centerlineIdsArray->InsertNextValue(cellId);
799 tractIdsArray->InsertNextValue(i);
800 blankingArray->InsertNextValue(tractBlanking[i]);
801 splitCenterline->GetCellData()->CopyData(input->GetCellData(),cellId,i);
802 }
803
804 splitCenterline->SetPoints(splitCenterlinePoints);
805 splitCenterline->SetLines(splitCenterlineCellArray);
806 splitCenterline->GetCellData()->AddArray(centerlineIdsArray);
807 splitCenterline->GetCellData()->AddArray(tractIdsArray);
808 splitCenterline->GetCellData()->AddArray(blankingArray);
809
810 splitCenterlinePoints->Delete();
811 splitCenterlineCellArray->Delete();
812 splitCenterlineCellPointIds->Delete();
813 centerlineIdsArray->Delete();
814 tractIdsArray->Delete();
815 blankingArray->Delete();
816}
#define VTK_VMTK_FLOAT_TOL