45 vtkIdType dummySubId0, dummySubId1;
46 double dummyPCoord0, dummyPCoord1;
48 if (numberOfTouchingSpheres == 0)
50 touchingSubId = subId;
51 touchingPCoord = pcoord;
56 dummyPCoord0 = pcoord;
58 for (
int i=0; i<numberOfTouchingSpheres; i++)
61 if (dummySubId1 == -1)
65 dummySubId0 = dummySubId1;
66 dummyPCoord0 = dummyPCoord1;
69 touchingSubId = dummySubId1;
70 touchingPCoord = dummyPCoord1;
78 vtkCell* centerline = centerlines->GetCell(cellId);
80 if (centerline->GetCellType() != VTK_LINE && centerline->GetCellType() != VTK_POLY_LINE)
90 vtkDataArray* radiusArray = centerlines->GetPointData()->GetArray(radiusArrayName);
97 vtkIdList* subIds = vtkIdList::New();
102 for (k=0; k<subId; k++)
104 subIds->InsertNextId(k);
109 for (k=centerline->GetNumberOfPoints()-2; k>subId; k--)
111 subIds->InsertNextId(k);
115 double point[3], point0[3], point1[3];
116 centerline->GetPoints()->GetPoint(subId,point0);
117 centerline->GetPoints()->GetPoint(subId+1,point1);
120 point[k] = point0[k] + pcoord*(point1[k] - point0[k]);
123 vtkIdType centerId0, centerId1;
124 double center0[3], center1[3], radius0, radius1;
125 vtkIdType currentSubId;
126 double currentPCoord;
127 double sphereDistance0, sphereDistance1;
130 touchingPCoord = 0.0;
133 for (i=0; i<subIds->GetNumberOfIds(); i++)
135 currentSubId = subIds->GetId(i);
137 centerId0 = centerline->GetPointId(currentSubId);
138 centerId1 = centerline->GetPointId(currentSubId+1);
139 centerlines->GetPoint(centerId0,center0);
140 centerlines->GetPoint(centerId1,center1);
141 radius0 = radiusArray->GetComponent(centerId0,0);
142 radius1 = radiusArray->GetComponent(centerId1,0);
148 if ((sphereDistance0 > 0.0) && (sphereDistance1 <= 0.0))
150 touchingSubId = currentSubId;
156 if ((sphereDistance0 <= 0.0) && (sphereDistance1 > 0.0))
158 touchingSubId = currentSubId;
164 if (touchingSubId == -1)
166 centerId0 = centerline->GetPointId(subId);
167 centerId1 = centerline->GetPointId(subId+1);
168 centerlines->GetPoint(centerId0,center0);
169 centerlines->GetPoint(centerId1,center1);
170 radius0 = radiusArray->GetComponent(centerId0,0);
171 radius1 = radiusArray->GetComponent(centerId1,0);
176 if ((sphereDistance0<=0.0) && (sphereDistance1<=0.0))
183 touchingSubId = subId;
190 centerId0 = centerline->GetPointId(touchingSubId);
191 centerId1 = centerline->GetPointId(touchingSubId+1);
192 centerlines->GetPoint(centerId0,center0);
193 centerlines->GetPoint(centerId1,center1);
194 radius0 = radiusArray->GetComponent(centerId0,0);
195 radius1 = radiusArray->GetComponent(centerId1,0);
197 double segmentLength, stepSize, pcoordStepSize;
199 double subCenter0[3], subCenter1[3], subRadius0, subRadius1;
200 segmentLength = vtkMath::Distance2BetweenPoints(center0,center1);
201 stepSize = 1E-6 * (radius0 + radius1) / 2.0;
202 const double maxNumberOfSteps = 1e5;
203 numberOfSteps = (int)ceil(std::min(segmentLength / stepSize, maxNumberOfSteps));
204 stepSize = segmentLength / numberOfSteps;
205 pcoordStepSize = 1.0 / (double)numberOfSteps;
207 touchingPCoord = 0.0;
209 for (i=0; i<numberOfSteps; i++)
211 for (
int k=0; k<3; k++)
213 subCenter0[k] = center0[k] + currentPCoord*(center1[k] - center0[k]);
214 subCenter1[k] = center0[k] + (currentPCoord+pcoordStepSize)*(center1[k] - center0[k]);
216 subRadius0 = radius0 + currentPCoord*(radius1 - radius0);
217 subRadius1 = radius0 + (currentPCoord+pcoordStepSize)*(radius1 - radius0);
224 if ((sphereDistance0 > 0.0) && (sphereDistance1 <= 0.0))
226 touchingPCoord = currentPCoord;
232 if ((sphereDistance0 <= 0.0) && (sphereDistance1 > 0.0))
234 touchingPCoord = currentPCoord+pcoordStepSize;
238 currentPCoord += pcoordStepSize;
243 if ((touchingSubId == subId) && (touchingPCoord > pcoord))
246 touchingPCoord = 0.0;
251 if ((touchingSubId == subId) && (touchingPCoord < pcoord))
254 touchingPCoord = 0.0;