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

Method EvaluatePosition

Common/DataModel/vtkTriangle.cxx:105–311  ·  view source on GitHub ↗

------------------------------------------------------------------------------ Create a new cell and copy this triangle's information into the cell. Returns a pointer to the new cell created.

Source from the content-addressed store, hash-verified

103// Create a new cell and copy this triangle's information into the cell.
104// Returns a pointer to the new cell created.
105int vtkTriangle::EvaluatePosition(const double x[3], double closestPoint[3], int& subId,
106 double pcoords[3], double& dist2, double weights[])
107{
108 int i, j;
109 const double *pt1, *pt2, *pt3, *closest;
110 double n[3], fabsn;
111 double rhs[2], c1[2], c2[2];
112 double det;
113 int idx = 0, indices[2];
114 double dist2Point, dist2Line1, dist2Line2;
115 double closestPoint1[3], closestPoint2[3], cp[3];
116
117 subId = 0;
118 pcoords[2] = 0.0;
119
120 // Efficient point access
121 const auto pointsArray = vtkDoubleArray::FastDownCast(this->Points->GetData());
122 if (!pointsArray)
123 {
124 vtkErrorMacro(<< "Points should be double type");
125 return 0;
126 }
127 const double* pts = pointsArray->GetPointer(0);
128
129 // Get normal for triangle, only the normal direction is needed, i.e. the
130 // normal need not be normalized (unit length)
131 //
132 pt1 = pts + 3;
133 pt2 = pts + 6;
134 pt3 = pts;
135
136 vtkTriangle::ComputeNormalDirection(pt1, pt2, pt3, n);
137
138 // Project point to plane
139 //
140 vtkPlane::GeneralizedProjectPoint(x, pt1, n, cp);
141
142 // Construct matrices. Since we have over determined system, need to find
143 // which 2 out of 3 equations to use to develop equations. (Any 2 should
144 // work since we've projected point to plane.)
145 //
146 double maxComponent = 0.0;
147 for (i = 0; i < 3; i++)
148 {
149 // trying to avoid an expensive call to fabs()
150 if (n[i] < 0)
151 {
152 fabsn = -n[i];
153 }
154 else
155 {
156 fabsn = n[i];
157 }
158 if (fabsn > maxComponent)
159 {
160 maxComponent = fabsn;
161 idx = i;
162 }

Callers 1

IntersectWithLineMethod · 0.95

Calls 5

Determinant2x2Function · 0.85
FastDownCastFunction · 0.50
assertFunction · 0.50
GetDataMethod · 0.45
GetPointerMethod · 0.45

Tested by

no test coverage detected