72 if (input->GetCell(cellId)->GetCellType() != VTK_LINE && input->GetCell(cellId)->GetCellType() != VTK_POLY_LINE)
77 vtkDataArray* radiusArray = input->GetPointData()->GetArray(this->
RadiusArrayName);
91 vtkIdList* tubeCellIds = vtkIdList::New();
93 vtkIdList* intersectionSubIds = vtkIdList::New();
94 vtkDoubleArray* intersectionPCoords = vtkDoubleArray::New();
96 vtkIdType numberOfCells = input->GetNumberOfCells();
100 for (j=0; j<numberOfCells; j++)
107 if (input->GetCell(j)->GetCellType() != VTK_LINE && input->GetCell(j)->GetCellType() != VTK_POLY_LINE)
112 tubeCellIds->Initialize();
113 tubeCellIds->InsertNextId(j);
116 int numberOfCellPoints = input->GetCell(cellId)->GetNumberOfPoints();
118 double point0[3], point1[3];
119 double tubeValue0, tubeValue1;
120 for (
int k=0; k<numberOfCellPoints-1; k++)
122 input->GetCell(cellId)->GetPoints()->GetPoint(k,point0);
123 input->GetCell(cellId)->GetPoints()->GetPoint(k+1,point1);
128 if ((tubeValue0 <= 0.0) && (tubeValue1 > 0.0))
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);
135 double segmentLength, stepSize, pcoordStepSize;
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;
147 for (s=0; s<numberOfSteps; s++)
149 for (
int d=0; d<3; d++)
151 subPoint0[d] = point0[d] + pcoord * (point1[d] - point0[d]);
152 subPoint1[d] = point0[d] + (pcoord + pcoordStepSize) * (point1[d] - point0[d]);
159 if ((subTubeValue0 <= 0.0) && (subTubeValue1 > 0.0))
161 pcoord += pcoordStepSize;
165 pcoord += pcoordStepSize;
169 int numberOfIntersections = intersectionSubIds->GetNumberOfIds();
170 int insertLocation = 0;
171 for (s=0; s<numberOfIntersections; s++)
173 bool afterThis = (k > intersectionSubIds->GetId(s)) || (k==intersectionSubIds->GetId(s) && pcoord > intersectionPCoords->GetValue(s));
174 bool beforeNext =
true;
175 if (s<numberOfIntersections-1)
177 beforeNext = (k < intersectionSubIds->GetId(s+1)) || (k==intersectionSubIds->GetId(s+1) && pcoord <= intersectionPCoords->GetValue(s+1));
179 if (afterThis && beforeNext)
181 insertLocation = s+1;
185 for (s=numberOfIntersections-1; s>=insertLocation; s--)
187 intersectionSubIds->InsertId(s+1,intersectionSubIds->GetId(s));
188 intersectionPCoords->InsertValue(s+1,intersectionPCoords->GetValue(s));
190 intersectionSubIds->InsertId(insertLocation,k);
191 intersectionPCoords->InsertValue(insertLocation,pcoord);
198 vtkIdType touchingSubId;
199 double touchingPCoord;
201 const int numberOfGapSpheres = 1;
202 const bool forward =
true;
204 vtkIdList* touchingSubIds = vtkIdList::New();
205 vtkDoubleArray* touchingPCoords = vtkDoubleArray::New();
208 for (i=0; i<intersectionSubIds->GetNumberOfIds(); i++)
211 if (touchingSubId == -1)
214 touchingPCoord = 0.0;
215 touchingSubIds->InsertNextId(touchingSubId);
216 touchingPCoords->InsertNextValue(touchingPCoord);
220 touchingSubIds->InsertNextId(touchingSubId);
221 touchingPCoords->InsertNextValue(touchingPCoord);
224 vtkIdList* splittingSubIds = vtkIdList::New();
225 vtkDoubleArray* splittingPCoords = vtkDoubleArray::New();
226 vtkIdList* blankingFlags = vtkIdList::New();
228 blankingFlags->InsertNextId(0);
275 vtkIdType prevIntersectionId = -1;
276 for (i=0; i<touchingSubIds->GetNumberOfIds(); i++)
280 if ((touchingSubIds->GetId(i) < intersectionSubIds->GetId(prevIntersectionId)) ||
281 ((touchingSubIds->GetId(i) == intersectionSubIds->GetId(prevIntersectionId)) && (touchingPCoords->GetValue(i) <= intersectionPCoords->GetValue(prevIntersectionId))))
287 splittingSubIds->InsertNextId(touchingSubIds->GetId(i));
288 splittingPCoords->InsertNextValue(touchingPCoords->GetValue(i));
289 blankingFlags->InsertNextId(1);
291 vtkIdType maxIntersectionId = i;
293 if (i < touchingSubIds->GetNumberOfIds()-1)
295 for (j=i+1; j<touchingSubIds->GetNumberOfIds(); j++)
297 if ((touchingSubIds->GetId(j) < intersectionSubIds->GetId(maxIntersectionId)) ||
298 ((touchingSubIds->GetId(j) == intersectionSubIds->GetId(maxIntersectionId)) && (touchingPCoords->GetValue(j) <= intersectionPCoords->GetValue(maxIntersectionId))))
300 if ((intersectionSubIds->GetId(j) > intersectionSubIds->GetId(maxIntersectionId)) ||
301 ((intersectionSubIds->GetId(j) == intersectionSubIds->GetId(maxIntersectionId)) && (intersectionPCoords->GetValue(j) >= intersectionPCoords->GetValue(maxIntersectionId))))
303 maxIntersectionId = j;
313 splittingSubIds->InsertNextId(intersectionSubIds->GetId(maxIntersectionId));
314 splittingPCoords->InsertNextValue(intersectionPCoords->GetValue(maxIntersectionId));
315 blankingFlags->InsertNextId(0);
317 prevIntersectionId = maxIntersectionId;
325 for (i=0; i<splittingSubIds->GetNumberOfIds(); i++)
327 this->
SubIds[i] = splittingSubIds->GetId(i);
328 this->
PCoords[i] = splittingPCoords->GetValue(i);
339 tubeCellIds->Delete();
341 intersectionSubIds->Delete();
342 intersectionPCoords->Delete();
344 touchingSubIds->Delete();
345 touchingPCoords->Delete();
347 splittingSubIds->Delete();
348 splittingPCoords->Delete();
349 blankingFlags->Delete();