777{
778 vtkIdTypeArray* marksArray = vtkIdTypeArray::SafeDownCast(model->GetPointData()->GetArray(
MarksArrayName));
779
780 double center[3];
781 double radius;
783
784 bool sameCenter = false;
785 if (oldRadius > 0.0)
786 {
788 {
789 radius = 2.0 * oldRadius;
790 sameCenter = true;
791 }
792 }
793
794
795 vtkIdTypeArray* edgeTableForNewProfiles = vtkIdTypeArray::New();
796 edgeTableForNewProfiles->SetNumberOfComponents(2);
797 vtkIdTypeArray* cellPairsForNewProfiles = vtkIdTypeArray::New();
798 cellPairsForNewProfiles->SetNumberOfComponents(2);
799 vtkIdList* pointIdsForNewProfiles = vtkIdList::New();
800
801 vtkIdTypeArray* edgeTableForIncludedGlobalProfiles = vtkIdTypeArray::New();
802 edgeTableForIncludedGlobalProfiles->SetNumberOfComponents(2);
803
804 vtkPoints* markedPoints = vtkPoints::New();
805 vtkIdList* markedPointIds = vtkIdList::New();
806
807 vtkIdType i;
808 baseProfiles->InitTraversal();
809 baseProfilesEdgeTables->InitTraversal();
810 vtkIdList* old2MarkedPointIds = vtkIdList::New();
811 for (i=0; i<baseProfiles->GetNumberOfItems(); i++)
812 {
813 vtkPolyData* baseProfile = baseProfiles->GetNextItem();
814 vtkIdTypeArray* baseProfileEdgeTable = (vtkIdTypeArray*)baseProfilesEdgeTables->GetNextItemAsObject();
815 vtkIdType j;
816 for (j=0; j<baseProfile->GetNumberOfPoints(); j++)
817 {
818 vtkIdType currentEdge[2];
820 if (marksArray->GetValue(currentEdge[0]) ==
GLOBAL)
821 {
822 marksArray->InsertValue(currentEdge[0],
VISITED);
823 old2MarkedPointIds->InsertNextId(currentEdge[0]);
824 }
825 }
826 }
827
828
829 baseProfiles->InitTraversal();
830 baseProfilesEdgeTables->InitTraversal();
831
832 vtkIdList* toVisitPointIds = vtkIdList::New();
833 for (i=0; i<baseProfiles->GetNumberOfItems(); i++)
834 {
835 vtkPolyData* baseProfile = baseProfiles->GetNextItem();
836 vtkIdTypeArray* baseProfileEdgeTable = (vtkIdTypeArray*)baseProfilesEdgeTables->GetNextItemAsObject();
837
838 vtkIdType j;
839 for (j=0; j<baseProfile->GetNumberOfPoints(); j++)
840 {
841 vtkIdType currentEdge[2];
844
845 if (marksArray->GetValue(currentEdge[1]) ==
GLOBAL)
846 {
847 this->
InsertInEdgeTable(edgeTableForIncludedGlobalProfiles,currentEdge[0],currentEdge[1]);
848 }
849
850 if (currentPointId!=-1)
851 {
852 if (this->
Distance(model->GetPoint(currentPointId),center)>radius)
853 {
854 this->
InsertEdgeForNewProfiles(model,currentEdge,edgeTableForNewProfiles,cellPairsForNewProfiles,pointIdsForNewProfiles);
855 }
856 else
857 {
858 toVisitPointIds->InsertNextId(currentPointId);
859 }
860 }
861 }
862 }
863
864 this->
PropagateFromBaseProfilePoint(model,toVisitPointIds,center,radius,edgeTableForNewProfiles,cellPairsForNewProfiles,pointIdsForNewProfiles,markedPoints,markedPointIds,edgeTableForIncludedGlobalProfiles);
865
866 toVisitPointIds->Delete();
867
868 for (i=0; i<old2MarkedPointIds->GetNumberOfIds(); i++)
869 {
870 marksArray->InsertValue(old2MarkedPointIds->GetId(i),
GLOBAL);
871 }
872
873 old2MarkedPointIds->Delete();
874
875 if (edgeTableForIncludedGlobalProfiles->GetNumberOfTuples() > 0)
876 {
877 vtkIdTypeArray* edgeTableForEffectiveIncludedGlobalProfiles = vtkIdTypeArray::New();
878 edgeTableForEffectiveIncludedGlobalProfiles->SetNumberOfComponents(2);
879
880 vtkIdType i;
881 for (i=0; i<edgeTableForIncludedGlobalProfiles->GetNumberOfTuples(); i++)
882 {
883 vtkIdType edgeForIncludedGlobalProfile[2];
884 this->
GetFromEdgeTable(edgeTableForIncludedGlobalProfiles,i,edgeForIncludedGlobalProfile);
885 if (this->
Distance(model->GetPoint(edgeForIncludedGlobalProfile[1]),center) <= radius)
886 {
887 this->
InsertInEdgeTable(edgeTableForEffectiveIncludedGlobalProfiles,edgeForIncludedGlobalProfile[0],edgeForIncludedGlobalProfile[1]);
888 }
889 }
890
891 if (edgeTableForEffectiveIncludedGlobalProfiles->GetNumberOfTuples() > 0)
892 {
893 vtkIdList* includedGlobalProfilesIds = vtkIdList::New();
894 for (i=0; i<edgeTableForEffectiveIncludedGlobalProfiles->GetNumberOfTuples(); i++)
895 {
896 vtkIdType edgeForIncludedGlobalProfile[2];
897 this->
GetFromEdgeTable(edgeTableForEffectiveIncludedGlobalProfiles,i,edgeForIncludedGlobalProfile);
898 globalProfiles->InitTraversal();
899 globalProfilesEdgeTables->InitTraversal();
900 vtkIdType j;
901 for (j=0; j<globalProfiles->GetNumberOfItems(); j++)
902 {
903
904 vtkIdTypeArray* globalProfileEdgeTable = (vtkIdTypeArray*)globalProfilesEdgeTables->GetNextItemAsObject();
905 vtkIdType k;
906 for (k=0; k<globalProfileEdgeTable->GetNumberOfTuples(); k++)
907 {
908 vtkIdType globalProfileEdge[2];
910 if (globalProfileEdge[0]!=globalProfileEdge[1])
911 {
912 if ((edgeForIncludedGlobalProfile[0] == globalProfileEdge[0] && edgeForIncludedGlobalProfile[1] == globalProfileEdge[1]) || (edgeForIncludedGlobalProfile[0] == globalProfileEdge[1] && edgeForIncludedGlobalProfile[1] == globalProfileEdge[0]))
913 {
914 includedGlobalProfilesIds->InsertUniqueId(j);
915 }
916 }
917 else if (globalProfileEdge[0] == globalProfileEdge[1])
918 {
919 if (edgeForIncludedGlobalProfile[0] == globalProfileEdge[0] || edgeForIncludedGlobalProfile[1] == globalProfileEdge[0])
920 {
921 includedGlobalProfilesIds->InsertUniqueId(j);
922 }
923 }
924 }
925 }
926 }
927
928 vtkPolyDataCollection* includedGlobalProfiles = vtkPolyDataCollection::New();
929 vtkCollection* includedGlobalProfilesEdgeTables = vtkCollection::New();
930 globalProfiles->InitTraversal();
931 globalProfilesEdgeTables->InitTraversal();
932 for (i=0; i<globalProfiles->GetNumberOfItems(); i++)
933 {
934 vtkPolyData* globalProfile = globalProfiles->GetNextItem();
935 vtkIdTypeArray* globalProfileEdgeTable = (vtkIdTypeArray*)globalProfilesEdgeTables->GetNextItemAsObject();
936 if (includedGlobalProfilesIds->IsId(i) != -1)
937 {
938 includedGlobalProfiles->AddItem(globalProfile);
939 baseProfiles->AddItem(globalProfile);
940 includedGlobalProfilesEdgeTables->AddItem(globalProfileEdgeTable);
941 baseProfilesEdgeTables->AddItem(globalProfileEdgeTable);
942 }
943 }
944
945 includedGlobalProfiles->InitTraversal();
946 includedGlobalProfilesEdgeTables->InitTraversal();
947 for (i=0; i<includedGlobalProfiles->GetNumberOfItems(); i++)
948 {
949 globalProfiles->RemoveItem(includedGlobalProfiles->GetNextItem());
950 globalProfilesEdgeTables->RemoveItem(includedGlobalProfilesEdgeTables->GetNextItemAsObject());
951 }
952
954
955 edgeTableForNewProfiles->Delete();
956 cellPairsForNewProfiles->Delete();
957 pointIdsForNewProfiles->Delete();
958 edgeTableForIncludedGlobalProfiles->Delete();
959 markedPoints->Delete();
960 markedPointIds->Delete();
961 edgeTableForEffectiveIncludedGlobalProfiles->Delete();
962
963 includedGlobalProfilesIds->Delete();
964
965 includedGlobalProfiles->Delete();
966 includedGlobalProfilesEdgeTables->Delete();
968 }
969 else
970 {
971 for (i=0; i<edgeTableForIncludedGlobalProfiles->GetNumberOfTuples(); i++)
972 {
973 vtkIdType currentEdge[2];
975 this->
InsertEdgeForNewProfiles(model,currentEdge,edgeTableForNewProfiles,cellPairsForNewProfiles,pointIdsForNewProfiles);
976 }
977 }
978 edgeTableForEffectiveIncludedGlobalProfiles->Delete();
979 }
980
981
982 this->
GenerateNewProfiles(model,center,radius,edgeTableForNewProfiles,cellPairsForNewProfiles,pointIdsForNewProfiles,newProfiles,newProfilesEdgeTables);
983
985
986
987 vtkIdType numberOfBaseProfiles = baseProfiles->GetNumberOfItems();
988 vtkIdType numberOfNewProfiles = newProfiles->GetNumberOfItems();
989
990 if (numberOfBaseProfiles == 1 && numberOfNewProfiles == 0)
991 {
992 segmentPoints->InsertNextPoint(center);
993 edgeTableForNewProfiles->Delete();
994 cellPairsForNewProfiles->Delete();
995 pointIdsForNewProfiles->Delete();
996 edgeTableForIncludedGlobalProfiles->Delete();
997 markedPoints->Delete();
998 markedPointIds->Delete();
999
1001 }
1002 else if (numberOfBaseProfiles == 2 && numberOfNewProfiles == 0)
1003 {
1004 baseProfiles->InitTraversal();
1005 vtkPolyData* profile;
1006 profile = baseProfiles->GetNextItem();
1007 double point1[3];
1009 segmentPoints->InsertNextPoint(point1);
1010 profile = baseProfiles->GetNextItem();
1011 double point2[3];
1013 segmentPoints->InsertNextPoint(point2);
1014
1015 vtkPoints *pointsForRadius = vtkPoints::New();
1016 this->
PointsForRadius(markedPoints,baseProfiles,NULL,pointsForRadius);
1017 segmentRadii->InsertNextValue(
ComputeStepRadius(pointsForRadius,point1,point2));
1018
1019 pointsForRadius->Delete();
1020
1021 edgeTableForNewProfiles->Delete();
1022 cellPairsForNewProfiles->Delete();
1023 pointIdsForNewProfiles->Delete();
1024 edgeTableForIncludedGlobalProfiles->Delete();
1025 markedPoints->Delete();
1026 markedPointIds->Delete();
1027
1029 }
1030 else if (numberOfBaseProfiles + numberOfNewProfiles > 2)
1031 {
1032 double lastCenter[3];
1033 if (numberOfBaseProfiles==1)
1034 {
1035 lastCenter[0] = center[0];
1036 lastCenter[1] = center[1];
1037 lastCenter[2] = center[2];
1038 }
1039 else
1040 {
1041 baseProfiles->InitTraversal();
1042 vtkPolyData* profile;
1043 profile = baseProfiles->GetNextItem();
1045 }
1046
1047 segmentPoints->InsertNextPoint(lastCenter);
1048
1049 double firstBranchRadius = 0.0;
1050 vtkIdType intersectingPointId = -1;
1051 if (segmentRadii->GetNumberOfTuples() > 0)
1052 {
1054
1055 vtkIdType i;
1056 vtkPoints* backupSegmentPoints = vtkPoints::New();
1057 for (i=0; i<segmentPoints->GetNumberOfPoints(); i++)
1058 {
1059 backupSegmentPoints->InsertNextPoint(segmentPoints->GetPoint(i));
1060 }
1061 vtkDoubleArray* backupSegmentRadii = vtkDoubleArray::New();
1062 for (i=0; i<segmentRadii->GetNumberOfTuples(); i++)
1063 {
1064 backupSegmentRadii->InsertNextValue(segmentRadii->GetValue(i));
1065 }
1066
1067 segmentPoints->Initialize();
1068 for (i=0; i<=intersectingPointId; i++)
1069 {
1070 segmentPoints->InsertNextPoint(backupSegmentPoints->GetPoint(i));
1071 }
1072 segmentRadii->Initialize();
1073 for (i=0; i<intersectingPointId; i++)
1074 {
1075 segmentRadii->InsertNextValue(backupSegmentRadii->GetValue(i));
1076 }
1077
1078 firstBranchRadius = backupSegmentRadii->GetValue(intersectingPointId-1);
1079
1080 backupSegmentPoints->Delete();
1081 backupSegmentRadii->Delete();
1082 }
1083
1084 double bifurcationBarycenter[3];
1085 bifurcationBarycenter[0] = center[0];
1086 bifurcationBarycenter[1] = center[1];
1087 bifurcationBarycenter[2] = center[2];
1088
1089 bifurcationPoints->InsertNextPoint(bifurcationBarycenter);
1090 bifurcationRadii->InsertNextValue(0.0);
1091
1092 vtkPolyData* profile;
1093 baseProfiles->InitTraversal();
1094 vtkIdType i;
1095 double bifurcationPoint[3];
1096 for (i=0; i<baseProfiles->GetNumberOfItems(); i++)
1097 {
1098 profile=baseProfiles->GetNextItem();
1099 if (i==0 && segmentRadii->GetNumberOfTuples())
1100 {
1101 bifurcationPoints->InsertNextPoint(segmentPoints->GetPoint(intersectingPointId));
1102 bifurcationRadii->InsertNextValue(firstBranchRadius);
1103 }
1104 else
1105 {
1107 bifurcationPoints->InsertNextPoint(bifurcationPoint);
1108 bifurcationRadii->InsertNextValue(this->
ComputeMeanRadius(profile->GetPoints(),bifurcationPoint));
1109 }
1110 }
1111 newProfiles->InitTraversal();
1112 for (i=0; i<newProfiles->GetNumberOfItems(); i++)
1113 {
1114 profile=newProfiles->GetNextItem();
1116 bifurcationPoints->InsertNextPoint(bifurcationPoint);
1117 bifurcationRadii->InsertNextValue(this->
ComputeMeanRadius(profile->GetPoints(),bifurcationPoint));
1118 }
1119
1120 vtkIdType j;
1121 bifurcationBarycenter[0] = bifurcationBarycenter[1] = bifurcationBarycenter[2] = 0.0;
1122 double weightSum = 0.0;
1123 for (i=1; i<bifurcationPoints->GetNumberOfPoints(); i++)
1124 {
1125 double bifurcationPoint[3];
1126 bifurcationPoints->GetPoint(i,bifurcationPoint);
1127 double bifurcationPointRadius = bifurcationRadii->GetValue(i);
1128 weightSum+=bifurcationPointRadius;
1129 for (j=0; j<3; j++)
1130 {
1131 bifurcationBarycenter[j] += bifurcationPoint[j] * bifurcationPointRadius;
1132 }
1133 }
1134 for (j=0; j<3; j++)
1135 {
1136 bifurcationBarycenter[j] /= weightSum;
1137 }
1138 bifurcationPoints->InsertPoint(0,bifurcationBarycenter);
1139
1140 edgeTableForNewProfiles->Delete();
1141 cellPairsForNewProfiles->Delete();
1142 pointIdsForNewProfiles->Delete();
1143 edgeTableForIncludedGlobalProfiles->Delete();
1144 markedPoints->Delete();
1145 markedPointIds->Delete();
1146
1148 }
1149
1150 vtkPoints *pointsForRadius = vtkPoints::New();
1151 this->
PointsForRadius(markedPoints,baseProfiles,newProfiles,pointsForRadius);
1152
1153 newProfiles->InitTraversal();
1154 double profileBarycenter[3];
1155 this->
ProfileBarycenter(newProfiles->GetNextItem()->GetPoints(),profileBarycenter);
1156 double stepRadius = this->
ComputeStepRadius(pointsForRadius,center,profileBarycenter);
1157
1158 pointsForRadius->Delete();
1159
1160 if (!sameCenter)
1161 {
1162 segmentRadii->InsertNextValue(stepRadius);
1163 segmentPoints->InsertNextPoint(center);
1164 }
1165 else
1166 {
1167 segmentRadii->InsertValue(segmentRadii->GetNumberOfTuples()-1,stepRadius);
1168 segmentPoints->InsertPoint(segmentPoints->GetNumberOfPoints()-1,center);
1169 }
1170
1171 oldCenter[0] = center[0];
1172 oldCenter[1] = center[1];
1173 oldCenter[2] = center[2];
1174 oldRadius = radius;
1175
1176 edgeTableForNewProfiles->Delete();
1177 cellPairsForNewProfiles->Delete();
1178 pointIdsForNewProfiles->Delete();
1179 edgeTableForIncludedGlobalProfiles->Delete();
1180 markedPoints->Delete();
1181 markedPointIds->Delete();
1182
1184}