9 #ifndef OPENVDB_TOOLS_GRID_OPERATORS_HAS_BEEN_INCLUDED
10 #define OPENVDB_TOOLS_GRID_OPERATORS_HAS_BEEN_INCLUDED
21 #include <tbb/parallel_for.h>
53 template<
typename Gr
idType,
typename InterruptT>
55 cpt(
const GridType& grid,
bool threaded, InterruptT* interrupt);
57 template<
typename Gr
idType,
typename MaskT,
typename InterruptT>
59 cpt(
const GridType& grid,
const MaskT&
mask,
bool threaded, InterruptT* interrupt);
61 template<
typename Gr
idType>
63 cpt(
const GridType& grid,
bool threaded =
true)
65 return cpt<GridType, util::NullInterrupter>(grid, threaded,
nullptr);
68 template<
typename Gr
idType,
typename MaskT>
69 typename ScalarToVectorConverter<GridType>::Type::Ptr
70 cpt(
const GridType& grid,
const MaskT&
mask,
bool threaded =
true)
72 return cpt<GridType, MaskT, util::NullInterrupter>(grid,
mask, threaded,
nullptr);
81 template<
typename Gr
idType,
typename InterruptT>
82 typename GridType::Ptr
83 curl(
const GridType& grid,
bool threaded, InterruptT* interrupt);
85 template<
typename Gr
idType,
typename MaskT,
typename InterruptT>
86 typename GridType::Ptr
87 curl(
const GridType& grid,
const MaskT&
mask,
bool threaded, InterruptT* interrupt);
89 template<
typename Gr
idType>
90 typename GridType::Ptr
91 curl(
const GridType& grid,
bool threaded =
true)
93 return curl<GridType, util::NullInterrupter>(grid, threaded,
nullptr);
96 template<
typename Gr
idType,
typename MaskT>
97 typename GridType::Ptr
98 curl(
const GridType& grid,
const MaskT&
mask,
bool threaded =
true)
100 return curl<GridType, MaskT, util::NullInterrupter>(grid,
mask, threaded,
nullptr);
110 template<
typename Gr
idType,
typename InterruptT>
111 typename VectorToScalarConverter<GridType>::Type::Ptr
112 divergence(
const GridType& grid,
bool threaded, InterruptT* interrupt);
114 template<
typename Gr
idType,
typename MaskT,
typename InterruptT>
115 typename VectorToScalarConverter<GridType>::Type::Ptr
116 divergence(
const GridType& grid,
const MaskT&
mask,
bool threaded, InterruptT* interrupt);
118 template<
typename Gr
idType>
119 typename VectorToScalarConverter<GridType>::Type::Ptr
122 return divergence<GridType, util::NullInterrupter>(grid, threaded,
nullptr);
125 template<
typename Gr
idType,
typename MaskT>
126 typename VectorToScalarConverter<GridType>::Type::Ptr
129 return divergence<GridType, MaskT, util::NullInterrupter>(grid,
mask, threaded,
nullptr);
139 template<
typename Gr
idType,
typename InterruptT>
140 typename ScalarToVectorConverter<GridType>::Type::Ptr
141 gradient(
const GridType& grid,
bool threaded, InterruptT* interrupt);
143 template<
typename Gr
idType,
typename MaskT,
typename InterruptT>
144 typename ScalarToVectorConverter<GridType>::Type::Ptr
145 gradient(
const GridType& grid,
const MaskT&
mask,
bool threaded, InterruptT* interrupt);
147 template<
typename Gr
idType>
148 typename ScalarToVectorConverter<GridType>::Type::Ptr
149 gradient(
const GridType& grid,
bool threaded =
true)
151 return gradient<GridType, util::NullInterrupter>(grid, threaded,
nullptr);
154 template<
typename Gr
idType,
typename MaskT>
155 typename ScalarToVectorConverter<GridType>::Type::Ptr
156 gradient(
const GridType& grid,
const MaskT&
mask,
bool threaded =
true)
158 return gradient<GridType, MaskT, util::NullInterrupter>(grid,
mask, threaded,
nullptr);
167 template<
typename Gr
idType,
typename InterruptT>
168 typename GridType::Ptr
169 laplacian(
const GridType& grid,
bool threaded, InterruptT* interrupt);
171 template<
typename Gr
idType,
typename MaskT,
typename InterruptT>
172 typename GridType::Ptr
173 laplacian(
const GridType& grid,
const MaskT&
mask,
bool threaded, InterruptT* interrupt);
175 template<
typename Gr
idType>
176 typename GridType::Ptr
179 return laplacian<GridType, util::NullInterrupter>(grid, threaded,
nullptr);
182 template<
typename Gr
idType,
typename MaskT>
183 typename GridType::Ptr
186 return laplacian<GridType, MaskT, util::NullInterrupter>(grid,
mask, threaded,
nullptr);
195 template<
typename Gr
idType,
typename InterruptT>
196 typename GridType::Ptr
197 meanCurvature(
const GridType& grid,
bool threaded, InterruptT* interrupt);
199 template<
typename Gr
idType,
typename MaskT,
typename InterruptT>
200 typename GridType::Ptr
201 meanCurvature(
const GridType& grid,
const MaskT&
mask,
bool threaded, InterruptT* interrupt);
203 template<
typename Gr
idType>
204 typename GridType::Ptr
207 return meanCurvature<GridType, util::NullInterrupter>(grid, threaded,
nullptr);
210 template<
typename Gr
idType,
typename MaskT>
211 typename GridType::Ptr
214 return meanCurvature<GridType, MaskT, util::NullInterrupter>(grid,
mask, threaded,
nullptr);
224 template<
typename Gr
idType,
typename InterruptT>
225 typename VectorToScalarConverter<GridType>::Type::Ptr
226 magnitude(
const GridType& grid,
bool threaded, InterruptT* interrupt);
228 template<
typename Gr
idType,
typename MaskT,
typename InterruptT>
229 typename VectorToScalarConverter<GridType>::Type::Ptr
230 magnitude(
const GridType& grid,
const MaskT&
mask,
bool threaded, InterruptT* interrupt);
232 template<
typename Gr
idType>
233 typename VectorToScalarConverter<GridType>::Type::Ptr
236 return magnitude<GridType, util::NullInterrupter>(grid, threaded,
nullptr);
239 template<
typename Gr
idType,
typename MaskT>
240 typename VectorToScalarConverter<GridType>::Type::Ptr
243 return magnitude<GridType, MaskT, util::NullInterrupter>(grid,
mask, threaded,
nullptr);
252 template<
typename Gr
idType,
typename InterruptT>
253 typename GridType::Ptr
254 normalize(
const GridType& grid,
bool threaded, InterruptT* interrupt);
256 template<
typename Gr
idType,
typename MaskT,
typename InterruptT>
257 typename GridType::Ptr
258 normalize(
const GridType& grid,
const MaskT&
mask,
bool threaded, InterruptT* interrupt);
260 template<
typename Gr
idType>
261 typename GridType::Ptr
264 return normalize<GridType, util::NullInterrupter>(grid, threaded,
nullptr);
267 template<
typename Gr
idType,
typename MaskT>
268 typename GridType::Ptr
271 return normalize<GridType, MaskT, util::NullInterrupter>(grid,
mask, threaded,
nullptr);
283 template<
typename Gr
idType>
296 typename MaskGridType,
309 InterruptT* interrupt =
nullptr,
bool densify =
true)
310 :
mAcc(grid.getConstAccessor())
321 typename OutGridT::Ptr
process(
bool threaded =
true)
326 typename InGridT::TreeType tmp(
mAcc.tree().background());
335 if (
mDensify) tree->voxelizeActiveTiles();
338 typename OutGridT::Ptr
result(
new OutGridT(tree));
342 result->topologyIntersection(*
mMask);
358 using TileIter =
typename OutTreeT::ValueOnIter;
360 TileIter tileIter = tree->beginValueOn();
361 tileIter.setMaxDepth(tileIter.getLeafDepth() - 1);
364 auto tileOp = [
this, inAcc](
const TileIter& it) {
392 for (
typename LeafManagerT::LeafRange::Iterator leaf=range.
begin(); leaf; ++leaf) {
393 for (
typename OutLeafT::ValueOnIter
value=leaf->beginValueOn();
value; ++
value) {
426 mInputGrid(grid), mInterrupt(interrupt), mMask(nullptr)
431 mInputGrid(grid), mInterrupt(interrupt), mMask(&mask)
435 typename OutGridType::Ptr
process(
bool threaded =
true,
bool useWorldTransform =
true)
437 Functor functor(mInputGrid, mMask, threaded, useWorldTransform, mInterrupt);
440 return functor.mOutputGrid;
446 template<
typename MapT,
typename AccT>
447 static typename OutGridType::ValueType
448 result(
const MapT& map,
const AccT& acc,
const Coord& xyz)
455 template<
typename MapT,
typename AccT>
456 static typename OutGridType::ValueType
457 result(
const MapT& map,
const AccT& acc,
const Coord& xyz)
465 bool threaded,
bool worldspace, InterruptT* interrupt)
466 : mThreaded(threaded)
467 , mWorldSpace(worldspace)
469 , mInterrupt(interrupt)
473 template<
typename MapT>
474 void operator()(
const MapT& map)
477 gridop::GridOperator<InGridType, MaskGridType, OutGridType, MapT, WsOpT, InterruptT>
478 op(mInputGrid, mMask, map, mInterrupt,
false);
479 mOutputGrid = op.process(mThreaded);
481 gridop::GridOperator<InGridType, MaskGridType, OutGridType, MapT, IsOpT, InterruptT>
482 op(mInputGrid, mMask, map, mInterrupt,
false);
483 mOutputGrid = op.process(mThreaded);
486 const bool mThreaded;
487 const bool mWorldSpace;
489 typename OutGridType::Ptr mOutputGrid;
490 InterruptT* mInterrupt;
491 const MaskGridType* mMask;
494 InterruptT* mInterrupt;
495 const MaskGridType* mMask;
506 typename InterruptT = util::NullInterrupter>
513 Curl(
const GridT& grid, InterruptT* interrupt =
nullptr):
514 mInputGrid(grid), mInterrupt(interrupt), mMask(nullptr)
518 Curl(
const GridT& grid,
const MaskGridType&
mask, InterruptT* interrupt =
nullptr):
519 mInputGrid(grid), mInterrupt(interrupt), mMask(&mask)
523 typename GridT::Ptr
process(
bool threaded =
true)
525 Functor functor(mInputGrid, mMask, threaded, mInterrupt);
527 if (functor.mOutputGrid) functor.mOutputGrid->setVectorType(
VEC_COVARIANT);
528 return functor.mOutputGrid;
534 Functor(
const GridT& grid,
const MaskGridType*
mask,
535 bool threaded, InterruptT* interrupt):
536 mThreaded(threaded), mInputGrid(grid), mInterrupt(interrupt), mMask(mask) {}
538 template<
typename MapT>
539 void operator()(
const MapT& map)
542 gridop::GridOperator<GridT, MaskGridType, GridT, MapT, OpT, InterruptT>
543 op(mInputGrid, mMask, map, mInterrupt);
544 mOutputGrid = op.process(mThreaded);
547 const bool mThreaded;
548 const GridT& mInputGrid;
549 typename GridT::Ptr mOutputGrid;
550 InterruptT* mInterrupt;
551 const MaskGridType* mMask;
554 const GridT& mInputGrid;
555 InterruptT* mInterrupt;
556 const MaskGridType* mMask;
567 typename InterruptT = util::NullInterrupter>
574 Divergence(
const InGridT& grid, InterruptT* interrupt =
nullptr):
579 Divergence(
const InGridT& grid,
const MaskGridType&
mask, InterruptT* interrupt =
nullptr):
584 typename OutGridType::Ptr
process(
bool threaded =
true)
589 return functor.mOutputGrid;
593 return functor.mOutputGrid;
598 template<math::DScheme DiffScheme>
602 bool threaded, InterruptT* interrupt):
605 template<
typename MapT>
641 Gradient(
const InGridT& grid, InterruptT* interrupt =
nullptr):
646 Gradient(
const InGridT& grid,
const MaskGridType&
mask, InterruptT* interrupt =
nullptr):
651 typename OutGridType::Ptr
process(
bool threaded =
true)
655 if (functor.mOutputGrid) functor.mOutputGrid->setVectorType(
VEC_COVARIANT);
656 return functor.mOutputGrid;
663 bool threaded, InterruptT* interrupt):
666 template<
typename MapT>
701 Laplacian(
const GridT& grid, InterruptT* interrupt =
nullptr):
706 Laplacian(
const GridT& grid,
const MaskGridType&
mask, InterruptT* interrupt =
nullptr):
711 typename GridT::Ptr
process(
bool threaded =
true)
715 if (functor.mOutputGrid) functor.mOutputGrid->setVectorType(
VEC_COVARIANT);
716 return functor.mOutputGrid;
722 Functor(
const GridT& grid,
const MaskGridType*
mask,
bool threaded, InterruptT* interrupt):
725 template<
typename MapT>
770 typename GridT::Ptr
process(
bool threaded =
true)
774 if (functor.mOutputGrid) functor.mOutputGrid->setVectorType(
VEC_COVARIANT);
775 return functor.mOutputGrid;
781 Functor(
const GridT& grid,
const MaskGridType*
mask,
bool threaded, InterruptT* interrupt):
784 template<
typename MapT>
829 typename OutGridType::Ptr
process(
bool threaded =
true)
833 return functor.mOutputGrid;
839 template<
typename MapT,
typename AccT>
840 static typename OutGridType::ValueType
841 result(
const MapT&,
const AccT& acc,
const Coord& xyz) {
return acc.getValue(xyz).length();}
846 bool threaded, InterruptT* interrupt):
849 template<
typename MapT>
883 Normalize(
const GridT& grid, InterruptT* interrupt =
nullptr):
888 Normalize(
const GridT& grid,
const MaskGridType&
mask, InterruptT* interrupt =
nullptr):
893 typename GridT::Ptr
process(
bool threaded =
true)
897 if (
typename GridT::Ptr outGrid = functor.mOutputGrid) {
902 outGrid->setVectorType(vecType);
905 return functor.mOutputGrid;
911 template<
typename MapT,
typename AccT>
912 static typename OutGridType::ValueType
913 result(
const MapT&,
const AccT& acc,
const Coord& xyz)
915 typename OutGridType::ValueType vec = acc.getValue(xyz);
916 if ( !vec.normalize() ) vec.setZero();
922 Functor(
const GridT& grid,
const MaskGridType*
mask,
bool threaded, InterruptT* interrupt):
925 template<
typename MapT>
949 template<
typename Gr
idType,
typename InterruptT>
951 cpt(
const GridType& grid,
bool threaded, InterruptT* interrupt)
957 template<
typename Gr
idType,
typename MaskT,
typename InterruptT>
958 typename ScalarToVectorConverter<GridType>::Type::Ptr
959 cpt(
const GridType& grid,
const MaskT&
mask,
bool threaded, InterruptT* interrupt)
965 template<
typename Gr
idType,
typename InterruptT>
966 typename GridType::Ptr
967 curl(
const GridType& grid,
bool threaded, InterruptT* interrupt)
973 template<
typename Gr
idType,
typename MaskT,
typename InterruptT>
974 typename GridType::Ptr
975 curl(
const GridType& grid,
const MaskT&
mask,
bool threaded, InterruptT* interrupt)
981 template<
typename Gr
idType,
typename InterruptT>
982 typename VectorToScalarConverter<GridType>::Type::Ptr
983 divergence(
const GridType& grid,
bool threaded, InterruptT* interrupt)
990 template<
typename Gr
idType,
typename MaskT,
typename InterruptT>
991 typename VectorToScalarConverter<GridType>::Type::Ptr
992 divergence(
const GridType& grid,
const MaskT&
mask,
bool threaded, InterruptT* interrupt)
998 template<
typename Gr
idType,
typename InterruptT>
999 typename ScalarToVectorConverter<GridType>::Type::Ptr
1000 gradient(
const GridType& grid,
bool threaded, InterruptT* interrupt)
1003 op(grid, interrupt);
1007 template<
typename Gr
idType,
typename MaskT,
typename InterruptT>
1008 typename ScalarToVectorConverter<GridType>::Type::Ptr
1009 gradient(
const GridType& grid,
const MaskT&
mask,
bool threaded, InterruptT* interrupt)
1015 template<
typename Gr
idType,
typename InterruptT>
1016 typename GridType::Ptr
1017 laplacian(
const GridType& grid,
bool threaded, InterruptT* interrupt)
1020 op(grid, interrupt);
1024 template<
typename Gr
idType,
typename MaskT,
typename InterruptT>
1025 typename GridType::Ptr
1026 laplacian(
const GridType& grid,
const MaskT&
mask,
bool threaded, InterruptT* interrupt)
1032 template<
typename Gr
idType,
typename InterruptT>
1033 typename GridType::Ptr
1037 op(grid, interrupt);
1041 template<
typename Gr
idType,
typename MaskT,
typename InterruptT>
1042 typename GridType::Ptr
1049 template<
typename Gr
idType,
typename InterruptT>
1050 typename VectorToScalarConverter<GridType>::Type::Ptr
1051 magnitude(
const GridType& grid,
bool threaded, InterruptT* interrupt)
1054 op(grid, interrupt);
1058 template<
typename Gr
idType,
typename MaskT,
typename InterruptT>
1059 typename VectorToScalarConverter<GridType>::Type::Ptr
1060 magnitude(
const GridType& grid,
const MaskT&
mask,
bool threaded, InterruptT* interrupt)
1066 template<
typename Gr
idType,
typename InterruptT>
1067 typename GridType::Ptr
1068 normalize(
const GridType& grid,
bool threaded, InterruptT* interrupt)
1071 op(grid, interrupt);
1075 template<
typename Gr
idType,
typename MaskT,
typename InterruptT>
1076 typename GridType::Ptr
1077 normalize(
const GridType& grid,
const MaskT&
mask,
bool threaded, InterruptT* interrupt)
1088 #ifdef OPENVDB_USE_EXPLICIT_INSTANTIATION
1090 #ifdef OPENVDB_INSTANTIATE_GRIDOPERATORS
1094 #define _FUNCTION(TreeT) \
1095 ScalarToVectorConverter<Grid<TreeT>>::Type::Ptr cpt(const Grid<TreeT>&, bool, util::NullInterrupter*)
1099 #define _FUNCTION(TreeT) \
1100 ScalarToVectorConverter<Grid<TreeT>>::Type::Ptr cpt(const Grid<TreeT>&, const BoolGrid&, bool, util::NullInterrupter*)
1104 #define _FUNCTION(TreeT) \
1105 Grid<TreeT>::Ptr curl(const Grid<TreeT>&, bool, util::NullInterrupter*)
1109 #define _FUNCTION(TreeT) \
1110 Grid<TreeT>::Ptr curl(const Grid<TreeT>&, const BoolGrid&, bool, util::NullInterrupter*)
1114 #define _FUNCTION(TreeT) \
1115 VectorToScalarConverter<Grid<TreeT>>::Type::Ptr divergence(const Grid<TreeT>&, bool, util::NullInterrupter*)
1119 #define _FUNCTION(TreeT) \
1120 VectorToScalarConverter<Grid<TreeT>>::Type::Ptr divergence(const Grid<TreeT>&, const BoolGrid&, bool, util::NullInterrupter*)
1124 #define _FUNCTION(TreeT) \
1125 ScalarToVectorConverter<Grid<TreeT>>::Type::Ptr gradient(const Grid<TreeT>&, bool, util::NullInterrupter*)
1129 #define _FUNCTION(TreeT) \
1130 ScalarToVectorConverter<Grid<TreeT>>::Type::Ptr gradient(const Grid<TreeT>&, const BoolGrid&, bool, util::NullInterrupter*)
1134 #define _FUNCTION(TreeT) \
1135 Grid<TreeT>::Ptr laplacian(const Grid<TreeT>&, bool, util::NullInterrupter*)
1139 #define _FUNCTION(TreeT) \
1140 Grid<TreeT>::Ptr laplacian(const Grid<TreeT>&, const BoolGrid&, bool, util::NullInterrupter*)
1144 #define _FUNCTION(TreeT) \
1145 Grid<TreeT>::Ptr meanCurvature(const Grid<TreeT>&, bool, util::NullInterrupter*)
1149 #define _FUNCTION(TreeT) \
1150 Grid<TreeT>::Ptr meanCurvature(const Grid<TreeT>&, const BoolGrid&, bool, util::NullInterrupter*)
1154 #define _FUNCTION(TreeT) \
1155 VectorToScalarConverter<Grid<TreeT>>::Type::Ptr magnitude(const Grid<TreeT>&, bool, util::NullInterrupter*)
1159 #define _FUNCTION(TreeT) \
1160 VectorToScalarConverter<Grid<TreeT>>::Type::Ptr magnitude(const Grid<TreeT>&, const BoolGrid&, bool, util::NullInterrupter*)
1164 #define _FUNCTION(TreeT) \
1165 Grid<TreeT>::Ptr normalize(const Grid<TreeT>&, bool, util::NullInterrupter*)
1169 #define _FUNCTION(TreeT) \
1170 Grid<TreeT>::Ptr normalize(const Grid<TreeT>&, const BoolGrid&, bool, util::NullInterrupter*)
1174 #endif // OPENVDB_USE_EXPLICIT_INSTANTIATION
1181 #endif // OPENVDB_TOOLS_GRID_OPERATORS_HAS_BEEN_INCLUDED
void parallel_for(int64_t start, int64_t end, std::function< void(int64_t index)> &&task, parallel_options opt=parallel_options(0, Split_Y, 1))
LeafRange leafRange(size_t grainsize=1) const
Return a TBB-compatible LeafRange.
#define OPENVDB_REAL_TREE_INSTANTIATE(Function)
#define OPENVDB_USE_VERSION_NAMESPACE
Signed (x, y, z) 32-bit integer coordinates.
Base class for interrupters.
Compute the Laplacian at a given location in a grid using finite differencing of various orders...
static math::Vec3< typename Accessor::ValueType > result(const MapType &map, const Accessor &grid, const Coord &ijk)
Compute the mean curvature.
This class manages a linear array of pointers to a given tree's leaf nodes, as well as optional auxil...
Center difference gradient operators, defined with respect to the range-space of the map...
#define OPENVDB_VEC3_TREE_INSTANTIATE(Function)
Container class that associates a tree with a transform and metadata.
Compute the curl of a vector-valued grid using differencing of various orders in the space defined by...
static Vec3< typename Accessor::ValueType > result(const MapType &map, const Accessor &grid, const Coord &ijk)
#define OPENVDB_NUMERIC_TREE_INSTANTIATE(Function)
bool cancelGroupExecution()
GLsizei const GLfloat * value
Tag dispatch class that distinguishes topology copy constructors from deep copy constructors.
A LeafManager manages a linear array of pointers to a given tree's leaf nodes, as well as optional au...
Compute the divergence of a vector-valued grid using differencing of various orders, the result defined with respect to the range-space of the map.
bool wasInterrupted(T *i, int percent=-1)
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
bool processTypedMap(TransformType &transform, OpType &op)
Utility function that, given a generic map pointer, calls a functor on the fully-resoved map...