VMTK
Loading...
Searching...
No Matches
vtkvmtkCenterlineGeometry Class Reference

Compute length, curvature, torsion, tortuosity, and frenet frames for individual centerlines. More...

#include <vtkvmtkCenterlineGeometry.h>

Inheritance diagram for vtkvmtkCenterlineGeometry:
[legend]
Collaboration diagram for vtkvmtkCenterlineGeometry:
[legend]

Public Types

typedef vtkPolyDataAlgorithm Superclass

Public Member Functions

virtual int IsA (const char *type)
vtkvmtkCenterlineGeometry * NewInstance () const
void PrintSelf (std::ostream &os, vtkIndent indent) override
virtual void SetLengthArrayName (const char *)
virtual char * GetLengthArrayName ()
virtual void SetCurvatureArrayName (const char *)
virtual char * GetCurvatureArrayName ()
virtual void SetTorsionArrayName (const char *)
virtual char * GetTorsionArrayName ()
virtual void SetTortuosityArrayName (const char *)
virtual char * GetTortuosityArrayName ()
virtual void SetFrenetTangentArrayName (const char *)
virtual char * GetFrenetTangentArrayName ()
virtual void SetFrenetNormalArrayName (const char *)
virtual char * GetFrenetNormalArrayName ()
virtual void SetFrenetBinormalArrayName (const char *)
virtual char * GetFrenetBinormalArrayName ()
virtual void SetSmoothingFactor (double)
virtual double GetSmoothingFactor ()
virtual void SetNumberOfSmoothingIterations (int)
virtual int GetNumberOfSmoothingIterations ()
virtual void SetLineSmoothing (int)
virtual int GetLineSmoothing ()
virtual void LineSmoothingOn ()
virtual void LineSmoothingOff ()
virtual void SetOutputSmoothedLines (int)
virtual int GetOutputSmoothedLines ()
virtual void OutputSmoothedLinesOn ()
virtual void OutputSmoothedLinesOff ()

Static Public Member Functions

static int IsTypeOf (const char *type)
static vtkvmtkCenterlineGeometry * SafeDownCast (vtkObjectBase *o)
static vtkvmtkCenterlineGeometry * New ()
static double ComputeLineCurvature (vtkPoints *linePoints, vtkDoubleArray *curvatureArray)
static double ComputeLineTorsion (vtkPoints *linePoints, vtkDoubleArray *torsionArray)
static void ComputeLineFrenetReferenceSystem (vtkPoints *linePoints, vtkDoubleArray *lineTangentArray, vtkDoubleArray *lineNormalArray, vtkDoubleArray *lineBinormalArray)

Protected Member Functions

virtual vtkObjectBase * NewInstanceInternal () const
 vtkvmtkCenterlineGeometry ()
 ~vtkvmtkCenterlineGeometry ()
virtual int RequestData (vtkInformation *, vtkInformationVector **, vtkInformationVector *) override

Protected Attributes

char * LengthArrayName
char * CurvatureArrayName
char * TorsionArrayName
char * TortuosityArrayName
char * FrenetTangentArrayName
char * FrenetNormalArrayName
char * FrenetBinormalArrayName
int LineSmoothing
int OutputSmoothedLines
double SmoothingFactor
int NumberOfSmoothingIterations

Detailed Description

Compute length, curvature, torsion, tortuosity, and frenet frames for individual centerlines.

vtkvmtkCenterlineGeometry takes a vtkPolyData composed of polyline (or line) cells representing centerlines – typically the output of vtkvmtkCenterlineBranchExtractor / vtkvmtkCenterlineSplittingAndGroupingFilter after splitting and grouping, so that each cell is a single, non-branching tract – and computes, for every cell, its arc length and Frenet-frame differential geometry (curvature, torsion, tortuosity, tangent/normal/binormal vectors). This is the filter behind the vmtkcenterlinegeometry pype script, and its output is commonly used to characterize vessel curvature/torsion (e.g. for tortuosity indices) or to build a local reference frame for stent/graft deployment analysis.

The length, curvature, torsion, and tortuosity metrics are scalar quantities which are identical for each point / tract that makes up a cell. They are cell data which are attached to the centerline (which should only consist of one cell, as it has not been split or grouped).

The frenet reference frame is composed of three orthogonal vectors (tangent, normal, and binormal) unique to their parameterization along the centerline. Three vectors are stored as point data for each point making up the centerline.

A laplacian smoothing filter can be applied to the line if the computation appears to be unstable (as we are using second derivatives and such here).

See also
vtkvmtkCenterlineBranchExtractor, vtkvmtkCenterlineSplittingAndGroupingFilter, vtkvmtkCenterlineSmoothing, vtkvmtkCenterlineAttributesFilter

Definition at line 53 of file vtkvmtkCenterlineGeometry.h.

Member Typedef Documentation

◆ Superclass

typedef vtkPolyDataAlgorithm vtkvmtkCenterlineGeometry::Superclass

Definition at line 56 of file vtkvmtkCenterlineGeometry.h.

Constructor & Destructor Documentation

◆ vtkvmtkCenterlineGeometry()

vtkvmtkCenterlineGeometry::vtkvmtkCenterlineGeometry ( )
protected

Definition at line 39 of file vtkvmtkCenterlineGeometry.cxx.

40{
41 this->LengthArrayName = NULL;
42 this->CurvatureArrayName = NULL;
43 this->TorsionArrayName = NULL;
44 this->TortuosityArrayName = NULL;
45
46 this->FrenetTangentArrayName = NULL;
47 this->FrenetNormalArrayName = NULL;
48 this->FrenetBinormalArrayName = NULL;
49
50 this->LineSmoothing = 0;
51 this->OutputSmoothedLines = 0;
52 this->SmoothingFactor = 0.01;
54}

◆ ~vtkvmtkCenterlineGeometry()

vtkvmtkCenterlineGeometry::~vtkvmtkCenterlineGeometry ( )
protected

Definition at line 56 of file vtkvmtkCenterlineGeometry.cxx.

57{
58 if (this->LengthArrayName)
59 {
60 delete[] this->LengthArrayName;
61 this->LengthArrayName = NULL;
62 }
63
64 if (this->CurvatureArrayName)
65 {
66 delete[] this->CurvatureArrayName;
67 this->CurvatureArrayName = NULL;
68 }
69
70 if (this->TorsionArrayName)
71 {
72 delete[] this->TorsionArrayName;
73 this->TorsionArrayName = NULL;
74 }
75
76 if (this->TortuosityArrayName)
77 {
78 delete[] this->TortuosityArrayName;
79 this->TortuosityArrayName = NULL;
80 }
81
82 if (this->FrenetTangentArrayName)
83 {
84 delete[] this->FrenetTangentArrayName;
85 this->FrenetTangentArrayName = NULL;
86 }
87
88 if (this->FrenetNormalArrayName)
89 {
90 delete[] this->FrenetNormalArrayName;
91 this->FrenetNormalArrayName = NULL;
92 }
93
95 {
96 delete[] this->FrenetBinormalArrayName;
97 this->FrenetBinormalArrayName = NULL;
98 }
99}

Member Function Documentation

◆ IsTypeOf()

int vtkvmtkCenterlineGeometry::IsTypeOf ( const char * type)
static

◆ IsA()

virtual int vtkvmtkCenterlineGeometry::IsA ( const char * type)
virtual

◆ SafeDownCast()

vtkvmtkCenterlineGeometry * vtkvmtkCenterlineGeometry::SafeDownCast ( vtkObjectBase * o)
static

◆ NewInstanceInternal()

virtual vtkObjectBase * vtkvmtkCenterlineGeometry::NewInstanceInternal ( ) const
protectedvirtual

◆ NewInstance()

vtkvmtkCenterlineGeometry * vtkvmtkCenterlineGeometry::NewInstance ( ) const

◆ PrintSelf()

void vtkvmtkCenterlineGeometry::PrintSelf ( std::ostream & os,
vtkIndent indent )
override

Definition at line 606 of file vtkvmtkCenterlineGeometry.cxx.

607{
608 this->Superclass::PrintSelf(os,indent);
609}

◆ New()

vtkvmtkCenterlineGeometry * vtkvmtkCenterlineGeometry::New ( )
static

◆ SetLengthArrayName()

virtual void vtkvmtkCenterlineGeometry::SetLengthArrayName ( const char * )
virtual

Set/get the name of the cell data array (one value per centerline cell) where the arc length of each line is stored. Must be specified before Update() is called. Commonly named "Length".

◆ GetLengthArrayName()

virtual char * vtkvmtkCenterlineGeometry::GetLengthArrayName ( )
virtual

Set/get the name of the cell data array (one value per centerline cell) where the arc length of each line is stored. Must be specified before Update() is called. Commonly named "Length".

◆ SetCurvatureArrayName()

virtual void vtkvmtkCenterlineGeometry::SetCurvatureArrayName ( const char * )
virtual

Set/get the name of the point data array (one value per centerline point) where the local curvature, estimated from finite differences of the discrete Frenet frame, is stored. Must be specified before Update() is called. Commonly named "Curvature".

◆ GetCurvatureArrayName()

virtual char * vtkvmtkCenterlineGeometry::GetCurvatureArrayName ( )
virtual

Set/get the name of the point data array (one value per centerline point) where the local curvature, estimated from finite differences of the discrete Frenet frame, is stored. Must be specified before Update() is called. Commonly named "Curvature".

◆ SetTorsionArrayName()

virtual void vtkvmtkCenterlineGeometry::SetTorsionArrayName ( const char * )
virtual

Set/get the name of the point data array (one value per centerline point) where the local torsion, estimated from finite differences of the discrete Frenet frame, is stored. Must be specified before Update() is called. Commonly named "Torsion".

◆ GetTorsionArrayName()

virtual char * vtkvmtkCenterlineGeometry::GetTorsionArrayName ( )
virtual

Set/get the name of the point data array (one value per centerline point) where the local torsion, estimated from finite differences of the discrete Frenet frame, is stored. Must be specified before Update() is called. Commonly named "Torsion".

◆ SetTortuosityArrayName()

virtual void vtkvmtkCenterlineGeometry::SetTortuosityArrayName ( const char * )
virtual

Set/get the name of the cell data array (one value per centerline cell) where the tortuosity of each line is stored, computed as (arc length / chord length) - 1, where the chord is the straight-line distance between the first and last point of the cell. Must be specified before Update() is called. Commonly named "Tortuosity".

◆ GetTortuosityArrayName()

virtual char * vtkvmtkCenterlineGeometry::GetTortuosityArrayName ( )
virtual

Set/get the name of the cell data array (one value per centerline cell) where the tortuosity of each line is stored, computed as (arc length / chord length) - 1, where the chord is the straight-line distance between the first and last point of the cell. Must be specified before Update() is called. Commonly named "Tortuosity".

◆ SetFrenetTangentArrayName()

virtual void vtkvmtkCenterlineGeometry::SetFrenetTangentArrayName ( const char * )
virtual

Set/get the name of the 3-component point data array where the Frenet tangent unit vector (direction of travel along the centerline) is stored for each point. Must be specified before Update() is called. Commonly named "FrenetTangent".

◆ GetFrenetTangentArrayName()

virtual char * vtkvmtkCenterlineGeometry::GetFrenetTangentArrayName ( )
virtual

Set/get the name of the 3-component point data array where the Frenet tangent unit vector (direction of travel along the centerline) is stored for each point. Must be specified before Update() is called. Commonly named "FrenetTangent".

◆ SetFrenetNormalArrayName()

virtual void vtkvmtkCenterlineGeometry::SetFrenetNormalArrayName ( const char * )
virtual

Set/get the name of the 3-component point data array where the Frenet normal unit vector (points towards the local center of curvature) is stored for each point. Must be specified before Update() is called. Commonly named "FrenetNormal".

◆ GetFrenetNormalArrayName()

virtual char * vtkvmtkCenterlineGeometry::GetFrenetNormalArrayName ( )
virtual

Set/get the name of the 3-component point data array where the Frenet normal unit vector (points towards the local center of curvature) is stored for each point. Must be specified before Update() is called. Commonly named "FrenetNormal".

◆ SetFrenetBinormalArrayName()

virtual void vtkvmtkCenterlineGeometry::SetFrenetBinormalArrayName ( const char * )
virtual

Set/get the name of the 3-component point data array where the Frenet binormal unit vector (tangent cross normal, completing the right-handed frame) is stored for each point. Must be specified before Update() is called. Commonly named "FrenetBinormal".

◆ GetFrenetBinormalArrayName()

virtual char * vtkvmtkCenterlineGeometry::GetFrenetBinormalArrayName ( )
virtual

Set/get the name of the 3-component point data array where the Frenet binormal unit vector (tangent cross normal, completing the right-handed frame) is stored for each point. Must be specified before Update() is called. Commonly named "FrenetBinormal".

◆ SetSmoothingFactor()

virtual void vtkvmtkCenterlineGeometry::SetSmoothingFactor ( double )
virtual

Set/get the relaxation factor used by the optional Laplacian smoothing pass applied to each line's points before curvature/torsion are computed (see LineSmoothing). Higher values smooth more aggressively per iteration. Default: 0.01.

◆ GetSmoothingFactor()

virtual double vtkvmtkCenterlineGeometry::GetSmoothingFactor ( )
virtual

Set/get the relaxation factor used by the optional Laplacian smoothing pass applied to each line's points before curvature/torsion are computed (see LineSmoothing). Higher values smooth more aggressively per iteration. Default: 0.01.

◆ SetNumberOfSmoothingIterations()

virtual void vtkvmtkCenterlineGeometry::SetNumberOfSmoothingIterations ( int )
virtual

Set/get the number of Laplacian smoothing iterations applied to each line's points before curvature/torsion are computed (see LineSmoothing). Default: 100.

◆ GetNumberOfSmoothingIterations()

virtual int vtkvmtkCenterlineGeometry::GetNumberOfSmoothingIterations ( )
virtual

Set/get the number of Laplacian smoothing iterations applied to each line's points before curvature/torsion are computed (see LineSmoothing). Default: 100.

◆ SetLineSmoothing()

virtual void vtkvmtkCenterlineGeometry::SetLineSmoothing ( int )
virtual

Toggle Laplacian smoothing of each line's points prior to computing curvature, torsion, and the Frenet frame. Since these quantities involve second derivatives of the line geometry, smoothing can stabilize the computation on noisy or piecewise-linear centerlines. The output geometry arrays (points) are only replaced with the smoothed coordinates if OutputSmoothedLines is also on. Default: off.

◆ GetLineSmoothing()

virtual int vtkvmtkCenterlineGeometry::GetLineSmoothing ( )
virtual

Toggle Laplacian smoothing of each line's points prior to computing curvature, torsion, and the Frenet frame. Since these quantities involve second derivatives of the line geometry, smoothing can stabilize the computation on noisy or piecewise-linear centerlines. The output geometry arrays (points) are only replaced with the smoothed coordinates if OutputSmoothedLines is also on. Default: off.

◆ LineSmoothingOn()

virtual void vtkvmtkCenterlineGeometry::LineSmoothingOn ( )
virtual

Toggle Laplacian smoothing of each line's points prior to computing curvature, torsion, and the Frenet frame. Since these quantities involve second derivatives of the line geometry, smoothing can stabilize the computation on noisy or piecewise-linear centerlines. The output geometry arrays (points) are only replaced with the smoothed coordinates if OutputSmoothedLines is also on. Default: off.

◆ LineSmoothingOff()

virtual void vtkvmtkCenterlineGeometry::LineSmoothingOff ( )
virtual

Toggle Laplacian smoothing of each line's points prior to computing curvature, torsion, and the Frenet frame. Since these quantities involve second derivatives of the line geometry, smoothing can stabilize the computation on noisy or piecewise-linear centerlines. The output geometry arrays (points) are only replaced with the smoothed coordinates if OutputSmoothedLines is also on. Default: off.

◆ SetOutputSmoothedLines()

virtual void vtkvmtkCenterlineGeometry::SetOutputSmoothedLines ( int )
virtual

Toggle whether the output centerline points are replaced by the smoothed points used internally for the differential geometry computation (only relevant when LineSmoothing is on). When off, the output retains the original input point coordinates and only the computed arrays change. Default: off.

◆ GetOutputSmoothedLines()

virtual int vtkvmtkCenterlineGeometry::GetOutputSmoothedLines ( )
virtual

Toggle whether the output centerline points are replaced by the smoothed points used internally for the differential geometry computation (only relevant when LineSmoothing is on). When off, the output retains the original input point coordinates and only the computed arrays change. Default: off.

◆ OutputSmoothedLinesOn()

virtual void vtkvmtkCenterlineGeometry::OutputSmoothedLinesOn ( )
virtual

Toggle whether the output centerline points are replaced by the smoothed points used internally for the differential geometry computation (only relevant when LineSmoothing is on). When off, the output retains the original input point coordinates and only the computed arrays change. Default: off.

◆ OutputSmoothedLinesOff()

virtual void vtkvmtkCenterlineGeometry::OutputSmoothedLinesOff ( )
virtual

Toggle whether the output centerline points are replaced by the smoothed points used internally for the differential geometry computation (only relevant when LineSmoothing is on). When off, the output retains the original input point coordinates and only the computed arrays change. Default: off.

◆ ComputeLineCurvature()

double vtkvmtkCenterlineGeometry::ComputeLineCurvature ( vtkPoints * linePoints,
vtkDoubleArray * curvatureArray )
static

Compute the discrete curvature at every point of a single polyline, given as an ordered set of points, and store the per-point values in curvatureArray (resized/filled by this call). Returns the length-weighted average curvature over the line. Used internally by RequestData, but also usable standalone on an arbitrary vtkPoints polyline.

Definition at line 409 of file vtkvmtkCenterlineGeometry.cxx.

410{
411 int numberOfPoints = linePoints->GetNumberOfPoints();
412
413 curvatureArray->SetNumberOfComponents(1);
414 curvatureArray->SetNumberOfTuples(numberOfPoints);
415 curvatureArray->FillComponent(0,0.0);
416
417 double point0[3], point1[3], point2[3];
418 double vector0[3], vector1[3];
419
420 double averageCurvature = 0.0;
421 double weightSum = 0.0;
422
423 for (int j=1; j<numberOfPoints-1; j++)
424 {
425 linePoints->GetPoint(j-1,point0);
426 linePoints->GetPoint(j,point1);
427 linePoints->GetPoint(j+1,point2);
428
429 vector0[0] = point1[0] - point0[0];
430 vector0[1] = point1[1] - point0[1];
431 vector0[2] = point1[2] - point0[2];
432
433 vector1[0] = point2[0] - point1[0];
434 vector1[1] = point2[1] - point1[1];
435 vector1[2] = point2[2] - point1[2];
436
437 double norm0 = vtkMath::Norm(vector0);
438 double norm1 = vtkMath::Norm(vector1);
439
440 if (norm0 < VTK_VMTK_DOUBLE_TOL || norm1 < VTK_VMTK_DOUBLE_TOL)
441 {
442 continue;
443 }
444
445 double xp[3];
446 xp[0] = point2[0] - point0[0];
447 xp[1] = point2[1] - point0[1];
448 xp[2] = point2[2] - point0[2];
449 xp[0] /= norm0 + norm1;
450 xp[1] /= norm0 + norm1;
451 xp[2] /= norm0 + norm1;
452
453 double xpp[3];
454 xpp[0] = (point2[0] - point1[0]) / norm1 - (point1[0] - point0[0]) / norm0;
455 xpp[1] = (point2[1] - point1[1]) / norm1 - (point1[1] - point0[1]) / norm0;
456 xpp[2] = (point2[2] - point1[2]) / norm1 - (point1[2] - point0[2]) / norm0;
457 xpp[0] /= (norm0 + norm1) / 2.0;
458 xpp[1] /= (norm0 + norm1) / 2.0;
459 xpp[2] /= (norm0 + norm1) / 2.0;
460
461 double xpxppcross[3];
462 vtkMath::Cross(xp,xpp,xpxppcross);
463
464 double curvature = vtkMath::Norm(xpxppcross) / pow(vtkMath::Norm(xp),3.0);
465 curvatureArray->SetComponent(j,0,curvature);
466 double weight = (norm0 + norm1) / 2.0;
467 averageCurvature += curvature * weight;
468
469 weightSum += weight;
470 }
471
472 if (weightSum>0.0)
473 {
474 averageCurvature /= weightSum;
475 }
476
477 return averageCurvature;
478}
#define VTK_VMTK_DOUBLE_TOL

◆ ComputeLineTorsion()

double vtkvmtkCenterlineGeometry::ComputeLineTorsion ( vtkPoints * linePoints,
vtkDoubleArray * torsionArray )
static

Compute the discrete torsion at every point of a single polyline, given as an ordered set of points, and store the per-point values in torsionArray (resized/filled by this call). Returns the length-weighted average torsion over the line. Used internally by RequestData, but also usable standalone on an arbitrary vtkPoints polyline.

Definition at line 480 of file vtkvmtkCenterlineGeometry.cxx.

481{
482 int numberOfPoints = linePoints->GetNumberOfPoints();
483
484 torsionArray->SetNumberOfComponents(1);
485 torsionArray->SetNumberOfTuples(numberOfPoints);
486 torsionArray->FillComponent(0,0.0);
487
488 double point0[3], point1[3], point2[3];
489 double vector0[3], vector1[3];
490
491 double averageTorsion = 0.0;
492 double weightSum = 0.0;
493
494 double* xps = new double[3*numberOfPoints];
495 double* xpps = new double[3*numberOfPoints];
496
497 int j;
498 for (j=0; j<numberOfPoints; j++)
499 {
500 xps[3*j+0] = xps[3*j+1] = xps[3*j+2] = 0.0;
501 xpps[3*j+0] = xpps[3*j+1] = xpps[3*j+2] = 0.0;
502 }
503
504 for (j=1; j<numberOfPoints-1; j++)
505 {
506 linePoints->GetPoint(j-1,point0);
507 linePoints->GetPoint(j,point1);
508 linePoints->GetPoint(j+1,point2);
509
510 vector0[0] = point1[0] - point0[0];
511 vector0[1] = point1[1] - point0[1];
512 vector0[2] = point1[2] - point0[2];
513
514 vector1[0] = point2[0] - point1[0];
515 vector1[1] = point2[1] - point1[1];
516 vector1[2] = point2[2] - point1[2];
517
518 double norm0 = vtkMath::Norm(vector0);
519 double norm1 = vtkMath::Norm(vector1);
520
521 if (norm0 < VTK_VMTK_DOUBLE_TOL || norm1 < VTK_VMTK_DOUBLE_TOL)
522 {
523 continue;
524 }
525
526 xps[3*j+0] = point2[0] - point0[0];
527 xps[3*j+1] = point2[1] - point0[1];
528 xps[3*j+2] = point2[2] - point0[2];
529 xps[3*j+0] /= norm0 + norm1;
530 xps[3*j+1] /= norm0 + norm1;
531 xps[3*j+2] /= norm0 + norm1;
532
533 xpps[3*j+0] = (point2[0] - point1[0]) / norm1 - (point1[0] - point0[0]) / norm0;
534 xpps[3*j+1] = (point2[1] - point1[1]) / norm1 - (point1[1] - point0[1]) / norm0;
535 xpps[3*j+2] = (point2[2] - point1[2]) / norm1 - (point1[2] - point0[2]) / norm0;
536 xpps[3*j+0] /= (norm0 + norm1) / 2.0;
537 xpps[3*j+1] /= (norm0 + norm1) / 2.0;
538 xpps[3*j+2] /= (norm0 + norm1) / 2.0;
539 }
540
541 for (j=2; j<numberOfPoints-2; j++)
542 {
543 linePoints->GetPoint(j-1,point0);
544 linePoints->GetPoint(j,point1);
545 linePoints->GetPoint(j+1,point2);
546
547 vector0[0] = point1[0] - point0[0];
548 vector0[1] = point1[1] - point0[1];
549 vector0[2] = point1[2] - point0[2];
550
551 vector1[0] = point2[0] - point1[0];
552 vector1[1] = point2[1] - point1[1];
553 vector1[2] = point2[2] - point1[2];
554
555 double norm0 = vtkMath::Norm(vector0);
556 double norm1 = vtkMath::Norm(vector1);
557
558 if (norm0 < VTK_VMTK_DOUBLE_TOL || norm1 < VTK_VMTK_DOUBLE_TOL)
559 {
560 continue;
561 }
562
563 double xp[3];
564 xp[0] = xps[3*j+0];
565 xp[1] = xps[3*j+1];
566 xp[2] = xps[3*j+2];
567
568 double xpp[3];
569 xpp[0] = xpps[3*j+0];
570 xpp[1] = xpps[3*j+1];
571 xpp[2] = xpps[3*j+2];
572
573 double xpxppcross[3];
574 vtkMath::Cross(xp,xpp,xpxppcross);
575
576 double xppp[3];
577 xppp[0] = xpps[3*(j+1)+0] - xpps[3*(j-1)+0];
578 xppp[1] = xpps[3*(j+1)+1] - xpps[3*(j-1)+1];
579 xppp[2] = xpps[3*(j+1)+2] - xpps[3*(j-1)+2];
580
581 xppp[0] /= norm0 + norm1;
582 xppp[1] /= norm0 + norm1;
583 xppp[2] /= norm0 + norm1;
584
585 double xpxppcrossNorm = vtkMath::Norm(xpxppcross);
586 double torsion = (xpxppcrossNorm > 0 ? vtkMath::Dot(xpxppcross, xppp) / pow(xpxppcrossNorm, 2.0) : 0);
587
588 torsionArray->SetComponent(j,0,torsion);
589 double weight = (norm0 + norm1) / 2.0;
590 averageTorsion += torsion * weight;
591
592 weightSum += weight;
593 }
594
595 delete[] xps;
596 delete[] xpps;
597
598 if (weightSum>0.0)
599 {
600 averageTorsion /= weightSum;
601 }
602
603 return averageTorsion;
604}

◆ ComputeLineFrenetReferenceSystem()

void vtkvmtkCenterlineGeometry::ComputeLineFrenetReferenceSystem ( vtkPoints * linePoints,
vtkDoubleArray * lineTangentArray,
vtkDoubleArray * lineNormalArray,
vtkDoubleArray * lineBinormalArray )
static

Compute the discrete Frenet reference frame (tangent, normal, binormal unit vectors) at every point of a single polyline, given as an ordered set of points, and store the per-point vectors in the three supplied 3-component arrays (resized/filled by this call). Used internally by RequestData, but also usable standalone on an arbitrary vtkPoints polyline.

Definition at line 308 of file vtkvmtkCenterlineGeometry.cxx.

309{
310 int numberOfPoints = linePoints->GetNumberOfPoints();
311
312 lineTangentArray->SetNumberOfComponents(3);
313 lineTangentArray->SetNumberOfTuples(numberOfPoints);
314 lineTangentArray->FillComponent(0,0.0);
315 lineTangentArray->FillComponent(1,0.0);
316 lineTangentArray->FillComponent(2,0.0);
317
318 lineNormalArray->SetNumberOfComponents(3);
319 lineNormalArray->SetNumberOfTuples(numberOfPoints);
320 lineNormalArray->FillComponent(0,0.0);
321 lineNormalArray->FillComponent(1,0.0);
322 lineNormalArray->FillComponent(2,0.0);
323
324 lineBinormalArray->SetNumberOfComponents(3);
325 lineBinormalArray->SetNumberOfTuples(numberOfPoints);
326 lineBinormalArray->FillComponent(0,0.0);
327 lineBinormalArray->FillComponent(1,0.0);
328 lineBinormalArray->FillComponent(2,0.0);
329
330 double point0[3], point1[3], point2[3];
331 double vector0[3], vector1[3];
332
333 for (int j=1; j<numberOfPoints-1; j++)
334 {
335 linePoints->GetPoint(j-1,point0);
336 linePoints->GetPoint(j,point1);
337 linePoints->GetPoint(j+1,point2);
338
339 vector0[0] = point1[0] - point0[0];
340 vector0[1] = point1[1] - point0[1];
341 vector0[2] = point1[2] - point0[2];
342
343 vector1[0] = point2[0] - point1[0];
344 vector1[1] = point2[1] - point1[1];
345 vector1[2] = point2[2] - point1[2];
346
347 double norm0 = vtkMath::Norm(vector0);
348 double norm1 = vtkMath::Norm(vector1);
349
350 if (norm0 < VTK_VMTK_DOUBLE_TOL || norm1 < VTK_VMTK_DOUBLE_TOL)
351 {
352 continue;
353 }
354
355 double xp[3];
356 xp[0] = point2[0] - point0[0];
357 xp[1] = point2[1] - point0[1];
358 xp[2] = point2[2] - point0[2];
359 xp[0] /= norm0 + norm1;
360 xp[1] /= norm0 + norm1;
361 xp[2] /= norm0 + norm1;
362
363 double xpp[3];
364 xpp[0] = (point2[0] - point1[0]) / norm1 - (point1[0] - point0[0]) / norm0;
365 xpp[1] = (point2[1] - point1[1]) / norm1 - (point1[1] - point0[1]) / norm0;
366 xpp[2] = (point2[2] - point1[2]) / norm1 - (point1[2] - point0[2]) / norm0;
367 xpp[0] /= (norm0 + norm1) / 2.0;
368 xpp[1] /= (norm0 + norm1) / 2.0;
369 xpp[2] /= (norm0 + norm1) / 2.0;
370
371 double xpxppcross[3];
372 vtkMath::Cross(xp,xpp,xpxppcross);
373
374 double tangent[3], normal[3], binormal[3];
375
376 tangent[0] = xp[0];
377 tangent[1] = xp[1];
378 tangent[2] = xp[2];
379 vtkMath::Normalize(tangent);
380
381 binormal[0] = xpxppcross[0];
382 binormal[1] = xpxppcross[1];
383 binormal[2] = xpxppcross[2];
384 vtkMath::Normalize(binormal);
385
386 vtkMath::Cross(binormal,tangent,normal);
387 vtkMath::Normalize(normal);
388
389 lineTangentArray->SetTuple(j,tangent);
390 lineNormalArray->SetTuple(j,normal);
391 lineBinormalArray->SetTuple(j,binormal);
392 }
393
394 double tuple[3];
395 lineTangentArray->GetTuple(1,tuple);
396 lineTangentArray->SetTuple(0,tuple);
397 lineNormalArray->GetTuple(1,tuple);
398 lineNormalArray->SetTuple(0,tuple);
399 lineBinormalArray->GetTuple(1,tuple);
400 lineBinormalArray->SetTuple(0,tuple);
401 lineTangentArray->GetTuple(numberOfPoints-2,tuple);
402 lineTangentArray->SetTuple(numberOfPoints-1,tuple);
403 lineNormalArray->GetTuple(numberOfPoints-2,tuple);
404 lineNormalArray->SetTuple(numberOfPoints-1,tuple);
405 lineBinormalArray->GetTuple(numberOfPoints-2,tuple);
406 lineBinormalArray->SetTuple(numberOfPoints-1,tuple);
407}

◆ RequestData()

int vtkvmtkCenterlineGeometry::RequestData ( vtkInformation * ,
vtkInformationVector ** ,
vtkInformationVector *  )
overrideprotectedvirtual

Definition at line 101 of file vtkvmtkCenterlineGeometry.cxx.

105{
106 // get the info objects
107 vtkInformation *inInfo = inputVector[0]->GetInformationObject(0);
108 vtkInformation *outInfo = outputVector->GetInformationObject(0);
109
110 // get the input and output
111 vtkPolyData *input = vtkPolyData::SafeDownCast(
112 inInfo->Get(vtkDataObject::DATA_OBJECT()));
113 vtkPolyData *output = vtkPolyData::SafeDownCast(
114 outInfo->Get(vtkDataObject::DATA_OBJECT()));
115
116 if (!this->LengthArrayName)
117 {
118 vtkErrorMacro(<<"LengthArrayName not specified");
119 return 1;
120 }
121
122 if (!this->CurvatureArrayName)
123 {
124 vtkErrorMacro(<<"CurvatureArrayName not specified");
125 return 1;
126 }
127
128 if (!this->TorsionArrayName)
129 {
130 vtkErrorMacro(<<"TorsionArrayName not specified");
131 return 1;
132 }
133
134 if (!this->TortuosityArrayName)
135 {
136 vtkErrorMacro(<<"TorsionArrayName not specified");
137 return 1;
138 }
139
140 if (!this->FrenetTangentArrayName)
141 {
142 vtkErrorMacro(<<"FrenetTangentArrayName not specified");
143 return 1;
144 }
145
146 if (!this->FrenetNormalArrayName)
147 {
148 vtkErrorMacro(<<"FrenetNormalArrayName not specified");
149 return 1;
150 }
151
152 if (!this->FrenetBinormalArrayName)
153 {
154 vtkErrorMacro(<<"FrenetBinormalArrayName not specified");
155 return 1;
156 }
157
158 output->DeepCopy(input);
159
160 int numberOfInputPoints = input->GetNumberOfPoints();
161 int numberOfInputCells = input->GetNumberOfCells();
162
163 vtkDoubleArray* lengthArray = vtkDoubleArray::New();
164 lengthArray->SetName(this->LengthArrayName);
165 lengthArray->SetNumberOfComponents(1);
166 lengthArray->SetNumberOfTuples(numberOfInputCells);
167 lengthArray->FillComponent(0,0.0);
168
169 output->GetCellData()->AddArray(lengthArray);
170
171 vtkDoubleArray* curvatureArray = vtkDoubleArray::New();
172 curvatureArray->SetName(this->CurvatureArrayName);
173 curvatureArray->SetNumberOfComponents(1);
174 curvatureArray->SetNumberOfTuples(numberOfInputPoints);
175 curvatureArray->FillComponent(0,0.0);
176
177 output->GetPointData()->AddArray(curvatureArray);
178
179 vtkDoubleArray* torsionArray = vtkDoubleArray::New();
180 torsionArray->SetName(this->TorsionArrayName);
181 torsionArray->SetNumberOfComponents(1);
182 torsionArray->SetNumberOfTuples(numberOfInputPoints);
183 torsionArray->FillComponent(0,0.0);
184
185 output->GetPointData()->AddArray(torsionArray);
186
187 vtkDoubleArray* tortuosityArray = vtkDoubleArray::New();
188 tortuosityArray->SetName(this->TortuosityArrayName);
189 tortuosityArray->SetNumberOfComponents(1);
190 tortuosityArray->SetNumberOfTuples(numberOfInputCells);
191 tortuosityArray->FillComponent(0,0.0);
192
193 output->GetCellData()->AddArray(tortuosityArray);
194
195 vtkDoubleArray* frenetTangentArray = vtkDoubleArray::New();
196 frenetTangentArray->SetName(this->FrenetTangentArrayName);
197 frenetTangentArray->SetNumberOfComponents(3);
198 frenetTangentArray->SetNumberOfTuples(numberOfInputPoints);
199 frenetTangentArray->FillComponent(0,0.0);
200 frenetTangentArray->FillComponent(1,0.0);
201 frenetTangentArray->FillComponent(2,0.0);
202
203 output->GetPointData()->AddArray(frenetTangentArray);
204
205 vtkDoubleArray* frenetNormalArray = vtkDoubleArray::New();
206 frenetNormalArray->SetName(this->FrenetNormalArrayName);
207 frenetNormalArray->SetNumberOfComponents(3);
208 frenetNormalArray->SetNumberOfTuples(numberOfInputPoints);
209 frenetNormalArray->FillComponent(0,0.0);
210 frenetNormalArray->FillComponent(1,0.0);
211 frenetNormalArray->FillComponent(2,0.0);
212
213 output->GetPointData()->AddArray(frenetNormalArray);
214
215 vtkDoubleArray* frenetBinormalArray = vtkDoubleArray::New();
216 frenetBinormalArray->SetName(this->FrenetBinormalArrayName);
217 frenetBinormalArray->SetNumberOfComponents(3);
218 frenetBinormalArray->SetNumberOfTuples(numberOfInputPoints);
219 frenetBinormalArray->FillComponent(0,0.0);
220 frenetBinormalArray->FillComponent(1,0.0);
221 frenetBinormalArray->FillComponent(2,0.0);
222
223 output->GetPointData()->AddArray(frenetBinormalArray);
224
225 for (int i=0; i<input->GetNumberOfCells(); i++)
226 {
227 vtkCell* line = input->GetCell(i);
228 if (line->GetCellType() != VTK_LINE && line->GetCellType() != VTK_POLY_LINE)
229 {
230 continue;
231 }
232
233 vtkDoubleArray* lineCurvatureArray = vtkDoubleArray::New();
234 vtkDoubleArray* lineTorsionArray = vtkDoubleArray::New();
235 vtkDoubleArray* lineTangentArray = vtkDoubleArray::New();
236 vtkDoubleArray* lineNormalArray = vtkDoubleArray::New();
237 vtkDoubleArray* lineBinormalArray = vtkDoubleArray::New();
238
239 vtkPoints* linePoints = vtkPoints::New();
240 linePoints->DeepCopy(line->GetPoints());
241
242 if (this->LineSmoothing)
243 {
244 vtkPoints* smoothLinePoints = vtkPoints::New();
246 linePoints->DeepCopy(smoothLinePoints);
247 smoothLinePoints->Delete();
248 }
249
250 this->ComputeLineCurvature(linePoints,lineCurvatureArray);
251 this->ComputeLineTorsion(linePoints,lineTorsionArray);
252 this->ComputeLineFrenetReferenceSystem(linePoints,lineTangentArray,lineNormalArray,lineBinormalArray);
253
254 int numberOfLinePoints = linePoints->GetNumberOfPoints();
255
256 double length = 0.0;
257 double point0[3], point1[3];
258 for (int j=0; j<numberOfLinePoints; j++)
259 {
260 vtkIdType pointId = line->GetPointId(j);
261 if (this->OutputSmoothedLines)
262 {
263 output->GetPoints()->SetPoint(pointId,linePoints->GetPoint(j));
264 }
265 if (j>0)
266 {
267 linePoints->GetPoint(j-1,point0);
268 linePoints->GetPoint(j,point1);
269 length += sqrt(vtkMath::Distance2BetweenPoints(point0,point1));
270 }
271 curvatureArray->SetComponent(pointId,0,lineCurvatureArray->GetComponent(j,0));
272 torsionArray->SetComponent(pointId,0,lineTorsionArray->GetComponent(j,0));
273 double tuple[3];
274 lineTangentArray->GetTuple(j,tuple);
275 frenetTangentArray->SetTuple(pointId,tuple);
276 lineNormalArray->GetTuple(j,tuple);
277 frenetNormalArray->SetTuple(pointId,tuple);
278 lineBinormalArray->GetTuple(j,tuple);
279 frenetBinormalArray->SetTuple(pointId,tuple);
280 }
281
282 linePoints->GetPoint(0,point0);
283 linePoints->GetPoint(numberOfLinePoints-1,point1);
284 double tortuosity = length / sqrt(vtkMath::Distance2BetweenPoints(point0,point1)) - 1.0;
285
286 lengthArray->SetComponent(i,0,length);
287 tortuosityArray->SetComponent(i,0,tortuosity);
288
289 lineCurvatureArray->Delete();
290 lineTorsionArray->Delete();
291 linePoints->Delete();
292 lineTangentArray->Delete();
293 lineNormalArray->Delete();
294 lineBinormalArray->Delete();
295 }
296
297 lengthArray->Delete();
298 curvatureArray->Delete();
299 torsionArray->Delete();
300 tortuosityArray->Delete();
301 frenetTangentArray->Delete();
302 frenetNormalArray->Delete();
303 frenetBinormalArray->Delete();
304
305 return 1;
306}
static void ComputeLineFrenetReferenceSystem(vtkPoints *linePoints, vtkDoubleArray *lineTangentArray, vtkDoubleArray *lineNormalArray, vtkDoubleArray *lineBinormalArray)
static double ComputeLineTorsion(vtkPoints *linePoints, vtkDoubleArray *torsionArray)
static double ComputeLineCurvature(vtkPoints *linePoints, vtkDoubleArray *curvatureArray)
static void SmoothLine(vtkPoints *linePoints, vtkPoints *smoothLinePoints, int numberOfIterations=10, double relaxation=0.1)

Member Data Documentation

◆ LengthArrayName

char* vtkvmtkCenterlineGeometry::LengthArrayName
protected

Definition at line 191 of file vtkvmtkCenterlineGeometry.h.

◆ CurvatureArrayName

char* vtkvmtkCenterlineGeometry::CurvatureArrayName
protected

Definition at line 192 of file vtkvmtkCenterlineGeometry.h.

◆ TorsionArrayName

char* vtkvmtkCenterlineGeometry::TorsionArrayName
protected

Definition at line 193 of file vtkvmtkCenterlineGeometry.h.

◆ TortuosityArrayName

char* vtkvmtkCenterlineGeometry::TortuosityArrayName
protected

Definition at line 194 of file vtkvmtkCenterlineGeometry.h.

◆ FrenetTangentArrayName

char* vtkvmtkCenterlineGeometry::FrenetTangentArrayName
protected

Definition at line 195 of file vtkvmtkCenterlineGeometry.h.

◆ FrenetNormalArrayName

char* vtkvmtkCenterlineGeometry::FrenetNormalArrayName
protected

Definition at line 196 of file vtkvmtkCenterlineGeometry.h.

◆ FrenetBinormalArrayName

char* vtkvmtkCenterlineGeometry::FrenetBinormalArrayName
protected

Definition at line 197 of file vtkvmtkCenterlineGeometry.h.

◆ LineSmoothing

int vtkvmtkCenterlineGeometry::LineSmoothing
protected

Definition at line 199 of file vtkvmtkCenterlineGeometry.h.

◆ OutputSmoothedLines

int vtkvmtkCenterlineGeometry::OutputSmoothedLines
protected

Definition at line 200 of file vtkvmtkCenterlineGeometry.h.

◆ SmoothingFactor

double vtkvmtkCenterlineGeometry::SmoothingFactor
protected

Definition at line 201 of file vtkvmtkCenterlineGeometry.h.

◆ NumberOfSmoothingIterations

int vtkvmtkCenterlineGeometry::NumberOfSmoothingIterations
protected

Definition at line 202 of file vtkvmtkCenterlineGeometry.h.


The documentation for this class was generated from the following files: