38 template <
typename Real,
typename TriangleMesh>
56 Real
const* FX, Real
const* FY);
94 template <
typename Real,
typename TriangleMesh>
96 TriangleMesh
const& mesh, Real
const* F, Real spatialDelta)
107 template <
typename Real,
typename TriangleMesh>
109 TriangleMesh
const& mesh, Real
const* F, Real
const* FX, Real
const* FY)
119 template <
typename Real,
typename TriangleMesh>
123 int t =
mMesh->GetContainingTriangle(P);
131 std::array<Vector2<Real>, 3> V;
132 mMesh->GetVertices(t, V);
145 Real
const zero = (Real)0, one = (Real)1;
149 Real minDistance = (Real)-1;
153 for (index = 1; index <= 6; ++
index)
167 && zero <= bary[0] && bary[0] <= one
168 && zero <= bary[1] && bary[1] <= one
169 && zero <= bary[2] && bary[2] <= one)
180 Real
distance = pbQuery(bary, barybox).distance;
181 if (minIndex == 0 || distance < minDistance)
208 tData.
coeff[13 + (index % 6)],
210 tData.
coeff[6 + index],
211 tData.
coeff[1 + (index % 6)]
215 F = bary[0] * (bez[0] * bary[0] + bez[1] * bary[1] + bez[2] * bary[2]) +
216 bary[1] * (bez[1] * bary[0] + bez[3] * bary[1] + bez[4] * bary[2]) +
217 bary[2] * (bez[2] * bary[0] + bez[4] * bary[1] + bez[5] * bary[2]);
220 Real FU = ((Real)2)*(bez[0] * bary[0] + bez[1] * bary[1] +
222 Real FV = ((Real)2)*(bez[1] * bary[0] + bez[3] * bary[1] +
224 Real FW = ((Real)2)*(bez[2] * bary[0] + bez[4] * bary[1] +
230 Real m00 = sub0[0] - sub2[0];
231 Real m10 = sub0[1] - sub2[1];
232 Real m01 = sub1[0] - sub2[0];
233 Real m11 = sub1[1] - sub2[1];
234 Real inv = ((Real)1) / (m00*m11 - m10*m01);
236 FX = inv*(m11*duw - m10*dvw);
237 FY = inv*(m00*dvw - m01*duw);
241 template <
typename Real,
typename TriangleMesh>
245 int numVertices =
mMesh->GetNumVertices();
247 int numTriangles =
mMesh->GetNumTriangles();
252 std::vector<Real> FZ(numVertices);
255 std::fill(FZ.begin(), FZ.end(), (Real)0);
261 for (
int t = 0;
t < numTriangles; ++
t)
269 Real dx1 = vertices[
v1][0] - vertices[
v0][0];
270 Real dy1 = vertices[
v1][1] - vertices[
v0][1];
272 Real dx2 = vertices[
v2][0] - vertices[
v0][0];
273 Real dy2 = vertices[
v2][1] - vertices[
v0][1];
274 Real dz2 = mF[
v2] - mF[
v0];
275 Real
nx = dy1*dz2 - dy2*dz1;
276 Real
ny = dz1*dx2 - dz2*dx1;
277 Real
nz = dx1*dy2 - dx2*dy1;
291 for (
int i = 0; i < numVertices; ++i)
293 if (FZ[i] != (Real)0)
295 Real inv = -spatialDelta / FZ[i];
307 template <
typename Real,
typename TriangleMesh>
316 int numTriangles =
mMesh->GetNumTriangles();
318 mTData.resize(numTriangles);
320 for (t = 0; t < numTriangles; ++
t)
326 Inscribe(vertices[v0], vertices[v1], vertices[v2], circle);
331 for (t = 0; t < numTriangles; ++
t)
337 for (t = 0; t < numTriangles; ++
t)
343 template <
typename Real,
typename TriangleMesh>
348 std::array<Vector2<Real>, 3> V;
349 mMesh->GetVertices(t, V);
353 std::array<int, 3> adjacencies;
354 mMesh->GetAdjacencies(t, adjacencies);
355 for (
int j0 = 2, j1 = 0; j1 < 3; j0 = j1++)
357 int a = adjacencies[j0];
362 Real m00 = V[j0][1] - V[j1][1];
363 Real m01 = V[j1][0] - V[j0][0];
364 Real m10 = tData.
center[1] - U[1];
365 Real m11 = U[0] - tData.
center[0];
366 Real r0 = m00*V[j0][0] + m01*V[j0][1];
368 Real invDet = ((Real)1) / (m00*m11 - m01*m10);
369 tData.
intersect[j0][0] = (m11*r0 - m01*r1)*invDet;
370 tData.
intersect[j0][1] = (m00*r1 - m10*r0)*invDet;
375 tData.
intersect[j0] = ((Real)0.5)*(V[j0] + V[j1]);
380 template <
typename Real,
typename TriangleMesh>
384 std::array<Vector2<Real>, 3> V;
385 mMesh->GetVertices(t, V);
392 mMesh->GetIndices(t, indices);
394 for (
int j = 0; j < 3; ++j)
403 std::array<int, 3> adjacencies;
404 mMesh->GetAdjacencies(t, adjacencies);
406 for (
int j0 = 2, j1 = 0; j1 < 3; j0 = j1++)
408 int a = adjacencies[j0];
417 U[j0] = ((Real)0.5)*(V[j0] + V[j1]);
422 std::array<Real, 3> cenT, cen0, cen1, cen2;
424 mMesh->GetBarycentrics(t, U[0], cen0);
425 mMesh->GetBarycentrics(t, U[1], cen1);
426 mMesh->GetBarycentrics(t, U[2], cen2);
428 Real
alpha = (cenT[1] * cen1[0] - cenT[0] * cen1[1])
429 / (cen1[0] - cenT[0]);
430 Real beta = (cenT[2] * cen2[1] - cenT[1] * cen2[2])
431 / (cen2[1] - cenT[1]);
432 Real gamma = (cenT[0] * cen0[2] - cenT[2] * cen0[0])
433 / (cen0[2] - cenT[2]);
434 Real oneMinusAlpha = (Real)1 - alpha;
435 Real oneMinusBeta = (Real)1 - beta;
436 Real oneMinusGamma = (Real)1 - gamma;
438 Real tmp, A[9], B[9];
440 tmp = cenT[0] * V[0][0] + cenT[1] * V[1][0] + cenT[2] * V[2][0];
441 A[0] = ((Real)0.5)*(tmp - V[0][0]);
442 A[1] = ((Real)0.5)*(tmp - V[1][0]);
443 A[2] = ((Real)0.5)*(tmp - V[2][0]);
444 A[3] = ((Real)0.5)*beta*(V[2][0] - V[0][0]);
445 A[4] = ((Real)0.5)*oneMinusGamma*(V[1][0] - V[0][0]);
446 A[5] = ((Real)0.5)*gamma*(V[0][0] - V[1][0]);
447 A[6] = ((Real)0.5)*oneMinusAlpha*(V[2][0] - V[1][0]);
448 A[7] = ((Real)0.5)*alpha*(V[1][0] - V[2][0]);
449 A[8] = ((Real)0.5)*oneMinusBeta*(V[0][0] - V[2][0]);
451 tmp = cenT[0] * V[0][1] + cenT[1] * V[1][1] + cenT[2] * V[2][1];
452 B[0] = ((Real)0.5)*(tmp - V[0][1]);
453 B[1] = ((Real)0.5)*(tmp - V[1][1]);
454 B[2] = ((Real)0.5)*(tmp - V[2][1]);
455 B[3] = ((Real)0.5)*beta*(V[2][1] - V[0][1]);
456 B[4] = ((Real)0.5)*oneMinusGamma*(V[1][1] - V[0][1]);
457 B[5] = ((Real)0.5)*gamma*(V[0][1] - V[1][1]);
458 B[6] = ((Real)0.5)*oneMinusAlpha*(V[2][1] - V[1][1]);
459 B[7] = ((Real)0.5)*alpha*(V[1][1] - V[2][1]);
460 B[8] = ((Real)0.5)*oneMinusBeta*(V[0][1] - V[2][1]);
463 tData.
coeff[2] = jet[0].
F;
464 tData.
coeff[4] = jet[1].
F;
465 tData.
coeff[6] = jet[2].
F;
467 tData.
coeff[14] = jet[0].
F + A[0] * jet[0].
FX + B[0] * jet[0].
FY;
468 tData.
coeff[7] = jet[0].
F + A[3] * jet[0].
FX + B[3] * jet[0].
FY;
469 tData.
coeff[8] = jet[0].
F + A[4] * jet[0].
FX + B[4] * jet[0].
FY;
470 tData.
coeff[16] = jet[1].
F + A[1] * jet[1].
FX + B[1] * jet[1].
FY;
471 tData.
coeff[9] = jet[1].
F + A[5] * jet[1].
FX + B[5] * jet[1].
FY;
472 tData.
coeff[10] = jet[1].
F + A[6] * jet[1].
FX + B[6] * jet[1].
FY;
473 tData.
coeff[18] = jet[2].
F + A[2] * jet[2].
FX + B[2] * jet[2].
FY;
474 tData.
coeff[11] = jet[2].
F + A[7] * jet[2].
FX + B[7] * jet[2].
FY;
475 tData.
coeff[12] = jet[2].
F + A[8] * jet[2].
FX + B[8] * jet[2].
FY;
477 tData.
coeff[5] = alpha*tData.
coeff[10] + oneMinusAlpha*tData.
coeff[11];
478 tData.
coeff[17] = alpha*tData.
coeff[16] + oneMinusAlpha*tData.
coeff[18];
482 tData.
coeff[15] = gamma*tData.
coeff[14] + oneMinusGamma*tData.
coeff[16];
483 tData.
coeff[0] = cenT[0] * tData.
coeff[14] + cenT[1] * tData.
coeff[16] +
484 cenT[2] * tData.
coeff[18];
GLfloat GLfloat GLfloat alpha
bool Inscribe(Vector2< Real > const &v0, Vector2< Real > const &v1, Vector2< Real > const &v2, Circle2< Real > &circle)
GLsizei GLsizei GLfloat distance
GLboolean GLboolean GLboolean GLboolean a
GLsizei GLenum const void * indices
bool ComputeBarycentrics(Vector2< Real > const &p, Vector2< Real > const &v0, Vector2< Real > const &v1, Vector2< Real > const &v2, Real bary[3], Real epsilon=(Real) 0)
GLfloat GLfloat GLfloat v2