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

Create an explicitly deformable model which evolves a surface to gradient magnitudes of an input image. More...

#include <vtkvmtkPolyDataPotentialFit.h>

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

Public Types

typedef vtkPolyDataAlgorithm Superclass

Public Member Functions

virtual int IsA (const char *type)
vtkvmtkPolyDataPotentialFit * NewInstance () const
void PrintSelf (std::ostream &os, vtkIndent indent) override
virtual void SetPotentialImage (vtkImageData *)
virtual vtkImageData * GetPotentialImage ()
virtual void SetInflationImage (vtkImageData *)
virtual vtkImageData * GetInflationImage ()
virtual void SetInflationThreshold (double)
virtual double GetInflationThreshold ()
virtual void SetNumberOfIterations (int)
virtual int GetNumberOfIterations ()
virtual void SetNumberOfStiffnessSubIterations (int)
virtual int GetNumberOfStiffnessSubIterations ()
virtual void SetNumberOfInflationSubIterations (int)
virtual int GetNumberOfInflationSubIterations ()
virtual void SetRelaxation (double)
virtual double GetRelaxation ()
virtual void SetPotentialWeight (double)
virtual double GetPotentialWeight ()
virtual void SetStiffnessWeight (double)
virtual double GetStiffnessWeight ()
virtual void SetInflationWeight (double)
virtual double GetInflationWeight ()
virtual void SetConvergence (double)
virtual double GetConvergence ()
virtual void SetMaxTimeStep (double)
virtual double GetMaxTimeStep ()
virtual void SetTimeStep (double)
virtual double GetTimeStep ()
virtual void SetAdaptiveTimeStep (int)
virtual int GetAdaptiveTimeStep ()
virtual void AdaptiveTimeStepOn ()
virtual void AdaptiveTimeStepOff ()
virtual void SetFlipNormals (int)
virtual int GetFlipNormals ()
virtual void FlipNormalsOn ()
virtual void FlipNormalsOff ()
virtual void SetUsePotentialInInflation (int)
virtual int GetUsePotentialInInflation ()
virtual void UsePotentialInInflationOn ()
virtual void UsePotentialInInflationOff ()
virtual void SetDimensionality (int)
virtual int GetDimensionality ()

Static Public Member Functions

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

Protected Member Functions

virtual vtkObjectBase * NewInstanceInternal () const
 vtkvmtkPolyDataPotentialFit ()
 ~vtkvmtkPolyDataPotentialFit ()
virtual int RequestData (vtkInformation *, vtkInformationVector **, vtkInformationVector *) override
void EvaluateForce (double point[3], double force[3], bool normalize=true)
double EvaluatePotential (double point[3])
double EvaluateInflation (double point[3])
void ComputeDisplacements (bool potential, bool stiffness, bool inflation)
void ComputePotentialDisplacement (vtkIdType pointId, double potentialDisplacement[3])
void ComputeStiffnessDisplacement (vtkIdType pointId, double stiffnessDisplacement[3])
void ComputeInflationDisplacement (vtkIdType pointId, double inflationDisplacement[3])
void ComputeTimeStep ()
void ApplyDisplacements ()
int TestConvergence ()

Static Protected Member Functions

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

Protected Attributes

vtkImageData * PotentialImage
vtkImageData * InflationImage
vtkImageData * PotentialGradientImage
int NumberOfIterations
int NumberOfStiffnessSubIterations
int NumberOfInflationSubIterations
double TimeStep
double Relaxation
double MaxDisplacementNorm
double MinEdgeLength
double MinPotentialSpacing
double Convergence
double PotentialWeight
double StiffnessWeight
double InflationWeight
double InflationThreshold
double PotentialMaxNorm
int UsePotentialInInflation
double MaxTimeStep
int AdaptiveTimeStep
int FlipNormals
int Dimensionality
vtkDoubleArray * Displacements
vtkvmtkNeighborhoods * Neighborhoods
vtkDataArray * Normals

Detailed Description

Create an explicitly deformable model which evolves a surface to gradient magnitudes of an input image.

vtkvmtkPolyDataPotentialFit implements an explicit (mesh-based) deformable model ("snake") that iteratively displaces the points of an input surface under three combined forces: a potential force that pulls points towards local maxima of PotentialImage's gradient magnitude (typically an edge/gradient-magnitude image derived from the volume being segmented), a stiffness (Laplacian-smoothing) force that regularizes the surface by pulling each point towards the centroid of its one-ring neighbors, and an inflation force that expands/contracts the surface along its normal based on InflationImage. This is the filter behind the vmtkpotentialfit pype script, used e.g. to snap a coarse initial surface onto image edges. At each of NumberOfIterations outer iterations, the filter alternates NumberOfStiffnessSubIterations pure-stiffness relaxation steps, NumberOfInflationSubIterations pure-inflation steps, and one combined potential+stiffness+inflation step, adaptively choosing the time step (see AdaptiveTimeStep) so that the largest point displacement does not exceed one voxel; iteration stops early once the scaled maximum displacement falls below Convergence.

Definition at line 51 of file vtkvmtkPolyDataPotentialFit.h.

Member Typedef Documentation

◆ Superclass

typedef vtkPolyDataAlgorithm vtkvmtkPolyDataPotentialFit::Superclass

Definition at line 54 of file vtkvmtkPolyDataPotentialFit.h.

Constructor & Destructor Documentation

◆ vtkvmtkPolyDataPotentialFit()

vtkvmtkPolyDataPotentialFit::vtkvmtkPolyDataPotentialFit ( )
protected

Definition at line 49 of file vtkvmtkPolyDataPotentialFit.cxx.

50{
51 this->PotentialImage = NULL;
52 this->InflationImage = NULL;
53 this->PotentialGradientImage = NULL;
55 this->TimeStep = 0.0;
56 this->MaxDisplacementNorm = 0.0;
57 this->MinEdgeLength = 0.0;
58 this->Relaxation = 1.0;
59 this->Displacements = NULL;
60 this->MinPotentialSpacing = 0.0;
61 this->Convergence = 1E-1;
62 this->PotentialWeight = 0.0;
63 this->StiffnessWeight = 0.0;
64 this->InflationWeight = 0.0;
65 this->PotentialMaxNorm = 0.0;
67 this->InflationThreshold = 0.0;
68
69 this->MaxTimeStep = 1.0; // pixels per time step
70 this->AdaptiveTimeStep = 1;
71
72 this->FlipNormals = 0;
73 this->Dimensionality = 3;
74
77
78 this->Neighborhoods = NULL;
79}
#define VTK_VMTK_LARGE_INTEGER

◆ ~vtkvmtkPolyDataPotentialFit()

vtkvmtkPolyDataPotentialFit::~vtkvmtkPolyDataPotentialFit ( )
protected

Definition at line 81 of file vtkvmtkPolyDataPotentialFit.cxx.

82{
83 if (this->PotentialImage)
84 {
85 this->PotentialImage->Delete();
86 this->PotentialImage = NULL;
87 }
88
89 if (this->InflationImage)
90 {
91 this->InflationImage->Delete();
92 this->InflationImage = NULL;
93 }
94
95 if (this->PotentialGradientImage)
96 {
97 this->PotentialGradientImage->Delete();
98 this->PotentialGradientImage = NULL;
99 }
100
101 if (this->Displacements)
102 {
103 this->Displacements->Delete();
104 this->Displacements = NULL;
105 }
106
107 if (this->Neighborhoods)
108 {
109 this->Neighborhoods->Delete();
110 this->Neighborhoods = NULL;
111 }
112}

Member Function Documentation

◆ IsTypeOf()

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

◆ IsA()

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

◆ SafeDownCast()

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

◆ NewInstanceInternal()

virtual vtkObjectBase * vtkvmtkPolyDataPotentialFit::NewInstanceInternal ( ) const
protectedvirtual

◆ NewInstance()

vtkvmtkPolyDataPotentialFit * vtkvmtkPolyDataPotentialFit::NewInstance ( ) const

◆ PrintSelf()

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

Definition at line 636 of file vtkvmtkPolyDataPotentialFit.cxx.

637{
638 this->Superclass::PrintSelf(os,indent);
639}

◆ New()

vtkvmtkPolyDataPotentialFit * vtkvmtkPolyDataPotentialFit::New ( )
static

◆ SetPotentialImage()

virtual void vtkvmtkPolyDataPotentialFit::SetPotentialImage ( vtkImageData * )
virtual

Set/get the scalar image (typically a gradient-magnitude/edge image) whose spatial gradient defines the potential force that attracts surface points towards image edges. Required; its gradient is (re)computed internally at the start of RequestData.

◆ GetPotentialImage()

virtual vtkImageData * vtkvmtkPolyDataPotentialFit::GetPotentialImage ( )
virtual

Set/get the scalar image (typically a gradient-magnitude/edge image) whose spatial gradient defines the potential force that attracts surface points towards image edges. Required; its gradient is (re)computed internally at the start of RequestData.

◆ SetInflationImage()

virtual void vtkvmtkPolyDataPotentialFit::SetInflationImage ( vtkImageData * )
virtual

Set/get the scalar image sampled (relative to InflationThreshold) to drive the inflation force; if not set, EvaluateInflation returns a constant 1.0 everywhere (uniform inflation).

◆ GetInflationImage()

virtual vtkImageData * vtkvmtkPolyDataPotentialFit::GetInflationImage ( )
virtual

Set/get the scalar image sampled (relative to InflationThreshold) to drive the inflation force; if not set, EvaluateInflation returns a constant 1.0 everywhere (uniform inflation).

◆ SetInflationThreshold()

virtual void vtkvmtkPolyDataPotentialFit::SetInflationThreshold ( double )
virtual

Set/get the value subtracted from InflationImage samples when evaluating the inflation force, effectively the iso-value at which the inflation force changes sign. Default: 0.0.

◆ GetInflationThreshold()

virtual double vtkvmtkPolyDataPotentialFit::GetInflationThreshold ( )
virtual

Set/get the value subtracted from InflationImage samples when evaluating the inflation force, effectively the iso-value at which the inflation force changes sign. Default: 0.0.

◆ SetNumberOfIterations()

virtual void vtkvmtkPolyDataPotentialFit::SetNumberOfIterations ( int )
virtual

Set/get the maximum number of outer deformation iterations to perform (evolution may stop earlier once TestConvergence succeeds). Default: VTK_VMTK_LARGE_INTEGER.

◆ GetNumberOfIterations()

virtual int vtkvmtkPolyDataPotentialFit::GetNumberOfIterations ( )
virtual

Set/get the maximum number of outer deformation iterations to perform (evolution may stop earlier once TestConvergence succeeds). Default: VTK_VMTK_LARGE_INTEGER.

◆ SetNumberOfStiffnessSubIterations()

virtual void vtkvmtkPolyDataPotentialFit::SetNumberOfStiffnessSubIterations ( int )
virtual

Set/get the number of pure-stiffness (Laplacian smoothing) sub-iterations performed at the start of each outer iteration, before the combined potential+stiffness+inflation step. Default: 5.

◆ GetNumberOfStiffnessSubIterations()

virtual int vtkvmtkPolyDataPotentialFit::GetNumberOfStiffnessSubIterations ( )
virtual

Set/get the number of pure-stiffness (Laplacian smoothing) sub-iterations performed at the start of each outer iteration, before the combined potential+stiffness+inflation step. Default: 5.

◆ SetNumberOfInflationSubIterations()

virtual void vtkvmtkPolyDataPotentialFit::SetNumberOfInflationSubIterations ( int )
virtual

Set/get the number of pure-inflation sub-iterations performed at the start of each outer iteration, before the combined potential+stiffness+inflation step. Default: 0.

◆ GetNumberOfInflationSubIterations()

virtual int vtkvmtkPolyDataPotentialFit::GetNumberOfInflationSubIterations ( )
virtual

Set/get the number of pure-inflation sub-iterations performed at the start of each outer iteration, before the combined potential+stiffness+inflation step. Default: 0.

◆ SetRelaxation()

virtual void vtkvmtkPolyDataPotentialFit::SetRelaxation ( double )
virtual

Set/get the relaxation factor applied to the total displacement at each sub-step (a fraction in (0,1] used to damp the update). Default: 1.0.

◆ GetRelaxation()

virtual double vtkvmtkPolyDataPotentialFit::GetRelaxation ( )
virtual

Set/get the relaxation factor applied to the total displacement at each sub-step (a fraction in (0,1] used to damp the update). Default: 1.0.

◆ SetPotentialWeight()

virtual void vtkvmtkPolyDataPotentialFit::SetPotentialWeight ( double )
virtual

Set/get the weight of the potential (image-gradient-attraction) force in the combined displacement. Default: 0.0.

◆ GetPotentialWeight()

virtual double vtkvmtkPolyDataPotentialFit::GetPotentialWeight ( )
virtual

Set/get the weight of the potential (image-gradient-attraction) force in the combined displacement. Default: 0.0.

◆ SetStiffnessWeight()

virtual void vtkvmtkPolyDataPotentialFit::SetStiffnessWeight ( double )
virtual

Set/get the weight of the stiffness (Laplacian smoothing) force in the combined displacement. Default: 0.0.

◆ GetStiffnessWeight()

virtual double vtkvmtkPolyDataPotentialFit::GetStiffnessWeight ( )
virtual

Set/get the weight of the stiffness (Laplacian smoothing) force in the combined displacement. Default: 0.0.

◆ SetInflationWeight()

virtual void vtkvmtkPolyDataPotentialFit::SetInflationWeight ( double )
virtual

Set/get the weight of the inflation (normal expansion/contraction) force in the combined displacement. Default: 0.0.

◆ GetInflationWeight()

virtual double vtkvmtkPolyDataPotentialFit::GetInflationWeight ( )
virtual

Set/get the weight of the inflation (normal expansion/contraction) force in the combined displacement. Default: 0.0.

◆ SetConvergence()

virtual void vtkvmtkPolyDataPotentialFit::SetConvergence ( double )
virtual

Set/get the convergence threshold: iteration stops once TimeStep times the maximum point displacement norm drops below this value. Default: 1E-1.

◆ GetConvergence()

virtual double vtkvmtkPolyDataPotentialFit::GetConvergence ( )
virtual

Set/get the convergence threshold: iteration stops once TimeStep times the maximum point displacement norm drops below this value. Default: 1E-1.

◆ SetMaxTimeStep()

virtual void vtkvmtkPolyDataPotentialFit::SetMaxTimeStep ( double )
virtual

Set/get the upper bound on the (possibly adaptive) time step, expressed in pixels per time step. Default: 1.0.

◆ GetMaxTimeStep()

virtual double vtkvmtkPolyDataPotentialFit::GetMaxTimeStep ( )
virtual

Set/get the upper bound on the (possibly adaptive) time step, expressed in pixels per time step. Default: 1.0.

◆ SetTimeStep()

virtual void vtkvmtkPolyDataPotentialFit::SetTimeStep ( double )
virtual

Set/get the time step used to scale point displacements at each sub-step. Overwritten every sub-step when AdaptiveTimeStep is on; used as a fixed value otherwise. Default: 0.0.

◆ GetTimeStep()

virtual double vtkvmtkPolyDataPotentialFit::GetTimeStep ( )
virtual

Set/get the time step used to scale point displacements at each sub-step. Overwritten every sub-step when AdaptiveTimeStep is on; used as a fixed value otherwise. Default: 0.0.

◆ SetAdaptiveTimeStep()

virtual void vtkvmtkPolyDataPotentialFit::SetAdaptiveTimeStep ( int )
virtual

Toggle automatic time step selection: when on, TimeStep is recomputed at every sub-step as the minimum potential image spacing divided by the maximum displacement norm (capped at MaxTimeStep), keeping point motion below about one voxel per step. Default: on.

◆ GetAdaptiveTimeStep()

virtual int vtkvmtkPolyDataPotentialFit::GetAdaptiveTimeStep ( )
virtual

Toggle automatic time step selection: when on, TimeStep is recomputed at every sub-step as the minimum potential image spacing divided by the maximum displacement norm (capped at MaxTimeStep), keeping point motion below about one voxel per step. Default: on.

◆ AdaptiveTimeStepOn()

virtual void vtkvmtkPolyDataPotentialFit::AdaptiveTimeStepOn ( )
virtual

Toggle automatic time step selection: when on, TimeStep is recomputed at every sub-step as the minimum potential image spacing divided by the maximum displacement norm (capped at MaxTimeStep), keeping point motion below about one voxel per step. Default: on.

◆ AdaptiveTimeStepOff()

virtual void vtkvmtkPolyDataPotentialFit::AdaptiveTimeStepOff ( )
virtual

Toggle automatic time step selection: when on, TimeStep is recomputed at every sub-step as the minimum potential image spacing divided by the maximum displacement norm (capped at MaxTimeStep), keeping point motion below about one voxel per step. Default: on.

◆ SetFlipNormals()

virtual void vtkvmtkPolyDataPotentialFit::SetFlipNormals ( int )
virtual

Toggle flipping of the computed surface normals used for the inflation force direction (passed through to the internal vtkPolyDataNormals as FlipNormals). Default: off.

◆ GetFlipNormals()

virtual int vtkvmtkPolyDataPotentialFit::GetFlipNormals ( )
virtual

Toggle flipping of the computed surface normals used for the inflation force direction (passed through to the internal vtkPolyDataNormals as FlipNormals). Default: off.

◆ FlipNormalsOn()

virtual void vtkvmtkPolyDataPotentialFit::FlipNormalsOn ( )
virtual

Toggle flipping of the computed surface normals used for the inflation force direction (passed through to the internal vtkPolyDataNormals as FlipNormals). Default: off.

◆ FlipNormalsOff()

virtual void vtkvmtkPolyDataPotentialFit::FlipNormalsOff ( )
virtual

Toggle flipping of the computed surface normals used for the inflation force direction (passed through to the internal vtkPolyDataNormals as FlipNormals). Default: off.

◆ SetUsePotentialInInflation()

virtual void vtkvmtkPolyDataPotentialFit::SetUsePotentialInInflation ( int )
virtual

Toggle whether the inflation force is additionally modulated by the local potential value (EvaluatePotential), so that inflation slows down near strong image edges. Default: on.

◆ GetUsePotentialInInflation()

virtual int vtkvmtkPolyDataPotentialFit::GetUsePotentialInInflation ( )
virtual

Toggle whether the inflation force is additionally modulated by the local potential value (EvaluatePotential), so that inflation slows down near strong image edges. Default: on.

◆ UsePotentialInInflationOn()

virtual void vtkvmtkPolyDataPotentialFit::UsePotentialInInflationOn ( )
virtual

Toggle whether the inflation force is additionally modulated by the local potential value (EvaluatePotential), so that inflation slows down near strong image edges. Default: on.

◆ UsePotentialInInflationOff()

virtual void vtkvmtkPolyDataPotentialFit::UsePotentialInInflationOff ( )
virtual

Toggle whether the inflation force is additionally modulated by the local potential value (EvaluatePotential), so that inflation slows down near strong image edges. Default: on.

◆ SetDimensionality()

virtual void vtkvmtkPolyDataPotentialFit::SetDimensionality ( int )
virtual

Set/get the spatial dimensionality (2 or 3) used when computing the gradient of PotentialImage. Default: 3.

◆ GetDimensionality()

virtual int vtkvmtkPolyDataPotentialFit::GetDimensionality ( )
virtual

Set/get the spatial dimensionality (2 or 3) used when computing the gradient of PotentialImage. Default: 3.

◆ RequestData()

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

Definition at line 510 of file vtkvmtkPolyDataPotentialFit.cxx.

514{
515 vtkInformation *inInfo = inputVector[0]->GetInformationObject(0);
516 vtkInformation *outInfo = outputVector->GetInformationObject(0);
517
518 vtkPolyData *input = vtkPolyData::SafeDownCast(
519 inInfo->Get(vtkDataObject::DATA_OBJECT()));
520 vtkPolyData *output = vtkPolyData::SafeDownCast(
521 outInfo->Get(vtkDataObject::DATA_OBJECT()));
522
523 bool potential, stiffness, inflation;
524 vtkIdType n, m;
525 vtkIdType numberOfPoints;
526 vtkPoints *newPoints;
527
528 numberOfPoints = input->GetNumberOfPoints();
529
530 newPoints = vtkPoints::New();
531 newPoints->DeepCopy(input->GetPoints());
532
533 if (this->Displacements)
534 {
535 this->Displacements->Delete();
536 this->Displacements = NULL;
537 }
538
539 this->Displacements = vtkDoubleArray::New();
540 this->Displacements->SetNumberOfComponents(3);
541 this->Displacements->SetNumberOfTuples(numberOfPoints);
542
543 vtkImageGradient* gradientFilter = vtkImageGradient::New();
544 gradientFilter->SetInputData(this->PotentialImage);
545 gradientFilter->SetDimensionality(this->Dimensionality);
546 gradientFilter->Update();
547
548 if (this->PotentialGradientImage)
549 {
550 this->PotentialGradientImage->Delete();
551 this->PotentialGradientImage = NULL;
552 }
553
554 this->PotentialGradientImage = vtkImageData::New();
555 this->PotentialGradientImage->DeepCopy(gradientFilter->GetOutput());
556
557 gradientFilter->Delete();
558
559 output->SetPoints(newPoints);
560 output->SetVerts(input->GetVerts());
561 output->SetLines(input->GetLines());
562 output->SetPolys(input->GetPolys());
563 output->SetStrips(input->GetStrips());
564 output->GetPointData()->PassData(input->GetPointData());
565 output->GetCellData()->PassData(input->GetCellData());
566
567 newPoints->Delete();
568
569 if (this->Neighborhoods)
570 {
571 this->Neighborhoods->Delete();
572 this->Neighborhoods = NULL;
573 }
574
576 this->Neighborhoods->SetNeighborhoodTypeToPolyDataManifoldNeighborhood();
577 this->Neighborhoods->SetDataSet(input);
578 this->Neighborhoods->Build();
579
580 vtkPolyDataNormals* surfaceNormals = vtkPolyDataNormals::New();
581 surfaceNormals->SetInputData(input);
582 surfaceNormals->SplittingOff();
583 surfaceNormals->AutoOrientNormalsOn();
584 surfaceNormals->SetFlipNormals(this->FlipNormals);
585 surfaceNormals->ComputePointNormalsOn();
586 surfaceNormals->ConsistencyOn();
587 surfaceNormals->Update();
588
589 this->Normals = surfaceNormals->GetOutput()->GetPointData()->GetNormals();
590
591 this->MinPotentialSpacing = this->ComputeMinSpacing(this->PotentialImage->GetSpacing());
592
593 this->PotentialMaxNorm = this->PotentialGradientImage->GetPointData()->GetScalars()->GetMaxNorm();
594
595 for (n=0; n<this->NumberOfIterations; n++)
596 {
597 for (m=0; m<this->NumberOfStiffnessSubIterations; m++)
598 {
599 potential = false;
600 stiffness = true;
601 inflation = false;
602 this->ComputeDisplacements(potential, stiffness, inflation);
603 this->ComputeTimeStep();
604 this->ApplyDisplacements();
605 }
606
607 for (m=0; m<this->NumberOfInflationSubIterations; m++)
608 {
609 potential = false;
610 stiffness = false;
611 inflation = true;
612 this->ComputeDisplacements(potential, stiffness, inflation);
613 this->ComputeTimeStep();
614 this->ApplyDisplacements();
615 }
616
617 potential = true;
618 stiffness = true;
619 inflation = true;
620 this->ComputeDisplacements(potential, stiffness, inflation);
621 this->ComputeTimeStep();
622 this->ApplyDisplacements();
623
624 if (this->TestConvergence())
625 {
626 break;
627 }
628 }
629
630 surfaceNormals->Delete();
631 this->Normals = NULL;
632
633 return 1;
634}
static vtkvmtkNeighborhoods * New()
static double ComputeMinSpacing(double spacing[3])
void ComputeDisplacements(bool potential, bool stiffness, bool inflation)

◆ EvaluateForce()

void vtkvmtkPolyDataPotentialFit::EvaluateForce ( double point[3],
double force[3],
bool normalize = true )
protected

Definition at line 117 of file vtkvmtkPolyDataPotentialFit.cxx.

118{
119 int ijk[3];
120 double pcoords[3];
121 double weights[8];
122 int inBounds;
123 int i;
124
125 force[0] = force[1] = force[2] = 0.0;
126
127 inBounds = this->PotentialGradientImage->ComputeStructuredCoordinates(point,ijk,pcoords);
128
129 if (!inBounds)
130// if (!inBounds || !this->IsCellInExtent(this->PotentialGradientImage->GetExtent(),ijk,0))
131 {
132 vtkWarningMacro("Point out of extent.");
133 return;
134 }
135
136 vtkCell* cell = this->PotentialGradientImage->GetCell(this->PotentialGradientImage->ComputeCellId(ijk));
137
138 if (cell->GetCellType() == VTK_VOXEL)
139 {
140 vtkVoxel::InterpolationFunctions(pcoords,weights);
141 }
142 else if (cell->GetCellType() == VTK_PIXEL)
143 {
144 vtkPixel::InterpolationFunctions(pcoords,weights);
145 }
146 else
147 {
148 vtkErrorMacro("Non voxel or pixel cell found in PotentialImage");
149 }
150
151 int numberOfCellPoints = cell->GetNumberOfPoints();
152
153 vtkDataArray* gradientVectorsArray = this->PotentialGradientImage->GetPointData()->GetScalars();
154
155 for (i=0; i<numberOfCellPoints; i++)
156 {
157 double vectorValue[3];
158 gradientVectorsArray->GetTuple(cell->GetPointId(i),vectorValue);
159 force[0] += weights[i] * vectorValue[0];
160 force[1] += weights[i] * vectorValue[1];
161 force[2] += weights[i] * vectorValue[2];
162 }
163
164 if (normalize && this->PotentialMaxNorm > VTK_VMTK_DOUBLE_TOL)
165 {
166 force[0] /= this->PotentialMaxNorm;
167 force[1] /= this->PotentialMaxNorm;
168 force[2] /= this->PotentialMaxNorm;
169 }
170
171 force[0] *= -1.0;
172 force[1] *= -1.0;
173 force[2] *= -1.0;
174}
#define VTK_VMTK_DOUBLE_TOL

◆ EvaluatePotential()

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

Definition at line 176 of file vtkvmtkPolyDataPotentialFit.cxx.

177{
178 int ijk[3];
179 double pcoords[3];
180 double weights[8];
181 int inBounds;
182 int i;
183
184 double potential = 0.0;
185
186 inBounds = this->PotentialImage->ComputeStructuredCoordinates(point,ijk,pcoords);
187
188 if (!inBounds)
189// if (!inBounds || !this->IsCellInExtent(this->PotentialImage->GetExtent(),ijk,0))
190 {
191 vtkWarningMacro("Point out of extent.");
192 return 0.0;
193 }
194
195 vtkCell* cell = this->PotentialImage->GetCell(this->PotentialImage->ComputeCellId(ijk));
196
197 if (cell->GetCellType() == VTK_VOXEL)
198 {
199 vtkVoxel::InterpolationFunctions(pcoords,weights);
200 }
201 else if (cell->GetCellType() == VTK_PIXEL)
202 {
203 vtkPixel::InterpolationFunctions(pcoords,weights);
204 }
205 else
206 {
207 vtkErrorMacro("Non voxel or pixel cell found in PotentialImage");
208 return 0.0;
209 }
210
211 int numberOfCellPoints = cell->GetNumberOfPoints();
212
213 vtkDataArray* potentialArray = this->PotentialImage->GetPointData()->GetScalars();
214
215 for (i=0; i<numberOfCellPoints; i++)
216 {
217 double value = potentialArray->GetTuple1(cell->GetPointId(i));
218 potential += weights[i] * value;
219 }
220
221 return potential;
222}

◆ EvaluateInflation()

double vtkvmtkPolyDataPotentialFit::EvaluateInflation ( double point[3])
protected

Definition at line 224 of file vtkvmtkPolyDataPotentialFit.cxx.

225{
226 if (this->InflationImage == NULL) {
227 return 1.0;
228 }
229
230 int ijk[3];
231 double pcoords[3];
232 double weights[8];
233 int inBounds;
234 int i;
235
236 double inflation = 0.0;
237
238 inBounds = this->InflationImage->ComputeStructuredCoordinates(point,ijk,pcoords);
239
240 if (!inBounds)
241// if (!inBounds || !this->IsCellInExtent(this->PotentialImage->GetExtent(),ijk,0))
242 {
243 vtkWarningMacro("Point out of extent.");
244 return 0.0;
245 }
246
247 vtkCell* cell = this->InflationImage->GetCell(this->InflationImage->ComputeCellId(ijk));
248
249 if (cell->GetCellType() == VTK_VOXEL)
250 {
251 vtkVoxel::InterpolationFunctions(pcoords,weights);
252 }
253 else if (cell->GetCellType() == VTK_PIXEL)
254 {
255 vtkPixel::InterpolationFunctions(pcoords,weights);
256 }
257 else
258 {
259 vtkErrorMacro("Non voxel or pixel cell found in PotentialImage");
260 return 0.0;
261 }
262
263 int numberOfCellPoints = cell->GetNumberOfPoints();
264
265 vtkDataArray* inflationArray = this->InflationImage->GetPointData()->GetScalars();
266
267 for (i=0; i<numberOfCellPoints; i++)
268 {
269 double value = inflationArray->GetTuple1(cell->GetPointId(i));
270 inflation += weights[i] * value;
271 }
272
273 return inflation - this->InflationThreshold;
274}

◆ ComputeDisplacements()

void vtkvmtkPolyDataPotentialFit::ComputeDisplacements ( bool potential,
bool stiffness,
bool inflation )
protected

Definition at line 404 of file vtkvmtkPolyDataPotentialFit.cxx.

405{
406 vtkIdType i;
407 vtkIdType numberOfPoints;
408 double displacement[3];
409 double potentialDisplacement[3];
410 double stiffnessDisplacement[3];
411 double inflationDisplacement[3];
412 double displacementNorm;
413
414 numberOfPoints = this->GetOutput()->GetNumberOfPoints();
415
416 this->MaxDisplacementNorm = 0.0;
417
418 for (i=0; i<numberOfPoints; i++)
419 {
420 displacement[0] = displacement[1] = displacement[2] = 0.0;
421
422 if (potential)
423 {
424 this->ComputePotentialDisplacement(i, potentialDisplacement);
425 displacement[0] += this->PotentialWeight * potentialDisplacement[0];
426 displacement[1] += this->PotentialWeight * potentialDisplacement[1];
427 displacement[2] += this->PotentialWeight * potentialDisplacement[2];
428 }
429
430 if (stiffness)
431 {
432 this->ComputeStiffnessDisplacement(i, stiffnessDisplacement);
433 displacement[0] += this->StiffnessWeight * stiffnessDisplacement[0];
434 displacement[1] += this->StiffnessWeight * stiffnessDisplacement[1];
435 displacement[2] += this->StiffnessWeight * stiffnessDisplacement[2];
436 }
437
438 if (inflation)
439 {
440 this->ComputeInflationDisplacement(i, inflationDisplacement);
441 displacement[0] += this->InflationWeight * inflationDisplacement[0];
442 displacement[1] += this->InflationWeight * inflationDisplacement[1];
443 displacement[2] += this->InflationWeight * inflationDisplacement[2];
444 }
445
446 this->Displacements->SetTuple(i, displacement);
447 displacementNorm = vtkMath::Norm(displacement);
448
449 if (displacementNorm > this->MaxDisplacementNorm)
450 {
451 this->MaxDisplacementNorm = displacementNorm;
452 }
453 }
454}
void ComputeInflationDisplacement(vtkIdType pointId, double inflationDisplacement[3])
void ComputePotentialDisplacement(vtkIdType pointId, double potentialDisplacement[3])
void ComputeStiffnessDisplacement(vtkIdType pointId, double stiffnessDisplacement[3])

◆ ComputePotentialDisplacement()

void vtkvmtkPolyDataPotentialFit::ComputePotentialDisplacement ( vtkIdType pointId,
double potentialDisplacement[3] )
protected

Definition at line 276 of file vtkvmtkPolyDataPotentialFit.cxx.

277{
278 double point[3];
279 double force[3];
280 this->GetOutput()->GetPoint(pointId, point);
281 this->EvaluateForce(point, force);
282 potentialDisplacement[0] = force[0];
283 potentialDisplacement[1] = force[1];
284 potentialDisplacement[2] = force[2];
285}
void EvaluateForce(double point[3], double force[3], bool normalize=true)

◆ ComputeStiffnessDisplacement()

void vtkvmtkPolyDataPotentialFit::ComputeStiffnessDisplacement ( vtkIdType pointId,
double stiffnessDisplacement[3] )
protected

Definition at line 287 of file vtkvmtkPolyDataPotentialFit.cxx.

288{
289 vtkIdType j;
290 double point[3];
291 double laplacianPoint[3], neighborhoodPoint[3];
292 vtkIdType numberOfNeighborhoodPoints;
293 vtkvmtkNeighborhood *neighborhood;
294 vtkPolyData *output;
295
296 output = this->GetOutput();
297 neighborhood = this->Neighborhoods->GetNeighborhood(pointId);
298
299 output->GetPoint(pointId,point);
300
301 stiffnessDisplacement[0] = stiffnessDisplacement[1] = stiffnessDisplacement[2] = 0.0;
302
303// double weight;
304// double weightSum;
305// weightSum = 0.0;
306
307 laplacianPoint[0] = laplacianPoint[1] = laplacianPoint[2] = 0.0;
308 numberOfNeighborhoodPoints = neighborhood->GetNumberOfPoints();
309 for (j=0; j<numberOfNeighborhoodPoints; j++)
310 {
311 output->GetPoint(neighborhood->GetPointId(j),neighborhoodPoint);
312
313 laplacianPoint[0] += neighborhoodPoint[0];
314 laplacianPoint[1] += neighborhoodPoint[1];
315 laplacianPoint[2] += neighborhoodPoint[2];
316
317// weight = fabs(neighborhoodPoint[2] - point[2]);
318// laplacianPoint[0] += weight * neighborhoodPoint[0];
319// laplacianPoint[1] += weight * neighborhoodPoint[1];
320// laplacianPoint[2] += weight * neighborhoodPoint[2];
321// weightSum += weight;
322 }
323 laplacianPoint[0] /= (double)numberOfNeighborhoodPoints;
324 laplacianPoint[1] /= (double)numberOfNeighborhoodPoints;
325 laplacianPoint[2] /= (double)numberOfNeighborhoodPoints;
326// laplacianPoint[0] /= weightSum;
327// laplacianPoint[1] /= weightSum;
328// laplacianPoint[2] /= weightSum;
329
330 stiffnessDisplacement[0] = laplacianPoint[0] - point[0];
331 stiffnessDisplacement[1] = laplacianPoint[1] - point[1];
332 stiffnessDisplacement[2] = laplacianPoint[2] - point[2];
333}
vtkIdType GetPointId(vtkIdType i)

◆ ComputeInflationDisplacement()

void vtkvmtkPolyDataPotentialFit::ComputeInflationDisplacement ( vtkIdType pointId,
double inflationDisplacement[3] )
protected

Definition at line 335 of file vtkvmtkPolyDataPotentialFit.cxx.

336{
337 vtkIdType j;
338 double point[3], inputOutwardNormal[3];
339 double neighborhoodVector[3], firstNeighborhoodVector[3];
340 double cross[3], neighborhoodNormal[3];
341 double neighborhoodPoint[3];
342 double dot;
343 vtkIdType numberOfNeighborhoodPoints;
344 vtkvmtkNeighborhood *neighborhood;
345 vtkPolyData *output;
346
347 output = this->GetOutput();
348 neighborhood = this->Neighborhoods->GetNeighborhood(pointId);
349
350 if (neighborhood->GetNumberOfPoints() == 0)
351 {
352 inflationDisplacement[0] = 0.0;
353 inflationDisplacement[1] = 0.0;
354 inflationDisplacement[2] = 0.0;
355 return;
356 }
357
358 output->GetPoint(pointId,point);
359 this->Normals->GetTuple(pointId,inputOutwardNormal);
360
361 double inflation = this->EvaluateInflation(point);
362 double potential = 1.0;
363 if (this->UsePotentialInInflation) {
364 potential = this->EvaluatePotential(point);
365 }
366
367 neighborhoodNormal[0] = 0.0;
368 neighborhoodNormal[1] = 0.0;
369 neighborhoodNormal[2] = 0.0;
370
371 output->GetPoint(neighborhood->GetPointId(0),neighborhoodPoint);
372 firstNeighborhoodVector[0] = neighborhoodPoint[0] - point[0];
373 firstNeighborhoodVector[1] = neighborhoodPoint[1] - point[1];
374 firstNeighborhoodVector[2] = neighborhoodPoint[2] - point[2];
375
376 numberOfNeighborhoodPoints = neighborhood->GetNumberOfPoints();
377 for (j=1; j<numberOfNeighborhoodPoints; j++)
378 {
379 output->GetPoint(neighborhood->GetPointId(j),neighborhoodPoint);
380 neighborhoodVector[0] = neighborhoodPoint[0] - point[0];
381 neighborhoodVector[1] = neighborhoodPoint[1] - point[1];
382 neighborhoodVector[2] = neighborhoodPoint[2] - point[2];
383 vtkMath::Cross(firstNeighborhoodVector,neighborhoodVector,cross);
384 neighborhoodNormal[0] += cross[0];
385 neighborhoodNormal[1] += cross[1];
386 neighborhoodNormal[2] += cross[2];
387 }
388 vtkMath::Normalize(neighborhoodNormal);
389
390 dot = vtkMath::Dot(inputOutwardNormal,neighborhoodNormal);
391
392 if (dot < 0.0)
393 {
394 neighborhoodNormal[0] *= -1.0;
395 neighborhoodNormal[1] *= -1.0;
396 neighborhoodNormal[2] *= -1.0;
397 }
398
399 inflationDisplacement[0] = inflation * potential * neighborhoodNormal[0];
400 inflationDisplacement[1] = inflation * potential * neighborhoodNormal[1];
401 inflationDisplacement[2] = inflation * potential * neighborhoodNormal[2];
402}

◆ ComputeTimeStep()

void vtkvmtkPolyDataPotentialFit::ComputeTimeStep ( )
protected

Definition at line 456 of file vtkvmtkPolyDataPotentialFit.cxx.

457{
458 if (!this->AdaptiveTimeStep)
459 {
460 return;
461 }
462
464 {
466 if (this->TimeStep > this->MaxTimeStep)
467 {
468 this->TimeStep = this->MaxTimeStep;
469 }
470 }
471 else
472 {
473 this->TimeStep = this->MaxTimeStep;
474 }
475}

◆ ApplyDisplacements()

void vtkvmtkPolyDataPotentialFit::ApplyDisplacements ( )
protected

Definition at line 477 of file vtkvmtkPolyDataPotentialFit.cxx.

478{
479 vtkIdType i;
480 vtkIdType numberOfPoints;
481 double point[3], displacement[3], newPoint[3];
482 vtkPoints *points;
483
484 points = this->GetOutput()->GetPoints();
485 numberOfPoints = points->GetNumberOfPoints();
486
487 for (i=0; i<numberOfPoints; i++)
488 {
489 points->GetPoint(i,point);
490 this->Displacements->GetTuple(i,displacement);
491 newPoint[0] = point[0] + this->Relaxation * this->TimeStep * displacement[0];
492 newPoint[1] = point[1] + this->Relaxation * this->TimeStep * displacement[1];
493 newPoint[2] = point[2] + this->Relaxation * this->TimeStep * displacement[2];
494 points->SetPoint(i,newPoint);
495 }
496}

◆ TestConvergence()

int vtkvmtkPolyDataPotentialFit::TestConvergence ( )
protected

Definition at line 505 of file vtkvmtkPolyDataPotentialFit.cxx.

506{
507 return this->TimeStep * this->MaxDisplacementNorm < this->Convergence ? 1 : 0;
508}

◆ ComputeMinSpacing()

double vtkvmtkPolyDataPotentialFit::ComputeMinSpacing ( double spacing[3])
staticprotected

Definition at line 498 of file vtkvmtkPolyDataPotentialFit.cxx.

499{
500 double minSpacing;
501 minSpacing = (spacing[0] < spacing[1]) && (spacing[0] < spacing[2]) ? spacing[0] : (spacing[1] < spacing[2]) ? spacing[1] : spacing[2];
502 return minSpacing;
503}

◆ IsInExtent()

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

Definition at line 238 of file vtkvmtkPolyDataPotentialFit.h.

239 {
240 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;
241 }

◆ IsCellInExtent()

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

Definition at line 243 of file vtkvmtkPolyDataPotentialFit.h.

244 {
245 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;
246 }

Member Data Documentation

◆ PotentialImage

vtkImageData* vtkvmtkPolyDataPotentialFit::PotentialImage
protected

Definition at line 248 of file vtkvmtkPolyDataPotentialFit.h.

◆ InflationImage

vtkImageData* vtkvmtkPolyDataPotentialFit::InflationImage
protected

Definition at line 249 of file vtkvmtkPolyDataPotentialFit.h.

◆ PotentialGradientImage

vtkImageData* vtkvmtkPolyDataPotentialFit::PotentialGradientImage
protected

Definition at line 250 of file vtkvmtkPolyDataPotentialFit.h.

◆ NumberOfIterations

int vtkvmtkPolyDataPotentialFit::NumberOfIterations
protected

Definition at line 252 of file vtkvmtkPolyDataPotentialFit.h.

◆ NumberOfStiffnessSubIterations

int vtkvmtkPolyDataPotentialFit::NumberOfStiffnessSubIterations
protected

Definition at line 254 of file vtkvmtkPolyDataPotentialFit.h.

◆ NumberOfInflationSubIterations

int vtkvmtkPolyDataPotentialFit::NumberOfInflationSubIterations
protected

Definition at line 255 of file vtkvmtkPolyDataPotentialFit.h.

◆ TimeStep

double vtkvmtkPolyDataPotentialFit::TimeStep
protected

Definition at line 257 of file vtkvmtkPolyDataPotentialFit.h.

◆ Relaxation

double vtkvmtkPolyDataPotentialFit::Relaxation
protected

Definition at line 258 of file vtkvmtkPolyDataPotentialFit.h.

◆ MaxDisplacementNorm

double vtkvmtkPolyDataPotentialFit::MaxDisplacementNorm
protected

Definition at line 259 of file vtkvmtkPolyDataPotentialFit.h.

◆ MinEdgeLength

double vtkvmtkPolyDataPotentialFit::MinEdgeLength
protected

Definition at line 260 of file vtkvmtkPolyDataPotentialFit.h.

◆ MinPotentialSpacing

double vtkvmtkPolyDataPotentialFit::MinPotentialSpacing
protected

Definition at line 261 of file vtkvmtkPolyDataPotentialFit.h.

◆ Convergence

double vtkvmtkPolyDataPotentialFit::Convergence
protected

Definition at line 262 of file vtkvmtkPolyDataPotentialFit.h.

◆ PotentialWeight

double vtkvmtkPolyDataPotentialFit::PotentialWeight
protected

Definition at line 264 of file vtkvmtkPolyDataPotentialFit.h.

◆ StiffnessWeight

double vtkvmtkPolyDataPotentialFit::StiffnessWeight
protected

Definition at line 265 of file vtkvmtkPolyDataPotentialFit.h.

◆ InflationWeight

double vtkvmtkPolyDataPotentialFit::InflationWeight
protected

Definition at line 266 of file vtkvmtkPolyDataPotentialFit.h.

◆ InflationThreshold

double vtkvmtkPolyDataPotentialFit::InflationThreshold
protected

Definition at line 268 of file vtkvmtkPolyDataPotentialFit.h.

◆ PotentialMaxNorm

double vtkvmtkPolyDataPotentialFit::PotentialMaxNorm
protected

Definition at line 269 of file vtkvmtkPolyDataPotentialFit.h.

◆ UsePotentialInInflation

int vtkvmtkPolyDataPotentialFit::UsePotentialInInflation
protected

Definition at line 270 of file vtkvmtkPolyDataPotentialFit.h.

◆ MaxTimeStep

double vtkvmtkPolyDataPotentialFit::MaxTimeStep
protected

Definition at line 272 of file vtkvmtkPolyDataPotentialFit.h.

◆ AdaptiveTimeStep

int vtkvmtkPolyDataPotentialFit::AdaptiveTimeStep
protected

Definition at line 273 of file vtkvmtkPolyDataPotentialFit.h.

◆ FlipNormals

int vtkvmtkPolyDataPotentialFit::FlipNormals
protected

Definition at line 275 of file vtkvmtkPolyDataPotentialFit.h.

◆ Dimensionality

int vtkvmtkPolyDataPotentialFit::Dimensionality
protected

Definition at line 277 of file vtkvmtkPolyDataPotentialFit.h.

◆ Displacements

vtkDoubleArray* vtkvmtkPolyDataPotentialFit::Displacements
protected

Definition at line 279 of file vtkvmtkPolyDataPotentialFit.h.

◆ Neighborhoods

vtkvmtkNeighborhoods* vtkvmtkPolyDataPotentialFit::Neighborhoods
protected

Definition at line 281 of file vtkvmtkPolyDataPotentialFit.h.

◆ Normals

vtkDataArray* vtkvmtkPolyDataPotentialFit::Normals
protected

Definition at line 282 of file vtkvmtkPolyDataPotentialFit.h.


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