MCPcopy Create free account
hub / github.com/Kitware/VTK / GetPolyDataDistance

Method GetPolyDataDistance

Filters/General/vtkDistancePolyDataFilter.cxx:67–202  ·  view source on GitHub ↗

------------------------------------------------------------------------------

Source from the content-addressed store, hash-verified

65
66//------------------------------------------------------------------------------
67void vtkDistancePolyDataFilter::GetPolyDataDistance(vtkPolyData* mesh, vtkPolyData* src)
68{
69 vtkDebugMacro(<< "Start vtkDistancePolyDataFilter::GetPolyDataDistance");
70
71 if (mesh->GetNumberOfCells() == 0 || mesh->GetNumberOfPoints() == 0)
72 {
73 vtkErrorMacro(<< "No points/cells to operate on");
74 return;
75 }
76
77 if (src->GetNumberOfPolys() == 0 || src->GetNumberOfPoints() == 0)
78 {
79 vtkErrorMacro(<< "No points/cells to difference from");
80 return;
81 }
82
83 vtkNew<vtkImplicitPolyDataDistance> imp;
84 imp->SetInput(src);
85
86 // Calculate distance from points.
87 const vtkIdType numPts = mesh->GetNumberOfPoints();
88
89 vtkNew<vtkDoubleArray> pointArray;
90 pointArray->SetName("Distance");
91 pointArray->SetNumberOfComponents(1);
92 pointArray->SetNumberOfTuples(numPts);
93
94 vtkNew<vtkDoubleArray> directionArray;
95 if (this->ComputeDirection)
96 {
97 directionArray->SetName("Direction");
98 directionArray->SetNumberOfComponents(3);
99 directionArray->SetNumberOfTuples(numPts);
100 }
101
102 auto DistanceWithSign = [&](const double& val)
103 // NOLINTNEXTLINE(readability-avoid-nested-conditional-operator)
104 { return this->SignedDistance ? (this->NegateDistance ? -val : val) : std::abs(val); };
105
106 vtkSMPTools::For(0, numPts,
107 [&](vtkIdType begin, vtkIdType end)
108 {
109 double pt[3];
110 for (vtkIdType ptId = begin; ptId < end; ptId++)
111 {
112 mesh->GetPoint(ptId, pt);
113 if (this->ComputeDirection)
114 {
115 double closestPoint[3];
116 double direction[3];
117 double val = imp->EvaluateFunctionAndGetClosestPoint(pt, closestPoint);
118 double dist = DistanceWithSign(val);
119 vtkMath::Subtract(closestPoint, pt, direction);
120 vtkMath::Normalize(direction);
121 pointArray->SetValue(ptId, dist);
122 directionArray->SetTuple(ptId, direction);
123 }
124 else

Callers 1

RequestDataMethod · 0.95

Calls 15

GetNumberOfPolysMethod · 0.80
SetActiveScalarsMethod · 0.80
SetActiveVectorsMethod · 0.80
absFunction · 0.50
ForFunction · 0.50
SubtractFunction · 0.50
NormalizeFunction · 0.50
GetNumberOfCellsMethod · 0.45
GetNumberOfPointsMethod · 0.45
SetInputMethod · 0.45
SetNameMethod · 0.45

Tested by

no test coverage detected