34 template<
typename GeometryTraits >
41 const GeometryTraits >)
44 typedef typename GeometryTraits::Scalar Scalar;
46 Vector vap = Pos - a, vbp = Pos - b,
49 vab = b - a, vac = c - a, vad = d - a, vbc = c - b, vbd = d - b;
51 Vector temp_ac_ad(vac[1] * vad[2] - vac[2] * vad[1],
52 vac[2] * vad[0] - vac[0] * vad[2],
53 vac[0] * vad[1] - vac[1] * vad[0]);
55 Vector temp(vbd[1] * vbc[2] - vbd[2] * vbc[1],
56 vbd[2] * vbc[0] - vbd[0] * vbc[2],
57 vbd[0] * vbc[1] - vbd[1] * vbc[0]);
59 Scalar va = (vbp * temp) * 1.f / 6;
61 Scalar vb = (vap * temp_ac_ad) * 1.f / 6;
63 temp =
Vector(vad[1] * vab[2] - vad[2] * vab[1],
64 vad[2] * vab[0] - vad[0] * vab[2],
65 vad[0] * vab[1] - vad[1] * vab[0]);
67 Scalar vc = (vap * temp) * 1.f / 6;
69 temp =
Vector(vab[1] * vac[2] - vab[2] * vac[1],
70 vab[2] * vac[0] - vab[0] * vac[2],
71 vab[0] * vac[1] - vab[1] * vac[0]);
73 Scalar vd = (vap * temp) * 1.f / 6;
75 Scalar v = (vab * temp_ac_ad) * 1.f / 6;
77 Scalar alpha = va / v, beta = vb / v, gamma = vc / v, delta = vd / v;
82 return !((alpha < 0.f) || (beta < 0.f) || (gamma < 0.f) || (delta < 0.f));
107 template<
typename GeometryTraits >
109 typename GeometryTraits::Scalar
115 typename GeometryTraits::Scalar vala,
116 typename GeometryTraits::Scalar valb,
117 typename GeometryTraits::Scalar valc,
118 typename GeometryTraits::Scalar vald,
119 const GeometryTraits >)
122 typedef typename GeometryTraits::Scalar Scalar;
124 Vector vap = Pos - a, vbp = Pos - b,
127 vab = b - a, vac = c - a, vad = d - a, vbc = c - b, vbd = d - b;
129 Vector temp_ac_ad(vac[1] * vad[2] - vac[2] * vad[1],
130 vac[2] * vad[0] - vac[0] * vad[2],
131 vac[0] * vad[1] - vac[1] * vad[0]);
133 Vector temp(vbd[1] * vbc[2] - vbd[2] * vbc[1],
134 vbd[2] * vbc[0] - vbd[0] * vbc[2],
135 vbd[0] * vbc[1] - vbd[1] * vbc[0]);
137 Scalar va = (vbp * temp) * 1.f / 6;
139 Scalar vb = (vap * temp_ac_ad) * 1.f / 6;
141 temp =
Vector(vad[1] * vab[2] - vad[2] * vab[1],
142 vad[2] * vab[0] - vad[0] * vab[2],
143 vad[0] * vab[1] - vad[1] * vab[0]);
145 Scalar vc = (vap * temp) * 1.f / 6;
147 temp =
Vector(vab[1] * vac[2] - vab[2] * vac[1],
148 vab[2] * vac[0] - vab[0] * vac[2],
149 vab[0] * vac[1] - vab[1] * vac[0]);
151 Scalar vd = (vap * temp) * 1.f / 6;
153 Scalar v = (vab * temp_ac_ad) * 1.f / 6;
155 Scalar alpha = va / v, beta = vb / v, gamma = vc / v, delta = vd / v;
177 return alpha * vala + beta * valb + gamma * valc + delta * vald;
202 template<
typename GeometryTraits >
203 static inline std::vector< typename GeometryTraits::Scalar >
209 const std::vector< typename GeometryTraits::Scalar > &vala,
210 const std::vector< typename GeometryTraits::Scalar > &valb,
211 const std::vector< typename GeometryTraits::Scalar > &valc,
212 const std::vector< typename GeometryTraits::Scalar > &vald,
213 const GeometryTraits >)
215 size_t nbe = vala.size();
216 if(valb.size() < nbe)
218 if(valc.size() < nbe)
220 if(vald.size() < nbe)
223 std::vector< typename GeometryTraits::Scalar > res(nbe, 0.f);
225 for(
size_t i = 0; i < nbe; ++i)
227 res[i] = trilinear_interpolation< GeometryTraits >(
228 a, b, c, d, Pos, vala[i], valb[i], valc[i], vald[i], gt);
250 template<
typename GeometryTraits >
256 const GeometryTraits >)
260 Vector vab(gt.sub_p(b, a)), vaPos(gt.sub_p(Pos, a)), inter, N, Ntmp;
262 inter = gt.cross_product(vab, vaPos);
265 Ntmp = gt.cross_product(inter, vab);
268 N = gt.normalize(Ntmp);
271 diff = gt.scalar_mult(N,
272 -gt.dot_product(vaPos, N));
275 interp =
Point(Pos[0] + diff[0], Pos[1] + diff[1], Pos[2] + diff[2]);
278 return (gt.dot_product(
279 Vector(interp[0] - a[0], interp[1] - a[1], interp[2] - a[2]),
282 Vector(b[0] - interp[0], b[1] - interp[1], b[2] - interp[2]),
301 template<
typename GeometryTraits >
307 const GeometryTraits >)
310 typedef typename GeometryTraits::Scalar Scalar;
313 Vector p1p(a[0] - c[0], a[1] - c[1], a[2] - c[2]),
314 p2p(b[0] - c[0], b[1] - c[1], b[2] - c[2]),
315 Posp(Pos[0] - c[0], Pos[1] - c[1], Pos[2] - c[2]);
317 Scalar p1p2 = gt.dot_product(p1p, p1p), p2p2 = gt.dot_product(p2p, p2p),
318 p1pp2p = gt.dot_product(p1p, p2p), p1pPosp = gt.dot_product(p1p, Posp),
319 p2pPosp = gt.dot_product(p2p, Posp);
321 Scalar den = p1p2 * p2p2 - p1pp2p * p1pp2p;
322 Scalar alpha = (p2p2 * p1pPosp - p1pp2p * p2pPosp) / den,
323 beta = (p1p2 * p2pPosp - p1pp2p * p1pPosp) / den, gamma;
324 gamma = 1 - (alpha + beta);
326 return !((alpha < 0.0) || (beta < 0.0) || (gamma < 0.0) || (alpha > 1.0) ||
327 (beta > 1.0) || (gamma > 1.0));
350 template<
typename GeometryTraits >
351 static inline typename GeometryTraits::Scalar
356 typename GeometryTraits::Scalar vala,
357 typename GeometryTraits::Scalar valb,
358 typename GeometryTraits::Scalar valc,
359 const GeometryTraits >)
362 typedef typename GeometryTraits::Scalar Scalar;
364 Vector p1p = a - c, p2p = b - c, Posp = Pos - c;
365 Scalar p1p2 = gt.dot_product(p1p, p1p), p2p2 = gt.dot_product(p2p, p2p),
366 p1pp2p = gt.dot_product(p1p, p2p), p1pPosp = gt.dot_product(p1p, Posp),
367 p2pPosp = gt.dot_product(p2p, Posp);
369 Scalar den = p1p2 * p2p2 - p1pp2p * p1pp2p;
370 Scalar alpha = (p2p2 * p1pPosp - p1pp2p * p2pPosp) / den,
371 beta = (p1p2 * p2pPosp - p1pp2p * p1pPosp) / den, gamma;
372 gamma = 1 - (alpha + beta);
389 return alpha * vala + beta * valb + gamma * valc;
411 template<
typename GeometryTraits >
412 static inline std::vector< typename GeometryTraits::Scalar >
418 const std::vector< typename GeometryTraits::Scalar > &vala,
419 const std::vector< typename GeometryTraits::Scalar > &valb,
420 const std::vector< typename GeometryTraits::Scalar > &valc,
421 const GeometryTraits >)
423 size_t nbe = vala.size();
424 if(valb.size() < nbe)
426 if(valc.size() < nbe)
429 std::vector< typename GeometryTraits::Scalar > res(nbe, 0);
431 for(
size_t i = 0; i < nbe; ++i)
433 res[i] = bilinear_interpolation< GeometryTraits >(
434 a, b, c, Pos, vala[i], valb[i], valc[i], gt);