97{
98 bool done;
99 double startingPoint[3], endingPoint[3], currentPoint[3], currentScalar;
100 double currentS;
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;
109 vtkIdList* lineIds;
110
111 vtkPoints* newPoints;
112 vtkDataArray* newScalars;
113 vtkCellArray* newLines;
114
115 newPoints = this->GetOutput()->GetPoints();
116 newScalars = this->GetOutput()->GetPointData()->GetArray(this->
DataArrayName);
117 newLines = this->GetOutput()->GetLines();
118
119 neighborCells = vtkIdList::New();
120 lineIds = vtkIdList::New();
121
122 directionFactor = 0.0;
124 {
125 directionFactor = 1.0;
126 }
128 {
129 directionFactor = - 1.0;
130 }
131
132 done = false;
133
134 input->GetPoint(seedId,startingPoint);
135
136 currentPoint[0] = startingPoint[0];
137 currentPoint[1] = startingPoint[1];
138 currentPoint[2] = startingPoint[2];
139
140 pointId = newPoints->InsertNextPoint(startingPoint);
141
144 lineIds->InsertNextId(pointId);
145
146 currentEdge[0] = seedId;
147 currentEdge[1] = seedId;
148 currentS = 0.0;
149
150 previousS = 0.0;
151 previousS2 = 0.0;
152
153 newScalars->InsertComponent(pointId,0,currentRadius);
154 this->
Edges->InsertComponent(pointId,0,currentEdge[0]);
155 this->
Edges->InsertComponent(pointId,1,currentEdge[1]);
157
158 std::size_t numIterations = 0;
159
160 previousEdge[0] = currentEdge[0];
161 previousEdge[1] = currentEdge[1];
162
163 previousEdge2[0] = -1;
164 previousEdge2[1] = -1;
165
166 while (!done)
167 {
168 if ((this->
StopOnTargets) && ((this->
Targets->IsId(currentEdge[0]) != -1) || (this->Targets->IsId(currentEdge[1]) != -1)))
169 {
170 if (this->
Targets->IsId(currentEdge[0]) != -1)
171 {
172 targetId = currentEdge[0];
173 }
174 else
175 {
176 targetId = currentEdge[1];
177 }
178
179 input->GetPoint(targetId,endingPoint);
181 {
182 pointId = newPoints->InsertNextPoint(endingPoint);
183 currentScalar = this->
DescentArray->GetTuple1(targetId);
185 lineIds->InsertNextId(pointId);
186
187 currentEdge[0] = targetId;
188 currentEdge[1] = targetId;
189 currentS = 0.0;
190
191 newScalars->InsertTuple1(pointId,currentRadius);
192 this->
Edges->InsertComponent(pointId,0,currentEdge[0]);
193 this->
Edges->InsertComponent(pointId,1,currentEdge[1]);
195 }
196
198
199 done = true;
200 break;
201 }
202 if (done)
203 {
204 break;
205 }
206
207 input->GetCellEdgeNeighbors(-1,currentEdge[0],currentEdge[1],neighborCells);
208
209 steepestDescent = this->
GetSteepestDescent(input,currentEdge,currentS,steepestDescentEdge,steepestDescentS);
210
211 if (steepestDescentEdge[0] == -1 || steepestDescentEdge[1] == -1)
212 {
213 vtkWarningMacro(<<"Can't find a steepest descent edge. Target not reached.");
214 done = true;
215 break;
216 }
217
219 {
221
222 {
223 vtkWarningMacro(<<"Target not reached.");
224 done = true;
225 break;
226 }
227 }
228
229 currentEdge[0] = steepestDescentEdge[0];
230 currentEdge[1] = steepestDescentEdge[1];
231 currentS = steepestDescentS;
232
233 if (numIterations > 0 &&
234 (
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)
237 )
238 )
239 {
240 vtkWarningMacro(<<"Degenerate descent detected. Target not reached.");
241 done = true;
242 break;
243 }
244
245 previousPoint[0] = currentPoint[0];
246 previousPoint[1] = currentPoint[1];
247 previousPoint[2] = currentPoint[2];
248
249
250
251
252 {
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;
259 }
260
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;
263
265 {
266 for (j=newPoints->GetNumberOfPoints()-1; j>=0; j--)
267 {
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])))
270 {
271 double newPoint[3];
272 newPoints->GetPoint(j,newPoint);
273 if (sqrt(vtkMath::Distance2BetweenPoints(currentPoint,newPoint)) <= this->
MergeTolerance)
274 {
275 pointId = j;
276 lineIds->InsertNextId(pointId);
277 done = true;
278 break;
279 }
280 }
281 }
282 if (done)
283 break;
284 }
285
286 pointId = newPoints->InsertNextPoint(currentPoint);
287 lineIds->InsertNextId(pointId);
288
289 newScalars->InsertTuple1(pointId,currentRadius);
290 this->
Edges->InsertComponent(pointId,0,currentEdge[0]);
291 this->
Edges->InsertComponent(pointId,1,currentEdge[1]);
293
294 previousEdge2[0] = previousEdge[0];
295 previousEdge2[1] = previousEdge[1];
296 previousS2 = previousS;
297
298 previousEdge[0] = currentEdge[0];
299 previousEdge[1] = currentEdge[1];
300 previousS = currentS;
301
302 ++numIterations;
303 }
304
305 if (numIterations == 0)
306 {
307
308
309
310
311
312
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]);
319 }
320
321 newLines->InsertNextCell(lineIds);
322
323 neighborCells->Delete();
324 lineIds->Delete();
325}
double GetSteepestDescent(vtkPolyData *input, vtkIdType *edge, double s, vtkIdType *steepestDescentEdge, double &steepestDescentS)
#define VTK_VMTK_DOWNWARD