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

Experimental: for each seed point (e.g. a Voronoi pole), backtrace a steepest descent path over a non-manifold to the nearest point of a target polyline, recording where it lands. More...

#include <vtkvmtkSteepestDescentShooter.h>

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

Public Types

typedef vtkvmtkNonManifoldSteepestDescent Superclass
Public Types inherited from vtkvmtkNonManifoldSteepestDescent
typedef vtkPolyDataAlgorithm Superclass

Public Member Functions

virtual int IsA (const char *type)
vtkvmtkSteepestDescentShooter * NewInstance () const
void PrintSelf (std::ostream &os, vtkIndent indent) override
virtual void SetTarget (vtkPolyData *)
virtual vtkPolyData * GetTarget ()
virtual void SetSeeds (vtkIdList *)
virtual vtkIdList * GetSeeds ()
virtual void SetEdgeArrayName (const char *)
virtual char * GetEdgeArrayName ()
virtual void SetTargetVectorsArrayName (const char *)
virtual char * GetTargetVectorsArrayName ()
virtual void SetTargetCellIdsArrayName (const char *)
virtual char * GetTargetCellIdsArrayName ()
virtual void SetTargetPCoordsArrayName (const char *)
virtual char * GetTargetPCoordsArrayName ()
Public Member Functions inherited from vtkvmtkNonManifoldSteepestDescent
vtkvmtkNonManifoldSteepestDescent * NewInstance () const
void PrintSelf (std::ostream &os, vtkIndent indent) override
virtual void SetDescentArrayName (const char *)
virtual char * GetDescentArrayName ()
virtual void SetDirection (int)
virtual int GetDirection ()
void SetDirectionToDownward ()
void SetDirectionToUpward ()

Static Public Member Functions

static int IsTypeOf (const char *type)
static vtkvmtkSteepestDescentShooter * SafeDownCast (vtkObjectBase *o)
static vtkvmtkSteepestDescentShooter * New ()
Static Public Member Functions inherited from vtkvmtkNonManifoldSteepestDescent
static int IsTypeOf (const char *type)
static vtkvmtkNonManifoldSteepestDescent * SafeDownCast (vtkObjectBase *o)
static vtkvmtkNonManifoldSteepestDescent * New ()

Protected Member Functions

virtual vtkObjectBase * NewInstanceInternal () const
 vtkvmtkSteepestDescentShooter ()
 ~vtkvmtkSteepestDescentShooter ()
virtual int RequestData (vtkInformation *, vtkInformationVector **, vtkInformationVector *) override
void Backtrace (vtkPolyData *input, vtkIdType seedId)
void FindNearestPolyLinePoint (double *currentPoint, double *lineClosestPoint, int &lineCellId, int &lineCellSubId, double &linePCoord)
Protected Member Functions inherited from vtkvmtkNonManifoldSteepestDescent
 vtkvmtkNonManifoldSteepestDescent ()
 ~vtkvmtkNonManifoldSteepestDescent ()
double GetSteepestDescent (vtkPolyData *input, vtkIdType *edge, double s, vtkIdType *steepestDescentEdge, double &steepestDescentS)
double GetSteepestDescentInCell (vtkPolyData *input, vtkIdType cellId, vtkIdType *edge, double s, vtkIdType *steepestDescentEdge, double &steepestDescentS, double &steepestDescentLength)

Protected Attributes

vtkPolyData * Target
vtkIdList * Seeds
vtkIntArray * TargetArray
vtkDataArray * EdgeArray
vtkDoubleArray * TargetVectors
vtkIntArray * TargetCellIds
vtkDoubleArray * TargetPCoords
char * EdgeArrayName
char * TargetVectorsArrayName
char * TargetCellIdsArrayName
char * TargetPCoordsArrayName
Protected Attributes inherited from vtkvmtkNonManifoldSteepestDescent
vtkDataArray * DescentArray
char * DescentArrayName
int NumberOfEdgeSubdivisions
int Direction

Detailed Description

Experimental: for each seed point (e.g. a Voronoi pole), backtrace a steepest descent path over a non-manifold to the nearest point of a target polyline, recording where it lands.

This class is meant to be used after solving the Eikonal equation, with the target polyline (typically the centerlines) as boundary condition, over a non-manifold polygonal domain (typically a Voronoi diagram, via vtkNonManifoldFastMarching). For every seed, it follows the steepest descent of the resulting scalar field (using the machinery of the base class vtkvmtkNonManifoldSteepestDescent) until it reaches Target, and records, for each seed, the vector from seed to the landing point, the target cell id/sub-id, and the parametric coordinate along the target cell. This is used e.g. to associate each surface point's Voronoi pole to the closest point on the centerlines. Implement with caution: this method is experimental and has known limitations when a path must cross multiple Voronoi diagram "spikes" to reach the target.

Definition at line 45 of file vtkvmtkSteepestDescentShooter.h.

Member Typedef Documentation

◆ Superclass

Constructor & Destructor Documentation

◆ vtkvmtkSteepestDescentShooter()

vtkvmtkSteepestDescentShooter::vtkvmtkSteepestDescentShooter ( )
protected

Definition at line 36 of file vtkvmtkSteepestDescentShooter.cxx.

37{
38 this->Seeds = NULL;
39 this->Target = NULL;
40
41 this->EdgeArrayName = NULL;
42
43 this->TargetVectorsArrayName = NULL;
44 this->TargetCellIdsArrayName = NULL;
45 this->TargetPCoordsArrayName = NULL;
46
47 this->TargetVectors = vtkDoubleArray::New();
48 this->TargetCellIds = vtkIntArray::New();
49 this->TargetPCoords = vtkDoubleArray::New();
50
51 this->TargetArray = vtkIntArray::New();
52
53}

◆ ~vtkvmtkSteepestDescentShooter()

vtkvmtkSteepestDescentShooter::~vtkvmtkSteepestDescentShooter ( )
protected

Definition at line 55 of file vtkvmtkSteepestDescentShooter.cxx.

56{
57 this->TargetVectors->Delete();
58 this->TargetCellIds->Delete();
59 this->TargetPCoords->Delete();
60
61 this->TargetArray->Delete();
62
63 if (this->Seeds)
64 {
65 this->Seeds->Delete();
66 this->Seeds = NULL;
67 }
68
69 if (this->Target)
70 {
71 this->Target->Delete();
72 this->Target = NULL;
73 }
74}

Member Function Documentation

◆ IsTypeOf()

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

◆ IsA()

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

Reimplemented from vtkvmtkNonManifoldSteepestDescent.

◆ SafeDownCast()

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

◆ NewInstanceInternal()

virtual vtkObjectBase * vtkvmtkSteepestDescentShooter::NewInstanceInternal ( ) const
protectedvirtual

Reimplemented from vtkvmtkNonManifoldSteepestDescent.

◆ NewInstance()

vtkvmtkSteepestDescentShooter * vtkvmtkSteepestDescentShooter::NewInstance ( ) const

◆ PrintSelf()

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

Definition at line 337 of file vtkvmtkSteepestDescentShooter.cxx.

338{
339 this->Superclass::PrintSelf(os,indent);
340}
void PrintSelf(std::ostream &os, vtkIndent indent) override

◆ New()

vtkvmtkSteepestDescentShooter * vtkvmtkSteepestDescentShooter::New ( )
static

◆ SetTarget()

virtual void vtkvmtkSteepestDescentShooter::SetTarget ( vtkPolyData * )
virtual

Set/Get the target polyline (typically the centerlines) that seed backtraces are shot towards. Required input.

◆ GetTarget()

virtual vtkPolyData * vtkvmtkSteepestDescentShooter::GetTarget ( )
virtual

Set/Get the target polyline (typically the centerlines) that seed backtraces are shot towards. Required input.

◆ SetSeeds()

virtual void vtkvmtkSteepestDescentShooter::SetSeeds ( vtkIdList * )
virtual

Set/Get the ids, on the input non-manifold domain, of the seed points to backtrace from. Required input.

◆ GetSeeds()

virtual vtkIdList * vtkvmtkSteepestDescentShooter::GetSeeds ( )
virtual

Set/Get the ids, on the input non-manifold domain, of the seed points to backtrace from. Required input.

◆ SetEdgeArrayName()

virtual void vtkvmtkSteepestDescentShooter::SetEdgeArrayName ( const char * )
virtual

Set/Get the name of the point data array of the input domain used internally to track, for each point, the edge of the shortest-path tree it was reached through (as produced by vtkvmtkNonManifoldFastMarching). Commonly named "EdgeArray".

◆ GetEdgeArrayName()

virtual char * vtkvmtkSteepestDescentShooter::GetEdgeArrayName ( )
virtual

Set/Get the name of the point data array of the input domain used internally to track, for each point, the edge of the shortest-path tree it was reached through (as produced by vtkvmtkNonManifoldFastMarching). Commonly named "EdgeArray".

◆ SetTargetVectorsArrayName()

virtual void vtkvmtkSteepestDescentShooter::SetTargetVectorsArrayName ( const char * )
virtual

Set/Get the name of the output point data array where, for each seed, the vector from the seed to its landing point on Target is stored. Commonly named "VoronoiPoleCenterlineVectors".

◆ GetTargetVectorsArrayName()

virtual char * vtkvmtkSteepestDescentShooter::GetTargetVectorsArrayName ( )
virtual

Set/Get the name of the output point data array where, for each seed, the vector from the seed to its landing point on Target is stored. Commonly named "VoronoiPoleCenterlineVectors".

◆ SetTargetCellIdsArrayName()

virtual void vtkvmtkSteepestDescentShooter::SetTargetCellIdsArrayName ( const char * )
virtual

Set/Get the name of the output point data array where, for each seed, the id of the Target cell its backtrace path landed on is stored. Commonly named "VoronoiCellIds".

◆ GetTargetCellIdsArrayName()

virtual char * vtkvmtkSteepestDescentShooter::GetTargetCellIdsArrayName ( )
virtual

Set/Get the name of the output point data array where, for each seed, the id of the Target cell its backtrace path landed on is stored. Commonly named "VoronoiCellIds".

◆ SetTargetPCoordsArrayName()

virtual void vtkvmtkSteepestDescentShooter::SetTargetPCoordsArrayName ( const char * )
virtual

Set/Get the name of the output point data array where, for each seed, the parametric coordinate along the landing Target cell is stored.

◆ GetTargetPCoordsArrayName()

virtual char * vtkvmtkSteepestDescentShooter::GetTargetPCoordsArrayName ( )
virtual

Set/Get the name of the output point data array where, for each seed, the parametric coordinate along the landing Target cell is stored.

◆ RequestData()

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

Reimplemented from vtkvmtkNonManifoldSteepestDescent.

Definition at line 192 of file vtkvmtkSteepestDescentShooter.cxx.

196{
197 vtkInformation *inInfo = inputVector[0]->GetInformationObject(0);
198 vtkInformation *outInfo = outputVector->GetInformationObject(0);
199
200 vtkPolyData *input = vtkPolyData::SafeDownCast(
201 inInfo->Get(vtkDataObject::DATA_OBJECT()));
202 vtkPolyData *output = vtkPolyData::SafeDownCast(
203 outInfo->Get(vtkDataObject::DATA_OBJECT()));
204
205 vtkIdType i, j, k, h, l, m;
206 vtkIdType poleId;
207 vtkIdType npts, targetNpts, *cells;
208 const vtkIdType *pts;
209 const vtkIdType *targetPts;
210 vtkIdType ncells;
211
212 if (!this->DescentArrayName)
213 {
214 vtkErrorMacro("Descent array name not specified.");
215 return 1;
216 }
217
218 if (!input->GetPointData()->GetArray(this->DescentArrayName))
219 {
220 vtkErrorMacro(<< "Descent array with name specified does not exist!");
221 return 1;
222 }
223
224 if (!this->Seeds)
225 {
226 vtkErrorMacro(<< "No seeds specified!");
227 return 1;
228 }
229
230 if (!this->Target)
231 {
232 vtkErrorMacro(<< "No target specified!");
233 return 1;
234 }
235
236 if (!this->EdgeArrayName)
237 {
238 vtkErrorMacro(<< "No edge array name specified!");
239 return 1;
240 }
241
242 if (!this->Target->GetPointData()->GetArray(this->EdgeArrayName))
243 {
244 vtkErrorMacro(<< "Edge array with name specified does not exist in target!");
245 return 1;
246 }
247
248 if (this->TargetVectorsArrayName)
249 {
251 }
252 else
253 {
254 this->TargetVectors->SetName("TargetVectors");
255 }
256
257 if (this->TargetCellIdsArrayName)
258 {
260 }
261 else
262 {
263 this->TargetCellIds->SetName("TargetCellIds");
264 }
265
266 if (this->TargetPCoordsArrayName)
267 {
269 }
270 else
271 {
272 this->TargetPCoords->SetName("TargetPCoords");
273 }
274
275 this->DescentArray = input->GetPointData()->GetArray(this->DescentArrayName);
276 this->EdgeArray = this->Target->GetPointData()->GetArray(this->EdgeArrayName);
277
278 this->TargetVectors->SetNumberOfComponents(3);
279 this->TargetCellIds->SetNumberOfComponents(2);
280
281 this->TargetVectors->SetNumberOfTuples(input->GetNumberOfPoints());
282 this->TargetCellIds->SetNumberOfTuples(input->GetNumberOfPoints());
283 this->TargetPCoords->SetNumberOfTuples(input->GetNumberOfPoints());
284
285 this->TargetVectors->FillComponent(0,0.0);
286 this->TargetVectors->FillComponent(1,0.0);
287 this->TargetVectors->FillComponent(2,0.0);
288 this->TargetCellIds->FillComponent(0,0.0);
289 this->TargetCellIds->FillComponent(1,0.0);
290 this->TargetPCoords->FillComponent(0,0.0);
291
292 input->BuildCells();
293 input->BuildLinks();
294
295 this->TargetArray->SetNumberOfTuples(input->GetNumberOfPoints());
296 this->TargetArray->FillComponent(0,-1);
297
298 this->Target->BuildCells();
299
300 for (h=this->Target->GetNumberOfCells()-1; h>=0; h--)
301 {
302 this->Target->GetCellPoints(h,targetNpts,targetPts);
303 for (l=0; l<targetNpts; l++)
304 {
305 for (m=0; m<2; m++)
306 {
307 input->GetPointCells(static_cast<vtkIdType>(this->EdgeArray->GetComponent(targetPts[l],m)),ncells,cells);
308 for (j=0; j<ncells; j++)
309 {
310 input->GetCellPoints(cells[j],npts,pts);
311 for (k=0; k<npts; k++)
312 {
313 this->TargetArray->SetValue(pts[k],h);
314 }
315 }
316 }
317 }
318 }
319
320 for (i=0; i<this->Seeds->GetNumberOfIds(); i++)
321 {
322 poleId = this->Seeds->GetId(i);
323 this->Backtrace(input,poleId);
324 }
325
326 output->CopyStructure(input);
327 output->GetPointData()->PassData(input->GetPointData());
328 output->GetCellData()->PassData(input->GetCellData());
329
330 output->GetPointData()->AddArray(this->TargetVectors);
331 output->GetPointData()->AddArray(this->TargetCellIds);
332 output->GetPointData()->AddArray(this->TargetPCoords);
333
334 return 1;
335}
void Backtrace(vtkPolyData *input, vtkIdType seedId)

◆ Backtrace()

void vtkvmtkSteepestDescentShooter::Backtrace ( vtkPolyData * input,
vtkIdType seedId )
protected

Definition at line 112 of file vtkvmtkSteepestDescentShooter.cxx.

113{
114 bool done;
115 double seedPoint[3];
116 double currentPoint[3], currentScalar;
117 double currentS;
118 vtkIdType currentEdge[2], steepestDescentEdge[2];
119 double steepestDescentS;
120 double previousPoint[3], lineClosestPoint[3];
121 double vector[3];
122 int lineCellId, lineCellSubId;
123 double linePCoord;
124
125 done = false;
126
127 input->GetPoint(seedId,seedPoint);
128 currentPoint[0] = seedPoint[0];
129 currentPoint[1] = seedPoint[1];
130 currentPoint[2] = seedPoint[2];
131
132 previousPoint[0] = seedPoint[0];
133 previousPoint[1] = seedPoint[1];
134 previousPoint[2] = seedPoint[2];
135
136 currentScalar = this->DescentArray->GetTuple1(seedId);
137
138 currentEdge[0] = seedId;
139 currentEdge[1] = seedId;
140 currentS = 0.0;
141
142 while (!done)
143 {
144 if (((this->TargetArray->GetValue(currentEdge[0])!=-1) && (this->TargetArray->GetValue(currentEdge[1])!=-1)))
145 {
146 this->FindNearestPolyLinePoint(currentPoint, lineClosestPoint, lineCellId, lineCellSubId, linePCoord);
147 vector[0] = lineClosestPoint[0] - seedPoint[0];
148 vector[1] = lineClosestPoint[1] - seedPoint[1];
149 vector[2] = lineClosestPoint[2] - seedPoint[2];
150 this->TargetVectors->SetTuple(seedId,vector);
151 this->TargetCellIds->SetComponent(seedId,0,lineCellId);
152 this->TargetCellIds->SetComponent(seedId,1,lineCellSubId);
153 this->TargetPCoords->SetTuple1(seedId,linePCoord);
154
155 done = true;
156 break;
157 }
158
159 if (currentScalar==0.0)
160 {
161 // THIS MEANS THERE'S SOMETHING WRONG SOMEWHERE!
162
163 done = true;
164 break;
165 }
166
167 this->GetSteepestDescent(input,currentEdge,currentS,steepestDescentEdge,steepestDescentS);
168
169 currentEdge[0] = steepestDescentEdge[0];
170 currentEdge[1] = steepestDescentEdge[1];
171 currentS = steepestDescentS;
172
173 previousPoint[0] = currentPoint[0];
174 previousPoint[1] = currentPoint[1];
175 previousPoint[2] = currentPoint[2];
176
177 // Safe GetPoint: avoid shared-temp aliasing when float points (VTK 9).
178 {
179 double edgePoint0[3], edgePoint1[3];
180 input->GetPoint(currentEdge[0], edgePoint0);
181 input->GetPoint(currentEdge[1], edgePoint1);
182 currentPoint[0] = edgePoint0[0] * (1.0 - currentS) + edgePoint1[0] * currentS;
183 currentPoint[1] = edgePoint0[1] * (1.0 - currentS) + edgePoint1[1] * currentS;
184 currentPoint[2] = edgePoint0[2] * (1.0 - currentS) + edgePoint1[2] * currentS;
185 }
186
187 currentScalar = this->DescentArray->GetTuple1(currentEdge[0]) * (1.0 - currentS) + this->DescentArray->GetTuple1(currentEdge[1]) * currentS;
188 }
189
190}
double GetSteepestDescent(vtkPolyData *input, vtkIdType *edge, double s, vtkIdType *steepestDescentEdge, double &steepestDescentS)
void FindNearestPolyLinePoint(double *currentPoint, double *lineClosestPoint, int &lineCellId, int &lineCellSubId, double &linePCoord)

◆ FindNearestPolyLinePoint()

void vtkvmtkSteepestDescentShooter::FindNearestPolyLinePoint ( double * currentPoint,
double * lineClosestPoint,
int & lineCellId,
int & lineCellSubId,
double & linePCoord )
protected

Definition at line 76 of file vtkvmtkSteepestDescentShooter.cxx.

77{
78 vtkIdType i;
79 int subId;
80 double closestPoint[3];
81 double parCoords[3];
82 double dist2, minDist2;
83 double* weights;
84 vtkPolyLine* polyLine;
85
86 minDist2 = VTK_VMTK_LARGE_DOUBLE;
87 for (i=0; i<this->Target->GetNumberOfCells(); i++)
88 {
89 polyLine = vtkPolyLine::SafeDownCast(this->Target->GetCell(i));
90 if (!polyLine)
91 {
92 continue;
93 }
94 weights = new double[polyLine->GetNumberOfPoints()];
95 polyLine->EvaluatePosition(currentPoint,closestPoint,subId,parCoords,dist2,weights);
96
97 if (dist2 - minDist2 < -VTK_VMTK_DOUBLE_TOL)
98 {
99 minDist2 = dist2;
100 lineCellId = i;
101 lineCellSubId = subId;
102 linePCoord = parCoords[0];
103 lineClosestPoint[0] = closestPoint[0];
104 lineClosestPoint[1] = closestPoint[1];
105 lineClosestPoint[2] = closestPoint[2];
106 }
107
108 delete weights;
109 }
110}
#define VTK_VMTK_DOUBLE_TOL
#define VTK_VMTK_LARGE_DOUBLE

Member Data Documentation

◆ Target

vtkPolyData* vtkvmtkSteepestDescentShooter::Target
protected

Definition at line 121 of file vtkvmtkSteepestDescentShooter.h.

◆ Seeds

vtkIdList* vtkvmtkSteepestDescentShooter::Seeds
protected

Definition at line 122 of file vtkvmtkSteepestDescentShooter.h.

◆ TargetArray

vtkIntArray* vtkvmtkSteepestDescentShooter::TargetArray
protected

Definition at line 124 of file vtkvmtkSteepestDescentShooter.h.

◆ EdgeArray

vtkDataArray* vtkvmtkSteepestDescentShooter::EdgeArray
protected

Definition at line 125 of file vtkvmtkSteepestDescentShooter.h.

◆ TargetVectors

vtkDoubleArray* vtkvmtkSteepestDescentShooter::TargetVectors
protected

Definition at line 127 of file vtkvmtkSteepestDescentShooter.h.

◆ TargetCellIds

vtkIntArray* vtkvmtkSteepestDescentShooter::TargetCellIds
protected

Definition at line 128 of file vtkvmtkSteepestDescentShooter.h.

◆ TargetPCoords

vtkDoubleArray* vtkvmtkSteepestDescentShooter::TargetPCoords
protected

Definition at line 129 of file vtkvmtkSteepestDescentShooter.h.

◆ EdgeArrayName

char* vtkvmtkSteepestDescentShooter::EdgeArrayName
protected

Definition at line 131 of file vtkvmtkSteepestDescentShooter.h.

◆ TargetVectorsArrayName

char* vtkvmtkSteepestDescentShooter::TargetVectorsArrayName
protected

Definition at line 133 of file vtkvmtkSteepestDescentShooter.h.

◆ TargetCellIdsArrayName

char* vtkvmtkSteepestDescentShooter::TargetCellIdsArrayName
protected

Definition at line 134 of file vtkvmtkSteepestDescentShooter.h.

◆ TargetPCoordsArrayName

char* vtkvmtkSteepestDescentShooter::TargetPCoordsArrayName
protected

Definition at line 135 of file vtkvmtkSteepestDescentShooter.h.


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