------------------------------------------------------------------------------ Evaluate plane equations. Return smallest absolute value.
| 90 | //------------------------------------------------------------------------------ |
| 91 | // Evaluate plane equations. Return smallest absolute value. |
| 92 | double vtkImplicitSelectionLoop::EvaluateFunction(double x[3]) |
| 93 | { |
| 94 | int i, numPts; |
| 95 | double xProj[3]; |
| 96 | double t, dist2, minDist2, closest[3]; |
| 97 | int inside = 0; |
| 98 | |
| 99 | if (this->InitializationTime < this->GetMTime()) |
| 100 | { |
| 101 | this->Initialize(); |
| 102 | } |
| 103 | // Initialize may change the number of points |
| 104 | numPts = this->Polygon->Points->GetNumberOfPoints(); |
| 105 | |
| 106 | // project point onto plane |
| 107 | vtkPlane::ProjectPoint(x, this->Origin, this->Normal, xProj); |
| 108 | |
| 109 | // determine whether it's in the selection loop and then evaluate point |
| 110 | // in polygon only if absolutely necessary. |
| 111 | if (xProj[0] >= this->Bounds[0] && xProj[0] <= this->Bounds[1] && xProj[1] >= this->Bounds[2] && |
| 112 | xProj[1] <= this->Bounds[3] && xProj[2] >= this->Bounds[4] && xProj[2] <= this->Bounds[5] && |
| 113 | vtkPolygon::PointInPolygon(xProj, numPts, |
| 114 | vtkArrayDownCast<vtkDoubleArray>(this->Polygon->Points->GetData())->GetPointer(0), |
| 115 | this->Bounds, this->Normal) == 1) |
| 116 | { |
| 117 | inside = 1; |
| 118 | } |
| 119 | |
| 120 | // determine distance to boundary |
| 121 | for (minDist2 = VTK_DOUBLE_MAX, i = 0; i < numPts; i++) |
| 122 | { |
| 123 | double p1[3], p2[3]; |
| 124 | this->Polygon->Points->GetPoint(i, p1); |
| 125 | this->Polygon->Points->GetPoint((i + 1) % numPts, p2); |
| 126 | dist2 = vtkLine::DistanceToLine(xProj, p1, p2, t, closest); |
| 127 | minDist2 = std::min(dist2, minDist2); |
| 128 | } |
| 129 | |
| 130 | minDist2 = sqrt(minDist2); |
| 131 | return (inside ? -minDist2 : minDist2); |
| 132 | } |
| 133 | |
| 134 | //------------------------------------------------------------------------------ |
| 135 | // Evaluate gradient of the implicit function. Use a numerical scheme: evaluate |
no test coverage detected