Starting from the point at (cellId, subId, pcoord) on centerlines, walk forward (or backward, if forward is false) until reaching the point whose maximum inscribed sphere (radius taken from the radiusArrayName point data array) just touches the sphere centered at the starting point. The result is returned in touchingSubId/touchingPCoord.
74{
75 touchingSubId = -1;
76 touchingPCoord = 0.0;
77
78 vtkCell* centerline = centerlines->GetCell(cellId);
79
80 if (centerline->GetCellType() != VTK_LINE && centerline->GetCellType() != VTK_POLY_LINE)
81 {
82 return;
83 }
84
85 if (!radiusArrayName)
86 {
87 return;
88 }
89
90 vtkDataArray* radiusArray = centerlines->GetPointData()->GetArray(radiusArrayName);
91
92 if (!radiusArray)
93 {
94 return;
95 }
96
97 vtkIdList* subIds = vtkIdList::New();
98
99 int k;
100 if (forward)
101 {
102 for (k=0; k<subId; k++)
103 {
104 subIds->InsertNextId(k);
105 }
106 }
107 else
108 {
109 for (k=centerline->GetNumberOfPoints()-2; k>subId; k--)
110 {
111 subIds->InsertNextId(k);
112 }
113 }
114
115 double point[3], point0[3], point1[3];
116 centerline->GetPoints()->GetPoint(subId,point0);
117 centerline->GetPoints()->GetPoint(subId+1,point1);
118 for (k=0; k<3; k++)
119 {
120 point[k] = point0[k] + pcoord*(point1[k] - point0[k]);
121 }
122
123 vtkIdType centerId0, centerId1;
124 double center0[3], center1[3], radius0, radius1;
125 vtkIdType currentSubId;
126 double currentPCoord;
127 double sphereDistance0, sphereDistance1;
128
129 touchingSubId = -1;
130 touchingPCoord = 0.0;
131
132 int i;
133 for (i=0; i<subIds->GetNumberOfIds(); i++)
134 {
135 currentSubId = subIds->GetId(i);
136
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);
145
146 if (forward)
147 {
148 if ((sphereDistance0 > 0.0) && (sphereDistance1 <= 0.0))
149 {
150 touchingSubId = currentSubId;
151 break;
152 }
153 }
154 else
155 {
156 if ((sphereDistance0 <= 0.0) && (sphereDistance1 > 0.0))
157 {
158 touchingSubId = currentSubId;
159 break;
160 }
161 }
162 }
163
164 if (touchingSubId == -1)
165 {
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);
172
175
176 if ((sphereDistance0<=0.0) && (sphereDistance1<=0.0))
177 {
178 touchingSubId = -1;
179 subIds->Delete();
180 return;
181 }
182
183 touchingSubId = subId;
184 }
185
186
187
188
189
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);
196
197 double segmentLength, stepSize, pcoordStepSize;
198 int numberOfSteps;
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;
206
207 touchingPCoord = 0.0;
208 currentPCoord = 0.0;
209 for (i=0; i<numberOfSteps; i++)
210 {
211 for (int k=0; k<3; k++)
212 {
213 subCenter0[k] = center0[k] + currentPCoord*(center1[k] - center0[k]);
214 subCenter1[k] = center0[k] + (currentPCoord+pcoordStepSize)*(center1[k] - center0[k]);
215 }
216 subRadius0 = radius0 + currentPCoord*(radius1 - radius0);
217 subRadius1 = radius0 + (currentPCoord+pcoordStepSize)*(radius1 - radius0);
218
221
222 if (forward)
223 {
224 if ((sphereDistance0 > 0.0) && (sphereDistance1 <= 0.0))
225 {
226 touchingPCoord = currentPCoord;
227 break;
228 }
229 }
230 else
231 {
232 if ((sphereDistance0 <= 0.0) && (sphereDistance1 > 0.0))
233 {
234 touchingPCoord = currentPCoord+pcoordStepSize;
235 break;
236 }
237 }
238 currentPCoord += pcoordStepSize;
239 }
240
241 if (forward)
242 {
243 if ((touchingSubId == subId) && (touchingPCoord > pcoord))
244 {
245 touchingSubId = -1;
246 touchingPCoord = 0.0;
247 }
248 }
249 else
250 {
251 if ((touchingSubId == subId) && (touchingPCoord < pcoord))
252 {
253 touchingSubId = -1;
254 touchingPCoord = 0.0;
255 }
256 }
257
258 subIds->Delete();
259}
static double EvaluateSphereFunction(double center[3], double radius, double point[3])