99 double startingPoint[3], endingPoint[3], currentPoint[3], currentScalar;
101 double currentRadius;
102 vtkIdType currentEdge[2], steepestDescentEdge[2], previousEdge[2], previousEdge2[2];
103 double steepestDescentS, steepestDescent;
104 double previousS, previousS2;
105 double previousPoint[3];
106 double directionFactor;
107 vtkIdList* neighborCells;
108 vtkIdType pointId, j, targetId;
111 vtkPoints* newPoints;
112 vtkDataArray* newScalars;
113 vtkCellArray* newLines;
115 newPoints = this->GetOutput()->GetPoints();
116 newScalars = this->GetOutput()->GetPointData()->GetArray(this->
DataArrayName);
117 newLines = this->GetOutput()->GetLines();
119 neighborCells = vtkIdList::New();
120 lineIds = vtkIdList::New();
122 directionFactor = 0.0;
125 directionFactor = 1.0;
129 directionFactor = - 1.0;
134 input->GetPoint(seedId,startingPoint);
136 currentPoint[0] = startingPoint[0];
137 currentPoint[1] = startingPoint[1];
138 currentPoint[2] = startingPoint[2];
140 pointId = newPoints->InsertNextPoint(startingPoint);
144 lineIds->InsertNextId(pointId);
146 currentEdge[0] = seedId;
147 currentEdge[1] = seedId;
153 newScalars->InsertComponent(pointId,0,currentRadius);
154 this->
Edges->InsertComponent(pointId,0,currentEdge[0]);
155 this->
Edges->InsertComponent(pointId,1,currentEdge[1]);
158 std::size_t numIterations = 0;
160 previousEdge[0] = currentEdge[0];
161 previousEdge[1] = currentEdge[1];
163 previousEdge2[0] = -1;
164 previousEdge2[1] = -1;
168 if ((this->
StopOnTargets) && ((this->
Targets->IsId(currentEdge[0]) != -1) || (this->Targets->IsId(currentEdge[1]) != -1)))
170 if (this->
Targets->IsId(currentEdge[0]) != -1)
172 targetId = currentEdge[0];
176 targetId = currentEdge[1];
179 input->GetPoint(targetId,endingPoint);
182 pointId = newPoints->InsertNextPoint(endingPoint);
183 currentScalar = this->
DescentArray->GetTuple1(targetId);
185 lineIds->InsertNextId(pointId);
187 currentEdge[0] = targetId;
188 currentEdge[1] = targetId;
191 newScalars->InsertTuple1(pointId,currentRadius);
192 this->
Edges->InsertComponent(pointId,0,currentEdge[0]);
193 this->
Edges->InsertComponent(pointId,1,currentEdge[1]);
207 input->GetCellEdgeNeighbors(-1,currentEdge[0],currentEdge[1],neighborCells);
209 steepestDescent = this->
GetSteepestDescent(input,currentEdge,currentS,steepestDescentEdge,steepestDescentS);
211 if (steepestDescentEdge[0] == -1 || steepestDescentEdge[1] == -1)
213 vtkWarningMacro(<<
"Can't find a steepest descent edge. Target not reached.");
223 vtkWarningMacro(<<
"Target not reached.");
229 currentEdge[0] = steepestDescentEdge[0];
230 currentEdge[1] = steepestDescentEdge[1];
231 currentS = steepestDescentS;
233 if (numIterations > 0 &&
235 ((currentEdge[0] == previousEdge2[0] && currentEdge[1] == previousEdge2[1] && fabs(previousS2 - currentS) <
VTK_VMTK_DOUBLE_TOL)) ||
236 ((currentEdge[0] == previousEdge2[1] && currentEdge[1] == previousEdge2[0]) && fabs(1.0 - previousS2 - currentS) <
VTK_VMTK_DOUBLE_TOL)
240 vtkWarningMacro(<<
"Degenerate descent detected. Target not reached.");
245 previousPoint[0] = currentPoint[0];
246 previousPoint[1] = currentPoint[1];
247 previousPoint[2] = currentPoint[2];
253 double edgePoint0[3], edgePoint1[3];
254 input->GetPoint(currentEdge[0], edgePoint0);
255 input->GetPoint(currentEdge[1], edgePoint1);
256 currentPoint[0] = edgePoint0[0] * (1.0 - currentS) + edgePoint1[0] * currentS;
257 currentPoint[1] = edgePoint0[1] * (1.0 - currentS) + edgePoint1[1] * currentS;
258 currentPoint[2] = edgePoint0[2] * (1.0 - currentS) + edgePoint1[2] * currentS;
261 currentScalar = this->
DescentArray->GetTuple1(currentEdge[0]) * (1.0 - currentS) + this->
DescentArray->GetTuple1(currentEdge[1]) * currentS;
262 currentRadius = this->
LineDataArray->GetTuple1(currentEdge[0]) * (1.0 - currentS) + this->
LineDataArray->GetTuple1(currentEdge[1]) * currentS;
266 for (j=newPoints->GetNumberOfPoints()-1; j>=0; j--)
268 if (((this->
Edges->GetComponent(j,0)==currentEdge[0])&&(this->Edges->GetComponent(j,1)==currentEdge[1]))||
269 ((this->Edges->GetComponent(j,0)==currentEdge[1])&&(this->Edges->GetComponent(j,1)==currentEdge[0])))
272 newPoints->GetPoint(j,newPoint);
273 if (sqrt(vtkMath::Distance2BetweenPoints(currentPoint,newPoint)) <= this->
MergeTolerance)
276 lineIds->InsertNextId(pointId);
286 pointId = newPoints->InsertNextPoint(currentPoint);
287 lineIds->InsertNextId(pointId);
289 newScalars->InsertTuple1(pointId,currentRadius);
290 this->
Edges->InsertComponent(pointId,0,currentEdge[0]);
291 this->
Edges->InsertComponent(pointId,1,currentEdge[1]);
294 previousEdge2[0] = previousEdge[0];
295 previousEdge2[1] = previousEdge[1];
296 previousS2 = previousS;
298 previousEdge[0] = currentEdge[0];
299 previousEdge[1] = currentEdge[1];
300 previousS = currentS;
305 if (numIterations == 0)
313 pointId = newPoints->InsertNextPoint(currentPoint);
314 lineIds->InsertNextId(pointId);
315 newScalars->InsertTuple1(pointId, currentRadius);
316 this->
Edges->InsertComponent(pointId, 0, currentEdge[0]);
317 this->
Edges->InsertComponent(pointId, 1, currentEdge[1]);
321 newLines->InsertNextCell(lineIds);
323 neighborCells->Delete();
328 vtkInformation *vtkNotUsed(request),
329 vtkInformationVector **inputVector,
330 vtkInformationVector *outputVector)
332 vtkInformation *inInfo = inputVector[0]->GetInformationObject(0);
333 vtkInformation *outInfo = outputVector->GetInformationObject(0);
335 vtkPolyData *input = vtkPolyData::SafeDownCast(
336 inInfo->Get(vtkDataObject::DATA_OBJECT()));
337 vtkPolyData *output = vtkPolyData::SafeDownCast(
338 outInfo->Get(vtkDataObject::DATA_OBJECT()));
341 vtkPoints* newPoints;
342 vtkCellArray* newLines;
343 vtkDoubleArray* newScalars;
347 vtkErrorMacro(
"Descent array name not specified.");
351 if (!input->GetPointData()->GetArray(this->DescentArrayName))
353 vtkErrorMacro(<<
"Descent array with name specified does not exist!");
359 vtkErrorMacro(
"No Seeds set");
363 if (!this->
Seeds->GetNumberOfIds())
365 vtkErrorMacro(
"Empty Seeds list");
369 for (i=0; i<this->
Seeds->GetNumberOfIds(); i++)
371 if ((this->
Seeds->GetId(i)<0) || (this->Seeds->GetId(i)>input->GetNumberOfPoints()))
373 vtkErrorMacro(
"Seed id invalid or exceeds input number of points.");
380 for (i=0; i<this->
Targets->GetNumberOfIds(); i++)
382 if ((this->
Targets->GetId(i)<0) || (this->Targets->GetId(i) > input->GetNumberOfPoints()))
384 vtkErrorMacro(
"Invalid target id.");
397 vtkErrorMacro(<<
"Line data array with name specified does not exist!");
407 this->
Edges = vtkIntArray::New();
412 this->
Edges->SetNumberOfComponents(2);
421 this->
Edges->SetName(
"Edges");
433 newPoints = vtkPoints::New();
434 newLines = vtkCellArray::New();
435 newScalars = vtkDoubleArray::New();
443 output->SetPoints(newPoints);
444 output->SetLines(newLines);
445 output->GetPointData()->AddArray(newScalars);
449 newScalars->Delete();
456 for (i=0; i<this->
Seeds->GetNumberOfIds(); i++)
461 output->GetPointData()->AddArray(this->
Edges);
464 this->
Edges->Delete();