194{
195
196
197
198 vtkDataArray* radiusArray = lines->GetPointData()->GetArray(this->
RadiusArrayName);
199
200 vtkPolyLine* polyLine = vtkPolyLine::SafeDownCast(lines->GetCell(cellId));
201
202 if (!polyLine)
203 {
204 return;
205 }
206
207 vtkPoints* polyLinePoints = polyLine->GetPoints();
208
213
214 int numberOfPoints = polyLine->GetNumberOfPoints();
215 int numberOfSubIds = numberOfPoints - 1;
216
217 double cellLength = 0.0;
218 double point0[3], point1[3];
219 int i;
220 for (i=0; i<numberOfSubIds; i++)
221 {
222 polyLinePoints->GetPoint(i,point0);
223 polyLinePoints->GetPoint(i+1,point1);
224 cellLength += sqrt(vtkMath::Distance2BetweenPoints(point0,point1));
225 }
226
227 xSpline->SetParametricRange(0.0,cellLength);
228 ySpline->SetParametricRange(0.0,cellLength);
229 zSpline->SetParametricRange(0.0,cellLength);
230 rSpline->SetParametricRange(0.0,cellLength);
231
232 vtkDoubleArray* parametricCoordinates = vtkDoubleArray::New();
233 parametricCoordinates->SetNumberOfTuples(numberOfPoints);
234
235 double currentLength = 0.0;
236 polyLinePoints->GetPoint(0,point0);
237 double radius = radiusArray->GetTuple1(polyLine->GetPointId(0));
238 double t = 0.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++)
245 {
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));
250 t = currentLength;
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);
256 }
257
259 {
260 double point[3];
261 for (i=0; i<numberOfPoints; i++)
262 {
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);
271 }
272 }
273
274 vtkDoubleArray* probedForces = vtkDoubleArray::New();
275 probedForces->SetNumberOfComponents(3);
277
278 vtkDoubleArray* tubeNormals = vtkDoubleArray::New();
279 tubeNormals->SetNumberOfComponents(3);
281
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);
294
295
296
297 int numberOfLongitudinalEvaluations = numberOfPoints * 3 / 2;
298
299 for (i=0; i<numberOfLongitudinalEvaluations; i++)
300 {
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);
314
315 double tangent[3], normal[3];
316
317 tangent[0] = xp;
318 tangent[1] = yp;
319 tangent[2] = zp;
320
321 double tubeNormSquared = xp * xp + yp * yp + zp * zp - rp * rp;
322
323
324 if (tubeNormSquared <= 0.0)
325 {
327 {
328 vtkWarningMacro("Negative tubeNormSquared. Skipping.");
329 }
330 continue;
331 }
332
333 double tubeNorm = sqrt(tubeNormSquared);
334
335 double isotropicForce = 0.0;
336 double anisotropicForce[3];
337 anisotropicForce[0] = anisotropicForce[1] = anisotropicForce[2] = 0.0;
338
339 double tubeNormal[3], probePoint[3], probedForce[3];
340 double theta;
341 int j;
343 {
345
346 vtkMath::Perpendiculars(tangent,normal,NULL,theta);
347
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;
351
352 vtkMath::Normalize(tubeNormal);
353
354 probePoint[0] = x + tubeNormal[0] * r;
355 probePoint[1] = y + tubeNormal[1] * r;
356 probePoint[2] = z + tubeNormal[2] * r;
357
358
359
361
362 probedForces->SetTuple(j,probedForce);
363 tubeNormals->SetTuple(j,tubeNormal);
364
365 isotropicForce += vtkMath::Dot(probedForce,tubeNormal);
366 }
367
369
371 {
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;
377 }
378
382
383
384
385 for (j=0; j<numberOfPoints; j++)
386 {
387 double parametricCoordinate = parametricCoordinates->GetValue(j);
388 double influence = 0.1 * cellLength;
389 if (fabs(parametricCoordinate-t) > influence)
390 {
391 continue;
392 }
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);
407 dxArray->SetValue(j,dx);
408 dyArray->SetValue(j,dy);
409 dzArray->SetValue(j,dz);
410 drArray->SetValue(j,dr);
411 }
412 }
413
414 double spacing[3];
415#if 0
416 if (this->PotientialImage)
417 {
419 }
420 else
421#endif
422 {
424 }
425
427 for (i=0; i<3; i++)
428 {
429 minSpacing = spacing[i] < minSpacing ? spacing[i] : minSpacing;
430 }
431
432 double maxChange = 0.0;
433 for (i=0; i<numberOfPoints; i++)
434 {
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;
441 }
442
443 double timeStep;
444 if (maxChange > 0.0)
445 {
447 }
448 else
449 {
450 timeStep = 0.0;
451 }
452
453 vtkIdType pointId;
454 double point[3];
455 for (i=0; i<numberOfPoints; i++)
456 {
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;
465 {
467 }
469 {
470 lines->GetPoints()->SetPoint(pointId,point);
471 }
473 {
474 radiusArray->SetTuple1(pointId,radius);
475 }
476 }
477
478
479
480 xSpline->Delete();
481 ySpline->Delete();
482 zSpline->Delete();
483 rSpline->Delete();
484 parametricCoordinates->Delete();
485 probedForces->Delete();
486 tubeNormals->Delete();
487 dxArray->Delete();
488 dyArray->Delete();
489 dzArray->Delete();
490 drArray->Delete();
491}
void EvaluateForce(double point[3], double force[3], bool normalize)
virtual double EvaluateDerivative(double t)
virtual double EvaluateSecondDerivative(double t)
static vtkvmtkCardinalSpline * New()
#define VTK_VMTK_LARGE_DOUBLE