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

Method EvaluateFunction

Common/DataModel/vtkPolyPlane.cxx:133–271  ·  view source on GitHub ↗

------------------------------------------------------------------------------ Evaluate the distance to the poly plane for point x[3].

Source from the content-addressed store, hash-verified

131//------------------------------------------------------------------------------
132// Evaluate the distance to the poly plane for point x[3].
133double vtkPolyPlane::EvaluateFunction(double x[3])
134{
135 // Sanity check
136 if (!this->PolyLine || !this->PolyLine->GetPoints())
137 {
138 return 0;
139 }
140
141 double xFlat[3] = { x[0], x[1], 0.0 };
142
143 // No error checking, for speed... We will assume that we have a polyline
144 // and that it has at least 2 points.
145 // traverse the list of points in the polyline.
146 vtkPoints* points = this->PolyLine->GetPoints();
147
148 const vtkIdType nPoints = points->GetNumberOfPoints();
149 const vtkIdType nLines = nPoints - 1;
150
151 // At least 2 points needed to define a polyplane.
152 if (nLines < 1)
153 {
154 return 0;
155 }
156
157 // compute normals
158 this->ComputeNormals();
159
160 double p1[3], p2[3], t, closest[3];
161 double minDistance2 = VTK_DOUBLE_MAX, distance2, signedDistance = VTK_DOUBLE_MAX, sign = 1;
162
163 // Iterate through all the lines.
164
165 for (int pIdx = 0; pIdx < nLines; ++pIdx)
166 {
167
168 // Get the end points of this line segment in the polyline
169 points->GetPoint(pIdx, p1);
170 points->GetPoint(pIdx + 1, p2);
171
172 // Flatten it.
173 p1[2] = 0;
174 p2[2] = 0;
175
176 // Compute distance-squared to finite line. Store the closest point.
177 distance2 = vtkLine::DistanceToLine(xFlat, p1, p2, t, closest);
178
179 // if the closest point on the line is on the segment
180 if (t >= 0 && t <= 1)
181 {
182 // if this is the minimum distance found, use that distance
183 // and record whether it was right of or left of the line
184 if (distance2 < minDistance2)
185 {
186 minDistance2 = distance2;
187 sign = leftOf(p1, p2, xFlat) ? 1 : -1;
188 }
189 }
190 // if the closest point on the line is before the segment starts

Callers

nothing calls this directly

Calls 6

ComputeNormalsMethod · 0.95
leftOfFunction · 0.85
sqrtFunction · 0.50
GetPointsMethod · 0.45
GetNumberOfPointsMethod · 0.45
GetPointMethod · 0.45

Tested by

no test coverage detected