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

Implements the Fast Marching Method on polygonal non-manifolds. More...

#include <vtkvmtkNonManifoldFastMarching.h>

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

Public Types

typedef vtkPolyDataAlgorithm Superclass

Public Member Functions

virtual int IsA (const char *type)
vtkvmtkNonManifoldFastMarching * NewInstance () const
void PrintSelf (std::ostream &os, vtkIndent indent) override
virtual void SetStopTravelTime (double)
virtual double GetStopTravelTime ()
virtual void SetStopNumberOfPoints (int)
virtual int GetStopNumberOfPoints ()
virtual void SetRegularization (double)
virtual double GetRegularization ()
virtual void SetSeedsBoundaryConditions (int)
virtual int GetSeedsBoundaryConditions ()
virtual void SeedsBoundaryConditionsOn ()
virtual void SeedsBoundaryConditionsOff ()
virtual void SetPolyDataBoundaryConditions (int)
virtual int GetPolyDataBoundaryConditions ()
virtual void PolyDataBoundaryConditionsOn ()
virtual void PolyDataBoundaryConditionsOff ()
virtual void SetSeeds (vtkIdList *)
virtual vtkIdList * GetSeeds ()
virtual void SetStopSeedId (vtkIdList *)
virtual vtkIdList * GetStopSeedId ()
virtual void SetBoundaryPolyData (vtkPolyData *)
virtual vtkPolyData * GetBoundaryPolyData ()
virtual void SetIntersectedEdgesArrayName (const char *)
virtual char * GetIntersectedEdgesArrayName ()
virtual void SetInitializeFromScalars (int)
virtual int GetInitializeFromScalars ()
virtual void InitializeFromScalarsOn ()
virtual void InitializeFromScalarsOff ()
virtual void SetInitializationArrayName (const char *)
virtual char * GetInitializationArrayName ()
virtual void SetUnitSpeed (int)
virtual int GetUnitSpeed ()
virtual void UnitSpeedOn ()
virtual void UnitSpeedOff ()
virtual void SetCostFunctionArrayName (const char *)
virtual char * GetCostFunctionArrayName ()
virtual void SetSolutionArrayName (const char *)
virtual char * GetSolutionArrayName ()

Static Public Member Functions

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

Protected Member Functions

virtual vtkObjectBase * NewInstanceInternal () const
 vtkvmtkNonManifoldFastMarching ()
 ~vtkvmtkNonManifoldFastMarching ()
virtual int RequestData (vtkInformation *, vtkInformationVector **, vtkInformationVector *) override
void InitPropagation (vtkPolyData *input)
void SolveQuadratic (double a, double b, double c, char &nSol, double &x0, double &x1)
void GetNeighbors (vtkPolyData *input, vtkIdType pointId, vtkIdList *neighborIds)
double ComputeUpdateFromCellNeighbor (vtkPolyData *input, vtkIdType neighborId, vtkIdType *trianglePts)
void UpdateNeighbor (vtkPolyData *input, vtkIdType neighborId)
void UpdateNeighborhood (vtkPolyData *input, vtkIdType pointId)
void Propagate (vtkPolyData *input)

Static Protected Member Functions

static double Max (double a, double b)
static double Min (double a, double b)

Protected Attributes

vtkDoubleArray * TScalars
vtkCharArray * StatusScalars
vtkvmtkMinHeap * ConsideredMinHeap
vtkIdList * Seeds
vtkIdList * StopSeedId
vtkPolyData * BoundaryPolyData
double Regularization
double StopTravelTime
vtkIdType StopNumberOfPoints
int UnitSpeed
int InitializeFromScalars
char * IntersectedEdgesArrayName
char * InitializationArrayName
char * SolutionArrayName
char * CostFunctionArrayName
int SeedsBoundaryConditions
int PolyDataBoundaryConditions
vtkIdType NumberOfAcceptedPoints
int AllowLineUpdate
int UpdateFromConsidered

Detailed Description

Implements the Fast Marching Method on polygonal non-manifolds.

This class is used to solve the Eikonal equation

\[|\nabla T(\mathbf{x})| = F(\mathbf{x})\]

on non-manifolds made of convex polygons, using the Fast Marching Method, by J.A. Sethian (see below). The solution to the Eikonal equation represents the arrival times of a wave propagating on a domain with speed \(F^{-1}(\mathbf{x})\) from given seed points (or regions). If F(x)=1, T(x) represents the geodesic distance field to the seed points (Note: F(x) can be equivalently interpreted as a cost function). The Fast Marching Method takes O(N logN). For more insight see J.A. Sethian, Level Set Methods and Fast Marching Methods, Cambridge University Press, 2nd Edition, 1999.

The implementation given in this class is an extension of the Fast Marching Method for triangulated 2-manifolds proposed by Kimmel et al. (R. Kimmel and J.A. Sethian. Computing geodesic paths on manifolds. PNAS, 95(15): 8431-8435, Jul 1998.) to non-manifolds made of convex polygons, such as the Voronoi diagram.

The propagation starts from a set of seeds. By default the seed points are given a propagation time of 0.0, but activating InitializeFromScalars and providing the point data array of name InitializationArrayName, it is possible to assign nonzero initialization times (this is useful when the zero propagation time point lies inside a cell). For the specification of F(x), the user must either provide a point data array of name CostFunctionArrayName, or activate UnitSpeed, which sets F(x)=1 everywhere, thus yielding a geodesic distance field. The propagation stops when all the points in the domain path-connected to the seeds have been visited. Alternatively it is possible to limit the propagation by setting StopTravelTime or StopNumberOfPoints. The solution is stored in a point data array of name SolutionArrayName (name provided by the user; see SolutionArrayName for typical values).

The Regularization value adds a constant term to F(x), which acts as a regularization term for the minimal cost paths (see L.D. Cohen and R. Kimmel. Global minimum of active contour models: a minimal path approach. IJCV, 24(1): 57-78, Aug 1997).

See also
vtkVoronoiDiagram3D vtkMinHeap

Definition at line 54 of file vtkvmtkNonManifoldFastMarching.h.

Member Typedef Documentation

◆ Superclass

typedef vtkPolyDataAlgorithm vtkvmtkNonManifoldFastMarching::Superclass

Definition at line 57 of file vtkvmtkNonManifoldFastMarching.h.

Constructor & Destructor Documentation

◆ vtkvmtkNonManifoldFastMarching()

vtkvmtkNonManifoldFastMarching::vtkvmtkNonManifoldFastMarching ( )
protected

Definition at line 40 of file vtkvmtkNonManifoldFastMarching.cxx.

41{
42 this->Seeds = NULL;
43 this->TScalars = vtkDoubleArray::New();
44 this->StatusScalars = vtkCharArray::New();
46
47 this->Regularization = 0.0;
50 this->UnitSpeed = 0;
51 this->InitializeFromScalars = 0;
52 this->InitializationArrayName = NULL;
53 this->SolutionArrayName = NULL;
54 this->CostFunctionArrayName = NULL;
55
58
59 this->BoundaryPolyData = NULL;
60 this->IntersectedEdgesArrayName = NULL;
61
62 this->NumberOfAcceptedPoints = 0;
63
64 this->AllowLineUpdate = 1;
65 this->UpdateFromConsidered = 1;
66 this->StopSeedId = NULL;
67}
static vtkvmtkMinHeap * New()
#define VTK_VMTK_LARGE_INTEGER
#define VTK_VMTK_LARGE_DOUBLE

◆ ~vtkvmtkNonManifoldFastMarching()

vtkvmtkNonManifoldFastMarching::~vtkvmtkNonManifoldFastMarching ( )
protected

Definition at line 69 of file vtkvmtkNonManifoldFastMarching.cxx.

70{
71 if (this->Seeds)
72 {
73 this->Seeds->Delete();
74 this->Seeds = NULL;
75 }
76
77 if (this->BoundaryPolyData)
78 {
79 this->BoundaryPolyData->Delete();
80 this->BoundaryPolyData = NULL;
81 }
82
83 if (this->SolutionArrayName)
84 {
85 delete[] this->SolutionArrayName;
86 this->SolutionArrayName = NULL;
87 }
88
89 if (this->CostFunctionArrayName)
90 {
91 delete[] this->CostFunctionArrayName;
92 this->CostFunctionArrayName = NULL;
93 }
94
95 if (this->StopSeedId)
96 {
97 this->StopSeedId->Delete();
98 this->StopSeedId = NULL;
99 }
100 this->TScalars->Delete();
101 this->StatusScalars->Delete();
102 this->ConsideredMinHeap->Delete();
103}

Member Function Documentation

◆ IsTypeOf()

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

◆ IsA()

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

◆ SafeDownCast()

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

◆ NewInstanceInternal()

virtual vtkObjectBase * vtkvmtkNonManifoldFastMarching::NewInstanceInternal ( ) const
protectedvirtual

◆ NewInstance()

vtkvmtkNonManifoldFastMarching * vtkvmtkNonManifoldFastMarching::NewInstance ( ) const

◆ PrintSelf()

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

Definition at line 788 of file vtkvmtkNonManifoldFastMarching.cxx.

789{
790 this->Superclass::PrintSelf(os,indent);
791}

◆ New()

vtkvmtkNonManifoldFastMarching * vtkvmtkNonManifoldFastMarching::New ( )
static

◆ SetStopTravelTime()

virtual void vtkvmtkNonManifoldFastMarching::SetStopTravelTime ( double )
virtual

Set/Get maximum travel time for travel time-based stop criterion.

◆ GetStopTravelTime()

virtual double vtkvmtkNonManifoldFastMarching::GetStopTravelTime ( )
virtual

Set/Get maximum travel time for travel time-based stop criterion.

◆ SetStopNumberOfPoints()

virtual void vtkvmtkNonManifoldFastMarching::SetStopNumberOfPoints ( int )
virtual

Set/Get maximum number of visited points for number of visited points-based stop criterion.

◆ GetStopNumberOfPoints()

virtual int vtkvmtkNonManifoldFastMarching::GetStopNumberOfPoints ( )
virtual

Set/Get maximum number of visited points for number of visited points-based stop criterion.

◆ SetRegularization()

virtual void vtkvmtkNonManifoldFastMarching::SetRegularization ( double )
virtual

Set/Get minimal cost path regularization amount.

◆ GetRegularization()

virtual double vtkvmtkNonManifoldFastMarching::GetRegularization ( )
virtual

Set/Get minimal cost path regularization amount.

◆ SetSeedsBoundaryConditions()

virtual void vtkvmtkNonManifoldFastMarching::SetSeedsBoundaryConditions ( int )
virtual

Toggle on/off boundary conditions expressed as a list of seeds.

◆ GetSeedsBoundaryConditions()

virtual int vtkvmtkNonManifoldFastMarching::GetSeedsBoundaryConditions ( )
virtual

Toggle on/off boundary conditions expressed as a list of seeds.

◆ SeedsBoundaryConditionsOn()

virtual void vtkvmtkNonManifoldFastMarching::SeedsBoundaryConditionsOn ( )
virtual

Toggle on/off boundary conditions expressed as a list of seeds.

◆ SeedsBoundaryConditionsOff()

virtual void vtkvmtkNonManifoldFastMarching::SeedsBoundaryConditionsOff ( )
virtual

Toggle on/off boundary conditions expressed as a list of seeds.

◆ SetPolyDataBoundaryConditions()

virtual void vtkvmtkNonManifoldFastMarching::SetPolyDataBoundaryConditions ( int )
virtual

Toggle on/off boundary conditions expressed as poly data.

◆ GetPolyDataBoundaryConditions()

virtual int vtkvmtkNonManifoldFastMarching::GetPolyDataBoundaryConditions ( )
virtual

Toggle on/off boundary conditions expressed as poly data.

◆ PolyDataBoundaryConditionsOn()

virtual void vtkvmtkNonManifoldFastMarching::PolyDataBoundaryConditionsOn ( )
virtual

Toggle on/off boundary conditions expressed as poly data.

◆ PolyDataBoundaryConditionsOff()

virtual void vtkvmtkNonManifoldFastMarching::PolyDataBoundaryConditionsOff ( )
virtual

Toggle on/off boundary conditions expressed as poly data.

◆ SetSeeds()

virtual void vtkvmtkNonManifoldFastMarching::SetSeeds ( vtkIdList * )
virtual

Set/Get seeds were boundary conditions are specified.

◆ GetSeeds()

virtual vtkIdList * vtkvmtkNonManifoldFastMarching::GetSeeds ( )
virtual

Set/Get seeds were boundary conditions are specified.

◆ SetStopSeedId()

virtual void vtkvmtkNonManifoldFastMarching::SetStopSeedId ( vtkIdList * )
virtual

(Set/Get) when set, the algorithm will terminate when the front has propagated from the (source) "Seeds" to this (target) "Seed".

◆ GetStopSeedId()

virtual vtkIdList * vtkvmtkNonManifoldFastMarching::GetStopSeedId ( )
virtual

(Set/Get) when set, the algorithm will terminate when the front has propagated from the (source) "Seeds" to this (target) "Seed".

◆ SetBoundaryPolyData()

virtual void vtkvmtkNonManifoldFastMarching::SetBoundaryPolyData ( vtkPolyData * )
virtual

Set/Get poly data were boundary conditions are specified.

◆ GetBoundaryPolyData()

virtual vtkPolyData * vtkvmtkNonManifoldFastMarching::GetBoundaryPolyData ( )
virtual

Set/Get poly data were boundary conditions are specified.

◆ SetIntersectedEdgesArrayName()

virtual void vtkvmtkNonManifoldFastMarching::SetIntersectedEdgesArrayName ( const char * )
virtual

Set/Get the name of the 2-component point data array of boundary poly data where point ids of edges of the input intersected by boundary poly data are stored. Commonly named "EdgeArray".

◆ GetIntersectedEdgesArrayName()

virtual char * vtkvmtkNonManifoldFastMarching::GetIntersectedEdgesArrayName ( )
virtual

Set/Get the name of the 2-component point data array of boundary poly data where point ids of edges of the input intersected by boundary poly data are stored. Commonly named "EdgeArray".

◆ SetInitializeFromScalars()

virtual void vtkvmtkNonManifoldFastMarching::SetInitializeFromScalars ( int )
virtual

Toggle on/off using point data array of name InitializationArrayName for the solution value of seed points. If off, a value of 0.0 is used for all seeds.

◆ GetInitializeFromScalars()

virtual int vtkvmtkNonManifoldFastMarching::GetInitializeFromScalars ( )
virtual

Toggle on/off using point data array of name InitializationArrayName for the solution value of seed points. If off, a value of 0.0 is used for all seeds.

◆ InitializeFromScalarsOn()

virtual void vtkvmtkNonManifoldFastMarching::InitializeFromScalarsOn ( )
virtual

Toggle on/off using point data array of name InitializationArrayName for the solution value of seed points. If off, a value of 0.0 is used for all seeds.

◆ InitializeFromScalarsOff()

virtual void vtkvmtkNonManifoldFastMarching::InitializeFromScalarsOff ( )
virtual

Toggle on/off using point data array of name InitializationArrayName for the solution value of seed points. If off, a value of 0.0 is used for all seeds.

◆ SetInitializationArrayName()

virtual void vtkvmtkNonManifoldFastMarching::SetInitializationArrayName ( const char * )
virtual

Set/Get the name of point data InitializationArray

◆ GetInitializationArrayName()

virtual char * vtkvmtkNonManifoldFastMarching::GetInitializationArrayName ( )
virtual

Set/Get the name of point data InitializationArray

◆ SetUnitSpeed()

virtual void vtkvmtkNonManifoldFastMarching::SetUnitSpeed ( int )
virtual

Toggle on/off using a unit speed field over the whole domain (used to obtain geodesic distances). If off, a CostFunctionArray must be provided.

◆ GetUnitSpeed()

virtual int vtkvmtkNonManifoldFastMarching::GetUnitSpeed ( )
virtual

Toggle on/off using a unit speed field over the whole domain (used to obtain geodesic distances). If off, a CostFunctionArray must be provided.

◆ UnitSpeedOn()

virtual void vtkvmtkNonManifoldFastMarching::UnitSpeedOn ( )
virtual

Toggle on/off using a unit speed field over the whole domain (used to obtain geodesic distances). If off, a CostFunctionArray must be provided.

◆ UnitSpeedOff()

virtual void vtkvmtkNonManifoldFastMarching::UnitSpeedOff ( )
virtual

Toggle on/off using a unit speed field over the whole domain (used to obtain geodesic distances). If off, a CostFunctionArray must be provided.

◆ SetCostFunctionArrayName()

virtual void vtkvmtkNonManifoldFastMarching::SetCostFunctionArrayName ( const char * )
virtual

Set/Get the name of point data CostFunctionArray Commonly named "CostFunctionArray".

◆ GetCostFunctionArrayName()

virtual char * vtkvmtkNonManifoldFastMarching::GetCostFunctionArrayName ( )
virtual

Set/Get the name of point data CostFunctionArray Commonly named "CostFunctionArray".

◆ SetSolutionArrayName()

virtual void vtkvmtkNonManifoldFastMarching::SetSolutionArrayName ( const char * )
virtual

Set/Get the name of point data SolutionArray Commonly named "EikonalSolution" or "VoronoiGeodesicDistance", depending on context.

◆ GetSolutionArrayName()

virtual char * vtkvmtkNonManifoldFastMarching::GetSolutionArrayName ( )
virtual

Set/Get the name of point data SolutionArray Commonly named "EikonalSolution" or "VoronoiGeodesicDistance", depending on context.

◆ RequestData()

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

Definition at line 646 of file vtkvmtkNonManifoldFastMarching.cxx.

650{
651 vtkInformation *inInfo = inputVector[0]->GetInformationObject(0);
652 vtkInformation *outInfo = outputVector->GetInformationObject(0);
653
654 vtkPolyData *input = vtkPolyData::SafeDownCast(
655 inInfo->Get(vtkDataObject::DATA_OBJECT()));
656 vtkPolyData *output = vtkPolyData::SafeDownCast(
657 outInfo->Get(vtkDataObject::DATA_OBJECT()));
658
659 char eikonalSolutionArrayName[512];
660 vtkIdType i;
661
662 if (this->InitializeFromScalars)
663 {
664 if (!this->InitializationArrayName)
665 {
666 vtkErrorMacro(<<"No initialization array name defined!");
667 return 1;
668 }
669 if (!input->GetPointData()->GetArray(this->InitializationArrayName))
670 {
671 vtkErrorMacro(<< "Initialization array with name specified does not exist!");
672 return 1;
673 }
674 }
675
676 if (!this->UnitSpeed)
677 {
678 if (!this->CostFunctionArrayName)
679 {
680 vtkErrorMacro(<<"No cost function array name defined!");
681 return 1;
682 }
683 if (!input->GetPointData()->GetArray(this->CostFunctionArrayName))
684 {
685 vtkErrorMacro(<< "Cost function array with name specified does not exist!");
686 return 1;
687 }
688 }
689
691 {
692 vtkWarningMacro(<<"No boundary conditions activated!");
693 return 1;
694 }
695
696 if (this->SeedsBoundaryConditions)
697 {
698 if (!this->Seeds)
699 {
700 vtkErrorMacro(<<"Seeds not specified!");
701 return 1;
702 }
703 for (i=0; i<this->Seeds->GetNumberOfIds(); i++)
704 {
705 if ((this->Seeds->GetId(i)<0) || (this->Seeds->GetId(i)>input->GetNumberOfPoints()))
706 {
707 vtkErrorMacro(<<"Seed id exceeds input number of points!");
708 return 1;
709 }
710 }
711 }
712
714 {
715 if (!this->BoundaryPolyData)
716 {
717 vtkErrorMacro(<<"Boundary poly data not specified!");
718 return 1;
719 }
720 if (!this->IntersectedEdgesArrayName)
721 {
722 vtkErrorMacro(<<"Intersected edges array name not specified!");
723 return 1;
724 }
725 if (!this->BoundaryPolyData->GetPointData()->GetArray(this->IntersectedEdgesArrayName))
726 {
727 vtkErrorMacro(<<"Intersected edges array with name specified does not exist!");
728 return 1;
729 }
730 if (!this->UnitSpeed)
731 {
732 vtkWarningMacro(<<"Initialization can be inaccurate if unit speed is not used for poly data boundary conditions.");
733 }
734 }
735
736 this->InitPropagation(input);
737
738 this->Propagate(input);
739
740 int naccepted = 0, nconsidered = 0, nfar = 0;
741 for (i=0; i<input->GetNumberOfPoints(); i++)
742 {
743 if (this->TScalars->GetValue(i)>=VTK_VMTK_LARGE_DOUBLE)
744 {
745 if (this->StatusScalars->GetValue(i) == VTK_VMTK_ACCEPTED_STATUS)
746 {
747 this->TScalars->SetValue(i,0.0);
748 naccepted++;
749 }
750 if (this->StatusScalars->GetValue(i) == VTK_VMTK_CONSIDERED_STATUS)
751 {
752 this->TScalars->SetValue(i,0.0);
753 nconsidered++;
754 }
755 if (this->StatusScalars->GetValue(i) == VTK_VMTK_FAR_STATUS)
756 {
757 this->TScalars->SetValue(i,0.0);
758 nfar++;
759 }
760 }
761 }
762
763 if (naccepted||nconsidered||nfar)
764 {
765 // vtkWarningMacro(<<"Unvisited points found: "<<naccepted<<" accepted, "<<nconsidered<<" considered, "<<nfar<<" far.");
766 }
767
768 if (this->SolutionArrayName)
769 {
770 strcpy(eikonalSolutionArrayName,this->SolutionArrayName);
771 }
772 else
773 {
774 strcpy(eikonalSolutionArrayName,"EikonalSolution");
775 }
776
777 this->TScalars->SetName(eikonalSolutionArrayName);
778
779 output->CopyStructure(input);
780 output->GetPointData()->PassData(input->GetPointData());
781 output->GetCellData()->PassData(input->GetCellData());
782 output->GetPointData()->AddArray(this->TScalars);
783 output->GetPointData()->SetActiveScalars(eikonalSolutionArrayName);
784
785 return 1;
786}
const char VTK_VMTK_ACCEPTED_STATUS
const char VTK_VMTK_FAR_STATUS
const char VTK_VMTK_CONSIDERED_STATUS

◆ InitPropagation()

void vtkvmtkNonManifoldFastMarching::InitPropagation ( vtkPolyData * input)
protected

Definition at line 105 of file vtkvmtkNonManifoldFastMarching.cxx.

106{
107 vtkIdType i, j, k, l;
108 vtkIdType pointId;
109 vtkIdType npts, *cells;
110 const vtkIdType *pts;
111 vtkIdType ncells;
112 vtkIdType intersectedEdge[2];
113 vtkDataArray* initializationArray, *costFunctionArray, *intersectedEdgesArray;
114 vtkIdList* neighborCells;
115 vtkIdList* neighborIds;
116 vtkIdList* boundaryPointIds;
117 int subId;
118 double pcoords[3], *weights;
119 double closestPoint[3];
120 double distance, distance2, minDistance;
121 int allowLineUpdateBackup;
122 vtkPolyLine* polyLine;
123
124 boundaryPointIds = vtkIdList::New();
125 neighborCells = vtkIdList::New();
126 neighborIds = vtkIdList::New();
127
128 allowLineUpdateBackup = this->AllowLineUpdate;
129 this->AllowLineUpdate = 1;
130
131 initializationArray = NULL;
132 if (this->InitializeFromScalars)
133 {
134 initializationArray = input->GetPointData()->GetArray(this->InitializationArrayName);
135 }
136
137 if (!this->UnitSpeed)
138 {
139 costFunctionArray = input->GetPointData()->GetArray(this->CostFunctionArrayName);
140 }
141
142 input->BuildCells();
143 input->BuildLinks();
144
145 this->StatusScalars->SetNumberOfTuples(input->GetNumberOfPoints());
146 this->StatusScalars->FillComponent(0,VTK_VMTK_FAR_STATUS);
147
148 this->TScalars->SetNumberOfTuples(input->GetNumberOfPoints());
149 this->TScalars->FillComponent(0,VTK_VMTK_LARGE_DOUBLE);
150
151 this->NumberOfAcceptedPoints = 0;
152
153 this->ConsideredMinHeap->SetMinHeapScalars(this->TScalars);
154 this->ConsideredMinHeap->Initialize();
155
156 if (this->SeedsBoundaryConditions)
157 {
158 for (i=0; i<this->Seeds->GetNumberOfIds(); i++)
159 {
160 pointId = this->Seeds->GetId(i);
161 boundaryPointIds->InsertUniqueId(pointId);
162 if (this->InitializeFromScalars)
163 {
164 this->TScalars->SetComponent(pointId,0,initializationArray->GetTuple1(pointId));
165 }
166 else
167 {
168 this->TScalars->SetComponent(pointId,0,0.0f);
169 }
170 }
171 }
172
174 {
175 this->BoundaryPolyData->BuildCells();
176 this->BoundaryPolyData->BuildLinks();
177 intersectedEdgesArray = this->BoundaryPolyData->GetPointData()->GetArray(this->IntersectedEdgesArrayName);
178 for (i=0; i<this->BoundaryPolyData->GetNumberOfPoints(); i++)
179 {
180 intersectedEdge[0] = static_cast<vtkIdType>(intersectedEdgesArray->GetComponent(i,0));
181 intersectedEdge[1] = static_cast<vtkIdType>(intersectedEdgesArray->GetComponent(i,1));
182
183 neighborCells->Initialize();
184
185 if (intersectedEdge[0]==intersectedEdge[1])
186 {
187 input->GetPointCells(intersectedEdge[0],neighborCells);
188 boundaryPointIds->InsertUniqueId(intersectedEdge[0]);
189 this->TScalars->SetComponent(intersectedEdge[0],0,0.0);
190 }
191 else
192 {
193 input->GetCellEdgeNeighbors(-1,intersectedEdge[0],intersectedEdge[1],neighborCells);
194 boundaryPointIds->InsertUniqueId(intersectedEdge[0]);
195 boundaryPointIds->InsertUniqueId(intersectedEdge[1]);
196 }
197
198 for (j=0; j<neighborCells->GetNumberOfIds(); j++)
199 {
200 input->GetCellPoints(neighborCells->GetId(j),npts,pts);
201 for (k=0; k<npts; k++)
202 {
203 boundaryPointIds->InsertUniqueId(pts[k]);
204 minDistance = this->TScalars->GetComponent(pts[k],0);
205 this->BoundaryPolyData->GetPointCells(i,ncells,cells);
206 for (l=0; l<ncells; l++)
207 {
208 polyLine = vtkPolyLine::SafeDownCast(this->BoundaryPolyData->GetCell(cells[l]));
209 if (!polyLine)
210 {
211 vtkWarningMacro(<<"BoundaryPolyData is not all made up of PolyLines");
212 continue;
213 }
214 weights = new double[polyLine->GetNumberOfPoints()];
215 double point[3];
216 input->GetPoint(pts[k],point);
217 polyLine->EvaluatePosition(point,closestPoint,subId,pcoords,distance2,weights);
218 delete[] weights;
219 distance = sqrt(distance2);
220 if (distance - minDistance < -VTK_VMTK_DOUBLE_TOL)
221 {
222 this->TScalars->SetComponent(pts[k],0,distance);
223 minDistance = distance;
224 }
225 }
226 }
227 }
228 }
229 }
230
231 vtkIdType numberOfBoundaryPointIds;
232 numberOfBoundaryPointIds = boundaryPointIds->GetNumberOfIds();
233
234 for (i=0; i<numberOfBoundaryPointIds; i++)
235 {
236 this->StatusScalars->SetValue(boundaryPointIds->GetId(i),VTK_VMTK_ACCEPTED_STATUS);
238 }
239
240 for (k=0; k<3; k++) // get a good initial solution
241 {
242 for (i=0; i<numberOfBoundaryPointIds; i++)
243 {
244 this->UpdateNeighborhood(input,boundaryPointIds->GetId(i));
245 }
246 }
247
248 this->AllowLineUpdate = allowLineUpdateBackup;
249
250 boundaryPointIds->Delete();
251 neighborCells->Delete();
252 neighborIds->Delete();
253}
void UpdateNeighborhood(vtkPolyData *input, vtkIdType pointId)
#define VTK_VMTK_DOUBLE_TOL

◆ SolveQuadratic()

void vtkvmtkNonManifoldFastMarching::SolveQuadratic ( double a,
double b,
double c,
char & nSol,
double & x0,
double & x1 )
protected

Definition at line 276 of file vtkvmtkNonManifoldFastMarching.cxx.

277{
278 double delta, q;
279
280 delta = b*b - 4*a*c;
281
282 if (delta < -VTK_VMTK_DOUBLE_TOL)
283 {
284 nSol = -1;
287 return;
288 }
289
290 if (fabs(a) > VTK_VMTK_DOUBLE_TOL)
291 {
292 nSol = 2;
293 if (delta < VTK_VMTK_DOUBLE_TOL)
294 {
295 x0 = -b / 2.0*a;
296 x1 = -b / 2.0*a;
297 return;
298 }
299
300 if (b < - VTK_VMTK_DOUBLE_TOL)
301 {
302 q = - 0.5 * (b - sqrt(delta));
303 }
304 else if (b > VTK_VMTK_DOUBLE_TOL)
305 {
306 q = - 0.5 * (b + sqrt(delta));
307 }
308 else
309 {
310 x0 = - sqrt(-c / a);
311 x1 = sqrt(-c / a);
312 return;
313 }
314
315 x0 = q / a;
316 x1 = c / q;
317 }
318 else if (b > VTK_VMTK_DOUBLE_TOL)
319 {
320 nSol = 1;
321 x0 = -c / b;
323 }
324 else
325 {
326 nSol = 0;
329 }
330
331}

◆ GetNeighbors()

void vtkvmtkNonManifoldFastMarching::GetNeighbors ( vtkPolyData * input,
vtkIdType pointId,
vtkIdList * neighborIds )
protected

Definition at line 255 of file vtkvmtkNonManifoldFastMarching.cxx.

256{
257 vtkIdType i, j;
258 vtkIdType npts, *cells;
259 const vtkIdType *pts;
260 vtkIdType ncells;
261
262 input->GetPointCells(pointId,ncells,cells);
263 for (i=0; i<ncells; i++)
264 {
265 input->GetCellPoints(cells[i],npts,pts);
266 for (j=0; j<npts; j++)
267 {
268 if (pts[j]!=pointId)
269 {
270 neighborIds->InsertUniqueId(pts[j]);
271 }
272 }
273 }
274}

◆ ComputeUpdateFromCellNeighbor()

double vtkvmtkNonManifoldFastMarching::ComputeUpdateFromCellNeighbor ( vtkPolyData * input,
vtkIdType neighborId,
vtkIdType * trianglePts )
protected

Definition at line 333 of file vtkvmtkNonManifoldFastMarching.cxx.

334{
335 double fScalar, neighborT;
336 vtkIdType i;
337 bool canUpdateFromTriangle, canUpdateFromLine;
338 vtkIdType pointIdForLineUpdate, pointId;
339 vtkIdType edgesPointId[2];
340 double edgesLength[2], edgesTScalar[2];
341 double edgesVector[2][3];
342 double edgesNormal[2][3];
343 double cosTheta;
344 vtkIdType aEdgeId, bEdgeId;
345 char nSol;
346 double bEq, aEq, cEq, uEq, FEq, tEq, tCompEq, t0Eq, t1Eq, t0CompEq, tCompEqLower, tCompEqHigher;
347 double edgeLength;
348 vtkDataArray* costFunctionArray;
349
350 pointIdForLineUpdate = -1;
351 tCompEq = 0.0;
352 if (!this->UnitSpeed)
353 {
354 costFunctionArray = input->GetPointData()->GetArray(this->CostFunctionArrayName);
355 }
356
357 if (this->UnitSpeed)
358 {
359 fScalar = 1.0;
360 }
361 else
362 {
363 fScalar = costFunctionArray->GetTuple1(neighborId);
364 }
365
366 neighborT = this->TScalars->GetValue(neighborId);
367
368 canUpdateFromTriangle = true;
369 canUpdateFromLine = false;
370 for (i=1; i<3; i++)
371 {
372 pointId = trianglePts[i];
373 if (pointId!=neighborId)
374 {
375 if ((this->StatusScalars->GetValue(pointId) != VTK_VMTK_ACCEPTED_STATUS) ||
376 ((this->StatusScalars->GetValue(pointId) == VTK_VMTK_FAR_STATUS)&&(this->UpdateFromConsidered)))
377 {
378 canUpdateFromTriangle = false;
379 }
380 else
381 {
382 canUpdateFromLine = true;
383 pointIdForLineUpdate = pointId;
384 }
385 }
386 }
387
388 if (!canUpdateFromTriangle)
389 {
390 if ((canUpdateFromLine)&&(this->AllowLineUpdate))
391 {
392 double neighborPoint[3], lineUpdatePoint[3];
393 input->GetPoint(neighborId,neighborPoint);
394 input->GetPoint(pointIdForLineUpdate,lineUpdatePoint);
395 edgeLength = sqrt(vtkMath::Distance2BetweenPoints(neighborPoint,lineUpdatePoint));
396 neighborT = this->Min(this->TScalars->GetValue(pointIdForLineUpdate) + edgeLength * fScalar,neighborT);
397 return neighborT;
398 }
399 else
401 }
402
403 if (trianglePts[0]==neighborId)
404 {
405 edgesPointId[0] = trianglePts[1];
406 edgesPointId[1] = trianglePts[2];
407 }
408 else if (trianglePts[1]==neighborId)
409 {
410 edgesPointId[0] = trianglePts[2];
411 edgesPointId[1] = trianglePts[0];
412 }
413 else
414 {
415 edgesPointId[0] = trianglePts[0];
416 edgesPointId[1] = trianglePts[1];
417 }
418
419 double neighborPoint[3];
420 input->GetPoint(neighborId,neighborPoint);
421
422 double edgePoint0[3], edgePoint1[3];
423 input->GetPoint(edgesPointId[0],edgePoint0);
424 input->GetPoint(edgesPointId[1],edgePoint1);
425
426 edgesVector[0][0] = neighborPoint[0] - edgePoint0[0];
427 edgesVector[0][1] = neighborPoint[1] - edgePoint0[1];
428 edgesVector[0][2] = neighborPoint[2] - edgePoint0[2];
429
430 edgesVector[1][0] = neighborPoint[0] - edgePoint1[0];
431 edgesVector[1][1] = neighborPoint[1] - edgePoint1[1];
432 edgesVector[1][2] = neighborPoint[2] - edgePoint1[2];
433
434 edgesLength[0] = vtkMath::Norm(edgesVector[0]);
435 edgesLength[1] = vtkMath::Norm(edgesVector[1]);
436
437 if (edgesLength[0] > VTK_VMTK_DOUBLE_TOL)
438 {
439 edgesNormal[0][0] = edgesVector[0][0] / edgesLength[0];
440 edgesNormal[0][1] = edgesVector[0][1] / edgesLength[0];
441 edgesNormal[0][2] = edgesVector[0][2] / edgesLength[0];
442 }
443 else
444 {
445 edgesLength[0] = 0.0;
446 edgesNormal[0][0] = 0.0;
447 edgesNormal[0][1] = 0.0;
448 edgesNormal[0][2] = 0.0;
449 }
450
451 if (edgesLength[1] > VTK_VMTK_DOUBLE_TOL)
452 {
453 edgesNormal[1][0] = edgesVector[1][0] / edgesLength[1];
454 edgesNormal[1][1] = edgesVector[1][1] / edgesLength[1];
455 edgesNormal[1][2] = edgesVector[1][2] / edgesLength[1];
456 }
457 else
458 {
459 edgesLength[1] = 0.0;
460 edgesNormal[1][0] = 0.0;
461 edgesNormal[1][1] = 0.0;
462 edgesNormal[1][2] = 0.0;
463 }
464
465 cosTheta = vtkMath::Dot(edgesNormal[0],edgesNormal[1]);
466
467 if (fabs(cosTheta) < VTK_VMTK_DOUBLE_TOL)
468 cosTheta = 0.0f;
469
470 edgesTScalar[0] = this->TScalars->GetValue(edgesPointId[0]);
471 edgesTScalar[1] = this->TScalars->GetValue(edgesPointId[1]);
472
473 if (edgesTScalar[0]-edgesTScalar[1] > VTK_VMTK_DOUBLE_TOL)
474 {
475 aEdgeId = 0;
476 bEdgeId = 1;
477 }
478 else
479 {
480 aEdgeId = 1;
481 bEdgeId = 0;
482 }
483
484
485 FEq = fScalar + this->Regularization;
486
487 uEq = edgesTScalar[aEdgeId]-edgesTScalar[bEdgeId];
488 aEq = edgesLength[aEdgeId]*edgesLength[aEdgeId] + edgesLength[bEdgeId]*edgesLength[bEdgeId] - 2*edgesLength[aEdgeId]*edgesLength[bEdgeId]*cosTheta;
489 bEq = 2 * edgesLength[bEdgeId] * uEq * (edgesLength[aEdgeId] * cosTheta - edgesLength[bEdgeId]);
490 cEq = edgesLength[bEdgeId]*edgesLength[bEdgeId] * (uEq*uEq - FEq*FEq*edgesLength[aEdgeId]*edgesLength[aEdgeId]*(1-cosTheta*cosTheta));
491
492 this->SolveQuadratic(aEq,bEq,cEq,nSol,t0Eq,t1Eq);
493
494 if (nSol==2)
495 {
496 tEq = this->Min(t0Eq,t1Eq);
497 }
498 else
499 {
500 tEq = t0Eq;
501 }
502
503 if (fabs(tEq) > VTK_VMTK_DOUBLE_TOL)
504 {
505 tCompEq = edgesLength[bEdgeId] * (tEq - uEq) / tEq;
506 }
507 else
508 {
509 t0CompEq = VTK_VMTK_LARGE_DOUBLE;
510 }
511
512 tCompEqLower = edgesLength[aEdgeId]*cosTheta;
513
514 if (fabs(cosTheta) > VTK_VMTK_DOUBLE_TOL)
515 {
516 tCompEqHigher = edgesLength[aEdgeId]/cosTheta;
517 }
518 else
519 {
520 tCompEqHigher = VTK_VMTK_LARGE_DOUBLE;
521 }
522
523 if ((uEq - tEq < -VTK_VMTK_DOUBLE_TOL) && (tCompEq - tCompEqLower > VTK_VMTK_DOUBLE_TOL) && (tCompEq - tCompEqHigher < -VTK_VMTK_DOUBLE_TOL))
524 {
525 neighborT = this->Min(tEq + edgesTScalar[bEdgeId],neighborT);
526 }
527 else
528 {
529 neighborT = this->Min(edgesLength[aEdgeId]*FEq + edgesTScalar[aEdgeId] , edgesLength[bEdgeId]*FEq + edgesTScalar[bEdgeId]);
530 }
531
532 return neighborT;
533}
static double Min(double a, double b)
void SolveQuadratic(double a, double b, double c, char &nSol, double &x0, double &x1)

◆ UpdateNeighbor()

void vtkvmtkNonManifoldFastMarching::UpdateNeighbor ( vtkPolyData * input,
vtkIdType neighborId )
protected

Definition at line 535 of file vtkvmtkNonManifoldFastMarching.cxx.

536{
537 vtkIdType i, j, k;
538 vtkIdType npts;
539 const vtkIdType *pts;
540 vtkIdType trianglePts[3];
541 double tMin, tScalar;
542 vtkIdList* neighborCellNeighborIds;
543
544 if ((neighborId<0)||(neighborId>=this->TScalars->GetNumberOfTuples()))
545 {
546 vtkErrorMacro("Requested id exceeds TScalars dimension.");
547 return;
548 }
549
550 neighborCellNeighborIds = vtkIdList::New();
551
552 input->GetPointCells(neighborId,neighborCellNeighborIds);
553
554 tMin = this->TScalars->GetValue(neighborId);
555 trianglePts[0] = neighborId;
556 for (i=0; i<neighborCellNeighborIds->GetNumberOfIds(); i++)
557 {
558 // virtual triangulation
559 input->GetCellPoints(neighborCellNeighborIds->GetId(i),npts,pts);
560 for (j=0; j<npts; j++)
561 {
562 if (pts[j]!=neighborId)
563 {
564 trianglePts[1] = pts[j];
565 for (k=j+1; k<npts; k++)
566 {
567 if (pts[k]!=neighborId)
568 {
569 trianglePts[2] = pts[k];
570 tScalar = this->ComputeUpdateFromCellNeighbor(input,neighborId,trianglePts);
571 tMin = this->Min(tScalar,tMin);
572 }
573 }
574 }
575 }
576 }
577
578 this->TScalars->SetValue(neighborId,tMin);
579
580 neighborCellNeighborIds->Delete();
581}
double ComputeUpdateFromCellNeighbor(vtkPolyData *input, vtkIdType neighborId, vtkIdType *trianglePts)

◆ UpdateNeighborhood()

void vtkvmtkNonManifoldFastMarching::UpdateNeighborhood ( vtkPolyData * input,
vtkIdType pointId )
protected

Definition at line 583 of file vtkvmtkNonManifoldFastMarching.cxx.

584{
585 vtkIdList* neighborIds;
586 vtkIdType i, neighborId;
587
588 neighborIds = vtkIdList::New();
589
590 this->GetNeighbors(input,pointId,neighborIds);
591 for (i=0; i<neighborIds->GetNumberOfIds(); i++)
592 {
593 neighborId = neighborIds->GetId(i);
594 if (this->StatusScalars->GetValue(neighborId)!=VTK_VMTK_ACCEPTED_STATUS)
595 {
596 this->UpdateNeighbor(input,neighborId);
597 if (this->StatusScalars->GetValue(neighborId) == VTK_VMTK_FAR_STATUS)
598 {
599 this->StatusScalars->SetValue(neighborId,VTK_VMTK_CONSIDERED_STATUS);
600 this->ConsideredMinHeap->InsertNextId(neighborId);
601 }
602 else
603 {
604 this->ConsideredMinHeap->UpdateId(neighborId);
605 }
606 }
607 }
608
609 neighborIds->Delete();
610}
void GetNeighbors(vtkPolyData *input, vtkIdType pointId, vtkIdList *neighborIds)
void UpdateNeighbor(vtkPolyData *input, vtkIdType neighborId)

◆ Propagate()

void vtkvmtkNonManifoldFastMarching::Propagate ( vtkPolyData * input)
protected

Definition at line 612 of file vtkvmtkNonManifoldFastMarching.cxx.

613{
614 double currentTravelTime;
615 vtkIdType trialId;
616
617 while (this->ConsideredMinHeap->GetSize()>0)
618 {
619 trialId = this->ConsideredMinHeap->RemoveMin();
620 this->StatusScalars->SetValue(trialId,VTK_VMTK_ACCEPTED_STATUS);
622
623 this->UpdateNeighborhood(input,trialId);
624
625 currentTravelTime = this->TScalars->GetValue(trialId);
626
627 // This will stop execution once the front has propagated from the source point to the
628 // Stop point (in the case where StopSeedId is set. Default is NULL)
629 if (this->StopSeedId)
630 {
631 if (trialId == this->StopSeedId->GetId(0))
632 {
633 break;
634 }
635 }
636 if ((this->StopNumberOfPoints)||(this->StopTravelTime))
637 {
638 if ((this->NumberOfAcceptedPoints >= this->StopNumberOfPoints)||(currentTravelTime - this->StopTravelTime > VTK_VMTK_DOUBLE_TOL))
639 {
640 break;
641 }
642 }
643 }
644}

◆ Max()

double vtkvmtkNonManifoldFastMarching::Max ( double a,
double b )
inlinestaticprotected

Definition at line 201 of file vtkvmtkNonManifoldFastMarching.h.

202 { return a-b > VTK_VMTK_DOUBLE_TOL ? a : b; }

◆ Min()

double vtkvmtkNonManifoldFastMarching::Min ( double a,
double b )
inlinestaticprotected

Definition at line 204 of file vtkvmtkNonManifoldFastMarching.h.

205 { return a-b < - VTK_VMTK_DOUBLE_TOL ? a : b; }

Member Data Documentation

◆ TScalars

vtkDoubleArray* vtkvmtkNonManifoldFastMarching::TScalars
protected

Definition at line 207 of file vtkvmtkNonManifoldFastMarching.h.

◆ StatusScalars

vtkCharArray* vtkvmtkNonManifoldFastMarching::StatusScalars
protected

Definition at line 208 of file vtkvmtkNonManifoldFastMarching.h.

◆ ConsideredMinHeap

vtkvmtkMinHeap* vtkvmtkNonManifoldFastMarching::ConsideredMinHeap
protected

Definition at line 209 of file vtkvmtkNonManifoldFastMarching.h.

◆ Seeds

vtkIdList* vtkvmtkNonManifoldFastMarching::Seeds
protected

Definition at line 211 of file vtkvmtkNonManifoldFastMarching.h.

◆ StopSeedId

vtkIdList* vtkvmtkNonManifoldFastMarching::StopSeedId
protected

Definition at line 212 of file vtkvmtkNonManifoldFastMarching.h.

◆ BoundaryPolyData

vtkPolyData* vtkvmtkNonManifoldFastMarching::BoundaryPolyData
protected

Definition at line 213 of file vtkvmtkNonManifoldFastMarching.h.

◆ Regularization

double vtkvmtkNonManifoldFastMarching::Regularization
protected

Definition at line 215 of file vtkvmtkNonManifoldFastMarching.h.

◆ StopTravelTime

double vtkvmtkNonManifoldFastMarching::StopTravelTime
protected

Definition at line 216 of file vtkvmtkNonManifoldFastMarching.h.

◆ StopNumberOfPoints

vtkIdType vtkvmtkNonManifoldFastMarching::StopNumberOfPoints
protected

Definition at line 217 of file vtkvmtkNonManifoldFastMarching.h.

◆ UnitSpeed

int vtkvmtkNonManifoldFastMarching::UnitSpeed
protected

Definition at line 218 of file vtkvmtkNonManifoldFastMarching.h.

◆ InitializeFromScalars

int vtkvmtkNonManifoldFastMarching::InitializeFromScalars
protected

Definition at line 219 of file vtkvmtkNonManifoldFastMarching.h.

◆ IntersectedEdgesArrayName

char* vtkvmtkNonManifoldFastMarching::IntersectedEdgesArrayName
protected

Definition at line 220 of file vtkvmtkNonManifoldFastMarching.h.

◆ InitializationArrayName

char* vtkvmtkNonManifoldFastMarching::InitializationArrayName
protected

Definition at line 221 of file vtkvmtkNonManifoldFastMarching.h.

◆ SolutionArrayName

char* vtkvmtkNonManifoldFastMarching::SolutionArrayName
protected

Definition at line 222 of file vtkvmtkNonManifoldFastMarching.h.

◆ CostFunctionArrayName

char* vtkvmtkNonManifoldFastMarching::CostFunctionArrayName
protected

Definition at line 223 of file vtkvmtkNonManifoldFastMarching.h.

◆ SeedsBoundaryConditions

int vtkvmtkNonManifoldFastMarching::SeedsBoundaryConditions
protected

Definition at line 225 of file vtkvmtkNonManifoldFastMarching.h.

◆ PolyDataBoundaryConditions

int vtkvmtkNonManifoldFastMarching::PolyDataBoundaryConditions
protected

Definition at line 226 of file vtkvmtkNonManifoldFastMarching.h.

◆ NumberOfAcceptedPoints

vtkIdType vtkvmtkNonManifoldFastMarching::NumberOfAcceptedPoints
protected

Definition at line 228 of file vtkvmtkNonManifoldFastMarching.h.

◆ AllowLineUpdate

int vtkvmtkNonManifoldFastMarching::AllowLineUpdate
protected

Definition at line 230 of file vtkvmtkNonManifoldFastMarching.h.

◆ UpdateFromConsidered

int vtkvmtkNonManifoldFastMarching::UpdateFromConsidered
protected

Definition at line 231 of file vtkvmtkNonManifoldFastMarching.h.


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