9 #ifndef OPENVDB_TOOLS_GRID_OPERATORS_HAS_BEEN_INCLUDED 10 #define OPENVDB_TOOLS_GRID_OPERATORS_HAS_BEEN_INCLUDED 16 #include <openvdb/thread/Threading.h> 22 #include <tbb/parallel_for.h> 35 typedef typename VectorGridType::template ValueConverter<VecComponentValueT>::Type
Type;
44 typedef typename ScalarGridType::template ValueConverter<VectorValueT>::Type
Type;
54 template<
typename Gr
idType,
typename InterruptT>
58 template<
typename Gr
idType,
typename MaskT,
typename InterruptT>
62 template<
typename Gr
idType>
66 return cpt<GridType, util::NullInterrupter>(grid,
threaded,
nullptr);
69 template<
typename Gr
idType,
typename MaskT>
73 return cpt<GridType, MaskT, util::NullInterrupter>(grid, mask,
threaded,
nullptr);
82 template<
typename Gr
idType,
typename InterruptT>
83 typename GridType::Ptr
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
99 curl(
const GridType& grid,
const MaskT& mask,
bool threaded =
true)
101 return curl<GridType, MaskT, util::NullInterrupter>(grid, mask,
threaded,
nullptr);
111 template<
typename Gr
idType,
typename InterruptT>
115 template<
typename Gr
idType,
typename MaskT,
typename InterruptT>
117 divergence(
const GridType& grid,
const MaskT& mask,
bool threaded, InterruptT* interrupt);
119 template<
typename Gr
idType>
123 return divergence<GridType, util::NullInterrupter>(grid,
threaded,
nullptr);
126 template<
typename Gr
idType,
typename MaskT>
130 return divergence<GridType, MaskT, util::NullInterrupter>(grid, mask,
threaded,
nullptr);
140 template<
typename Gr
idType,
typename InterruptT>
144 template<
typename Gr
idType,
typename MaskT,
typename InterruptT>
146 gradient(
const GridType& grid,
const MaskT& mask,
bool threaded, InterruptT* interrupt);
148 template<
typename Gr
idType>
152 return gradient<GridType, util::NullInterrupter>(grid,
threaded,
nullptr);
155 template<
typename Gr
idType,
typename MaskT>
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
174 laplacian(
const GridType& grid,
const MaskT& mask,
bool threaded, InterruptT* interrupt);
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>
229 template<
typename Gr
idType,
typename MaskT,
typename InterruptT>
231 magnitude(
const GridType& grid,
const MaskT& mask,
bool threaded, InterruptT* interrupt);
233 template<
typename Gr
idType>
237 return magnitude<GridType, util::NullInterrupter>(grid,
threaded,
nullptr);
240 template<
typename Gr
idType,
typename MaskT>
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
259 normalize(
const GridType& grid,
const MaskT& mask,
bool threaded, InterruptT* interrupt);
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,
309 GridOperator(
const InGridT& grid,
const MaskGridType* mask,
const MapT& map,
310 InterruptT* interrupt =
nullptr,
bool densify =
true)
311 : mAcc(grid.getConstAccessor())
313 , mInterrupt(interrupt)
322 typename OutGridT::Ptr
process(
bool threaded =
true)
324 if (mInterrupt) mInterrupt->start(
"Processing grid");
327 typename InGridT::TreeType tmp(mAcc.tree().background());
328 typename OutGridT::ValueType backg = OperatorT::result(mMap, tmp,
math::Coord(0));
336 if (mDensify) tree->voxelizeActiveTiles();
339 typename OutGridT::Ptr result(
new OutGridT(tree));
343 result->topologyIntersection(*mMask);
349 LeafManagerT leafManager(*tree);
352 tbb::parallel_for(leafManager.
leafRange(), *
this);
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) {
368 it.setValue(OperatorT::result(this->mMap, inAcc, it.getCoord()));
376 if (mDensify) tree->prune();
378 if (mInterrupt) mInterrupt->end();
390 thread::cancelGroupExecution();
393 for (
typename LeafManagerT::LeafRange::Iterator leaf=range.
begin(); leaf; ++leaf) {
394 for (
typename OutLeafT::ValueOnIter value=leaf->beginValueOn(); value; ++value) {
395 value.setValue(OperatorT::result(mMap, mAcc, value.getCoord()));
426 Cpt(
const InGridType& grid, InterruptT* interrupt =
nullptr):
427 mInputGrid(grid), mInterrupt(interrupt), mMask(nullptr)
431 Cpt(
const InGridType& grid,
const MaskGridType& mask, InterruptT* interrupt =
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>
448 static typename OutGridType::ValueType
449 result(
const MapT& map,
const AccT& acc,
const Coord& xyz)
456 template<
typename MapT,
typename AccT>
457 static typename OutGridType::ValueType
458 result(
const MapT& map,
const AccT& acc,
const Coord& xyz)
465 Functor(
const InGridType& grid,
const MaskGridType* mask,
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)
479 op(mInputGrid, mMask, map, mInterrupt,
false);
480 mOutputGrid = op.
process(mThreaded);
483 op(mInputGrid, mMask, map, mInterrupt,
false);
484 mOutputGrid = op.
process(mThreaded);
487 const bool mThreaded;
488 const bool mWorldSpace;
489 const InGridType& mInputGrid;
490 typename OutGridType::Ptr mOutputGrid;
491 InterruptT* mInterrupt;
492 const MaskGridType* mMask;
494 const InGridType& mInputGrid;
495 InterruptT* mInterrupt;
496 const MaskGridType* mMask;
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)
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;
575 Divergence(
const InGridT& grid, InterruptT* interrupt =
nullptr):
576 mInputGrid(grid), mInterrupt(interrupt), mMask(nullptr)
580 Divergence(
const InGridT& grid,
const MaskGridType& mask, InterruptT* interrupt =
nullptr):
581 mInputGrid(grid), mInterrupt(interrupt), mMask(&mask)
585 typename OutGridType::Ptr
process(
bool threaded =
true)
590 return functor.mOutputGrid;
594 return functor.mOutputGrid;
599 template<math::DScheme DiffScheme>
602 Functor(
const InGridT& grid,
const MaskGridType* mask,
603 bool threaded, InterruptT* interrupt):
604 mThreaded(threaded), mInputGrid(grid), mInterrupt(interrupt), mMask(mask) {}
606 template<
typename MapT>
611 op(mInputGrid, mMask, map, mInterrupt);
612 mOutputGrid = op.
process(mThreaded);
642 Gradient(
const InGridT& grid, InterruptT* interrupt =
nullptr):
643 mInputGrid(grid), mInterrupt(interrupt), mMask(nullptr)
647 Gradient(
const InGridT& grid,
const MaskGridType& mask, InterruptT* interrupt =
nullptr):
648 mInputGrid(grid), mInterrupt(interrupt), mMask(&mask)
652 typename OutGridType::Ptr
process(
bool threaded =
true)
654 Functor functor(mInputGrid, mMask, threaded, mInterrupt);
656 if (functor.mOutputGrid) functor.mOutputGrid->setVectorType(
VEC_COVARIANT);
657 return functor.mOutputGrid;
663 Functor(
const InGridT& grid,
const MaskGridType* mask,
664 bool threaded, InterruptT* interrupt):
665 mThreaded(threaded), mInputGrid(grid), mInterrupt(interrupt), mMask(mask) {}
667 template<
typename MapT>
672 op(mInputGrid, mMask, map, mInterrupt);
673 mOutputGrid = op.
process(mThreaded);
702 Laplacian(
const GridT& grid, InterruptT* interrupt =
nullptr):
703 mInputGrid(grid), mInterrupt(interrupt), mMask(nullptr)
707 Laplacian(
const GridT& grid,
const MaskGridType& mask, InterruptT* interrupt =
nullptr):
708 mInputGrid(grid), mInterrupt(interrupt), mMask(&mask)
712 typename GridT::Ptr
process(
bool threaded =
true)
714 Functor functor(mInputGrid, mMask, threaded, mInterrupt);
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):
724 mThreaded(threaded), mInputGrid(grid), mInterrupt(interrupt), mMask(mask) {}
726 template<
typename MapT>
731 op(mInputGrid, mMask, map, mInterrupt);
732 mOutputGrid = op.
process(mThreaded);
762 mInputGrid(grid), mInterrupt(interrupt), mMask(nullptr)
766 MeanCurvature(
const GridT& grid,
const MaskGridType& mask, InterruptT* interrupt =
nullptr):
767 mInputGrid(grid), mInterrupt(interrupt), mMask(&mask)
771 typename GridT::Ptr
process(
bool threaded =
true)
773 Functor functor(mInputGrid, mMask, threaded, mInterrupt);
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):
783 mThreaded(threaded), mInputGrid(grid), mInterrupt(interrupt), mMask(mask) {}
785 template<
typename MapT>
790 op(mInputGrid, mMask, map, mInterrupt);
791 mOutputGrid = op.
process(mThreaded);
820 Magnitude(
const InGridType& grid, InterruptT* interrupt =
nullptr):
821 mInputGrid(grid), mInterrupt(interrupt), mMask(nullptr)
825 Magnitude(
const InGridType& grid,
const MaskGridType& mask, InterruptT* interrupt =
nullptr):
826 mInputGrid(grid), mInterrupt(interrupt), mMask(&mask)
830 typename OutGridType::Ptr
process(
bool threaded =
true)
832 Functor functor(mInputGrid, mMask, threaded, mInterrupt);
834 return functor.mOutputGrid;
840 template<
typename MapT,
typename AccT>
841 static typename OutGridType::ValueType
842 result(
const MapT&,
const AccT& acc,
const Coord& xyz) {
return acc.getValue(xyz).length();}
846 Functor(
const InGridT& grid,
const MaskGridType* mask,
847 bool threaded, InterruptT* interrupt):
848 mThreaded(threaded), mInputGrid(grid), mInterrupt(interrupt), mMask(mask) {}
850 template<
typename MapT>
854 op(mInputGrid, mMask, map, mInterrupt,
false);
855 mOutputGrid = op.
process(mThreaded);
884 Normalize(
const GridT& grid, InterruptT* interrupt =
nullptr):
885 mInputGrid(grid), mInterrupt(interrupt), mMask(nullptr)
889 Normalize(
const GridT& grid,
const MaskGridType& mask, InterruptT* interrupt =
nullptr):
890 mInputGrid(grid), mInterrupt(interrupt), mMask(&mask)
894 typename GridT::Ptr
process(
bool threaded =
true)
896 Functor functor(mInputGrid, mMask, threaded, mInterrupt);
898 if (
typename GridT::Ptr
outGrid = functor.mOutputGrid) {
899 const VecType vecType = mInputGrid.getVectorType();
903 outGrid->setVectorType(vecType);
906 return functor.mOutputGrid;
912 template<
typename MapT,
typename AccT>
913 static typename OutGridType::ValueType
914 result(
const MapT&,
const AccT& acc,
const Coord& xyz)
916 typename OutGridType::ValueType vec = acc.getValue(xyz);
917 if ( !vec.normalize() ) vec.setZero();
923 Functor(
const GridT& grid,
const MaskGridType* mask,
bool threaded, InterruptT* interrupt):
924 mThreaded(threaded), mInputGrid(grid), mInterrupt(interrupt), mMask(mask) {}
926 template<
typename MapT>
930 op(mInputGrid, mMask, map, mInterrupt,
false);
931 mOutputGrid = op.
process(mThreaded);
950 template<
typename Gr
idType,
typename InterruptT>
958 template<
typename Gr
idType,
typename MaskT,
typename InterruptT>
960 cpt(
const GridType& grid,
const MaskT& mask,
bool threaded, InterruptT* interrupt)
966 template<
typename Gr
idType,
typename InterruptT>
967 typename GridType::Ptr
974 template<
typename Gr
idType,
typename MaskT,
typename InterruptT>
975 typename GridType::Ptr
976 curl(
const GridType& grid,
const MaskT& mask,
bool threaded, InterruptT* interrupt)
982 template<
typename Gr
idType,
typename InterruptT>
991 template<
typename Gr
idType,
typename MaskT,
typename InterruptT>
999 template<
typename Gr
idType,
typename InterruptT>
1004 op(grid, interrupt);
1008 template<
typename Gr
idType,
typename MaskT,
typename InterruptT>
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>
1055 op(grid, interrupt);
1059 template<
typename Gr
idType,
typename MaskT,
typename InterruptT>
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
Compute the mean curvature.
Definition: Operators.h:1761
Iterator begin() const
Definition: LeafManager.h:156
#define OPENVDB_NUMERIC_TREE_INSTANTIATE(Function)
Definition: version.h.in:163
Signed (x, y, z) 32-bit integer coordinates.
Definition: Coord.h:25
Compute the curl of a vector-valued grid using differencing of various orders in the space defined by...
Definition: Operators.h:1274
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
Compute the Laplacian at a given location in a grid using finite differencing of various orders...
Definition: Operators.h:1419
Base class for interrupters.
Definition: NullInterrupter.h:25
bool wasInterrupted(T *i, int percent=-1)
Definition: NullInterrupter.h:49
LeafRange leafRange(size_t grainsize=1) const
Return a TBB-compatible LeafRange.
Definition: LeafManager.h:346
void foreach(T &&t, const F &func, std::integer_sequence< size_t, Is... >)
Definition: PointTransfer.h:335
Definition: Exceptions.h:13
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
ValueAccessors are designed to help accelerate accesses into the OpenVDB Tree structures by storing c...
GridType
List of types that are currently supported by NanoVDB.
Definition: NanoVDB.h:219
Definition: LeafManager.h:102
Center difference gradient operators, defined with respect to the range-space of the map...
Definition: Operators.h:619
#define OPENVDB_REAL_TREE_INSTANTIATE(Function)
Definition: version.h.in:162
This class manages a linear array of pointers to a given tree's leaf nodes, as well as optional auxil...
Definition: LeafManager.h:85
Tag dispatch class that distinguishes topology copy constructors from deep copy constructors.
Definition: Types.h:683
VecType
Definition: Types.h:483
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:121
#define OPENVDB_VEC3_TREE_INSTANTIATE(Function)
Definition: version.h.in:164
Container class that associates a tree with a transform and metadata.
Definition: Grid.h:28
Compute the closest-point transform to a level set.
Definition: Operators.h:1665
Compute the closest-point transform to a level set.
Definition: Operators.h:1718
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h.in:218