107 vtkIdType i, j, k, l;
109 vtkIdType npts, *cells;
110 const vtkIdType *pts;
112 vtkIdType intersectedEdge[2];
113 vtkDataArray* initializationArray, *costFunctionArray, *intersectedEdgesArray;
114 vtkIdList* neighborCells;
115 vtkIdList* neighborIds;
116 vtkIdList* boundaryPointIds;
118 double pcoords[3], *weights;
119 double closestPoint[3];
120 double distance, distance2, minDistance;
121 int allowLineUpdateBackup;
122 vtkPolyLine* polyLine;
124 boundaryPointIds = vtkIdList::New();
125 neighborCells = vtkIdList::New();
126 neighborIds = vtkIdList::New();
131 initializationArray = NULL;
145 this->
StatusScalars->SetNumberOfTuples(input->GetNumberOfPoints());
148 this->
TScalars->SetNumberOfTuples(input->GetNumberOfPoints());
158 for (i=0; i<this->
Seeds->GetNumberOfIds(); i++)
160 pointId = this->
Seeds->GetId(i);
161 boundaryPointIds->InsertUniqueId(pointId);
164 this->
TScalars->SetComponent(pointId,0,initializationArray->GetTuple1(pointId));
168 this->
TScalars->SetComponent(pointId,0,0.0f);
180 intersectedEdge[0] =
static_cast<vtkIdType
>(intersectedEdgesArray->GetComponent(i,0));
181 intersectedEdge[1] =
static_cast<vtkIdType
>(intersectedEdgesArray->GetComponent(i,1));
183 neighborCells->Initialize();
185 if (intersectedEdge[0]==intersectedEdge[1])
187 input->GetPointCells(intersectedEdge[0],neighborCells);
188 boundaryPointIds->InsertUniqueId(intersectedEdge[0]);
189 this->
TScalars->SetComponent(intersectedEdge[0],0,0.0);
193 input->GetCellEdgeNeighbors(-1,intersectedEdge[0],intersectedEdge[1],neighborCells);
194 boundaryPointIds->InsertUniqueId(intersectedEdge[0]);
195 boundaryPointIds->InsertUniqueId(intersectedEdge[1]);
198 for (j=0; j<neighborCells->GetNumberOfIds(); j++)
200 input->GetCellPoints(neighborCells->GetId(j),npts,pts);
201 for (k=0; k<npts; k++)
203 boundaryPointIds->InsertUniqueId(pts[k]);
204 minDistance = this->
TScalars->GetComponent(pts[k],0);
206 for (l=0; l<ncells; l++)
208 polyLine = vtkPolyLine::SafeDownCast(this->
BoundaryPolyData->GetCell(cells[l]));
211 vtkWarningMacro(<<
"BoundaryPolyData is not all made up of PolyLines");
214 weights =
new double[polyLine->GetNumberOfPoints()];
216 input->GetPoint(pts[k],point);
217 polyLine->EvaluatePosition(point,closestPoint,subId,pcoords,distance2,weights);
219 distance = sqrt(distance2);
222 this->
TScalars->SetComponent(pts[k],0,distance);
223 minDistance = distance;
231 vtkIdType numberOfBoundaryPointIds;
232 numberOfBoundaryPointIds = boundaryPointIds->GetNumberOfIds();
234 for (i=0; i<numberOfBoundaryPointIds; i++)
242 for (i=0; i<numberOfBoundaryPointIds; i++)
250 boundaryPointIds->Delete();
251 neighborCells->Delete();
252 neighborIds->Delete();
335 double fScalar, neighborT;
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];
344 vtkIdType aEdgeId, bEdgeId;
346 double bEq, aEq, cEq, uEq, FEq, tEq, tCompEq, t0Eq, t1Eq, t0CompEq, tCompEqLower, tCompEqHigher;
348 vtkDataArray* costFunctionArray;
350 pointIdForLineUpdate = -1;
363 fScalar = costFunctionArray->GetTuple1(neighborId);
366 neighborT = this->
TScalars->GetValue(neighborId);
368 canUpdateFromTriangle =
true;
369 canUpdateFromLine =
false;
372 pointId = trianglePts[i];
373 if (pointId!=neighborId)
376 ((this->StatusScalars->GetValue(pointId) ==
VTK_VMTK_FAR_STATUS)&&(this->UpdateFromConsidered)))
378 canUpdateFromTriangle =
false;
382 canUpdateFromLine =
true;
383 pointIdForLineUpdate = pointId;
388 if (!canUpdateFromTriangle)
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);
403 if (trianglePts[0]==neighborId)
405 edgesPointId[0] = trianglePts[1];
406 edgesPointId[1] = trianglePts[2];
408 else if (trianglePts[1]==neighborId)
410 edgesPointId[0] = trianglePts[2];
411 edgesPointId[1] = trianglePts[0];
415 edgesPointId[0] = trianglePts[0];
416 edgesPointId[1] = trianglePts[1];
419 double neighborPoint[3];
420 input->GetPoint(neighborId,neighborPoint);
422 double edgePoint0[3], edgePoint1[3];
423 input->GetPoint(edgesPointId[0],edgePoint0);
424 input->GetPoint(edgesPointId[1],edgePoint1);
426 edgesVector[0][0] = neighborPoint[0] - edgePoint0[0];
427 edgesVector[0][1] = neighborPoint[1] - edgePoint0[1];
428 edgesVector[0][2] = neighborPoint[2] - edgePoint0[2];
430 edgesVector[1][0] = neighborPoint[0] - edgePoint1[0];
431 edgesVector[1][1] = neighborPoint[1] - edgePoint1[1];
432 edgesVector[1][2] = neighborPoint[2] - edgePoint1[2];
434 edgesLength[0] = vtkMath::Norm(edgesVector[0]);
435 edgesLength[1] = vtkMath::Norm(edgesVector[1]);
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];
445 edgesLength[0] = 0.0;
446 edgesNormal[0][0] = 0.0;
447 edgesNormal[0][1] = 0.0;
448 edgesNormal[0][2] = 0.0;
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];
459 edgesLength[1] = 0.0;
460 edgesNormal[1][0] = 0.0;
461 edgesNormal[1][1] = 0.0;
462 edgesNormal[1][2] = 0.0;
465 cosTheta = vtkMath::Dot(edgesNormal[0],edgesNormal[1]);
470 edgesTScalar[0] = this->
TScalars->GetValue(edgesPointId[0]);
471 edgesTScalar[1] = this->
TScalars->GetValue(edgesPointId[1]);
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));
496 tEq = this->
Min(t0Eq,t1Eq);
505 tCompEq = edgesLength[bEdgeId] * (tEq - uEq) / tEq;
512 tCompEqLower = edgesLength[aEdgeId]*cosTheta;
516 tCompEqHigher = edgesLength[aEdgeId]/cosTheta;
525 neighborT = this->
Min(tEq + edgesTScalar[bEdgeId],neighborT);
529 neighborT = this->
Min(edgesLength[aEdgeId]*FEq + edgesTScalar[aEdgeId] , edgesLength[bEdgeId]*FEq + edgesTScalar[bEdgeId]);
539 const vtkIdType *pts;
540 vtkIdType trianglePts[3];
541 double tMin, tScalar;
542 vtkIdList* neighborCellNeighborIds;
544 if ((neighborId<0)||(neighborId>=this->
TScalars->GetNumberOfTuples()))
546 vtkErrorMacro(
"Requested id exceeds TScalars dimension.");
550 neighborCellNeighborIds = vtkIdList::New();
552 input->GetPointCells(neighborId,neighborCellNeighborIds);
554 tMin = this->
TScalars->GetValue(neighborId);
555 trianglePts[0] = neighborId;
556 for (i=0; i<neighborCellNeighborIds->GetNumberOfIds(); i++)
559 input->GetCellPoints(neighborCellNeighborIds->GetId(i),npts,pts);
560 for (j=0; j<npts; j++)
562 if (pts[j]!=neighborId)
564 trianglePts[1] = pts[j];
565 for (k=j+1; k<npts; k++)
567 if (pts[k]!=neighborId)
569 trianglePts[2] = pts[k];
571 tMin = this->
Min(tScalar,tMin);
578 this->
TScalars->SetValue(neighborId,tMin);
580 neighborCellNeighborIds->Delete();
647 vtkInformation *vtkNotUsed(request),
648 vtkInformationVector **inputVector,
649 vtkInformationVector *outputVector)
651 vtkInformation *inInfo = inputVector[0]->GetInformationObject(0);
652 vtkInformation *outInfo = outputVector->GetInformationObject(0);
654 vtkPolyData *input = vtkPolyData::SafeDownCast(
655 inInfo->Get(vtkDataObject::DATA_OBJECT()));
656 vtkPolyData *output = vtkPolyData::SafeDownCast(
657 outInfo->Get(vtkDataObject::DATA_OBJECT()));
659 char eikonalSolutionArrayName[512];
666 vtkErrorMacro(<<
"No initialization array name defined!");
669 if (!input->GetPointData()->GetArray(this->InitializationArrayName))
671 vtkErrorMacro(<<
"Initialization array with name specified does not exist!");
680 vtkErrorMacro(<<
"No cost function array name defined!");
683 if (!input->GetPointData()->GetArray(this->CostFunctionArrayName))
685 vtkErrorMacro(<<
"Cost function array with name specified does not exist!");
692 vtkWarningMacro(<<
"No boundary conditions activated!");
700 vtkErrorMacro(<<
"Seeds not specified!");
703 for (i=0; i<this->
Seeds->GetNumberOfIds(); i++)
705 if ((this->
Seeds->GetId(i)<0) || (this->Seeds->GetId(i)>input->GetNumberOfPoints()))
707 vtkErrorMacro(<<
"Seed id exceeds input number of points!");
717 vtkErrorMacro(<<
"Boundary poly data not specified!");
722 vtkErrorMacro(<<
"Intersected edges array name not specified!");
725 if (!this->
BoundaryPolyData->GetPointData()->GetArray(this->IntersectedEdgesArrayName))
727 vtkErrorMacro(<<
"Intersected edges array with name specified does not exist!");
732 vtkWarningMacro(<<
"Initialization can be inaccurate if unit speed is not used for poly data boundary conditions.");
740 int naccepted = 0, nconsidered = 0, nfar = 0;
741 for (i=0; i<input->GetNumberOfPoints(); i++)
763 if (naccepted||nconsidered||nfar)
774 strcpy(eikonalSolutionArrayName,
"EikonalSolution");
777 this->
TScalars->SetName(eikonalSolutionArrayName);
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);