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

Experimental: generates centerlines from an image. More...

#include <vtkvmtkActiveTubeFilter.h>

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

Public Types

typedef vtkPolyDataAlgorithm Superclass

Public Member Functions

virtual int IsA (const char *type)
vtkvmtkActiveTubeFilter * NewInstance () const
void PrintSelf (std::ostream &os, vtkIndent indent) override
virtual void SetPotentialImage (vtkImageData *)
virtual vtkImageData * GetPotentialImage ()
virtual void SetRadiusArrayName (const char *)
virtual char * GetRadiusArrayName ()
virtual void SetNumberOfIterations (int)
virtual int GetNumberOfIterations ()
virtual void SetPotentialWeight (double)
virtual double GetPotentialWeight ()
virtual void SetStiffnessWeight (double)
virtual double GetStiffnessWeight ()
virtual void SetConvergence (double)
virtual double GetConvergence ()
virtual void SetCFLCoefficient (double)
virtual double GetCFLCoefficient ()
virtual void SetMinimumRadius (double)
virtual double GetMinimumRadius ()
virtual void SetFixedEndpointCoordinates (int)
virtual int GetFixedEndpointCoordinates ()
virtual void FixedEndpointCoordinatesOn ()
virtual void FixedEndpointCoordinatesOff ()
virtual void SetFixedEndpointRadius (int)
virtual int GetFixedEndpointRadius ()
virtual void FixedEndpointRadiusOn ()
virtual void FixedEndpointRadiusOff ()
virtual void SetNumberOfAngularEvaluations (int)
virtual int GetNumberOfAngularEvaluations ()
virtual void SetSplineResamplingWhileIterating (int)
virtual int GetSplineResamplingWhileIterating ()
virtual void SplineResamplingWhileIteratingOn ()
virtual void SplineResamplingWhileIteratingOff ()
virtual void SetNegativeNormWarnings (int)
virtual int GetNegativeNormWarnings ()
virtual void NegativeNormWarningsOn ()
virtual void NegativeNormWarningsOff ()

Static Public Member Functions

static int IsTypeOf (const char *type)
static vtkvmtkActiveTubeFilter * SafeDownCast (vtkObjectBase *o)
static vtkvmtkActiveTubeFilter * New ()

Protected Member Functions

virtual vtkObjectBase * NewInstanceInternal () const
 vtkvmtkActiveTubeFilter ()
 ~vtkvmtkActiveTubeFilter ()
virtual int RequestData (vtkInformation *, vtkInformationVector **, vtkInformationVector *) override
void EvaluateForce (double point[3], double force[3], bool normalize)
double EvaluatePotential (double point[3])
void EvolveCellSpline (vtkPolyData *lines, vtkIdType cellId)

Static Protected Member Functions

static bool IsInExtent (vtkIdType extent[6], int ijk[3], vtkIdType border)
static bool IsCellInExtent (int extent[6], int ijk[3], vtkIdType border)

Protected Attributes

char * RadiusArrayName
vtkImageData * PotentialImage
vtkImageData * PotentialGradientImage
int NumberOfIterations
int NumberOfAngularEvaluations
double CFLCoefficient
double Convergence
double PotentialWeight
double StiffnessWeight
double MinimumRadius
double PotentialMaxNorm
int FixedEndpointCoordinates
int FixedEndpointRadius
int SplineResamplingWhileIterating
bool NegativeNormWarnings

Detailed Description

Experimental: generates centerlines from an image.

vtkvmtkActiveTubeFilter takes as input a vtkPolyData composed of polyline cells (a centerline, with a point data array giving the radius at each point) and evolves both the point coordinates and the radii, cell by cell, as an active-contour ("snake") tube: at each iteration a cardinal spline is fit through each cell's points and radii, the tube boundary is sampled at NumberOfAngularEvaluations directions around the circumference, and the gradient of a supplied PotentialImage is probed at each sampled point to compute an image force. The image force is decomposed into an isotropic component (which changes the radius) and an anisotropic component (which displaces the centerline), and combined with an internal stiffness force derived from the spline's second derivatives to regularize the shape. The result is a centerline/radius pair that has been pulled toward edges of the potential image while remaining smooth.

This is the filter behind the vmtkactivetubes pype script, used experimentally to refine centerlines (and their radius estimates) directly from an image, as an alternative to purely distance-map-based centerline extraction.

Developed with support from the EC FP7/2007-2013: ARCH, Project n. 224390

Definition at line 53 of file vtkvmtkActiveTubeFilter.h.

Member Typedef Documentation

◆ Superclass

typedef vtkPolyDataAlgorithm vtkvmtkActiveTubeFilter::Superclass

Definition at line 56 of file vtkvmtkActiveTubeFilter.h.

Constructor & Destructor Documentation

◆ vtkvmtkActiveTubeFilter()

vtkvmtkActiveTubeFilter::vtkvmtkActiveTubeFilter ( )
protected

Definition at line 50 of file vtkvmtkActiveTubeFilter.cxx.

51{
52 this->RadiusArrayName = NULL;
53
54 this->PotentialImage = NULL;
55 this->PotentialGradientImage = NULL;
58 this->Convergence = 1E-1;
59 this->PotentialWeight = 1.0;
60 this->StiffnessWeight = 1.0;
61 this->CFLCoefficient = 0.1;
62
63 this->PotentialMaxNorm = 0.0;
64 this->MinimumRadius = 0.0;
66 this->FixedEndpointRadius = 0;
67
69
70 this->NegativeNormWarnings = 0;
71}
#define VTK_VMTK_LARGE_INTEGER

◆ ~vtkvmtkActiveTubeFilter()

vtkvmtkActiveTubeFilter::~vtkvmtkActiveTubeFilter ( )
protected

Definition at line 73 of file vtkvmtkActiveTubeFilter.cxx.

74{
75 if (this->RadiusArrayName)
76 {
77 delete[] this->RadiusArrayName;
78 this->RadiusArrayName = NULL;
79 }
80
81 if (this->PotentialImage)
82 {
83 this->PotentialImage->Delete();
84 this->PotentialImage = NULL;
85 }
86
87 if (this->PotentialGradientImage)
88 {
89 this->PotentialGradientImage->Delete();
90 this->PotentialGradientImage = NULL;
91 }
92}

Member Function Documentation

◆ IsTypeOf()

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

◆ IsA()

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

◆ SafeDownCast()

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

◆ NewInstanceInternal()

virtual vtkObjectBase * vtkvmtkActiveTubeFilter::NewInstanceInternal ( ) const
protectedvirtual

◆ NewInstance()

vtkvmtkActiveTubeFilter * vtkvmtkActiveTubeFilter::NewInstance ( ) const

◆ PrintSelf()

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

Definition at line 550 of file vtkvmtkActiveTubeFilter.cxx.

551{
552 this->Superclass::PrintSelf(os,indent);
553}

◆ New()

vtkvmtkActiveTubeFilter * vtkvmtkActiveTubeFilter::New ( )
static

◆ SetPotentialImage()

virtual void vtkvmtkActiveTubeFilter::SetPotentialImage ( vtkImageData * )
virtual

Set/get the potential (cost) image whose negated gradient attracts the evolving tube surface, e.g. an edge or vesselness feature image that is low near vessel boundaries. Required before Update() is called; its gradient is recomputed internally at the start of RequestData.

◆ GetPotentialImage()

virtual vtkImageData * vtkvmtkActiveTubeFilter::GetPotentialImage ( )
virtual

Set/get the potential (cost) image whose negated gradient attracts the evolving tube surface, e.g. an edge or vesselness feature image that is low near vessel boundaries. Required before Update() is called; its gradient is recomputed internally at the start of RequestData.

◆ SetRadiusArrayName()

virtual void vtkvmtkActiveTubeFilter::SetRadiusArrayName ( const char * )
virtual

Set/get the name of the point data array, on the input centerline poly data, holding the per-point tube radius that is evolved together with the point coordinates. Required before Update() is called. Commonly named "MaximumInscribedSphereRadius".

◆ GetRadiusArrayName()

virtual char * vtkvmtkActiveTubeFilter::GetRadiusArrayName ( )
virtual

Set/get the name of the point data array, on the input centerline poly data, holding the per-point tube radius that is evolved together with the point coordinates. Required before Update() is called. Commonly named "MaximumInscribedSphereRadius".

◆ SetNumberOfIterations()

virtual void vtkvmtkActiveTubeFilter::SetNumberOfIterations ( int )
virtual

Set/get the number of active-contour evolution iterations applied to every line cell. Default: a very large integer (VTK_VMTK_LARGE_INTEGER) – in practice the loop always runs exactly this many iterations, since convergence is not currently checked (see Convergence).

◆ GetNumberOfIterations()

virtual int vtkvmtkActiveTubeFilter::GetNumberOfIterations ( )
virtual

Set/get the number of active-contour evolution iterations applied to every line cell. Default: a very large integer (VTK_VMTK_LARGE_INTEGER) – in practice the loop always runs exactly this many iterations, since convergence is not currently checked (see Convergence).

◆ SetPotentialWeight()

virtual void vtkvmtkActiveTubeFilter::SetPotentialWeight ( double )
virtual

Set/get the weight applied to the anisotropic image force (derived from the PotentialImage gradient) that displaces the centerline, relative to StiffnessWeight. Default: 1.0.

◆ GetPotentialWeight()

virtual double vtkvmtkActiveTubeFilter::GetPotentialWeight ( )
virtual

Set/get the weight applied to the anisotropic image force (derived from the PotentialImage gradient) that displaces the centerline, relative to StiffnessWeight. Default: 1.0.

◆ SetStiffnessWeight()

virtual void vtkvmtkActiveTubeFilter::SetStiffnessWeight ( double )
virtual

Set/get the weight applied to the internal stiffness force, derived from the second derivatives of the fitted spline, that regularizes (smooths) the evolving tube. Default: 1.0.

◆ GetStiffnessWeight()

virtual double vtkvmtkActiveTubeFilter::GetStiffnessWeight ( )
virtual

Set/get the weight applied to the internal stiffness force, derived from the second derivatives of the fitted spline, that regularizes (smooths) the evolving tube. Default: 1.0.

◆ SetConvergence()

virtual void vtkvmtkActiveTubeFilter::SetConvergence ( double )
virtual

Set/get the intended convergence threshold for the iterative evolution. Currently unused: the filter does not check this value to stop iteration early, and always runs NumberOfIterations iterations. Default: 0.1.

◆ GetConvergence()

virtual double vtkvmtkActiveTubeFilter::GetConvergence ( )
virtual

Set/get the intended convergence threshold for the iterative evolution. Currently unused: the filter does not check this value to stop iteration early, and always runs NumberOfIterations iterations. Default: 0.1.

◆ SetCFLCoefficient()

virtual void vtkvmtkActiveTubeFilter::SetCFLCoefficient ( double )
virtual

Set/get the fraction of the local minimum image spacing used to scale the per-iteration displacement (a CFL-like time step controlling how far points/radii can move in one iteration). Default: 0.1.

◆ GetCFLCoefficient()

virtual double vtkvmtkActiveTubeFilter::GetCFLCoefficient ( )
virtual

Set/get the fraction of the local minimum image spacing used to scale the per-iteration displacement (a CFL-like time step controlling how far points/radii can move in one iteration). Default: 0.1.

◆ SetMinimumRadius()

virtual void vtkvmtkActiveTubeFilter::SetMinimumRadius ( double )
virtual

Set/get the lower bound clamped onto the evolving tube radius at every point and iteration. Default: 0.0.

◆ GetMinimumRadius()

virtual double vtkvmtkActiveTubeFilter::GetMinimumRadius ( )
virtual

Set/get the lower bound clamped onto the evolving tube radius at every point and iteration. Default: 0.0.

◆ SetFixedEndpointCoordinates()

virtual void vtkvmtkActiveTubeFilter::SetFixedEndpointCoordinates ( int )
virtual

Toggle keeping the coordinates of each cell's first and last point fixed across iterations, instead of letting them evolve like interior points. Default: off.

◆ GetFixedEndpointCoordinates()

virtual int vtkvmtkActiveTubeFilter::GetFixedEndpointCoordinates ( )
virtual

Toggle keeping the coordinates of each cell's first and last point fixed across iterations, instead of letting them evolve like interior points. Default: off.

◆ FixedEndpointCoordinatesOn()

virtual void vtkvmtkActiveTubeFilter::FixedEndpointCoordinatesOn ( )
virtual

Toggle keeping the coordinates of each cell's first and last point fixed across iterations, instead of letting them evolve like interior points. Default: off.

◆ FixedEndpointCoordinatesOff()

virtual void vtkvmtkActiveTubeFilter::FixedEndpointCoordinatesOff ( )
virtual

Toggle keeping the coordinates of each cell's first and last point fixed across iterations, instead of letting them evolve like interior points. Default: off.

◆ SetFixedEndpointRadius()

virtual void vtkvmtkActiveTubeFilter::SetFixedEndpointRadius ( int )
virtual

Toggle keeping the radius of each cell's first and last point fixed across iterations, instead of letting it evolve like interior points. Default: off.

◆ GetFixedEndpointRadius()

virtual int vtkvmtkActiveTubeFilter::GetFixedEndpointRadius ( )
virtual

Toggle keeping the radius of each cell's first and last point fixed across iterations, instead of letting it evolve like interior points. Default: off.

◆ FixedEndpointRadiusOn()

virtual void vtkvmtkActiveTubeFilter::FixedEndpointRadiusOn ( )
virtual

Toggle keeping the radius of each cell's first and last point fixed across iterations, instead of letting it evolve like interior points. Default: off.

◆ FixedEndpointRadiusOff()

virtual void vtkvmtkActiveTubeFilter::FixedEndpointRadiusOff ( )
virtual

Toggle keeping the radius of each cell's first and last point fixed across iterations, instead of letting it evolve like interior points. Default: off.

◆ SetNumberOfAngularEvaluations()

virtual void vtkvmtkActiveTubeFilter::SetNumberOfAngularEvaluations ( int )
virtual

Set/get the number of directions sampled around the tube circumference, at each longitudinal evaluation point, to estimate the isotropic (radius-changing) and anisotropic (centerline-displacing) image forces. Default: 16.

◆ GetNumberOfAngularEvaluations()

virtual int vtkvmtkActiveTubeFilter::GetNumberOfAngularEvaluations ( )
virtual

Set/get the number of directions sampled around the tube circumference, at each longitudinal evaluation point, to estimate the isotropic (radius-changing) and anisotropic (centerline-displacing) image forces. Default: 16.

◆ SetSplineResamplingWhileIterating()

virtual void vtkvmtkActiveTubeFilter::SetSplineResamplingWhileIterating ( int )
virtual

Toggle re-sampling each cell's points uniformly along arc length, using the spline fit through the current points and radii, at every iteration. Default: on.

◆ GetSplineResamplingWhileIterating()

virtual int vtkvmtkActiveTubeFilter::GetSplineResamplingWhileIterating ( )
virtual

Toggle re-sampling each cell's points uniformly along arc length, using the spline fit through the current points and radii, at every iteration. Default: on.

◆ SplineResamplingWhileIteratingOn()

virtual void vtkvmtkActiveTubeFilter::SplineResamplingWhileIteratingOn ( )
virtual

Toggle re-sampling each cell's points uniformly along arc length, using the spline fit through the current points and radii, at every iteration. Default: on.

◆ SplineResamplingWhileIteratingOff()

virtual void vtkvmtkActiveTubeFilter::SplineResamplingWhileIteratingOff ( )
virtual

Toggle re-sampling each cell's points uniformly along arc length, using the spline fit through the current points and radii, at every iteration. Default: on.

◆ SetNegativeNormWarnings()

virtual void vtkvmtkActiveTubeFilter::SetNegativeNormWarnings ( int )
virtual

Toggle emission of a warning whenever a degenerate cross-section is encountered (the squared tube norm derived from the spline derivatives is non-positive), instead of silently skipping the longitudinal evaluation point. Default: off.

◆ GetNegativeNormWarnings()

virtual int vtkvmtkActiveTubeFilter::GetNegativeNormWarnings ( )
virtual

Toggle emission of a warning whenever a degenerate cross-section is encountered (the squared tube norm derived from the spline derivatives is non-positive), instead of silently skipping the longitudinal evaluation point. Default: off.

◆ NegativeNormWarningsOn()

virtual void vtkvmtkActiveTubeFilter::NegativeNormWarningsOn ( )
virtual

Toggle emission of a warning whenever a degenerate cross-section is encountered (the squared tube norm derived from the spline derivatives is non-positive), instead of silently skipping the longitudinal evaluation point. Default: off.

◆ NegativeNormWarningsOff()

virtual void vtkvmtkActiveTubeFilter::NegativeNormWarningsOff ( )
virtual

Toggle emission of a warning whenever a degenerate cross-section is encountered (the squared tube norm derived from the spline derivatives is non-positive), instead of silently skipping the longitudinal evaluation point. Default: off.

◆ RequestData()

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

Definition at line 493 of file vtkvmtkActiveTubeFilter.cxx.

494{
495 vtkInformation *inInfo = inputVector[0]->GetInformationObject(0);
496 vtkInformation *outInfo = outputVector->GetInformationObject(0);
497
498 vtkPolyData *input = vtkPolyData::SafeDownCast(inInfo->Get(vtkDataObject::DATA_OBJECT()));
499 vtkPolyData *output = vtkPolyData::SafeDownCast(outInfo->Get(vtkDataObject::DATA_OBJECT()));
500
501 output->DeepCopy(input);
502
503 if (!this->RadiusArrayName)
504 {
505 vtkErrorMacro("Error: RadiusArrayName not specified.");
506 return 0;
507 }
508
509 vtkDataArray* radiusArray = output->GetPointData()->GetArray(this->RadiusArrayName);
510
511 if (!radiusArray)
512 {
513 vtkErrorMacro("Error: RadiusArray with name specified does not exist.");
514 return 0;
515 }
516
517 vtkImageGradient* gradientFilter = vtkImageGradient::New();
518 gradientFilter->SetInputData(this->PotentialImage);
519 gradientFilter->SetDimensionality(3);
520 gradientFilter->Update();
521
522 if (this->PotentialGradientImage)
523 {
524 this->PotentialGradientImage->Delete();
525 this->PotentialGradientImage = NULL;
526 }
527
528 this->PotentialGradientImage = vtkImageData::New();
529 this->PotentialGradientImage->DeepCopy(gradientFilter->GetOutput());
530
531 this->PotentialMaxNorm = this->PotentialGradientImage->GetPointData()->GetScalars()->GetMaxNorm();
532
533 int numberOfCells = output->GetNumberOfCells();
534
535 int i;
536 for (i=0; i<this->NumberOfIterations; i++)
537 {
538 int c;
539 for (c=0; c<numberOfCells; c++)
540 {
541 this->EvolveCellSpline(output,c);
542 }
543 }
544
545 gradientFilter->Delete();
546
547 return 1;
548}
void EvolveCellSpline(vtkPolyData *lines, vtkIdType cellId)

◆ EvaluateForce()

void vtkvmtkActiveTubeFilter::EvaluateForce ( double point[3],
double force[3],
bool normalize )
protected

Definition at line 96 of file vtkvmtkActiveTubeFilter.cxx.

97{
98 int ijk[3];
99 double pcoords[3];
100 double weights[8];
101 int inBounds;
102 int i;
103
104 force[0] = force[1] = force[2] = 0.0;
105
106 inBounds = this->PotentialGradientImage->ComputeStructuredCoordinates(point,ijk,pcoords);
107
108 if (!inBounds)
109 {
110 //vtkWarningMacro("Point out of extent");
111 return;
112 }
113
114 vtkCell* cell = this->PotentialGradientImage->GetCell(this->PotentialGradientImage->ComputeCellId(ijk));
115
116 if (cell->GetCellType() == VTK_VOXEL)
117 {
118 vtkVoxel::InterpolationFunctions(pcoords,weights);
119 }
120 else
121 {
122 vtkErrorMacro("Non voxel cell found in PotentialImage");
123 }
124
125 int numberOfCellPoints = cell->GetNumberOfPoints();
126
127 vtkDataArray* gradientVectorsArray = this->PotentialGradientImage->GetPointData()->GetScalars();
128
129 for (i=0; i<numberOfCellPoints; i++)
130 {
131 double vectorValue[3];
132 gradientVectorsArray->GetTuple(cell->GetPointId(i),vectorValue);
133 force[0] += weights[i] * vectorValue[0];
134 force[1] += weights[i] * vectorValue[1];
135 force[2] += weights[i] * vectorValue[2];
136 }
137
138 if (normalize && this->PotentialMaxNorm > VTK_VMTK_DOUBLE_TOL)
139 {
140 force[0] /= this->PotentialMaxNorm;
141 force[1] /= this->PotentialMaxNorm;
142 force[2] /= this->PotentialMaxNorm;
143 }
144
145 force[0] *= -1.0;
146 force[1] *= -1.0;
147 force[2] *= -1.0;
148}
#define VTK_VMTK_DOUBLE_TOL

◆ EvaluatePotential()

double vtkvmtkActiveTubeFilter::EvaluatePotential ( double point[3])
protected

Definition at line 150 of file vtkvmtkActiveTubeFilter.cxx.

151{
152 int ijk[3];
153 double pcoords[3];
154 double weights[8];
155 int inBounds;
156 int i;
157
158 double potential = 0.0;
159
160 inBounds = this->PotentialImage->ComputeStructuredCoordinates(point,ijk,pcoords);
161
162 if (!inBounds)
163 {
164 //vtkWarningMacro("Point out of extent");
165 return 0.0;
166 }
167
168 vtkCell* cell = this->PotentialImage->GetCell(this->PotentialImage->ComputeCellId(ijk));
169
170 if (cell->GetCellType() == VTK_VOXEL)
171 {
172 vtkVoxel::InterpolationFunctions(pcoords,weights);
173 }
174 else
175 {
176 vtkErrorMacro("Non voxel cell found in PotentialImage");
177 return 0.0;
178 }
179
180 int numberOfCellPoints = cell->GetNumberOfPoints();
181
182 vtkDataArray* potentialArray = this->PotentialImage->GetPointData()->GetScalars();
183
184 for (i=0; i<numberOfCellPoints; i++)
185 {
186 double value = potentialArray->GetTuple1(cell->GetPointId(i));
187 potential += weights[i] * value;
188 }
189
190 return potential;
191}

◆ IsInExtent()

bool vtkvmtkActiveTubeFilter::IsInExtent ( vtkIdType extent[6],
int ijk[3],
vtkIdType border )
inlinestaticprotected

Definition at line 198 of file vtkvmtkActiveTubeFilter.h.

199 {
200 return (ijk[0]>=extent[0]+border && ijk[0]<=extent[1]-border) && (ijk[1]>=extent[2]+border && ijk[1]<=extent[3]-border) && (ijk[2]>=extent[4]+border && ijk[2]<=extent[5]-border) ? true : false;
201 }

◆ IsCellInExtent()

bool vtkvmtkActiveTubeFilter::IsCellInExtent ( int extent[6],
int ijk[3],
vtkIdType border )
inlinestaticprotected

Definition at line 203 of file vtkvmtkActiveTubeFilter.h.

204 {
205 return (ijk[0]>=extent[0]+border && ijk[0]<extent[1]-border) && (ijk[1]>=extent[2]+border && ijk[1]<extent[3]-border) && (ijk[2]>=extent[4]+border && ijk[2]<extent[5]-border) ? true : false;
206 }

◆ EvolveCellSpline()

void vtkvmtkActiveTubeFilter::EvolveCellSpline ( vtkPolyData * lines,
vtkIdType cellId )
protected

Definition at line 193 of file vtkvmtkActiveTubeFilter.cxx.

194{
195 //TODO: whip strategy - from start to end of spline, create displacement field simulating
196 //inertia (i.e. force on a point dependent on displacement on previous point)
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
209 vtkvmtkCardinalSpline* xSpline = vtkvmtkCardinalSpline::New();
210 vtkvmtkCardinalSpline* ySpline = vtkvmtkCardinalSpline::New();
211 vtkvmtkCardinalSpline* zSpline = vtkvmtkCardinalSpline::New();
212 vtkvmtkCardinalSpline* rSpline = vtkvmtkCardinalSpline::New();
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);
276 probedForces->SetNumberOfTuples(this->NumberOfAngularEvaluations);
277
278 vtkDoubleArray* tubeNormals = vtkDoubleArray::New();
279 tubeNormals->SetNumberOfComponents(3);
280 tubeNormals->SetNumberOfTuples(this->NumberOfAngularEvaluations);
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 //TODO: choose numberOfLongitudinalEvaluations with a strategy
296 // (fixed number, based on length, adaptive - higher curve or radius derivatives, more points)
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);
306 double xp = xSpline->EvaluateDerivative(t);
307 double yp = ySpline->EvaluateDerivative(t);
308 double zp = zSpline->EvaluateDerivative(t);
309 double rp = rSpline->EvaluateDerivative(t);
310 double xpp = xSpline->EvaluateSecondDerivative(t);
311 double ypp = ySpline->EvaluateSecondDerivative(t);
312 double zpp = zSpline->EvaluateSecondDerivative(t);
313 double rpp = rSpline->EvaluateSecondDerivative(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 //if (tubeNormSquared < 0.0)
324 if (tubeNormSquared <= 0.0)
325 {
326 if (this->NegativeNormWarnings)
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;
342 for (j=0; j<this->NumberOfAngularEvaluations; j++)
343 {
344 theta = j * 2.0 * vtkMath::Pi() / this->NumberOfAngularEvaluations;
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 //optional, but better be on the safe side
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 //double probedPotential = this->EvaluatePotential(probePoint);
359
360 this->EvaluateForce(probePoint,probedForce,false);
361
362 probedForces->SetTuple(j,probedForce);
363 tubeNormals->SetTuple(j,tubeNormal);
364
365 isotropicForce += vtkMath::Dot(probedForce,tubeNormal);
366 }
367
368 isotropicForce /= this->NumberOfAngularEvaluations;
369
370 for (j=0; j<this->NumberOfAngularEvaluations; j++)
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
379 anisotropicForce[0] /= this->NumberOfAngularEvaluations;
380 anisotropicForce[1] /= this->NumberOfAngularEvaluations;
381 anisotropicForce[2] /= this->NumberOfAngularEvaluations;
382
383 //TODO: define influence (based on parametric distance? Or also consider derivatives?)
384 // implement Gaussian RBF?
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);
399 dx += anisotropicForce[0] * weight * this->PotentialWeight;
400 dy += anisotropicForce[1] * weight * this->PotentialWeight;
401 dz += anisotropicForce[2] * weight * this->PotentialWeight;
402 dr += isotropicForce * weight * this->PotentialWeight;
403 dx += xpp * weight * this->StiffnessWeight;
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);
411 }
412 }
413
414 double spacing[3];
415#if 0
416 if (this->PotientialImage)
417 {
418 this->PotentialImage->GetSpacing(spacing);
419 }
420 else
421#endif
422 {
423 this->PotentialGradientImage->GetSpacing(spacing);
424 }
425
426 double minSpacing = VTK_VMTK_LARGE_DOUBLE;
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 {
446 timeStep = minSpacing / maxChange * this->CFLCoefficient;
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;
464 if (radius < this->MinimumRadius)
465 {
466 radius = this->MinimumRadius;
467 }
468 if (!(this->FixedEndpointCoordinates && (i==0 || i==numberOfPoints-1)))
469 {
470 lines->GetPoints()->SetPoint(pointId,point);
471 }
472 if (!(this->FixedEndpointRadius && (i==0 || i==numberOfPoints-1)))
473 {
474 radiusArray->SetTuple1(pointId,radius);
475 }
476 }
477
478 //TODO: longitudinal evolution
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

Member Data Documentation

◆ RadiusArrayName

char* vtkvmtkActiveTubeFilter::RadiusArrayName
protected

Definition at line 210 of file vtkvmtkActiveTubeFilter.h.

◆ PotentialImage

vtkImageData* vtkvmtkActiveTubeFilter::PotentialImage
protected

Definition at line 212 of file vtkvmtkActiveTubeFilter.h.

◆ PotentialGradientImage

vtkImageData* vtkvmtkActiveTubeFilter::PotentialGradientImage
protected

Definition at line 213 of file vtkvmtkActiveTubeFilter.h.

◆ NumberOfIterations

int vtkvmtkActiveTubeFilter::NumberOfIterations
protected

Definition at line 215 of file vtkvmtkActiveTubeFilter.h.

◆ NumberOfAngularEvaluations

int vtkvmtkActiveTubeFilter::NumberOfAngularEvaluations
protected

Definition at line 216 of file vtkvmtkActiveTubeFilter.h.

◆ CFLCoefficient

double vtkvmtkActiveTubeFilter::CFLCoefficient
protected

Definition at line 218 of file vtkvmtkActiveTubeFilter.h.

◆ Convergence

double vtkvmtkActiveTubeFilter::Convergence
protected

Definition at line 219 of file vtkvmtkActiveTubeFilter.h.

◆ PotentialWeight

double vtkvmtkActiveTubeFilter::PotentialWeight
protected

Definition at line 221 of file vtkvmtkActiveTubeFilter.h.

◆ StiffnessWeight

double vtkvmtkActiveTubeFilter::StiffnessWeight
protected

Definition at line 222 of file vtkvmtkActiveTubeFilter.h.

◆ MinimumRadius

double vtkvmtkActiveTubeFilter::MinimumRadius
protected

Definition at line 224 of file vtkvmtkActiveTubeFilter.h.

◆ PotentialMaxNorm

double vtkvmtkActiveTubeFilter::PotentialMaxNorm
protected

Definition at line 226 of file vtkvmtkActiveTubeFilter.h.

◆ FixedEndpointCoordinates

int vtkvmtkActiveTubeFilter::FixedEndpointCoordinates
protected

Definition at line 228 of file vtkvmtkActiveTubeFilter.h.

◆ FixedEndpointRadius

int vtkvmtkActiveTubeFilter::FixedEndpointRadius
protected

Definition at line 229 of file vtkvmtkActiveTubeFilter.h.

◆ SplineResamplingWhileIterating

int vtkvmtkActiveTubeFilter::SplineResamplingWhileIterating
protected

Definition at line 231 of file vtkvmtkActiveTubeFilter.h.

◆ NegativeNormWarnings

bool vtkvmtkActiveTubeFilter::NegativeNormWarnings
protected

Definition at line 233 of file vtkvmtkActiveTubeFilter.h.


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