46{
48
50 {
53 }
54
56 {
59 }
60
62 {
65 }
66
68 {
69 return;
70 }
71
72 if (input->GetCell(cellId)->GetCellType() != VTK_LINE && input->GetCell(cellId)->GetCellType() != VTK_POLY_LINE)
73 {
74 return;
75 }
76
77 vtkDataArray* radiusArray = input->GetPointData()->GetArray(this->
RadiusArrayName);
78
79 if (!radiusArray)
80 {
81 return;
82 }
83
84
85
87
90
91 vtkIdList* tubeCellIds = vtkIdList::New();
92
93 vtkIdList* intersectionSubIds = vtkIdList::New();
94 vtkDoubleArray* intersectionPCoords = vtkDoubleArray::New();
95
96 vtkIdType numberOfCells = input->GetNumberOfCells();
97
98
99 int j;
100 for (j=0; j<numberOfCells; j++)
101 {
102 if (j==cellId)
103 {
104 continue;
105 }
106
107 if (input->GetCell(j)->GetCellType() != VTK_LINE && input->GetCell(j)->GetCellType() != VTK_POLY_LINE)
108 {
109 continue;
110 }
111
112 tubeCellIds->Initialize();
113 tubeCellIds->InsertNextId(j);
115
116 int numberOfCellPoints = input->GetCell(cellId)->GetNumberOfPoints();
117
118 double point0[3], point1[3];
119 double tubeValue0, tubeValue1;
120 for (int k=0; k<numberOfCellPoints-1; k++)
121 {
122 input->GetCell(cellId)->GetPoints()->GetPoint(k,point0);
123 input->GetCell(cellId)->GetPoints()->GetPoint(k+1,point1);
126
127
128 if ((tubeValue0 <= 0.0) && (tubeValue1 > 0.0))
129 {
130 double radius0, radius1;
131 radius0 = radiusArray->GetComponent(input->GetCell(cellId)->GetPointId(k),0);
132 radius1 = radiusArray->GetComponent(input->GetCell(cellId)->GetPointId(k+1),0);
133
134
135 double segmentLength, stepSize, pcoordStepSize;
136 int numberOfSteps;
137 double subPoint0[3], subPoint1[3];
138 double subTubeValue0, subTubeValue1;
139 segmentLength = vtkMath::Distance2BetweenPoints(point0,point1);
140 stepSize = 1E-2 * (radius0 + radius1) / 2.0;
141 numberOfSteps = (int)ceil(segmentLength / stepSize);
142 stepSize = segmentLength / numberOfSteps;
143 pcoordStepSize = 1.0 / (double)numberOfSteps;
144
145 double pcoord = 0.0;
146 int s;
147 for (s=0; s<numberOfSteps; s++)
148 {
149 for (int d=0; d<3; d++)
150 {
151 subPoint0[d] = point0[d] + pcoord * (point1[d] - point0[d]);
152 subPoint1[d] = point0[d] + (pcoord + pcoordStepSize) * (point1[d] - point0[d]);
153 }
154
157
158
159 if ((subTubeValue0 <= 0.0) && (subTubeValue1 > 0.0))
160 {
161 pcoord += pcoordStepSize;
162 break;
163 }
164
165 pcoord += pcoordStepSize;
166 }
167
168
169 int numberOfIntersections = intersectionSubIds->GetNumberOfIds();
170 int insertLocation = 0;
171 for (s=0; s<numberOfIntersections; s++)
172 {
173 bool afterThis = (k > intersectionSubIds->GetId(s)) || (k==intersectionSubIds->GetId(s) && pcoord > intersectionPCoords->GetValue(s));
174 bool beforeNext = true;
175 if (s<numberOfIntersections-1)
176 {
177 beforeNext = (k < intersectionSubIds->GetId(s+1)) || (k==intersectionSubIds->GetId(s+1) && pcoord <= intersectionPCoords->GetValue(s+1));
178 }
179 if (afterThis && beforeNext)
180 {
181 insertLocation = s+1;
182 break;
183 }
184 }
185 for (s=numberOfIntersections-1; s>=insertLocation; s--)
186 {
187 intersectionSubIds->InsertId(s+1,intersectionSubIds->GetId(s));
188 intersectionPCoords->InsertValue(s+1,intersectionPCoords->GetValue(s));
189 }
190 intersectionSubIds->InsertId(insertLocation,k);
191 intersectionPCoords->InsertValue(insertLocation,pcoord);
192 }
193 }
194 }
195
196
197
198 vtkIdType touchingSubId;
199 double touchingPCoord;
200
201 const int numberOfGapSpheres = 1;
202 const bool forward = true;
203
204 vtkIdList* touchingSubIds = vtkIdList::New();
205 vtkDoubleArray* touchingPCoords = vtkDoubleArray::New();
206
207 int i;
208 for (i=0; i<intersectionSubIds->GetNumberOfIds(); i++)
209 {
211 if (touchingSubId == -1)
212 {
213 touchingSubId = 0;
214 touchingPCoord = 0.0;
215 touchingSubIds->InsertNextId(touchingSubId);
216 touchingPCoords->InsertNextValue(touchingPCoord);
217 continue;
218 }
219
220 touchingSubIds->InsertNextId(touchingSubId);
221 touchingPCoords->InsertNextValue(touchingPCoord);
222 }
223
224 vtkIdList* splittingSubIds = vtkIdList::New();
225 vtkDoubleArray* splittingPCoords = vtkDoubleArray::New();
226 vtkIdList* blankingFlags = vtkIdList::New();
227
228 blankingFlags->InsertNextId(0);
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275 vtkIdType prevIntersectionId = -1;
276 for (i=0; i<touchingSubIds->GetNumberOfIds(); i++)
277 {
278 if (i > 0)
279 {
280 if ((touchingSubIds->GetId(i) < intersectionSubIds->GetId(prevIntersectionId)) ||
281 ((touchingSubIds->GetId(i) == intersectionSubIds->GetId(prevIntersectionId)) && (touchingPCoords->GetValue(i) <= intersectionPCoords->GetValue(prevIntersectionId))))
282 {
283 continue;
284 }
285 }
286
287 splittingSubIds->InsertNextId(touchingSubIds->GetId(i));
288 splittingPCoords->InsertNextValue(touchingPCoords->GetValue(i));
289 blankingFlags->InsertNextId(1);
290
291 vtkIdType maxIntersectionId = i;
292
293 if (i < touchingSubIds->GetNumberOfIds()-1)
294 {
295 for (j=i+1; j<touchingSubIds->GetNumberOfIds(); j++)
296 {
297 if ((touchingSubIds->GetId(j) < intersectionSubIds->GetId(maxIntersectionId)) ||
298 ((touchingSubIds->GetId(j) == intersectionSubIds->GetId(maxIntersectionId)) && (touchingPCoords->GetValue(j) <= intersectionPCoords->GetValue(maxIntersectionId))))
299 {
300 if ((intersectionSubIds->GetId(j) > intersectionSubIds->GetId(maxIntersectionId)) ||
301 ((intersectionSubIds->GetId(j) == intersectionSubIds->GetId(maxIntersectionId)) && (intersectionPCoords->GetValue(j) >= intersectionPCoords->GetValue(maxIntersectionId))))
302 {
303 maxIntersectionId = j;
304 }
305 }
306 else
307 {
308 break;
309 }
310 }
311 }
312
313 splittingSubIds->InsertNextId(intersectionSubIds->GetId(maxIntersectionId));
314 splittingPCoords->InsertNextValue(intersectionPCoords->GetValue(maxIntersectionId));
315 blankingFlags->InsertNextId(0);
316
317 prevIntersectionId = maxIntersectionId;
318 }
319
321
324
325 for (i=0; i<splittingSubIds->GetNumberOfIds(); i++)
326 {
327 this->
SubIds[i] = splittingSubIds->GetId(i);
328 this->
PCoords[i] = splittingPCoords->GetValue(i);
329 }
330
332
334 {
336 }
337
338 tube->Delete();
339 tubeCellIds->Delete();
340
341 intersectionSubIds->Delete();
342 intersectionPCoords->Delete();
343
344 touchingSubIds->Delete();
345 touchingPCoords->Delete();
346
347 splittingSubIds->Delete();
348 splittingPCoords->Delete();
349 blankingFlags->Delete();
350}
static void FindNTouchingSphereCenter(vtkPolyData *centerlines, const char *radiusArrayName, vtkIdType cellId, vtkIdType subId, double pcoord, int numberOfTouchingSpheres, vtkIdType &touchingSubId, double &touchingPCoord, bool forward=true)
int NumberOfSplittingPoints
virtual void SetInput(vtkPolyData *)
virtual void SetPolyBallRadiusArrayName(const char *)
virtual void SetInputCellIds(vtkIdList *)
static vtkvmtkPolyBallLine * New()
double EvaluateFunction(double x[3]) override