9 #ifndef OPENVDB_TOOLS_GRID_OPERATORS_HAS_BEEN_INCLUDED 10 #define OPENVDB_TOOLS_GRID_OPERATORS_HAS_BEEN_INCLUDED 15 #include "openvdb/thread/Threading.h" 21 #include <tbb/parallel_for.h> 34 typedef typename VectorGridType::template ValueConverter<VecComponentValueT>::Type
Type;
43 typedef typename ScalarGridType::template ValueConverter<VectorValueT>::Type
Type;
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>
65 return cpt<GridType, util::NullInterrupter>(grid, threaded,
nullptr);
68 template<
typename Gr
idType,
typename MaskT>
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
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>
114 template<
typename Gr
idType,
typename MaskT,
typename InterruptT>
116 divergence(
const GridType& grid,
const MaskT& mask,
bool threaded, InterruptT* interrupt);
118 template<
typename Gr
idType>
122 return divergence<GridType, util::NullInterrupter>(grid, threaded,
nullptr);
125 template<
typename Gr
idType,
typename MaskT>
129 return divergence<GridType, MaskT, util::NullInterrupter>(grid, mask, threaded,
nullptr);
139 template<
typename Gr
idType,
typename InterruptT>
143 template<
typename Gr
idType,
typename MaskT,
typename InterruptT>
145 gradient(
const GridType& grid,
const MaskT& mask,
bool threaded, InterruptT* interrupt);
147 template<
typename Gr
idType>
151 return gradient<GridType, util::NullInterrupter>(grid, threaded,
nullptr);
154 template<
typename Gr
idType,
typename MaskT>
158 return gradient<GridType, MaskT, util::NullInterrupter>(grid, mask, threaded,
nullptr);
167 template<
typename Gr
idType,
typename InterruptT>
168 typename GridType::Ptr
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
199 template<
typename Gr
idType,
typename MaskT,
typename InterruptT>
200 typename GridType::Ptr
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>
228 template<
typename Gr
idType,
typename MaskT,
typename InterruptT>
230 magnitude(
const GridType& grid,
const MaskT& mask,
bool threaded, InterruptT* interrupt);
232 template<
typename Gr
idType>
236 return magnitude<GridType, util::NullInterrupter>(grid, threaded,
nullptr);
239 template<
typename Gr
idType,
typename MaskT>
243 return magnitude<GridType, MaskT, util::NullInterrupter>(grid, mask, threaded,
nullptr);
252 template<
typename Gr
idType,
typename InterruptT>
253 typename GridType::Ptr
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,
308 GridOperator(
const InGridT& grid,
const MaskGridType* mask,
const MapT& map,
309 InterruptT* interrupt =
nullptr,
bool densify =
true)
310 : mAcc(grid.getConstAccessor())
312 , mInterrupt(interrupt)
321 typename OutGridT::Ptr
process(
bool threaded =
true)
323 if (mInterrupt) mInterrupt->start(
"Processing grid");
326 typename InGridT::TreeType tmp(mAcc.tree().background());
327 typename OutGridT::ValueType backg = OperatorT::result(mMap, tmp,
math::Coord(0));
334 typename OutTreeT::Ptr tree(
new OutTreeT(mAcc.tree(), backg,
TopologyCopy()));
335 if (mDensify) tree->voxelizeActiveTiles();
338 typename OutGridT::Ptr result(
new OutGridT(tree));
342 result->topologyIntersection(*mMask);
348 LeafManagerT leafManager(*tree);
351 tbb::parallel_for(leafManager.
leafRange(), *
this);
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) {
367 it.setValue(OperatorT::result(this->mMap, inAcc, it.getCoord()));
375 if (mDensify) tree->prune();
377 if (mInterrupt) mInterrupt->end();
389 thread::cancelGroupExecution();
392 for (
typename LeafManagerT::LeafRange::Iterator leaf=range.
begin(); leaf; ++leaf) {
393 for (
typename OutLeafT::ValueOnIter
value=leaf->beginValueOn();
value; ++
value) {
394 value.setValue(OperatorT::result(mMap, mAcc,
value.getCoord()));
425 Cpt(
const InGridType& grid, InterruptT* interrupt =
nullptr):
426 mInputGrid(grid), mInterrupt(interrupt), mMask(nullptr)
430 Cpt(
const InGridType& grid,
const MaskGridType& mask, InterruptT* interrupt =
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)
464 Functor(
const InGridType& grid,
const MaskGridType* mask,
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)
478 op(mInputGrid, mMask, map, mInterrupt,
false);
479 mOutputGrid = op.
process(mThreaded);
482 op(mInputGrid, mMask, map, mInterrupt,
false);
483 mOutputGrid = op.
process(mThreaded);
486 const bool mThreaded;
487 const bool mWorldSpace;
488 const InGridType& mInputGrid;
489 typename OutGridType::Ptr mOutputGrid;
490 InterruptT* mInterrupt;
491 const MaskGridType* mMask;
493 const InGridType& mInputGrid;
494 InterruptT* mInterrupt;
495 const MaskGridType* mMask;
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)
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;
574 Divergence(
const InGridT& grid, InterruptT* interrupt =
nullptr):
575 mInputGrid(grid), mInterrupt(interrupt), mMask(nullptr)
579 Divergence(
const InGridT& grid,
const MaskGridType& mask, InterruptT* interrupt =
nullptr):
580 mInputGrid(grid), mInterrupt(interrupt), mMask(&mask)
584 typename OutGridType::Ptr
process(
bool threaded =
true)
589 return functor.mOutputGrid;
593 return functor.mOutputGrid;
598 template<math::DScheme DiffScheme>
601 Functor(
const InGridT& grid,
const MaskGridType* mask,
602 bool threaded, InterruptT* interrupt):
603 mThreaded(threaded), mInputGrid(grid), mInterrupt(interrupt), mMask(mask) {}
605 template<
typename MapT>
610 op(mInputGrid, mMask, map, mInterrupt);
611 mOutputGrid = op.
process(mThreaded);
641 Gradient(
const InGridT& grid, InterruptT* interrupt =
nullptr):
642 mInputGrid(grid), mInterrupt(interrupt), mMask(nullptr)
646 Gradient(
const InGridT& grid,
const MaskGridType& mask, InterruptT* interrupt =
nullptr):
647 mInputGrid(grid), mInterrupt(interrupt), mMask(&mask)
651 typename OutGridType::Ptr
process(
bool threaded =
true)
653 Functor functor(mInputGrid, mMask, threaded, mInterrupt);
655 if (functor.mOutputGrid) functor.mOutputGrid->setVectorType(
VEC_COVARIANT);
656 return functor.mOutputGrid;
662 Functor(
const InGridT& grid,
const MaskGridType* mask,
663 bool threaded, InterruptT* interrupt):
664 mThreaded(threaded), mInputGrid(grid), mInterrupt(interrupt), mMask(mask) {}
666 template<
typename MapT>
671 op(mInputGrid, mMask, map, mInterrupt);
672 mOutputGrid = op.
process(mThreaded);
701 Laplacian(
const GridT& grid, InterruptT* interrupt =
nullptr):
702 mInputGrid(grid), mInterrupt(interrupt), mMask(nullptr)
706 Laplacian(
const GridT& grid,
const MaskGridType& mask, InterruptT* interrupt =
nullptr):
707 mInputGrid(grid), mInterrupt(interrupt), mMask(&mask)
711 typename GridT::Ptr
process(
bool threaded =
true)
713 Functor functor(mInputGrid, mMask, threaded, mInterrupt);
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):
723 mThreaded(threaded), mInputGrid(grid), mInterrupt(interrupt), mMask(mask) {}
725 template<
typename MapT>
730 op(mInputGrid, mMask, map, mInterrupt);
731 mOutputGrid = op.
process(mThreaded);
761 mInputGrid(grid), mInterrupt(interrupt), mMask(nullptr)
765 MeanCurvature(
const GridT& grid,
const MaskGridType& mask, InterruptT* interrupt =
nullptr):
766 mInputGrid(grid), mInterrupt(interrupt), mMask(&mask)
770 typename GridT::Ptr
process(
bool threaded =
true)
772 Functor functor(mInputGrid, mMask, threaded, mInterrupt);
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):
782 mThreaded(threaded), mInputGrid(grid), mInterrupt(interrupt), mMask(mask) {}
784 template<
typename MapT>
789 op(mInputGrid, mMask, map, mInterrupt);
790 mOutputGrid = op.
process(mThreaded);
819 Magnitude(
const InGridType& grid, InterruptT* interrupt =
nullptr):
820 mInputGrid(grid), mInterrupt(interrupt), mMask(nullptr)
824 Magnitude(
const InGridType& grid,
const MaskGridType& mask, InterruptT* interrupt =
nullptr):
825 mInputGrid(grid), mInterrupt(interrupt), mMask(&mask)
829 typename OutGridType::Ptr
process(
bool threaded =
true)
831 Functor functor(mInputGrid, mMask, threaded, mInterrupt);
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();}
845 Functor(
const InGridT& grid,
const MaskGridType* mask,
846 bool threaded, InterruptT* interrupt):
847 mThreaded(threaded), mInputGrid(grid), mInterrupt(interrupt), mMask(mask) {}
849 template<
typename MapT>
853 op(mInputGrid, mMask, map, mInterrupt,
false);
854 mOutputGrid = op.
process(mThreaded);
883 Normalize(
const GridT& grid, InterruptT* interrupt =
nullptr):
884 mInputGrid(grid), mInterrupt(interrupt), mMask(nullptr)
888 Normalize(
const GridT& grid,
const MaskGridType& mask, InterruptT* interrupt =
nullptr):
889 mInputGrid(grid), mInterrupt(interrupt), mMask(&mask)
893 typename GridT::Ptr
process(
bool threaded =
true)
895 Functor functor(mInputGrid, mMask, threaded, mInterrupt);
897 if (
typename GridT::Ptr outGrid = functor.mOutputGrid) {
898 const VecType vecType = mInputGrid.getVectorType();
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):
923 mThreaded(threaded), mInputGrid(grid), mInterrupt(interrupt), mMask(mask) {}
925 template<
typename MapT>
929 op(mInputGrid, mMask, map, mInterrupt,
false);
930 mOutputGrid = op.
process(mThreaded);
949 template<
typename Gr
idType,
typename InterruptT>
957 template<
typename Gr
idType,
typename MaskT,
typename InterruptT>
959 cpt(
const GridType& grid,
const MaskT& mask,
bool threaded, InterruptT* interrupt)
965 template<
typename Gr
idType,
typename InterruptT>
966 typename GridType::Ptr
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>
990 template<
typename Gr
idType,
typename MaskT,
typename InterruptT>
998 template<
typename Gr
idType,
typename InterruptT>
1003 op(grid, interrupt);
1007 template<
typename Gr
idType,
typename MaskT,
typename InterruptT>
1015 template<
typename Gr
idType,
typename InterruptT>
1016 typename GridType::Ptr
1020 op(grid, interrupt);
1024 template<
typename Gr
idType,
typename MaskT,
typename InterruptT>
1025 typename GridType::Ptr
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>
1054 op(grid, interrupt);
1058 template<
typename Gr
idType,
typename MaskT,
typename InterruptT>
1066 template<
typename Gr
idType,
typename InterruptT>
1067 typename GridType::Ptr
1071 op(grid, interrupt);
1075 template<
typename Gr
idType,
typename MaskT,
typename InterruptT>
1076 typename GridType::Ptr
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
bool wasInterrupted(T *i, int percent=-1)
Definition: NullInterrupter.h:49
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.
Definition: Operators.h:949
Iterator begin() const
Definition: LeafManager.h:155
LeafRange leafRange(size_t grainsize=1) const
Return a TBB-compatible LeafRange.
Definition: LeafManager.h:345
Compute the mean curvature.
Definition: Operators.h:1761
Base class for interrupters.
Definition: NullInterrupter.h:25
#define OPENVDB_NUMERIC_TREE_INSTANTIATE(Function)
Definition: version.h.in:148
Signed (x, y, z) 32-bit integer coordinates.
Definition: Coord.h:24
Tag dispatch class that distinguishes topology copy constructors from deep copy constructors.
Definition: Types.h:644
Definition: LeafManager.h:101
Definition: Exceptions.h:13
Compute the closest-point transform to a level set.
Definition: Operators.h:1718
ValueT value
Definition: GridBuilder.h:1287
Center difference gradient operators, defined with respect to the range-space of the map...
Definition: Operators.h:619
Compute the Laplacian at a given location in a grid using finite differencing of various orders...
Definition: Operators.h:1419
This class manages a linear array of pointers to a given tree's leaf nodes, as well as optional auxil...
Definition: LeafManager.h:84
Compute the closest-point transform to a level set.
Definition: Operators.h:1665
Container class that associates a tree with a transform and metadata.
Definition: Grid.h:28
Compute the curl of a vector-valued grid using differencing of various orders in the space defined by...
Definition: Operators.h:1274
GridType
List of types that are currently supported by NanoVDB.
Definition: NanoVDB.h:216
VecType
Definition: Types.h:444
bool processTypedMap(TransformType &transform, OpType &op)
Utility function that, given a generic map pointer, calls a functor on the fully-resoved map...
Definition: Transform.h:233
#define OPENVDB_REAL_TREE_INSTANTIATE(Function)
Definition: version.h.in:147
A LeafManager manages a linear array of pointers to a given tree's leaf nodes, as well as optional au...
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition: version.h.in:116
#define OPENVDB_VEC3_TREE_INSTANTIATE(Function)
Definition: version.h.in:149
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h.in:202