9 #ifndef OPENVDB_TOOLS_GRID_OPERATORS_HAS_BEEN_INCLUDED
10 #define OPENVDB_TOOLS_GRID_OPERATORS_HAS_BEEN_INCLUDED
22 #include <tbb/parallel_for.h>
54 template<
typename Gr
idType,
typename InterruptT>
56 cpt(
const GridType& grid,
bool threaded, InterruptT* interrupt);
58 template<
typename Gr
idType,
typename MaskT,
typename InterruptT>
60 cpt(
const GridType& grid,
const MaskT&
mask,
bool threaded, InterruptT* interrupt);
62 template<
typename Gr
idType>
66 return cpt<GridType, util::NullInterrupter>(grid, threaded,
nullptr);
69 template<
typename Gr
idType,
typename MaskT>
70 typename ScalarToVectorConverter<GridType>::Type::Ptr
73 return cpt<GridType, MaskT, util::NullInterrupter>(grid,
mask, threaded,
nullptr);
82 template<
typename Gr
idType,
typename InterruptT>
83 typename GridType::Ptr
84 curl(
const GridType& grid,
bool threaded, InterruptT* interrupt);
86 template<
typename Gr
idType,
typename MaskT,
typename InterruptT>
87 typename GridType::Ptr
88 curl(
const GridType& grid,
const MaskT&
mask,
bool threaded, InterruptT* interrupt);
90 template<
typename Gr
idType>
91 typename GridType::Ptr
94 return curl<GridType, util::NullInterrupter>(grid, threaded,
nullptr);
97 template<
typename Gr
idType,
typename MaskT>
98 typename GridType::Ptr
101 return curl<GridType, MaskT, util::NullInterrupter>(grid,
mask, threaded,
nullptr);
111 template<
typename Gr
idType,
typename InterruptT>
112 typename VectorToScalarConverter<GridType>::Type::Ptr
115 template<
typename Gr
idType,
typename MaskT,
typename InterruptT>
116 typename VectorToScalarConverter<GridType>::Type::Ptr
119 template<
typename Gr
idType>
120 typename VectorToScalarConverter<GridType>::Type::Ptr
123 return divergence<GridType, util::NullInterrupter>(grid, threaded,
nullptr);
126 template<
typename Gr
idType,
typename MaskT>
127 typename VectorToScalarConverter<GridType>::Type::Ptr
130 return divergence<GridType, MaskT, util::NullInterrupter>(grid,
mask, threaded,
nullptr);
140 template<
typename Gr
idType,
typename InterruptT>
141 typename ScalarToVectorConverter<GridType>::Type::Ptr
144 template<
typename Gr
idType,
typename MaskT,
typename InterruptT>
145 typename ScalarToVectorConverter<GridType>::Type::Ptr
148 template<
typename Gr
idType>
149 typename ScalarToVectorConverter<GridType>::Type::Ptr
152 return gradient<GridType, util::NullInterrupter>(grid, threaded,
nullptr);
155 template<
typename Gr
idType,
typename MaskT>
156 typename ScalarToVectorConverter<GridType>::Type::Ptr
159 return gradient<GridType, MaskT, util::NullInterrupter>(grid,
mask, threaded,
nullptr);
168 template<
typename Gr
idType,
typename InterruptT>
169 typename GridType::Ptr
172 template<
typename Gr
idType,
typename MaskT,
typename InterruptT>
173 typename GridType::Ptr
176 template<
typename Gr
idType>
177 typename GridType::Ptr
180 return laplacian<GridType, util::NullInterrupter>(grid, threaded,
nullptr);
183 template<
typename Gr
idType,
typename MaskT>
184 typename GridType::Ptr
187 return laplacian<GridType, MaskT, util::NullInterrupter>(grid,
mask, threaded,
nullptr);
196 template<
typename Gr
idType,
typename InterruptT>
197 typename GridType::Ptr
200 template<
typename Gr
idType,
typename MaskT,
typename InterruptT>
201 typename GridType::Ptr
204 template<
typename Gr
idType>
205 typename GridType::Ptr
208 return meanCurvature<GridType, util::NullInterrupter>(grid, threaded,
nullptr);
211 template<
typename Gr
idType,
typename MaskT>
212 typename GridType::Ptr
215 return meanCurvature<GridType, MaskT, util::NullInterrupter>(grid,
mask, threaded,
nullptr);
225 template<
typename Gr
idType,
typename InterruptT>
226 typename VectorToScalarConverter<GridType>::Type::Ptr
229 template<
typename Gr
idType,
typename MaskT,
typename InterruptT>
230 typename VectorToScalarConverter<GridType>::Type::Ptr
233 template<
typename Gr
idType>
234 typename VectorToScalarConverter<GridType>::Type::Ptr
237 return magnitude<GridType, util::NullInterrupter>(grid, threaded,
nullptr);
240 template<
typename Gr
idType,
typename MaskT>
241 typename VectorToScalarConverter<GridType>::Type::Ptr
244 return magnitude<GridType, MaskT, util::NullInterrupter>(grid,
mask, threaded,
nullptr);
253 template<
typename Gr
idType,
typename InterruptT>
254 typename GridType::Ptr
257 template<
typename Gr
idType,
typename MaskT,
typename InterruptT>
258 typename GridType::Ptr
261 template<
typename Gr
idType>
262 typename GridType::Ptr
265 return normalize<GridType, util::NullInterrupter>(grid, threaded,
nullptr);
268 template<
typename Gr
idType,
typename MaskT>
269 typename GridType::Ptr
272 return normalize<GridType, MaskT, util::NullInterrupter>(grid,
mask, threaded,
nullptr);
284 template<
typename Gr
idType>
297 typename MaskGridType,
310 InterruptT* interrupt =
nullptr,
bool densify =
true)
311 :
mAcc(grid.getConstAccessor())
322 typename OutGridT::Ptr
process(
bool threaded =
true)
327 typename InGridT::TreeType tmp(
mAcc.tree().background());
336 if (
mDensify) tree->voxelizeActiveTiles();
339 typename OutGridT::Ptr
result(
new OutGridT(tree));
343 result->topologyIntersection(*
mMask);
359 using TileIter =
typename OutTreeT::ValueOnIter;
361 TileIter tileIter = tree->beginValueOn();
362 tileIter.setMaxDepth(tileIter.getLeafDepth() - 1);
365 auto tileOp = [
this, inAcc](
const TileIter& it) {
390 thread::cancelGroupExecution();
393 for (
typename LeafManagerT::LeafRange::Iterator leaf=range.
begin(); leaf; ++leaf) {
394 for (
typename OutLeafT::ValueOnIter
value=leaf->beginValueOn();
value; ++
value) {
427 mInputGrid(grid), mInterrupt(interrupt), mMask(nullptr)
432 mInputGrid(grid), mInterrupt(interrupt), mMask(&mask)
436 typename OutGridType::Ptr
process(
bool threaded =
true,
bool useWorldTransform =
true)
438 Functor functor(mInputGrid, mMask, threaded, useWorldTransform, mInterrupt);
441 return functor.mOutputGrid;
447 template<
typename MapT,
typename AccT>
449 result(
const MapT& map,
const AccT& acc,
const Coord& xyz)
456 template<
typename MapT,
typename AccT>
458 result(
const MapT& map,
const AccT& acc,
const Coord& xyz)
466 bool threaded,
bool worldspace, InterruptT* interrupt)
467 : mThreaded(threaded)
468 , mWorldSpace(worldspace)
470 , mInterrupt(interrupt)
474 template<
typename MapT>
475 void operator()(
const MapT& map)
478 gridop::GridOperator<InGridType, MaskGridType, OutGridType, MapT, WsOpT, InterruptT>
479 op(mInputGrid, mMask, map, mInterrupt,
false);
480 mOutputGrid = op.process(mThreaded);
482 gridop::GridOperator<InGridType, MaskGridType, OutGridType, MapT, IsOpT, InterruptT>
483 op(mInputGrid, mMask, map, mInterrupt,
false);
484 mOutputGrid = op.process(mThreaded);
487 const bool mThreaded;
488 const bool mWorldSpace;
490 typename OutGridType::Ptr mOutputGrid;
491 InterruptT* mInterrupt;
492 const MaskGridType*
mMask;
495 InterruptT* mInterrupt;
496 const MaskGridType* mMask;
507 typename InterruptT = util::NullInterrupter>
514 Curl(
const GridT& grid, InterruptT* interrupt =
nullptr):
515 mInputGrid(grid), mInterrupt(interrupt), mMask(nullptr)
519 Curl(
const GridT& grid,
const MaskGridType&
mask, InterruptT* interrupt =
nullptr):
520 mInputGrid(grid), mInterrupt(interrupt), mMask(&mask)
524 typename GridT::Ptr
process(
bool threaded =
true)
526 Functor functor(mInputGrid, mMask, threaded, mInterrupt);
528 if (functor.mOutputGrid) functor.mOutputGrid->setVectorType(
VEC_COVARIANT);
529 return functor.mOutputGrid;
535 Functor(
const GridT& grid,
const MaskGridType*
mask,
536 bool threaded, InterruptT* interrupt):
537 mThreaded(threaded), mInputGrid(grid), mInterrupt(interrupt), mMask(mask) {}
539 template<
typename MapT>
540 void operator()(
const MapT& map)
543 gridop::GridOperator<GridT, MaskGridType, GridT, MapT, OpT, InterruptT>
544 op(mInputGrid, mMask, map, mInterrupt);
545 mOutputGrid = op.process(mThreaded);
548 const bool mThreaded;
549 const GridT& mInputGrid;
550 typename GridT::Ptr mOutputGrid;
551 InterruptT* mInterrupt;
552 const MaskGridType* mMask;
555 const GridT& mInputGrid;
556 InterruptT* mInterrupt;
557 const MaskGridType* mMask;
568 typename InterruptT = util::NullInterrupter>
575 Divergence(
const InGridT& grid, InterruptT* interrupt =
nullptr):
580 Divergence(
const InGridT& grid,
const MaskGridType&
mask, InterruptT* interrupt =
nullptr):
585 typename OutGridType::Ptr
process(
bool threaded =
true)
590 return functor.mOutputGrid;
594 return functor.mOutputGrid;
599 template<math::DScheme DiffScheme>
603 bool threaded, InterruptT* interrupt):
606 template<
typename MapT>
642 Gradient(
const InGridT& grid, InterruptT* interrupt =
nullptr):
647 Gradient(
const InGridT& grid,
const MaskGridType&
mask, InterruptT* interrupt =
nullptr):
652 typename OutGridType::Ptr
process(
bool threaded =
true)
656 if (functor.mOutputGrid) functor.mOutputGrid->setVectorType(
VEC_COVARIANT);
657 return functor.mOutputGrid;
664 bool threaded, InterruptT* interrupt):
667 template<
typename MapT>
702 Laplacian(
const GridT& grid, InterruptT* interrupt =
nullptr):
707 Laplacian(
const GridT& grid,
const MaskGridType&
mask, InterruptT* interrupt =
nullptr):
712 typename GridT::Ptr
process(
bool threaded =
true)
716 if (functor.mOutputGrid) functor.mOutputGrid->setVectorType(
VEC_COVARIANT);
717 return functor.mOutputGrid;
723 Functor(
const GridT& grid,
const MaskGridType*
mask,
bool threaded, InterruptT* interrupt):
726 template<
typename MapT>
771 typename GridT::Ptr
process(
bool threaded =
true)
775 if (functor.mOutputGrid) functor.mOutputGrid->setVectorType(
VEC_COVARIANT);
776 return functor.mOutputGrid;
782 Functor(
const GridT& grid,
const MaskGridType*
mask,
bool threaded, InterruptT* interrupt):
785 template<
typename MapT>
830 typename OutGridType::Ptr
process(
bool threaded =
true)
834 return functor.mOutputGrid;
840 template<
typename MapT,
typename AccT>
842 result(
const MapT&,
const AccT& acc,
const Coord& xyz) {
return acc.getValue(xyz).length();}
847 bool threaded, InterruptT* interrupt):
850 template<
typename MapT>
884 Normalize(
const GridT& grid, InterruptT* interrupt =
nullptr):
889 Normalize(
const GridT& grid,
const MaskGridType&
mask, InterruptT* interrupt =
nullptr):
894 typename GridT::Ptr
process(
bool threaded =
true)
898 if (
typename GridT::Ptr outGrid = functor.mOutputGrid) {
903 outGrid->setVectorType(vecType);
906 return functor.mOutputGrid;
912 template<
typename MapT,
typename AccT>
914 result(
const MapT&,
const AccT& acc,
const Coord& xyz)
917 if ( !vec.normalize() ) vec.setZero();
923 Functor(
const GridT& grid,
const MaskGridType*
mask,
bool threaded, InterruptT* interrupt):
926 template<
typename MapT>
950 template<
typename Gr
idType,
typename InterruptT>
958 template<
typename Gr
idType,
typename MaskT,
typename InterruptT>
959 typename ScalarToVectorConverter<GridType>::Type::Ptr
966 template<
typename Gr
idType,
typename InterruptT>
967 typename GridType::Ptr
974 template<
typename Gr
idType,
typename MaskT,
typename InterruptT>
975 typename GridType::Ptr
982 template<
typename Gr
idType,
typename InterruptT>
983 typename VectorToScalarConverter<GridType>::Type::Ptr
991 template<
typename Gr
idType,
typename MaskT,
typename InterruptT>
992 typename VectorToScalarConverter<GridType>::Type::Ptr
999 template<
typename Gr
idType,
typename InterruptT>
1000 typename ScalarToVectorConverter<GridType>::Type::Ptr
1004 op(grid, interrupt);
1008 template<
typename Gr
idType,
typename MaskT,
typename InterruptT>
1009 typename ScalarToVectorConverter<GridType>::Type::Ptr
1016 template<
typename Gr
idType,
typename InterruptT>
1017 typename GridType::Ptr
1021 op(grid, interrupt);
1025 template<
typename Gr
idType,
typename MaskT,
typename InterruptT>
1026 typename GridType::Ptr
1033 template<
typename Gr
idType,
typename InterruptT>
1034 typename GridType::Ptr
1038 op(grid, interrupt);
1042 template<
typename Gr
idType,
typename MaskT,
typename InterruptT>
1043 typename GridType::Ptr
1050 template<
typename Gr
idType,
typename InterruptT>
1051 typename VectorToScalarConverter<GridType>::Type::Ptr
1055 op(grid, interrupt);
1059 template<
typename Gr
idType,
typename MaskT,
typename InterruptT>
1060 typename VectorToScalarConverter<GridType>::Type::Ptr
1067 template<
typename Gr
idType,
typename InterruptT>
1068 typename GridType::Ptr
1072 op(grid, interrupt);
1076 template<
typename Gr
idType,
typename MaskT,
typename InterruptT>
1077 typename GridType::Ptr
1089 #ifdef OPENVDB_USE_EXPLICIT_INSTANTIATION
1091 #ifdef OPENVDB_INSTANTIATE_GRIDOPERATORS
1095 #define _FUNCTION(TreeT) \
1096 ScalarToVectorConverter<Grid<TreeT>>::Type::Ptr cpt(const Grid<TreeT>&, bool, util::NullInterrupter*)
1100 #define _FUNCTION(TreeT) \
1101 ScalarToVectorConverter<Grid<TreeT>>::Type::Ptr cpt(const Grid<TreeT>&, const BoolGrid&, bool, util::NullInterrupter*)
1105 #define _FUNCTION(TreeT) \
1106 Grid<TreeT>::Ptr curl(const Grid<TreeT>&, bool, util::NullInterrupter*)
1110 #define _FUNCTION(TreeT) \
1111 Grid<TreeT>::Ptr curl(const Grid<TreeT>&, const BoolGrid&, bool, util::NullInterrupter*)
1115 #define _FUNCTION(TreeT) \
1116 VectorToScalarConverter<Grid<TreeT>>::Type::Ptr divergence(const Grid<TreeT>&, bool, util::NullInterrupter*)
1120 #define _FUNCTION(TreeT) \
1121 VectorToScalarConverter<Grid<TreeT>>::Type::Ptr divergence(const Grid<TreeT>&, const BoolGrid&, bool, util::NullInterrupter*)
1125 #define _FUNCTION(TreeT) \
1126 ScalarToVectorConverter<Grid<TreeT>>::Type::Ptr gradient(const Grid<TreeT>&, bool, util::NullInterrupter*)
1130 #define _FUNCTION(TreeT) \
1131 ScalarToVectorConverter<Grid<TreeT>>::Type::Ptr gradient(const Grid<TreeT>&, const BoolGrid&, bool, util::NullInterrupter*)
1135 #define _FUNCTION(TreeT) \
1136 Grid<TreeT>::Ptr laplacian(const Grid<TreeT>&, bool, util::NullInterrupter*)
1140 #define _FUNCTION(TreeT) \
1141 Grid<TreeT>::Ptr laplacian(const Grid<TreeT>&, const BoolGrid&, bool, util::NullInterrupter*)
1145 #define _FUNCTION(TreeT) \
1146 Grid<TreeT>::Ptr meanCurvature(const Grid<TreeT>&, bool, util::NullInterrupter*)
1150 #define _FUNCTION(TreeT) \
1151 Grid<TreeT>::Ptr meanCurvature(const Grid<TreeT>&, const BoolGrid&, bool, util::NullInterrupter*)
1155 #define _FUNCTION(TreeT) \
1156 VectorToScalarConverter<Grid<TreeT>>::Type::Ptr magnitude(const Grid<TreeT>&, bool, util::NullInterrupter*)
1160 #define _FUNCTION(TreeT) \
1161 VectorToScalarConverter<Grid<TreeT>>::Type::Ptr magnitude(const Grid<TreeT>&, const BoolGrid&, bool, util::NullInterrupter*)
1165 #define _FUNCTION(TreeT) \
1166 Grid<TreeT>::Ptr normalize(const Grid<TreeT>&, bool, util::NullInterrupter*)
1170 #define _FUNCTION(TreeT) \
1171 Grid<TreeT>::Ptr normalize(const Grid<TreeT>&, const BoolGrid&, bool, util::NullInterrupter*)
1175 #endif // OPENVDB_USE_EXPLICIT_INSTANTIATION
1182 #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.
GridType
List of types that are currently supported by NanoVDB.
GLsizei const GLfloat * value
#define OPENVDB_REAL_TREE_INSTANTIATE(Function)
#define OPENVDB_USE_VERSION_NAMESPACE
**But if you need a result
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...
ValueAccessors are designed to help accelerate accesses into the OpenVDB Tree structures by storing c...
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)
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...