VMTK
Loading...
Searching...
No Matches
vtkvmtkNonManifoldFastMarching.cxx
Go to the documentation of this file.
1/*=========================================================================
2
3Program: VMTK
4Module: $RCSfile: vtkvmtkNonManifoldFastMarching.cxx,v $
5Language: C++
6Date: $Date: 2006/04/06 16:46:43 $
7Version: $Revision: 1.5 $
8
9 Copyright (c) Luca Antiga, David Steinman. All rights reserved.
10 See LICENSE file for details.
11
12 Portions of this code are covered under the VTK copyright.
13 See VTKCopyright.txt or http://www.kitware.com/VTKCopyright.htm
14 for details.
15
16 This software is distributed WITHOUT ANY WARRANTY; without even
17 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
18 PURPOSE. See the above copyright notices for more information.
19
20=========================================================================*/
21
22
24#include "vtkvmtkConstants.h"
25#include "vtkCellData.h"
26#include "vtkPointData.h"
27#include "vtkDoubleArray.h"
28#include "vtkCharArray.h"
29#include "vtkMath.h"
30#include "vtkPolyLine.h"
31#include "vtkTriangle.h"
32#include "vtkInformation.h"
33#include "vtkInformationVector.h"
34#include "vtkObjectFactory.h"
35
36
38
39
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}
68
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}
104
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}
254
255void vtkvmtkNonManifoldFastMarching::GetNeighbors(vtkPolyData* input, vtkIdType pointId, vtkIdList* neighborIds)
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}
275
276void vtkvmtkNonManifoldFastMarching::SolveQuadratic(double a, double b, double c, char &nSol, double &x0, double &x1)
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}
332
333double vtkvmtkNonManifoldFastMarching::ComputeUpdateFromCellNeighbor(vtkPolyData* input, vtkIdType neighborId, vtkIdType* trianglePts)
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}
534
535void vtkvmtkNonManifoldFastMarching::UpdateNeighbor(vtkPolyData* input, vtkIdType neighborId)
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}
582
583void vtkvmtkNonManifoldFastMarching::UpdateNeighborhood(vtkPolyData* input, vtkIdType pointId)
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}
611
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}
645
647 vtkInformation *vtkNotUsed(request),
648 vtkInformationVector **inputVector,
649 vtkInformationVector *outputVector)
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}
787
788void vtkvmtkNonManifoldFastMarching::PrintSelf(std::ostream& os, vtkIndent indent)
789{
790 this->Superclass::PrintSelf(os,indent);
791}
static vtkvmtkMinHeap * New()
Implements the Fast Marching Method on polygonal non-manifolds.
void GetNeighbors(vtkPolyData *input, vtkIdType pointId, vtkIdList *neighborIds)
static double Min(double a, double b)
double ComputeUpdateFromCellNeighbor(vtkPolyData *input, vtkIdType neighborId, vtkIdType *trianglePts)
void PrintSelf(std::ostream &os, vtkIndent indent) override
void UpdateNeighbor(vtkPolyData *input, vtkIdType neighborId)
void UpdateNeighborhood(vtkPolyData *input, vtkIdType pointId)
void SolveQuadratic(double a, double b, double c, char &nSol, double &x0, double &x1)
virtual int RequestData(vtkInformation *, vtkInformationVector **, vtkInformationVector *) override
#define VTK_VMTK_LARGE_INTEGER
#define VTK_VMTK_DOUBLE_TOL
#define VTK_VMTK_LARGE_DOUBLE
vtkStandardNewMacro(vtkvmtkNonManifoldFastMarching)
const char VTK_VMTK_ACCEPTED_STATUS
const char VTK_VMTK_FAR_STATUS
const char VTK_VMTK_CONSIDERED_STATUS