198 vtkDataArray* radiusArray = lines->GetPointData()->GetArray(this->
RadiusArrayName);
200 vtkPolyLine* polyLine = vtkPolyLine::SafeDownCast(lines->GetCell(cellId));
207 vtkPoints* polyLinePoints = polyLine->GetPoints();
214 int numberOfPoints = polyLine->GetNumberOfPoints();
215 int numberOfSubIds = numberOfPoints - 1;
217 double cellLength = 0.0;
218 double point0[3], point1[3];
220 for (i=0; i<numberOfSubIds; i++)
222 polyLinePoints->GetPoint(i,point0);
223 polyLinePoints->GetPoint(i+1,point1);
224 cellLength += sqrt(vtkMath::Distance2BetweenPoints(point0,point1));
227 xSpline->SetParametricRange(0.0,cellLength);
228 ySpline->SetParametricRange(0.0,cellLength);
229 zSpline->SetParametricRange(0.0,cellLength);
230 rSpline->SetParametricRange(0.0,cellLength);
232 vtkDoubleArray* parametricCoordinates = vtkDoubleArray::New();
233 parametricCoordinates->SetNumberOfTuples(numberOfPoints);
235 double currentLength = 0.0;
236 polyLinePoints->GetPoint(0,point0);
237 double radius = radiusArray->GetTuple1(polyLine->GetPointId(0));
239 xSpline->AddPoint(0.0,point0[0]);
240 ySpline->AddPoint(0.0,point0[1]);
241 zSpline->AddPoint(0.0,point0[2]);
242 rSpline->AddPoint(0.0,radius);
243 parametricCoordinates->SetValue(0,0.0);
244 for (i=1; i<numberOfPoints; i++)
246 polyLinePoints->GetPoint(i-1,point0);
247 polyLinePoints->GetPoint(i,point1);
248 radius = radiusArray->GetTuple1(polyLine->GetPointId(i));
249 currentLength += sqrt(vtkMath::Distance2BetweenPoints(point0,point1));
251 xSpline->AddPoint(t,point1[0]);
252 ySpline->AddPoint(t,point1[1]);
253 zSpline->AddPoint(t,point1[2]);
254 rSpline->AddPoint(t,radius);
255 parametricCoordinates->SetValue(i,t);
261 for (i=0; i<numberOfPoints; i++)
263 t = (double)i / (numberOfPoints-1) * cellLength;
264 point[0] = xSpline->Evaluate(t);
265 point[1] = ySpline->Evaluate(t);
266 point[2] = zSpline->Evaluate(t);
267 radius = rSpline->Evaluate(t);
268 polyLinePoints->SetPoint(i,point);
269 radiusArray->SetTuple1(i,radius);
270 parametricCoordinates->SetValue(i,t);
274 vtkDoubleArray* probedForces = vtkDoubleArray::New();
275 probedForces->SetNumberOfComponents(3);
278 vtkDoubleArray* tubeNormals = vtkDoubleArray::New();
279 tubeNormals->SetNumberOfComponents(3);
282 vtkDoubleArray* dxArray = vtkDoubleArray::New();
283 dxArray->SetNumberOfTuples(numberOfPoints);
284 dxArray->FillComponent(0,0.0);
285 vtkDoubleArray* dyArray = vtkDoubleArray::New();
286 dyArray->SetNumberOfTuples(numberOfPoints);
287 dyArray->FillComponent(0,0.0);
288 vtkDoubleArray* dzArray = vtkDoubleArray::New();
289 dzArray->SetNumberOfTuples(numberOfPoints);
290 dzArray->FillComponent(0,0.0);
291 vtkDoubleArray* drArray = vtkDoubleArray::New();
292 drArray->SetNumberOfTuples(numberOfPoints);
293 drArray->FillComponent(0,0.0);
297 int numberOfLongitudinalEvaluations = numberOfPoints * 3 / 2;
299 for (i=0; i<numberOfLongitudinalEvaluations; i++)
301 t = (double)i / (numberOfLongitudinalEvaluations-1) * cellLength;
302 double x = xSpline->Evaluate(t);
303 double y = ySpline->Evaluate(t);
304 double z = zSpline->Evaluate(t);
305 double r = rSpline->Evaluate(t);
315 double tangent[3], normal[3];
321 double tubeNormSquared = xp * xp + yp * yp + zp * zp - rp * rp;
324 if (tubeNormSquared <= 0.0)
328 vtkWarningMacro(
"Negative tubeNormSquared. Skipping.");
333 double tubeNorm = sqrt(tubeNormSquared);
335 double isotropicForce = 0.0;
336 double anisotropicForce[3];
337 anisotropicForce[0] = anisotropicForce[1] = anisotropicForce[2] = 0.0;
339 double tubeNormal[3], probePoint[3], probedForce[3];
344 theta = j * 2.0 * vtkMath::Pi() / this->NumberOfAngularEvaluations;
346 vtkMath::Perpendiculars(tangent,normal,NULL,theta);
348 tubeNormal[0] = - tangent[0] * rp + normal[0] * tubeNorm;
349 tubeNormal[1] = - tangent[1] * rp + normal[1] * tubeNorm;
350 tubeNormal[2] = - tangent[2] * rp + normal[2] * tubeNorm;
352 vtkMath::Normalize(tubeNormal);
354 probePoint[0] = x + tubeNormal[0] * r;
355 probePoint[1] = y + tubeNormal[1] * r;
356 probePoint[2] = z + tubeNormal[2] * r;
362 probedForces->SetTuple(j,probedForce);
363 tubeNormals->SetTuple(j,tubeNormal);
365 isotropicForce += vtkMath::Dot(probedForce,tubeNormal);
368 isotropicForce /= this->NumberOfAngularEvaluations;
370 for (j=0; j<this->NumberOfAngularEvaluations; j++)
372 probedForces->GetTuple(j,probedForce);
373 tubeNormals->GetTuple(j,tubeNormal);
374 anisotropicForce[0] += probedForce[0] - tubeNormal[0] * isotropicForce;
375 anisotropicForce[1] += probedForce[1] - tubeNormal[1] * isotropicForce;
376 anisotropicForce[2] += probedForce[2] - tubeNormal[2] * isotropicForce;
379 anisotropicForce[0] /= this->NumberOfAngularEvaluations;
380 anisotropicForce[1] /= this->NumberOfAngularEvaluations;
381 anisotropicForce[2] /= this->NumberOfAngularEvaluations;
385 for (j=0; j<numberOfPoints; j++)
387 double parametricCoordinate = parametricCoordinates->GetValue(j);
388 double influence = 0.1 * cellLength;
389 if (fabs(parametricCoordinate-t) > influence)
393 double weight = (influence - fabs(parametricCoordinate-t)) / influence;
394 double dx, dy, dz, dr;
395 dx = dxArray->GetValue(j);
396 dy = dyArray->GetValue(j);
397 dz = dzArray->GetValue(j);
398 dr = drArray->GetValue(j);
400 dy += anisotropicForce[1] * weight * this->PotentialWeight;
401 dz += anisotropicForce[2] * weight * this->PotentialWeight;
402 dr += isotropicForce * weight * this->PotentialWeight;
404 dy += ypp * weight * this->StiffnessWeight;
405 dz += zpp * weight * this->StiffnessWeight;
406 dr += rpp * weight * this->StiffnessWeight;
407 dxArray->SetValue(j,dx);
408 dyArray->SetValue(j,dy);
409 dzArray->SetValue(j,dz);
410 drArray->SetValue(j,dr);
416 if (this->PotientialImage)
429 minSpacing = spacing[i] < minSpacing ? spacing[i] : minSpacing;
432 double maxChange = 0.0;
433 for (i=0; i<numberOfPoints; i++)
435 double dx = dxArray->GetValue(i);
436 double dy = dyArray->GetValue(i);
437 double dz = dzArray->GetValue(i);
438 double dr = drArray->GetValue(i);
439 double change = sqrt(dx*dx + dy*dy + dz*dz) + dr;
440 maxChange = change > maxChange ? change : maxChange;
455 for (i=0; i<numberOfPoints; i++)
457 pointId = polyLine->GetPointId(i);
458 polyLinePoints->GetPoint(i,point);
459 radius = radiusArray->GetTuple1(pointId);
460 point[0] += dxArray->GetValue(i) * timeStep;
461 point[1] += dyArray->GetValue(i) * timeStep;
462 point[2] += dzArray->GetValue(i) * timeStep;
463 radius += drArray->GetValue(i) * timeStep;
466 radius = this->MinimumRadius;
470 lines->GetPoints()->SetPoint(pointId,point);
474 radiusArray->SetTuple1(pointId,radius);
484 parametricCoordinates->Delete();
485 probedForces->Delete();
486 tubeNormals->Delete();