33 #ifndef OPENVDB_MATH_OPERATORS_HAS_BEEN_INCLUDED
34 #define OPENVDB_MATH_OPERATORS_HAS_BEEN_INCLUDED
49 template<
typename Vec3T>
struct is_vec3d {
static const bool value =
false; };
52 template<
typename T>
struct is_double {
static const bool value =
false; };
53 template<>
struct is_double<double> {
static const bool value =
true; };
61 template<
typename MapType,
typename OpType,
typename ResultType>
65 template<
typename AccessorType>
67 result(
const AccessorType& grid,
const Coord& ijk) {
return OpType::result(map, grid, ijk); }
69 template<
typename StencilType>
71 result(
const StencilType& stencil) {
return OpType::result(map, stencil); }
78 template<
typename OpType>
80 template<
typename AccessorType>
81 static inline double result(
const AccessorType& grid,
const Coord& ijk) {
82 return double(OpType::result(grid, ijk).length());
85 template<
typename StencilType>
86 static inline double result(
const StencilType& stencil) {
87 return double(OpType::result(stencil).length());
92 template<
typename OpType,
typename MapT>
94 template<
typename AccessorType>
95 static inline double result(
const MapT& map,
const AccessorType& grid,
const Coord& ijk) {
96 return double(OpType::result(map, grid, ijk).length());
99 template<
typename StencilType>
100 static inline double result(
const MapT& map,
const StencilType& stencil) {
101 return double(OpType::result(map, stencil).length());
121 template<DScheme DiffScheme>
129 using ValueType =
typename Accessor::ValueType;
140 using ValueType =
typename StencilT::ValueType;
152 template<BiasedGradientScheme bgs>
157 template<
typename Gr
idType,
bool IsSafe = true>
168 template<
typename Gr
idType,
bool IsSafe = true>
179 template<
typename Gr
idType,
bool IsSafe = true>
189 template<
typename Gr
idType,
bool IsSafe = true>
199 template<
typename Gr
idType,
bool IsSafe = true>
209 template<
typename Gr
idType,
bool IsSafe = true>
219 template<BiasedGradientScheme GradScheme,
typename Vec3Bias>
226 template<
typename Accessor>
230 using ValueType =
typename Accessor::ValueType;
239 template<
typename StencilT>
241 result(
const StencilT& stencil,
const Vec3Bias& V)
243 using ValueType =
typename StencilT::ValueType;
253 template<BiasedGradientScheme GradScheme>
261 template<
typename Accessor>
262 static typename Accessor::ValueType
265 using ValueType =
typename Accessor::ValueType;
274 template<
typename StencilT>
275 static typename StencilT::ValueType
278 using ValueType =
typename StencilT::ValueType;
287 #ifdef DWA_OPENVDB // for SIMD - note will do the computations in float
292 template<
typename Accessor>
293 static typename Accessor::ValueType result(
const Accessor& grid,
const Coord& ijk)
298 GetValue(
const Accessor& acc_): acc(acc_) {}
300 inline simd::Float4::value_type operator()(
const Coord& ijk_) {
301 return static_cast<simd::Float4::value_type>(acc.getValue(ijk_));
314 v3(valueAt(ijk ) - valueAt(ijk.
offsetBy(-1, 0, 0)),
315 valueAt(ijk ) - valueAt(ijk.
offsetBy( 0,-1, 0)),
316 valueAt(ijk ) - valueAt(ijk.
offsetBy( 0, 0,-1)), 0),
317 v4(valueAt(ijk.
offsetBy( 1, 0, 0)) - valueAt(ijk ),
318 valueAt(ijk.
offsetBy( 0, 1, 0)) - valueAt(ijk ),
319 valueAt(ijk.
offsetBy( 0, 0, 1)) - valueAt(ijk ), 0),
333 template<
typename StencilT>
334 static typename StencilT::ValueType result(
const StencilT& s)
336 using F4Val = simd::Float4::value_type;
340 v1(F4Val(s.template getValue<-2, 0, 0>()) - F4Val(s.template getValue<-3, 0, 0>()),
341 F4Val(s.template getValue< 0,-2, 0>()) - F4Val(s.template getValue< 0,-3, 0>()),
342 F4Val(s.template getValue< 0, 0,-2>()) - F4Val(s.template getValue< 0, 0,-3>()), 0),
343 v2(F4Val(s.template getValue<-1, 0, 0>()) - F4Val(s.template getValue<-2, 0, 0>()),
344 F4Val(s.template getValue< 0,-1, 0>()) - F4Val(s.template getValue< 0,-2, 0>()),
345 F4Val(s.template getValue< 0, 0,-1>()) - F4Val(s.template getValue< 0, 0,-2>()), 0),
346 v3(F4Val(s.template getValue< 0, 0, 0>()) - F4Val(s.template getValue<-1, 0, 0>()),
347 F4Val(s.template getValue< 0, 0, 0>()) - F4Val(s.template getValue< 0,-1, 0>()),
348 F4Val(s.template getValue< 0, 0, 0>()) - F4Val(s.template getValue< 0, 0,-1>()), 0),
349 v4(F4Val(s.template getValue< 1, 0, 0>()) - F4Val(s.template getValue< 0, 0, 0>()),
350 F4Val(s.template getValue< 0, 1, 0>()) - F4Val(s.template getValue< 0, 0, 0>()),
351 F4Val(s.template getValue< 0, 0, 1>()) - F4Val(s.template getValue< 0, 0, 0>()), 0),
352 v5(F4Val(s.template getValue< 2, 0, 0>()) - F4Val(s.template getValue< 1, 0, 0>()),
353 F4Val(s.template getValue< 0, 2, 0>()) - F4Val(s.template getValue< 0, 1, 0>()),
354 F4Val(s.template getValue< 0, 0, 2>()) - F4Val(s.template getValue< 0, 0, 1>()), 0),
355 v6(F4Val(s.template getValue< 3, 0, 0>()) - F4Val(s.template getValue< 2, 0, 0>()),
356 F4Val(s.template getValue< 0, 3, 0>()) - F4Val(s.template getValue< 0, 2, 0>()),
357 F4Val(s.template getValue< 0, 0, 3>()) - F4Val(s.template getValue< 0, 0, 2>()), 0),
364 #endif //DWA_OPENVDB // for SIMD - note will do the computations in float
369 template<DDScheme DiffScheme>
374 template<
typename Accessor>
375 static typename Accessor::ValueType result(
const Accessor& grid,
const Coord& ijk);
378 template<
typename StencilT>
379 static typename StencilT::ValueType result(
const StencilT& stencil);
387 template<
typename Accessor>
388 static typename Accessor::ValueType
result(
const Accessor& grid,
const Coord& ijk)
390 return grid.getValue(ijk.
offsetBy(1,0,0)) + grid.getValue(ijk.
offsetBy(-1, 0, 0)) +
391 grid.getValue(ijk.
offsetBy(0,1,0)) + grid.getValue(ijk.
offsetBy(0, -1, 0)) +
393 - 6*grid.getValue(ijk);
397 template<
typename StencilT>
398 static typename StencilT::ValueType
result(
const StencilT& stencil)
400 return stencil.template getValue< 1, 0, 0>() + stencil.template getValue<-1, 0, 0>() +
401 stencil.template getValue< 0, 1, 0>() + stencil.template getValue< 0,-1, 0>() +
402 stencil.template getValue< 0, 0, 1>() + stencil.template getValue< 0, 0,-1>()
403 - 6*stencil.template getValue< 0, 0, 0>();
411 template<
typename Accessor>
412 static typename Accessor::ValueType
result(
const Accessor& grid,
const Coord& ijk)
414 using ValueT =
typename Accessor::ValueType;
415 return static_cast<ValueT>(
417 grid.getValue(ijk.
offsetBy(2,0,0)) + grid.getValue(ijk.
offsetBy(-2, 0, 0)) +
418 grid.getValue(ijk.
offsetBy(0,2,0)) + grid.getValue(ijk.
offsetBy( 0,-2, 0)) +
419 grid.getValue(ijk.
offsetBy(0,0,2)) + grid.getValue(ijk.
offsetBy( 0, 0,-2)) )
421 grid.getValue(ijk.
offsetBy(1,0,0)) + grid.getValue(ijk.
offsetBy(-1, 0, 0)) +
422 grid.getValue(ijk.
offsetBy(0,1,0)) + grid.getValue(ijk.
offsetBy( 0,-1, 0)) +
423 grid.getValue(ijk.
offsetBy(0,0,1)) + grid.getValue(ijk.
offsetBy( 0, 0,-1)) )
424 - 7.5*grid.getValue(ijk));
428 template<
typename StencilT>
429 static typename StencilT::ValueType
result(
const StencilT& stencil)
431 using ValueT =
typename StencilT::ValueType;
432 return static_cast<ValueT>(
434 stencil.template getValue< 2, 0, 0>() + stencil.template getValue<-2, 0, 0>() +
435 stencil.template getValue< 0, 2, 0>() + stencil.template getValue< 0,-2, 0>() +
436 stencil.template getValue< 0, 0, 2>() + stencil.template getValue< 0, 0,-2>() )
438 stencil.template getValue< 1, 0, 0>() + stencil.template getValue<-1, 0, 0>() +
439 stencil.template getValue< 0, 1, 0>() + stencil.template getValue< 0,-1, 0>() +
440 stencil.template getValue< 0, 0, 1>() + stencil.template getValue< 0, 0,-1>() )
441 - 7.5*stencil.template getValue< 0, 0, 0>());
449 template<
typename Accessor>
450 static typename Accessor::ValueType
result(
const Accessor& grid,
const Coord& ijk)
452 using ValueT =
typename Accessor::ValueType;
453 return static_cast<ValueT>(
455 grid.getValue(ijk.
offsetBy(3,0,0)) + grid.getValue(ijk.
offsetBy(-3, 0, 0)) +
456 grid.getValue(ijk.
offsetBy(0,3,0)) + grid.getValue(ijk.
offsetBy( 0,-3, 0)) +
457 grid.getValue(ijk.
offsetBy(0,0,3)) + grid.getValue(ijk.
offsetBy( 0, 0,-3)) )
459 grid.getValue(ijk.
offsetBy(2,0,0)) + grid.getValue(ijk.
offsetBy(-2, 0, 0)) +
460 grid.getValue(ijk.
offsetBy(0,2,0)) + grid.getValue(ijk.
offsetBy( 0,-2, 0)) +
461 grid.getValue(ijk.
offsetBy(0,0,2)) + grid.getValue(ijk.
offsetBy( 0, 0,-2)) )
463 grid.getValue(ijk.
offsetBy(1,0,0)) + grid.getValue(ijk.
offsetBy(-1, 0, 0)) +
464 grid.getValue(ijk.
offsetBy(0,1,0)) + grid.getValue(ijk.
offsetBy( 0,-1, 0)) +
465 grid.getValue(ijk.
offsetBy(0,0,1)) + grid.getValue(ijk.
offsetBy( 0, 0,-1)) )
466 - (3*49/18.)*grid.getValue(ijk));
470 template<
typename StencilT>
471 static typename StencilT::ValueType
result(
const StencilT& stencil)
473 using ValueT =
typename StencilT::ValueType;
474 return static_cast<ValueT>(
476 stencil.template getValue< 3, 0, 0>() + stencil.template getValue<-3, 0, 0>() +
477 stencil.template getValue< 0, 3, 0>() + stencil.template getValue< 0,-3, 0>() +
478 stencil.template getValue< 0, 0, 3>() + stencil.template getValue< 0, 0,-3>() )
480 stencil.template getValue< 2, 0, 0>() + stencil.template getValue<-2, 0, 0>() +
481 stencil.template getValue< 0, 2, 0>() + stencil.template getValue< 0,-2, 0>() +
482 stencil.template getValue< 0, 0, 2>() + stencil.template getValue< 0, 0,-2>() )
484 stencil.template getValue< 1, 0, 0>() + stencil.template getValue<-1, 0, 0>() +
485 stencil.template getValue< 0, 1, 0>() + stencil.template getValue< 0,-1, 0>() +
486 stencil.template getValue< 0, 0, 1>() + stencil.template getValue< 0, 0,-1>() )
487 - (3*49/18.)*stencil.template getValue< 0, 0, 0>());
494 template<DScheme DiffScheme>
499 template<
typename Accessor>
static typename Accessor::ValueType::value_type
508 template<
typename StencilT>
static typename StencilT::ValueType::value_type
520 template<DScheme DiffScheme>
525 template<
typename Accessor>
526 static typename Accessor::ValueType
result(
const Accessor& grid,
const Coord& ijk)
528 using Vec3Type =
typename Accessor::ValueType;
538 template<
typename StencilT>
539 static typename StencilT::ValueType
result(
const StencilT& stencil)
541 using Vec3Type =
typename StencilT::ValueType;
554 template<DDScheme DiffScheme2, DScheme DiffScheme1>
562 template<
typename Accessor>
564 typename Accessor::ValueType& alpha,
565 typename Accessor::ValueType& beta)
567 using ValueType =
typename Accessor::ValueType;
573 const ValueType Dx2 = Dx*Dx;
574 const ValueType Dy2 = Dy*Dy;
575 const ValueType Dz2 = Dz*Dz;
576 const ValueType normGrad = Dx2 + Dy2 + Dz2;
591 alpha = (Dx2*(Dyy+Dzz)+Dy2*(Dxx+Dzz)+Dz2*(Dxx+Dyy)-2*(Dx*(Dy*Dxy+Dz*Dxz)+Dy*Dz*Dyz));
592 beta = ValueType(std::sqrt(
double(normGrad)));
600 template<
typename StencilT>
601 static bool result(
const StencilT& stencil,
602 typename StencilT::ValueType& alpha,
603 typename StencilT::ValueType& beta)
605 using ValueType =
typename StencilT::ValueType;
610 const ValueType Dx2 = Dx*Dx;
611 const ValueType Dy2 = Dy*Dy;
612 const ValueType Dz2 = Dz*Dz;
613 const ValueType normGrad = Dx2 + Dy2 + Dz2;
628 alpha = (Dx2*(Dyy+Dzz)+Dy2*(Dxx+Dzz)+Dz2*(Dxx+Dyy)-2*(Dx*(Dy*Dxy+Dz*Dxz)+Dy*Dz*Dyz));
629 beta = ValueType(std::sqrt(
double(normGrad)));
639 template<
typename MapType, DScheme DiffScheme>
646 template<
typename Accessor>
648 result(
const MapType& map,
const Accessor& grid,
const Coord& ijk)
653 return Vec3Type(map.applyIJT(iGradient, ijk.
asVec3d()));
657 template<
typename StencilT>
659 result(
const MapType& map,
const StencilT& stencil)
664 return Vec3Type(map.applyIJT(iGradient, stencil.getCenterCoord().asVec3d()));
670 template<DScheme DiffScheme>
674 template<
typename Accessor>
682 template<
typename StencilT>
696 template<
typename Accessor>
705 return iGradient * inv2dx;
709 template<
typename StencilT>
718 return iGradient * inv2dx;
728 template<
typename Accessor>
737 return iGradient * inv2dx;
741 template<
typename StencilT>
750 return iGradient * inv2dx;
760 template<
typename Accessor>
773 return Vec3Type(ValueType(gradient0),
774 ValueType(gradient1),
775 ValueType(gradient2));
779 template<
typename StencilT>
792 return Vec3Type(ValueType(gradient0),
793 ValueType(gradient1),
794 ValueType(gradient2));
804 template<
typename Accessor>
817 return Vec3Type(ValueType(gradient0),
818 ValueType(gradient1),
819 ValueType(gradient2));
823 template<
typename StencilT>
836 return Vec3Type(ValueType(gradient0),
837 ValueType(gradient1),
838 ValueType(gradient2));
845 template<
typename MapType, BiasedGradientScheme GradScheme>
852 result(
const MapType& map,
const Accessor& grid,
const Coord& ijk,
855 using ValueType =
typename Accessor::ValueType;
859 return Vec3Type(map.applyIJT(iGradient, ijk.
asVec3d()));
864 result(
const MapType& map,
const StencilT& stencil,
867 using ValueType =
typename StencilT::ValueType;
871 return Vec3Type(map.applyIJT(iGradient, stencil.getCenterCoord().asVec3d()));
880 template<
typename MapType, BiasedGradientScheme GradScheme>
888 template<
typename Accessor>
889 static typename Accessor::ValueType
890 result(
const MapType& map,
const Accessor& grid,
const Coord& ijk)
892 using ValueType =
typename Accessor::ValueType;
901 template<
typename StencilT>
902 static typename StencilT::ValueType
903 result(
const MapType& map,
const StencilT& stencil)
905 using ValueType =
typename StencilT::ValueType;
915 template<BiasedGradientScheme GradScheme>
919 template<
typename Accessor>
920 static typename Accessor::ValueType
923 using ValueType =
typename Accessor::ValueType;
930 template<
typename StencilT>
931 static typename StencilT::ValueType
934 using ValueType =
typename StencilT::ValueType;
942 template<BiasedGradientScheme GradScheme>
946 template<
typename Accessor>
947 static typename Accessor::ValueType
950 using ValueType =
typename Accessor::ValueType;
957 template<
typename StencilT>
958 static typename StencilT::ValueType
961 using ValueType =
typename StencilT::ValueType;
970 template<
typename MapType, DScheme DiffScheme>
976 template<
typename Accessor>
static typename Accessor::ValueType::value_type
977 result(
const MapType& map,
const Accessor& grid,
const Coord& ijk)
979 using ValueType =
typename Accessor::ValueType::value_type;
982 for (
int i=0; i < 3; i++) {
986 div += ValueType(map.applyIJT(vec, ijk.
asVec3d())[i]);
992 template<
typename StencilT>
static typename StencilT::ValueType::value_type
993 result(
const MapType& map,
const StencilT& stencil)
995 using ValueType =
typename StencilT::ValueType::value_type;
998 for (
int i=0; i < 3; i++) {
1002 div += ValueType(map.applyIJT(vec, stencil.getCenterCoord().asVec3d())[i]);
1010 template<DScheme DiffScheme>
1014 template<
typename Accessor>
static typename Accessor::ValueType::value_type
1017 using ValueType =
typename Accessor::ValueType::value_type;
1025 template<
typename StencilT>
static typename StencilT::ValueType::value_type
1028 using ValueType =
typename StencilT::ValueType::value_type;
1038 template<DScheme DiffScheme>
1042 template<
typename Accessor>
static typename Accessor::ValueType::value_type
1045 using ValueType =
typename Accessor::ValueType::value_type;
1050 ValueType invdx = ValueType(map.
getInvScale()[0]);
1055 template<
typename StencilT>
static typename StencilT::ValueType::value_type
1058 using ValueType =
typename StencilT::ValueType::value_type;
1063 ValueType invdx = ValueType(map.
getInvScale()[0]);
1070 template<DScheme DiffScheme>
1074 template<
typename Accessor>
static typename Accessor::ValueType::value_type
1077 using ValueType =
typename Accessor::ValueType::value_type;
1082 ValueType invdx = ValueType(map.
getInvScale()[0]);
1087 template<
typename StencilT>
static typename StencilT::ValueType::value_type
1090 using ValueType =
typename StencilT::ValueType::value_type;
1095 ValueType invdx = ValueType(map.
getInvScale()[0]);
1106 template<
typename Accessor>
static typename Accessor::ValueType::value_type
1109 using ValueType =
typename Accessor::ValueType::value_type;
1114 return div * inv2dx;
1118 template<
typename StencilT>
static typename StencilT::ValueType::value_type
1121 using ValueType =
typename StencilT::ValueType::value_type;
1126 return div * inv2dx;
1136 template<
typename Accessor>
static typename Accessor::ValueType::value_type
1139 using ValueType =
typename Accessor::ValueType::value_type;
1145 return div * inv2dx;
1149 template<
typename StencilT>
static typename StencilT::ValueType::value_type
1152 using ValueType =
typename StencilT::ValueType::value_type;
1158 return div * inv2dx;
1164 template<DScheme DiffScheme>
1168 template<
typename Accessor>
static typename Accessor::ValueType::value_type
1171 using ValueType =
typename Accessor::ValueType::value_type;
1173 ValueType div = ValueType(
1181 template<
typename StencilT>
static typename StencilT::ValueType::value_type
1184 using ValueType =
typename StencilT::ValueType::value_type;
1197 template<DScheme DiffScheme>
1201 template<
typename Accessor>
static typename Accessor::ValueType::value_type
1204 using ValueType =
typename Accessor::ValueType::value_type;
1206 ValueType div = ValueType(
1214 template<
typename StencilT>
static typename StencilT::ValueType::value_type
1217 using ValueType =
typename StencilT::ValueType::value_type;
1234 template<
typename Accessor>
static typename Accessor::ValueType::value_type
1237 using ValueType =
typename Accessor::ValueType::value_type;
1239 ValueType div = ValueType(
1247 template<
typename StencilT>
static typename StencilT::ValueType::value_type
1250 using ValueType =
typename StencilT::ValueType::value_type;
1252 ValueType div = ValueType(
1266 template<
typename Accessor>
static typename Accessor::ValueType::value_type
1269 using ValueType =
typename Accessor::ValueType::value_type;
1271 ValueType div = ValueType(
1279 template<
typename StencilT>
static typename StencilT::ValueType::value_type
1282 using ValueType =
typename StencilT::ValueType::value_type;
1284 ValueType div = ValueType(
1295 template<
typename MapType, DScheme DiffScheme>
1301 template<
typename Accessor>
static typename Accessor::ValueType
1304 using Vec3Type =
typename Accessor::ValueType;
1306 for (
int i = 0; i < 3; i++) {
1312 mat[i] = Vec3Type(map.applyIJT(vec, ijk.
asVec3d()));
1314 return Vec3Type(mat[2][1] - mat[1][2],
1315 mat[0][2] - mat[2][0],
1316 mat[1][0] - mat[0][1]);
1320 template<
typename StencilT>
static typename StencilT::ValueType
1321 result(
const MapType& map,
const StencilT& stencil)
1323 using Vec3Type =
typename StencilT::ValueType;
1325 for (
int i = 0; i < 3; i++) {
1331 mat[i] = Vec3Type(map.applyIJT(vec, stencil.getCenterCoord().asVec3d()));
1333 return Vec3Type(mat[2][1] - mat[1][2],
1334 mat[0][2] - mat[2][0],
1335 mat[1][0] - mat[0][1]);
1340 template<DScheme DiffScheme>
1344 template<
typename Accessor>
static typename Accessor::ValueType
1347 using Vec3Type =
typename Accessor::ValueType;
1348 using ValueType =
typename Vec3Type::value_type;
1353 template<
typename StencilT>
static typename StencilT::ValueType
1356 using Vec3Type =
typename StencilT::ValueType;
1357 using ValueType =
typename Vec3Type::value_type;
1363 template<DScheme DiffScheme>
1367 template<
typename Accessor>
static typename Accessor::ValueType
1370 using Vec3Type =
typename Accessor::ValueType;
1371 using ValueType =
typename Vec3Type::value_type;
1377 template<
typename StencilT>
static typename StencilT::ValueType
1380 using Vec3Type =
typename StencilT::ValueType;
1381 using ValueType =
typename Vec3Type::value_type;
1392 template<
typename Accessor>
static typename Accessor::ValueType
1395 using Vec3Type =
typename Accessor::ValueType;
1396 using ValueType =
typename Vec3Type::value_type;
1402 template<
typename StencilT>
static typename StencilT::ValueType
1405 using Vec3Type =
typename StencilT::ValueType;
1406 using ValueType =
typename Vec3Type::value_type;
1417 template<
typename Accessor>
static typename Accessor::ValueType
1420 using Vec3Type =
typename Accessor::ValueType;
1421 using ValueType =
typename Vec3Type::value_type;
1427 template<
typename StencilT>
static typename StencilT::ValueType
1430 using Vec3Type =
typename StencilT::ValueType;
1431 using ValueType =
typename Vec3Type::value_type;
1440 template<
typename MapType, DDScheme DiffScheme>
1446 template<
typename Accessor>
1447 static typename Accessor::ValueType
result(
const MapType& map,
1448 const Accessor& grid,
const Coord& ijk)
1450 using ValueType =
typename Accessor::ValueType;
1461 Mat3d d2_is(iddx, iddxy, iddxz,
1463 iddxz, iddyz, iddz);
1467 d2_rs = map.applyIJC(d2_is);
1474 d2_rs = map.applyIJC(d2_is, d1_is, ijk.
asVec3d());
1478 return ValueType(d2_rs(0,0) + d2_rs(1,1) + d2_rs(2,2));
1482 template<
typename StencilT>
1483 static typename StencilT::ValueType
result(
const MapType& map,
const StencilT& stencil)
1485 using ValueType =
typename StencilT::ValueType;
1496 Mat3d d2_is(iddx, iddxy, iddxz,
1498 iddxz, iddyz, iddz);
1502 d2_rs = map.applyIJC(d2_is);
1509 d2_rs = map.applyIJC(d2_is, d1_is, stencil.getCenterCoord().asVec3d());
1513 return ValueType(d2_rs(0,0) + d2_rs(1,1) + d2_rs(2,2));
1518 template<DDScheme DiffScheme>
1522 template<
typename Accessor>
1524 const Accessor& grid,
const Coord& ijk)
1530 template<
typename StencilT>
1539 template<DDScheme DiffScheme>
1543 template<
typename Accessor>
1545 const Accessor& grid,
const Coord& ijk)
1551 template<
typename StencilT>
1559 template<DDScheme DiffScheme>
1563 template<
typename Accessor>
static typename Accessor::ValueType
1566 using ValueType =
typename Accessor::ValueType;
1572 template<
typename StencilT>
static typename StencilT::ValueType
1575 using ValueType =
typename StencilT::ValueType;
1582 template<DDScheme DiffScheme>
1586 template<
typename Accessor>
static typename Accessor::ValueType
1589 using ValueType =
typename Accessor::ValueType;
1595 template<
typename StencilT>
static typename StencilT::ValueType
1598 using ValueType =
typename StencilT::ValueType;
1605 template<DDScheme DiffScheme>
1609 template<
typename Accessor>
static typename Accessor::ValueType
1612 using ValueType =
typename Accessor::ValueType;
1621 const ValueType value = iddx * invScaleSqr[0] + iddy * invScaleSqr[1] + iddz * invScaleSqr[2];
1627 template<
typename StencilT>
static typename StencilT::ValueType
1630 using ValueType =
typename StencilT::ValueType;
1639 const ValueType value = iddx * invScaleSqr[0] + iddy * invScaleSqr[1] + iddz * invScaleSqr[2];
1646 template<DDScheme DiffScheme>
1650 template<
typename Accessor>
static typename Accessor::ValueType
1653 using ValueType =
typename Accessor::ValueType;
1661 const ValueType value = iddx * invScaleSqr[0] + iddy * invScaleSqr[1] + iddz * invScaleSqr[2];
1667 template<
typename StencilT>
static typename StencilT::ValueType
1670 using ValueType =
typename StencilT::ValueType;
1678 const ValueType value = iddx * invScaleSqr[0] + iddy * invScaleSqr[1] + iddz * invScaleSqr[2];
1688 template<
typename MapType, DScheme DiffScheme>
1695 using ValueType =
typename Accessor::ValueType;
1699 ValueType d = grid.getValue(ijk);
1704 Vec3d result = ijk.
asVec3d() - map.applyInverseMap(vectorFromSurface);
1705 return Vec3Type(result);
1708 Vec3d result = map.applyInverseMap(location - vectorFromSurface);
1709 return Vec3Type(result);
1715 result(
const MapType& map,
const StencilT& stencil)
1717 using ValueType =
typename StencilT::ValueType;
1721 ValueType d = stencil.template getValue<0, 0, 0>();
1726 Vec3d result = stencil.getCenterCoord().asVec3d()
1727 - map.applyInverseMap(vectorFromSurface);
1728 return Vec3Type(result);
1730 Vec3d location = map.applyMap(stencil.getCenterCoord().asVec3d());
1731 Vec3d result = map.applyInverseMap(location - vectorFromSurface);
1732 return Vec3Type(result);
1741 template<
typename MapType, DScheme DiffScheme>
1748 using ValueType =
typename Accessor::ValueType;
1751 ValueType d = grid.getValue(ijk);
1754 Vec3Type vectorFromSurface =
1756 Vec3d result = map.applyMap(ijk.
asVec3d()) - vectorFromSurface;
1758 return Vec3Type(result);
1763 result(
const MapType& map,
const StencilT& stencil)
1765 using ValueType =
typename StencilT::ValueType;
1768 ValueType d = stencil.template getValue<0, 0, 0>();
1771 Vec3Type vectorFromSurface =
1773 Vec3d result = map.applyMap(stencil.getCenterCoord().asVec3d()) - vectorFromSurface;
1775 return Vec3Type(result);
1784 template<
typename MapType, DDScheme DiffScheme2, DScheme DiffScheme1>
1791 template<
typename Accessor>
1792 static bool compute(
const MapType& map,
const Accessor& grid,
const Coord& ijk,
1793 double& alpha,
double& beta)
1795 using ValueType =
typename Accessor::ValueType;
1802 d1_ws = map.applyIJT(d1_is);
1804 d1_ws = map.applyIJT(d1_is, ijk.
asVec3d());
1806 const double Dx2 = d1_ws(0)*d1_ws(0);
1807 const double Dy2 = d1_ws(1)*d1_ws(1);
1808 const double Dz2 = d1_ws(2)*d1_ws(2);
1809 const double normGrad = Dx2 + Dy2 + Dz2;
1825 Mat3d d2_is(iddx, iddxy, iddxz,
1827 iddxz, iddyz, iddz);
1832 d2_ws = map.applyIJC(d2_is);
1834 d2_ws = map.applyIJC(d2_is, d1_is, ijk.
asVec3d());
1838 alpha = (Dx2*(d2_ws(1,1)+d2_ws(2,2))+Dy2*(d2_ws(0,0)+d2_ws(2,2))
1839 +Dz2*(d2_ws(0,0)+d2_ws(1,1))
1840 -2*(d1_ws(0)*(d1_ws(1)*d2_ws(0,1)+d1_ws(2)*d2_ws(0,2))
1841 +d1_ws(1)*d1_ws(2)*d2_ws(1,2)));
1842 beta = std::sqrt(normGrad);
1846 template<
typename Accessor>
1847 static typename Accessor::ValueType
result(
const MapType& map,
1848 const Accessor& grid,
const Coord& ijk)
1850 using ValueType =
typename Accessor::ValueType;
1852 return compute(map, grid, ijk, alpha, beta) ?
1856 template<
typename Accessor>
1857 static typename Accessor::ValueType
normGrad(
const MapType& map,
1858 const Accessor& grid,
const Coord& ijk)
1860 using ValueType =
typename Accessor::ValueType;
1862 return compute(map, grid, ijk, alpha, beta) ?
1870 template<
typename StencilT>
1871 static bool compute(
const MapType& map,
const StencilT& stencil,
1872 double& alpha,
double& beta)
1874 using ValueType =
typename StencilT::ValueType;
1881 d1_ws = map.applyIJT(d1_is);
1883 d1_ws = map.applyIJT(d1_is, stencil.getCenterCoord().asVec3d());
1885 const double Dx2 = d1_ws(0)*d1_ws(0);
1886 const double Dy2 = d1_ws(1)*d1_ws(1);
1887 const double Dz2 = d1_ws(2)*d1_ws(2);
1888 const double normGrad = Dx2 + Dy2 + Dz2;
1904 Mat3d d2_is(iddx, iddxy, iddxz,
1906 iddxz, iddyz, iddz);
1911 d2_ws = map.applyIJC(d2_is);
1913 d2_ws = map.applyIJC(d2_is, d1_is, stencil.getCenterCoord().asVec3d());
1917 alpha = (Dx2*(d2_ws(1,1)+d2_ws(2,2))+Dy2*(d2_ws(0,0)+d2_ws(2,2))
1918 +Dz2*(d2_ws(0,0)+d2_ws(1,1))
1919 -2*(d1_ws(0)*(d1_ws(1)*d2_ws(0,1)+d1_ws(2)*d2_ws(0,2))
1920 +d1_ws(1)*d1_ws(2)*d2_ws(1,2)));
1921 beta = std::sqrt(normGrad);
1925 template<
typename StencilT>
1926 static typename StencilT::ValueType
1927 result(
const MapType& map,
const StencilT stencil)
1929 using ValueType =
typename StencilT::ValueType;
1931 return compute(map, stencil, alpha, beta) ?
1935 template<
typename StencilT>
1936 static typename StencilT::ValueType
normGrad(
const MapType& map,
const StencilT stencil)
1938 using ValueType =
typename StencilT::ValueType;
1940 return compute(map, stencil, alpha, beta) ?
1946 template<DDScheme DiffScheme2, DScheme DiffScheme1>
1950 template<
typename Accessor>
1952 const Accessor& grid,
const Coord& ijk)
1954 using ValueType =
typename Accessor::ValueType;
1956 ValueType alpha, beta;
1961 template<
typename Accessor>
1963 const Accessor& grid,
const Coord& ijk)
1965 using ValueType =
typename Accessor::ValueType;
1967 ValueType alpha, beta;
1973 template<
typename StencilT>
1976 using ValueType =
typename StencilT::ValueType;
1978 ValueType alpha, beta;
1983 template<
typename StencilT>
1986 using ValueType =
typename StencilT::ValueType;
1988 ValueType alpha, beta;
1995 template<DDScheme DiffScheme2, DScheme DiffScheme1>
1999 template<
typename Accessor>
2001 const Accessor& grid,
const Coord& ijk)
2003 using ValueType =
typename Accessor::ValueType;
2005 ValueType alpha, beta;
2008 return ValueType(alpha*inv2dx/
math::Pow3(beta));
2013 template<
typename Accessor>
2015 const Accessor& grid,
const Coord& ijk)
2017 using ValueType =
typename Accessor::ValueType;
2019 ValueType alpha, beta;
2022 return ValueType(alpha*invdxdx/(2*
math::Pow2(beta)));
2028 template<
typename StencilT>
2031 using ValueType =
typename StencilT::ValueType;
2033 ValueType alpha, beta;
2036 return ValueType(alpha*inv2dx/
math::Pow3(beta));
2041 template<
typename StencilT>
2044 using ValueType =
typename StencilT::ValueType;
2046 ValueType alpha, beta;
2049 return ValueType(alpha*invdxdx/(2*
math::Pow2(beta)));
2056 template<DDScheme DiffScheme2, DScheme DiffScheme1>
2060 template<
typename Accessor>
static typename Accessor::ValueType
2063 using ValueType =
typename Accessor::ValueType;
2065 ValueType alpha, beta;
2068 return ValueType(alpha*inv2dx/
math::Pow3(beta));
2073 template<
typename Accessor>
static typename Accessor::ValueType
2076 using ValueType =
typename Accessor::ValueType;
2078 ValueType alpha, beta;
2081 return ValueType(alpha*invdxdx/(2*
math::Pow2(beta)));
2087 template<
typename StencilT>
static typename StencilT::ValueType
2090 using ValueType =
typename StencilT::ValueType;
2092 ValueType alpha, beta;
2095 return ValueType(alpha*inv2dx/
math::Pow3(beta));
2100 template<
typename StencilT>
static typename StencilT::ValueType
2103 using ValueType =
typename StencilT::ValueType;
2105 ValueType alpha, beta;
2108 return ValueType(alpha*invdxdx/(2*
math::Pow2(beta)));
2122 template<
typename Gr
idType>
2137 {
return mMap->applyIJC(m,v,pos); }
2153 #endif // OPENVDB_MATH_OPERATORS_HAS_BEEN_INCLUDED