36 #ifndef OPENVDB_TOOLS_GRID_OPERATORS_HAS_BEEN_INCLUDED 37 #define OPENVDB_TOOLS_GRID_OPERATORS_HAS_BEEN_INCLUDED 39 #include <openvdb/Grid.h> 40 #include <openvdb/math/Operators.h> 41 #include <openvdb/util/NullInterrupter.h> 42 #include <openvdb/tree/LeafManager.h> 43 #include <openvdb/tree/ValueAccessor.h> 45 #include <tbb/parallel_for.h> 59 typedef typename VectorGridType::template ValueConverter<VecComponentValueT>::Type
Type;
68 typedef typename ScalarGridType::template ValueConverter<VectorValueT>::Type
Type;
78 template<
typename Gr
idType,
typename InterruptT>
inline 80 cpt(
const GridType& grid,
bool threaded, InterruptT* interrupt);
82 template<
typename Gr
idType,
typename MaskT,
typename InterruptT>
inline 84 cpt(
const GridType& grid,
const MaskT& mask,
bool threaded, InterruptT* interrupt);
86 template<
typename Gr
idType>
inline 88 cpt(
const GridType& grid,
bool threaded =
true)
90 return cpt<GridType, util::NullInterrupter>(grid, threaded,
nullptr);
93 template<
typename Gr
idType,
typename MaskT>
inline 95 cpt(
const GridType& grid,
const MaskT& mask,
bool threaded =
true)
97 return cpt<GridType, MaskT, util::NullInterrupter>(grid, mask, threaded,
nullptr);
106 template<
typename Gr
idType,
typename InterruptT>
inline 107 typename GridType::Ptr
108 curl(
const GridType& grid,
bool threaded, InterruptT* interrupt);
110 template<
typename Gr
idType,
typename MaskT,
typename InterruptT>
inline 111 typename GridType::Ptr
112 curl(
const GridType& grid,
const MaskT& mask,
bool threaded, InterruptT* interrupt);
114 template<
typename Gr
idType>
inline 115 typename GridType::Ptr
116 curl(
const GridType& grid,
bool threaded =
true)
118 return curl<GridType, util::NullInterrupter>(grid, threaded,
nullptr);
121 template<
typename Gr
idType,
typename MaskT>
inline 122 typename GridType::Ptr
123 curl(
const GridType& grid,
const MaskT& mask,
bool threaded =
true)
125 return curl<GridType, MaskT, util::NullInterrupter>(grid, mask, threaded,
nullptr);
135 template<
typename Gr
idType,
typename InterruptT>
inline 137 divergence(
const GridType& grid,
bool threaded, InterruptT* interrupt);
139 template<
typename Gr
idType,
typename MaskT,
typename InterruptT>
inline 141 divergence(
const GridType& grid,
const MaskT& mask,
bool threaded, InterruptT* interrupt);
143 template<
typename Gr
idType>
inline 147 return divergence<GridType, util::NullInterrupter>(grid, threaded,
nullptr);
150 template<
typename Gr
idType,
typename MaskT>
inline 152 divergence(
const GridType& grid,
const MaskT& mask,
bool threaded =
true)
154 return divergence<GridType, MaskT, util::NullInterrupter>(grid, mask, threaded,
nullptr);
164 template<
typename Gr
idType,
typename InterruptT>
inline 166 gradient(
const GridType& grid,
bool threaded, InterruptT* interrupt);
168 template<
typename Gr
idType,
typename MaskT,
typename InterruptT>
inline 170 gradient(
const GridType& grid,
const MaskT& mask,
bool threaded, InterruptT* interrupt);
172 template<
typename Gr
idType>
inline 174 gradient(
const GridType& grid,
bool threaded =
true)
176 return gradient<GridType, util::NullInterrupter>(grid, threaded,
nullptr);
179 template<
typename Gr
idType,
typename MaskT>
inline 181 gradient(
const GridType& grid,
const MaskT& mask,
bool threaded =
true)
183 return gradient<GridType, MaskT, util::NullInterrupter>(grid, mask, threaded,
nullptr);
192 template<
typename Gr
idType,
typename InterruptT>
inline 193 typename GridType::Ptr
194 laplacian(
const GridType& grid,
bool threaded, InterruptT* interrupt);
196 template<
typename Gr
idType,
typename MaskT,
typename InterruptT>
inline 197 typename GridType::Ptr
198 laplacian(
const GridType& grid,
const MaskT& mask,
bool threaded, InterruptT* interrupt);
200 template<
typename Gr
idType>
inline 201 typename GridType::Ptr
204 return laplacian<GridType, util::NullInterrupter>(grid, threaded,
nullptr);
207 template<
typename Gr
idType,
typename MaskT>
inline 208 typename GridType::Ptr
209 laplacian(
const GridType& grid,
const MaskT mask,
bool threaded =
true)
211 return laplacian<GridType, MaskT, util::NullInterrupter>(grid, mask, threaded,
nullptr);
220 template<
typename Gr
idType,
typename InterruptT>
inline 221 typename GridType::Ptr
222 meanCurvature(
const GridType& grid,
bool threaded, InterruptT* interrupt);
224 template<
typename Gr
idType,
typename MaskT,
typename InterruptT>
inline 225 typename GridType::Ptr
226 meanCurvature(
const GridType& grid,
const MaskT& mask,
bool threaded, InterruptT* interrupt);
228 template<
typename Gr
idType>
inline 229 typename GridType::Ptr
232 return meanCurvature<GridType, util::NullInterrupter>(grid, threaded,
nullptr);
235 template<
typename Gr
idType,
typename MaskT>
inline 236 typename GridType::Ptr
237 meanCurvature(
const GridType& grid,
const MaskT& mask,
bool threaded =
true)
239 return meanCurvature<GridType, MaskT, util::NullInterrupter>(grid, mask, threaded,
nullptr);
249 template<
typename Gr
idType,
typename InterruptT>
inline 251 magnitude(
const GridType& grid,
bool threaded, InterruptT* interrupt);
253 template<
typename Gr
idType,
typename MaskT,
typename InterruptT>
inline 255 magnitude(
const GridType& grid,
const MaskT& mask,
bool threaded, InterruptT* interrupt);
257 template<
typename Gr
idType>
inline 261 return magnitude<GridType, util::NullInterrupter>(grid, threaded,
nullptr);
264 template<
typename Gr
idType,
typename MaskT>
inline 266 magnitude(
const GridType& grid,
const MaskT& mask,
bool threaded =
true)
268 return magnitude<GridType, MaskT, util::NullInterrupter>(grid, mask, threaded,
nullptr);
277 template<
typename Gr
idType,
typename InterruptT>
inline 278 typename GridType::Ptr
279 normalize(
const GridType& grid,
bool threaded, InterruptT* interrupt);
281 template<
typename Gr
idType,
typename MaskT,
typename InterruptT>
inline 282 typename GridType::Ptr
283 normalize(
const GridType& grid,
const MaskT& mask,
bool threaded, InterruptT* interrupt);
285 template<
typename Gr
idType>
inline 286 typename GridType::Ptr
289 return normalize<GridType, util::NullInterrupter>(grid, threaded,
nullptr);
292 template<
typename Gr
idType,
typename MaskT>
inline 293 typename GridType::Ptr
294 normalize(
const GridType& grid,
const MaskT& mask,
bool threaded =
true)
296 return normalize<GridType, MaskT, util::NullInterrupter>(grid, mask, threaded,
nullptr);
308 template<
typename Gr
idType>
321 typename MaskGridType,
333 GridOperator(
const InGridT& grid,
const MaskGridType* mask,
const MapT& map,
334 InterruptT* interrupt =
nullptr,
bool densify =
true)
335 : mAcc(grid.getConstAccessor())
337 , mInterrupt(interrupt)
346 typename OutGridT::Ptr
process(
bool threaded =
true)
348 if (mInterrupt) mInterrupt->start(
"Processing grid");
351 typename InGridT::TreeType tmp(mAcc.tree().background());
352 typename OutGridT::ValueType backg = OperatorT::result(mMap, tmp,
math::Coord(0));
359 typename OutTreeT::Ptr tree(
new OutTreeT(mAcc.tree(), backg,
TopologyCopy()));
360 if (mDensify) tree->voxelizeActiveTiles();
363 typename OutGridT::Ptr result(
new OutGridT(tree));
367 result->topologyIntersection(*mMask);
373 LeafManagerT leafManager(*tree);
376 tbb::parallel_for(leafManager.
leafRange(), *
this);
383 using TileIter =
typename OutTreeT::ValueOnIter;
385 TileIter tileIter = tree->beginValueOn();
386 tileIter.setMaxDepth(tileIter.getLeafDepth() - 1);
389 auto tileOp = [
this, inAcc](
const TileIter& it) {
392 it.setValue(OperatorT::result(this->mMap, inAcc, it.getCoord()));
400 if (mDensify) tree->prune();
402 if (mInterrupt) mInterrupt->end();
415 for (
typename LeafManagerT::LeafRange::Iterator leaf=range.
begin(); leaf; ++leaf) {
416 for (
typename OutLeafT::ValueOnIter value=leaf->beginValueOn(); value; ++value) {
417 value.setValue(OperatorT::result(mMap, mAcc, value.getCoord()));
448 Cpt(
const InGridType& grid, InterruptT* interrupt =
nullptr):
449 mInputGrid(grid), mInterrupt(interrupt), mMask(nullptr)
453 Cpt(
const InGridType& grid,
const MaskGridType& mask, InterruptT* interrupt =
nullptr):
454 mInputGrid(grid), mInterrupt(interrupt), mMask(&mask)
458 typename OutGridType::Ptr
process(
bool threaded =
true,
bool useWorldTransform =
true)
460 Functor functor(mInputGrid, mMask, threaded, useWorldTransform, mInterrupt);
463 return functor.mOutputGrid;
469 template<
typename MapT,
typename AccT>
470 static typename OutGridType::ValueType
471 result(
const MapT& map,
const AccT& acc,
const Coord& xyz)
478 template<
typename MapT,
typename AccT>
479 static typename OutGridType::ValueType
480 result(
const MapT& map,
const AccT& acc,
const Coord& xyz)
487 Functor(
const InGridType& grid,
const MaskGridType* mask,
488 bool threaded,
bool worldspace, InterruptT* interrupt)
489 : mThreaded(threaded)
490 , mWorldSpace(worldspace)
492 , mInterrupt(interrupt)
496 template<
typename MapT>
497 void operator()(
const MapT& map)
501 op(mInputGrid, mMask, map, mInterrupt,
false);
502 mOutputGrid = op.
process(mThreaded);
505 op(mInputGrid, mMask, map, mInterrupt,
false);
506 mOutputGrid = op.
process(mThreaded);
509 const bool mThreaded;
510 const bool mWorldSpace;
511 const InGridType& mInputGrid;
512 typename OutGridType::Ptr mOutputGrid;
513 InterruptT* mInterrupt;
514 const MaskGridType* mMask;
516 const InGridType& mInputGrid;
517 InterruptT* mInterrupt;
518 const MaskGridType* mMask;
536 Curl(
const GridT& grid, InterruptT* interrupt =
nullptr):
537 mInputGrid(grid), mInterrupt(interrupt), mMask(nullptr)
541 Curl(
const GridT& grid,
const MaskGridType& mask, InterruptT* interrupt =
nullptr):
542 mInputGrid(grid), mInterrupt(interrupt), mMask(&mask)
546 typename GridT::Ptr
process(
bool threaded =
true)
548 Functor functor(mInputGrid, mMask, threaded, mInterrupt);
550 if (functor.mOutputGrid) functor.mOutputGrid->setVectorType(
VEC_COVARIANT);
551 return functor.mOutputGrid;
557 Functor(
const GridT& grid,
const MaskGridType* mask,
558 bool threaded, InterruptT* interrupt):
559 mThreaded(threaded), mInputGrid(grid), mInterrupt(interrupt), mMask(mask) {}
561 template<
typename MapT>
562 void operator()(
const MapT& map)
566 op(mInputGrid, mMask, map, mInterrupt);
567 mOutputGrid = op.
process(mThreaded);
570 const bool mThreaded;
571 const GridT& mInputGrid;
572 typename GridT::Ptr mOutputGrid;
573 InterruptT* mInterrupt;
574 const MaskGridType* mMask;
577 const GridT& mInputGrid;
578 InterruptT* mInterrupt;
579 const MaskGridType* mMask;
597 Divergence(
const InGridT& grid, InterruptT* interrupt =
nullptr):
598 mInputGrid(grid), mInterrupt(interrupt), mMask(nullptr)
602 Divergence(
const InGridT& grid,
const MaskGridType& mask, InterruptT* interrupt =
nullptr):
603 mInputGrid(grid), mInterrupt(interrupt), mMask(&mask)
607 typename OutGridType::Ptr
process(
bool threaded =
true)
612 return functor.mOutputGrid;
616 return functor.mOutputGrid;
621 template<math::DScheme DiffScheme>
624 Functor(
const InGridT& grid,
const MaskGridType* mask,
625 bool threaded, InterruptT* interrupt):
626 mThreaded(threaded), mInputGrid(grid), mInterrupt(interrupt), mMask(mask) {}
628 template<
typename MapT>
633 op(mInputGrid, mMask, map, mInterrupt);
634 mOutputGrid = op.
process(mThreaded);
664 Gradient(
const InGridT& grid, InterruptT* interrupt =
nullptr):
665 mInputGrid(grid), mInterrupt(interrupt), mMask(nullptr)
669 Gradient(
const InGridT& grid,
const MaskGridType& mask, InterruptT* interrupt =
nullptr):
670 mInputGrid(grid), mInterrupt(interrupt), mMask(&mask)
674 typename OutGridType::Ptr
process(
bool threaded =
true)
676 Functor functor(mInputGrid, mMask, threaded, mInterrupt);
678 if (functor.mOutputGrid) functor.mOutputGrid->setVectorType(
VEC_COVARIANT);
679 return functor.mOutputGrid;
685 Functor(
const InGridT& grid,
const MaskGridType* mask,
686 bool threaded, InterruptT* interrupt):
687 mThreaded(threaded), mInputGrid(grid), mInterrupt(interrupt), mMask(mask) {}
689 template<
typename MapT>
694 op(mInputGrid, mMask, map, mInterrupt);
695 mOutputGrid = op.
process(mThreaded);
724 Laplacian(
const GridT& grid, InterruptT* interrupt =
nullptr):
725 mInputGrid(grid), mInterrupt(interrupt), mMask(nullptr)
729 Laplacian(
const GridT& grid,
const MaskGridType& mask, InterruptT* interrupt =
nullptr):
730 mInputGrid(grid), mInterrupt(interrupt), mMask(&mask)
734 typename GridT::Ptr
process(
bool threaded =
true)
736 Functor functor(mInputGrid, mMask, threaded, mInterrupt);
738 if (functor.mOutputGrid) functor.mOutputGrid->setVectorType(
VEC_COVARIANT);
739 return functor.mOutputGrid;
745 Functor(
const GridT& grid,
const MaskGridType* mask,
bool threaded, InterruptT* interrupt):
746 mThreaded(threaded), mInputGrid(grid), mInterrupt(interrupt), mMask(mask) {}
748 template<
typename MapT>
753 op(mInputGrid, mMask, map, mInterrupt);
754 mOutputGrid = op.
process(mThreaded);
784 mInputGrid(grid), mInterrupt(interrupt), mMask(nullptr)
788 MeanCurvature(
const GridT& grid,
const MaskGridType& mask, InterruptT* interrupt =
nullptr):
789 mInputGrid(grid), mInterrupt(interrupt), mMask(&mask)
793 typename GridT::Ptr
process(
bool threaded =
true)
795 Functor functor(mInputGrid, mMask, threaded, mInterrupt);
797 if (functor.mOutputGrid) functor.mOutputGrid->setVectorType(
VEC_COVARIANT);
798 return functor.mOutputGrid;
804 Functor(
const GridT& grid,
const MaskGridType* mask,
bool threaded, InterruptT* interrupt):
805 mThreaded(threaded), mInputGrid(grid), mInterrupt(interrupt), mMask(mask) {}
807 template<
typename MapT>
812 op(mInputGrid, mMask, map, mInterrupt);
813 mOutputGrid = op.
process(mThreaded);
842 Magnitude(
const InGridType& grid, InterruptT* interrupt =
nullptr):
843 mInputGrid(grid), mInterrupt(interrupt), mMask(nullptr)
847 Magnitude(
const InGridType& grid,
const MaskGridType& mask, InterruptT* interrupt =
nullptr):
848 mInputGrid(grid), mInterrupt(interrupt), mMask(&mask)
852 typename OutGridType::Ptr
process(
bool threaded =
true)
854 Functor functor(mInputGrid, mMask, threaded, mInterrupt);
856 return functor.mOutputGrid;
862 template<
typename MapT,
typename AccT>
863 static typename OutGridType::ValueType
864 result(
const MapT&,
const AccT& acc,
const Coord& xyz) {
return acc.getValue(xyz).length();}
868 Functor(
const InGridT& grid,
const MaskGridType* mask,
869 bool threaded, InterruptT* interrupt):
870 mThreaded(threaded), mInputGrid(grid), mInterrupt(interrupt), mMask(mask) {}
872 template<
typename MapT>
876 op(mInputGrid, mMask, map, mInterrupt,
false);
877 mOutputGrid = op.
process(mThreaded);
906 Normalize(
const GridT& grid, InterruptT* interrupt =
nullptr):
907 mInputGrid(grid), mInterrupt(interrupt), mMask(nullptr)
911 Normalize(
const GridT& grid,
const MaskGridType& mask, InterruptT* interrupt =
nullptr):
912 mInputGrid(grid), mInterrupt(interrupt), mMask(&mask)
916 typename GridT::Ptr
process(
bool threaded =
true)
918 Functor functor(mInputGrid, mMask, threaded, mInterrupt);
920 if (
typename GridT::Ptr outGrid = functor.mOutputGrid) {
921 const VecType vecType = mInputGrid.getVectorType();
925 outGrid->setVectorType(vecType);
928 return functor.mOutputGrid;
934 template<
typename MapT,
typename AccT>
935 static typename OutGridType::ValueType
938 typename OutGridType::ValueType vec = acc.getValue(xyz);
939 if ( !vec.normalize() ) vec.setZero();
945 Functor(
const GridT& grid,
const MaskGridType* mask,
bool threaded, InterruptT* interrupt):
946 mThreaded(threaded), mInputGrid(grid), mInterrupt(interrupt), mMask(mask) {}
948 template<
typename MapT>
952 op(mInputGrid, mMask, map, mInterrupt,
false);
953 mOutputGrid = op.
process(mThreaded);
972 template<
typename Gr
idType,
typename InterruptT>
inline 974 cpt(
const GridType& grid,
bool threaded, InterruptT* interrupt)
980 template<
typename Gr
idType,
typename MaskT,
typename InterruptT>
inline 982 cpt(
const GridType& grid,
const MaskT& mask,
bool threaded, InterruptT* interrupt)
988 template<
typename Gr
idType,
typename InterruptT>
inline 989 typename GridType::Ptr
990 curl(
const GridType& grid,
bool threaded, InterruptT* interrupt)
996 template<
typename Gr
idType,
typename MaskT,
typename InterruptT>
inline 997 typename GridType::Ptr
998 curl(
const GridType& grid,
const MaskT& mask,
bool threaded, InterruptT* interrupt)
1004 template<
typename Gr
idType,
typename InterruptT>
inline 1006 divergence(
const GridType& grid,
bool threaded, InterruptT* interrupt)
1009 op(grid, interrupt);
1013 template<
typename Gr
idType,
typename MaskT,
typename InterruptT>
inline 1015 divergence(
const GridType& grid,
const MaskT& mask,
bool threaded, InterruptT* interrupt)
1021 template<
typename Gr
idType,
typename InterruptT>
inline 1023 gradient(
const GridType& grid,
bool threaded, InterruptT* interrupt)
1026 op(grid, interrupt);
1030 template<
typename Gr
idType,
typename MaskT,
typename InterruptT>
inline 1032 gradient(
const GridType& grid,
const MaskT& mask,
bool threaded, InterruptT* interrupt)
1038 template<
typename Gr
idType,
typename InterruptT>
inline 1039 typename GridType::Ptr
1040 laplacian(
const GridType& grid,
bool threaded, InterruptT* interrupt)
1043 op(grid, interrupt);
1047 template<
typename Gr
idType,
typename MaskT,
typename InterruptT>
inline 1048 typename GridType::Ptr
1049 laplacian(
const GridType& grid,
const MaskT& mask,
bool threaded, InterruptT* interrupt)
1055 template<
typename Gr
idType,
typename InterruptT>
inline 1056 typename GridType::Ptr
1060 op(grid, interrupt);
1064 template<
typename Gr
idType,
typename MaskT,
typename InterruptT>
inline 1065 typename GridType::Ptr
1066 meanCurvature(
const GridType& grid,
const MaskT& mask,
bool threaded, InterruptT* interrupt)
1072 template<
typename Gr
idType,
typename InterruptT>
inline 1074 magnitude(
const GridType& grid,
bool threaded, InterruptT* interrupt)
1077 op(grid, interrupt);
1081 template<
typename Gr
idType,
typename MaskT,
typename InterruptT>
inline 1083 magnitude(
const GridType& grid,
const MaskT& mask,
bool threaded, InterruptT* interrupt)
1089 template<
typename Gr
idType,
typename InterruptT>
inline 1090 typename GridType::Ptr
1091 normalize(
const GridType& grid,
bool threaded, InterruptT* interrupt)
1094 op(grid, interrupt);
1098 template<
typename Gr
idType,
typename MaskT,
typename InterruptT>
inline 1099 typename GridType::Ptr
1100 normalize(
const GridType& grid,
const MaskT& mask,
bool threaded, InterruptT* interrupt)
1110 #endif // OPENVDB_TOOLS_GRID_OPERATORS_HAS_BEEN_INCLUDED
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:953
LeafRange leafRange(size_t grainsize=1) const
Return a TBB-compatible LeafRange.
Definition: LeafManager.h:386
bool wasInterrupted(T *i, int percent=-1)
Definition: NullInterrupter.h:76
Signed (x, y, z) 32-bit integer coordinates.
Definition: Coord.h:51
Compute the Laplacian at a given location in a grid using finite differencing of various orders...
Definition: Operators.h:1423
Compute the closest-point transform to a level set.
Definition: Operators.h:1710
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition: version.h:136
Compute the mean curvature.
Definition: Operators.h:1753
Iterator begin() const
Definition: LeafManager.h:181
Compute the curl of a vector-valued grid using differencing of various orders in the space defined by...
Definition: Operators.h:1278
Definition: Exceptions.h:40
VecType
Definition: Types.h:305
Compute the closest-point transform to a level set.
Definition: Operators.h:1657
This class manages a linear array of pointers to a given tree's leaf nodes, as well as optional auxil...
Definition: LeafManager.h:110
Definition: LeafManager.h:127
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:268
Center difference gradient operators, defined with respect to the range-space of the map...
Definition: Operators.h:643
Container class that associates a tree with a transform and metadata.
Definition: Grid.h:55
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:188
Tag dispatch class that distinguishes topology copy constructors from deep copy constructors.
Definition: Types.h:518
Dummy NOOP interrupter class defining interface.
Definition: NullInterrupter.h:52