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>
774 template<
typename StencilT>
794 template<
typename Accessor>
808 template<
typename StencilT>
825 template<
typename MapType, BiasedGradientScheme GradScheme>
832 result(
const MapType& map,
const Accessor& grid,
const Coord& ijk,
835 using ValueType =
typename Accessor::ValueType;
839 return Vec3Type(map.applyIJT(iGradient, ijk.
asVec3d()));
844 result(
const MapType& map,
const StencilT& stencil,
847 using ValueType =
typename StencilT::ValueType;
851 return Vec3Type(map.applyIJT(iGradient, stencil.getCenterCoord().asVec3d()));
860 template<
typename MapType, BiasedGradientScheme GradScheme>
868 template<
typename Accessor>
869 static typename Accessor::ValueType
870 result(
const MapType& map,
const Accessor& grid,
const Coord& ijk)
872 using ValueType =
typename Accessor::ValueType;
881 template<
typename StencilT>
882 static typename StencilT::ValueType
883 result(
const MapType& map,
const StencilT& stencil)
885 using ValueType =
typename StencilT::ValueType;
895 template<BiasedGradientScheme GradScheme>
899 template<
typename Accessor>
900 static typename Accessor::ValueType
903 using ValueType =
typename Accessor::ValueType;
910 template<
typename StencilT>
911 static typename StencilT::ValueType
914 using ValueType =
typename StencilT::ValueType;
922 template<BiasedGradientScheme GradScheme>
926 template<
typename Accessor>
927 static typename Accessor::ValueType
930 using ValueType =
typename Accessor::ValueType;
937 template<
typename StencilT>
938 static typename StencilT::ValueType
941 using ValueType =
typename StencilT::ValueType;
950 template<
typename MapType, DScheme DiffScheme>
956 template<
typename Accessor>
static typename Accessor::ValueType::value_type
957 result(
const MapType& map,
const Accessor& grid,
const Coord& ijk)
959 using ValueType =
typename Accessor::ValueType::value_type;
962 for (
int i=0; i < 3; i++) {
966 div += ValueType(map.applyIJT(vec, ijk.
asVec3d())[i]);
972 template<
typename StencilT>
static typename StencilT::ValueType::value_type
973 result(
const MapType& map,
const StencilT& stencil)
975 using ValueType =
typename StencilT::ValueType::value_type;
978 for (
int i=0; i < 3; i++) {
982 div += ValueType(map.applyIJT(vec, stencil.getCenterCoord().asVec3d())[i]);
990 template<DScheme DiffScheme>
994 template<
typename Accessor>
static typename Accessor::ValueType::value_type
997 using ValueType =
typename Accessor::ValueType::value_type;
1005 template<
typename StencilT>
static typename StencilT::ValueType::value_type
1008 using ValueType =
typename StencilT::ValueType::value_type;
1018 template<DScheme DiffScheme>
1022 template<
typename Accessor>
static typename Accessor::ValueType::value_type
1025 using ValueType =
typename Accessor::ValueType::value_type;
1030 ValueType invdx = ValueType(map.
getInvScale()[0]);
1035 template<
typename StencilT>
static typename StencilT::ValueType::value_type
1038 using ValueType =
typename StencilT::ValueType::value_type;
1043 ValueType invdx = ValueType(map.
getInvScale()[0]);
1050 template<DScheme DiffScheme>
1054 template<
typename Accessor>
static typename Accessor::ValueType::value_type
1057 using ValueType =
typename Accessor::ValueType::value_type;
1062 ValueType invdx = ValueType(map.
getInvScale()[0]);
1067 template<
typename StencilT>
static typename StencilT::ValueType::value_type
1070 using ValueType =
typename StencilT::ValueType::value_type;
1075 ValueType invdx = ValueType(map.
getInvScale()[0]);
1086 template<
typename Accessor>
static typename Accessor::ValueType::value_type
1089 using ValueType =
typename Accessor::ValueType::value_type;
1094 return div * inv2dx;
1098 template<
typename StencilT>
static typename StencilT::ValueType::value_type
1101 using ValueType =
typename StencilT::ValueType::value_type;
1106 return div * inv2dx;
1116 template<
typename Accessor>
static typename Accessor::ValueType::value_type
1119 using ValueType =
typename Accessor::ValueType::value_type;
1125 return div * inv2dx;
1129 template<
typename StencilT>
static typename StencilT::ValueType::value_type
1132 using ValueType =
typename StencilT::ValueType::value_type;
1138 return div * inv2dx;
1144 template<DScheme DiffScheme>
1148 template<
typename Accessor>
static typename Accessor::ValueType::value_type
1151 using ValueType =
typename Accessor::ValueType::value_type;
1153 ValueType div = ValueType(
1161 template<
typename StencilT>
static typename StencilT::ValueType::value_type
1164 using ValueType =
typename StencilT::ValueType::value_type;
1177 template<DScheme DiffScheme>
1181 template<
typename Accessor>
static typename Accessor::ValueType::value_type
1184 using ValueType =
typename Accessor::ValueType::value_type;
1186 ValueType div = ValueType(
1194 template<
typename StencilT>
static typename StencilT::ValueType::value_type
1197 using ValueType =
typename StencilT::ValueType::value_type;
1214 template<
typename Accessor>
static typename Accessor::ValueType::value_type
1217 using ValueType =
typename Accessor::ValueType::value_type;
1219 ValueType div = ValueType(
1227 template<
typename StencilT>
static typename StencilT::ValueType::value_type
1230 using ValueType =
typename StencilT::ValueType::value_type;
1232 ValueType div = ValueType(
1246 template<
typename Accessor>
static typename Accessor::ValueType::value_type
1249 using ValueType =
typename Accessor::ValueType::value_type;
1251 ValueType div = ValueType(
1259 template<
typename StencilT>
static typename StencilT::ValueType::value_type
1262 using ValueType =
typename StencilT::ValueType::value_type;
1264 ValueType div = ValueType(
1275 template<
typename MapType, DScheme DiffScheme>
1281 template<
typename Accessor>
static typename Accessor::ValueType
1284 using Vec3Type =
typename Accessor::ValueType;
1286 for (
int i = 0; i < 3; i++) {
1292 mat[i] = Vec3Type(map.applyIJT(vec, ijk.
asVec3d()));
1294 return Vec3Type(mat[2][1] - mat[1][2],
1295 mat[0][2] - mat[2][0],
1296 mat[1][0] - mat[0][1]);
1300 template<
typename StencilT>
static typename StencilT::ValueType
1301 result(
const MapType& map,
const StencilT& stencil)
1303 using Vec3Type =
typename StencilT::ValueType;
1305 for (
int i = 0; i < 3; i++) {
1311 mat[i] = Vec3Type(map.applyIJT(vec, stencil.getCenterCoord().asVec3d()));
1313 return Vec3Type(mat[2][1] - mat[1][2],
1314 mat[0][2] - mat[2][0],
1315 mat[1][0] - mat[0][1]);
1320 template<DScheme DiffScheme>
1324 template<
typename Accessor>
static typename Accessor::ValueType
1327 using Vec3Type =
typename Accessor::ValueType;
1328 using ValueType =
typename Vec3Type::value_type;
1333 template<
typename StencilT>
static typename StencilT::ValueType
1336 using Vec3Type =
typename StencilT::ValueType;
1337 using ValueType =
typename Vec3Type::value_type;
1343 template<DScheme DiffScheme>
1347 template<
typename Accessor>
static typename Accessor::ValueType
1350 using Vec3Type =
typename Accessor::ValueType;
1351 using ValueType =
typename Vec3Type::value_type;
1357 template<
typename StencilT>
static typename StencilT::ValueType
1360 using Vec3Type =
typename StencilT::ValueType;
1361 using ValueType =
typename Vec3Type::value_type;
1372 template<
typename Accessor>
static typename Accessor::ValueType
1375 using Vec3Type =
typename Accessor::ValueType;
1376 using ValueType =
typename Vec3Type::value_type;
1382 template<
typename StencilT>
static typename StencilT::ValueType
1385 using Vec3Type =
typename StencilT::ValueType;
1386 using ValueType =
typename Vec3Type::value_type;
1397 template<
typename Accessor>
static typename Accessor::ValueType
1400 using Vec3Type =
typename Accessor::ValueType;
1401 using ValueType =
typename Vec3Type::value_type;
1407 template<
typename StencilT>
static typename StencilT::ValueType
1410 using Vec3Type =
typename StencilT::ValueType;
1411 using ValueType =
typename Vec3Type::value_type;
1420 template<
typename MapType, DDScheme DiffScheme>
1426 template<
typename Accessor>
1427 static typename Accessor::ValueType
result(
const MapType& map,
1428 const Accessor& grid,
const Coord& ijk)
1430 using ValueType =
typename Accessor::ValueType;
1441 Mat3d d2_is(iddx, iddxy, iddxz,
1443 iddxz, iddyz, iddz);
1447 d2_rs = map.applyIJC(d2_is);
1454 d2_rs = map.applyIJC(d2_is, d1_is, ijk.
asVec3d());
1458 return ValueType(d2_rs(0,0) + d2_rs(1,1) + d2_rs(2,2));
1462 template<
typename StencilT>
1463 static typename StencilT::ValueType
result(
const MapType& map,
const StencilT& stencil)
1465 using ValueType =
typename StencilT::ValueType;
1476 Mat3d d2_is(iddx, iddxy, iddxz,
1478 iddxz, iddyz, iddz);
1482 d2_rs = map.applyIJC(d2_is);
1489 d2_rs = map.applyIJC(d2_is, d1_is, stencil.getCenterCoord().asVec3d());
1493 return ValueType(d2_rs(0,0) + d2_rs(1,1) + d2_rs(2,2));
1498 template<DDScheme DiffScheme>
1502 template<
typename Accessor>
1504 const Accessor& grid,
const Coord& ijk)
1510 template<
typename StencilT>
1519 template<DDScheme DiffScheme>
1523 template<
typename Accessor>
1525 const Accessor& grid,
const Coord& ijk)
1531 template<
typename StencilT>
1539 template<DDScheme DiffScheme>
1543 template<
typename Accessor>
static typename Accessor::ValueType
1546 using ValueType =
typename Accessor::ValueType;
1552 template<
typename StencilT>
static typename StencilT::ValueType
1555 using ValueType =
typename StencilT::ValueType;
1562 template<DDScheme DiffScheme>
1566 template<
typename Accessor>
static typename Accessor::ValueType
1569 using ValueType =
typename Accessor::ValueType;
1575 template<
typename StencilT>
static typename StencilT::ValueType
1578 using ValueType =
typename StencilT::ValueType;
1585 template<DDScheme DiffScheme>
1589 template<
typename Accessor>
static typename Accessor::ValueType
1592 using ValueType =
typename Accessor::ValueType;
1600 return ValueType(iddx * invScaleSqr[0] + iddy * invScaleSqr[1] + iddz * invScaleSqr[2]);
1604 template<
typename StencilT>
static typename StencilT::ValueType
1607 using ValueType =
typename StencilT::ValueType;
1615 return ValueType(iddx * invScaleSqr[0] + iddy * invScaleSqr[1] + iddz * invScaleSqr[2]);
1620 template<DDScheme DiffScheme>
1624 template<
typename Accessor>
static typename Accessor::ValueType
1627 using ValueType =
typename Accessor::ValueType;
1634 return ValueType(iddx * invScaleSqr[0] + iddy * invScaleSqr[1] + iddz * invScaleSqr[2]);
1638 template<
typename StencilT>
static typename StencilT::ValueType
1641 using ValueType =
typename StencilT::ValueType;
1648 return ValueType(iddx * invScaleSqr[0] + iddy * invScaleSqr[1] + iddz * invScaleSqr[2]);
1656 template<
typename MapType, DScheme DiffScheme>
1663 using ValueType =
typename Accessor::ValueType;
1667 ValueType d = grid.getValue(ijk);
1672 Vec3d result = ijk.
asVec3d() - map.applyInverseMap(vectorFromSurface);
1673 return Vec3Type(result);
1676 Vec3d result = map.applyInverseMap(location - vectorFromSurface);
1677 return Vec3Type(result);
1683 result(
const MapType& map,
const StencilT& stencil)
1685 using ValueType =
typename StencilT::ValueType;
1689 ValueType d = stencil.template getValue<0, 0, 0>();
1694 Vec3d result = stencil.getCenterCoord().asVec3d()
1695 - map.applyInverseMap(vectorFromSurface);
1696 return Vec3Type(result);
1698 Vec3d location = map.applyMap(stencil.getCenterCoord().asVec3d());
1699 Vec3d result = map.applyInverseMap(location - vectorFromSurface);
1700 return Vec3Type(result);
1709 template<
typename MapType, DScheme DiffScheme>
1716 using ValueType =
typename Accessor::ValueType;
1719 ValueType d = grid.getValue(ijk);
1722 Vec3Type vectorFromSurface =
1724 Vec3d result = map.applyMap(ijk.
asVec3d()) - vectorFromSurface;
1726 return Vec3Type(result);
1731 result(
const MapType& map,
const StencilT& stencil)
1733 using ValueType =
typename StencilT::ValueType;
1736 ValueType d = stencil.template getValue<0, 0, 0>();
1739 Vec3Type vectorFromSurface =
1741 Vec3d result = map.applyMap(stencil.getCenterCoord().asVec3d()) - vectorFromSurface;
1743 return Vec3Type(result);
1752 template<
typename MapType, DDScheme DiffScheme2, DScheme DiffScheme1>
1759 template<
typename Accessor>
1760 static bool compute(
const MapType& map,
const Accessor& grid,
const Coord& ijk,
1761 double& alpha,
double& beta)
1763 using ValueType =
typename Accessor::ValueType;
1770 d1_ws = map.applyIJT(d1_is);
1772 d1_ws = map.applyIJT(d1_is, ijk.
asVec3d());
1774 const double Dx2 = d1_ws(0)*d1_ws(0);
1775 const double Dy2 = d1_ws(1)*d1_ws(1);
1776 const double Dz2 = d1_ws(2)*d1_ws(2);
1777 const double normGrad = Dx2 + Dy2 + Dz2;
1793 Mat3d d2_is(iddx, iddxy, iddxz,
1795 iddxz, iddyz, iddz);
1800 d2_ws = map.applyIJC(d2_is);
1802 d2_ws = map.applyIJC(d2_is, d1_is, ijk.
asVec3d());
1806 alpha = (Dx2*(d2_ws(1,1)+d2_ws(2,2))+Dy2*(d2_ws(0,0)+d2_ws(2,2))
1807 +Dz2*(d2_ws(0,0)+d2_ws(1,1))
1808 -2*(d1_ws(0)*(d1_ws(1)*d2_ws(0,1)+d1_ws(2)*d2_ws(0,2))
1809 +d1_ws(1)*d1_ws(2)*d2_ws(1,2)));
1810 beta = std::sqrt(normGrad);
1814 template<
typename Accessor>
1815 static typename Accessor::ValueType
result(
const MapType& map,
1816 const Accessor& grid,
const Coord& ijk)
1818 using ValueType =
typename Accessor::ValueType;
1820 return compute(map, grid, ijk, alpha, beta) ?
1824 template<
typename Accessor>
1825 static typename Accessor::ValueType
normGrad(
const MapType& map,
1826 const Accessor& grid,
const Coord& ijk)
1828 using ValueType =
typename Accessor::ValueType;
1830 return compute(map, grid, ijk, alpha, beta) ?
1838 template<
typename StencilT>
1839 static bool compute(
const MapType& map,
const StencilT& stencil,
1840 double& alpha,
double& beta)
1842 using ValueType =
typename StencilT::ValueType;
1849 d1_ws = map.applyIJT(d1_is);
1851 d1_ws = map.applyIJT(d1_is, stencil.getCenterCoord().asVec3d());
1853 const double Dx2 = d1_ws(0)*d1_ws(0);
1854 const double Dy2 = d1_ws(1)*d1_ws(1);
1855 const double Dz2 = d1_ws(2)*d1_ws(2);
1856 const double normGrad = Dx2 + Dy2 + Dz2;
1872 Mat3d d2_is(iddx, iddxy, iddxz,
1874 iddxz, iddyz, iddz);
1879 d2_ws = map.applyIJC(d2_is);
1881 d2_ws = map.applyIJC(d2_is, d1_is, stencil.getCenterCoord().asVec3d());
1885 alpha = (Dx2*(d2_ws(1,1)+d2_ws(2,2))+Dy2*(d2_ws(0,0)+d2_ws(2,2))
1886 +Dz2*(d2_ws(0,0)+d2_ws(1,1))
1887 -2*(d1_ws(0)*(d1_ws(1)*d2_ws(0,1)+d1_ws(2)*d2_ws(0,2))
1888 +d1_ws(1)*d1_ws(2)*d2_ws(1,2)));
1889 beta = std::sqrt(normGrad);
1893 template<
typename StencilT>
1894 static typename StencilT::ValueType
1895 result(
const MapType& map,
const StencilT stencil)
1897 using ValueType =
typename StencilT::ValueType;
1899 return compute(map, stencil, alpha, beta) ?
1903 template<
typename StencilT>
1904 static typename StencilT::ValueType
normGrad(
const MapType& map,
const StencilT stencil)
1906 using ValueType =
typename StencilT::ValueType;
1908 return compute(map, stencil, alpha, beta) ?
1914 template<DDScheme DiffScheme2, DScheme DiffScheme1>
1918 template<
typename Accessor>
1920 const Accessor& grid,
const Coord& ijk)
1922 using ValueType =
typename Accessor::ValueType;
1924 ValueType alpha, beta;
1929 template<
typename Accessor>
1931 const Accessor& grid,
const Coord& ijk)
1933 using ValueType =
typename Accessor::ValueType;
1935 ValueType alpha, beta;
1941 template<
typename StencilT>
1944 using ValueType =
typename StencilT::ValueType;
1946 ValueType alpha, beta;
1951 template<
typename StencilT>
1954 using ValueType =
typename StencilT::ValueType;
1956 ValueType alpha, beta;
1963 template<DDScheme DiffScheme2, DScheme DiffScheme1>
1967 template<
typename Accessor>
1969 const Accessor& grid,
const Coord& ijk)
1971 using ValueType =
typename Accessor::ValueType;
1973 ValueType alpha, beta;
1976 return ValueType(alpha*inv2dx/
math::Pow3(beta));
1981 template<
typename Accessor>
1983 const Accessor& grid,
const Coord& ijk)
1985 using ValueType =
typename Accessor::ValueType;
1987 ValueType alpha, beta;
1990 return ValueType(alpha*invdxdx/(2*
math::Pow2(beta)));
1996 template<
typename StencilT>
1999 using ValueType =
typename StencilT::ValueType;
2001 ValueType alpha, beta;
2004 return ValueType(alpha*inv2dx/
math::Pow3(beta));
2009 template<
typename StencilT>
2012 using ValueType =
typename StencilT::ValueType;
2014 ValueType alpha, beta;
2017 return ValueType(alpha*invdxdx/(2*
math::Pow2(beta)));
2024 template<DDScheme DiffScheme2, DScheme DiffScheme1>
2028 template<
typename Accessor>
static typename Accessor::ValueType
2031 using ValueType =
typename Accessor::ValueType;
2033 ValueType alpha, beta;
2036 return ValueType(alpha*inv2dx/
math::Pow3(beta));
2041 template<
typename Accessor>
static typename Accessor::ValueType
2044 using ValueType =
typename Accessor::ValueType;
2046 ValueType alpha, beta;
2049 return ValueType(alpha*invdxdx/(2*
math::Pow2(beta)));
2055 template<
typename StencilT>
static typename StencilT::ValueType
2058 using ValueType =
typename StencilT::ValueType;
2060 ValueType alpha, beta;
2063 return ValueType(alpha*inv2dx/
math::Pow3(beta));
2068 template<
typename StencilT>
static typename StencilT::ValueType
2071 using ValueType =
typename StencilT::ValueType;
2073 ValueType alpha, beta;
2076 return ValueType(alpha*invdxdx/(2*
math::Pow2(beta)));
2090 template<
typename Gr
idType>
2105 {
return mMap->applyIJC(m,v,pos); }
2121 #endif // OPENVDB_MATH_OPERATORS_HAS_BEEN_INCLUDED