36 #ifndef OPENVDB_TOOLS_GRID_OPERATORS_HAS_BEEN_INCLUDED
37 #define OPENVDB_TOOLS_GRID_OPERATORS_HAS_BEEN_INCLUDED
44 #include <tbb/parallel_for.h>
58 typedef typename VectorGridType::template ValueConverter<VecComponentValueT>::Type
Type;
67 typedef typename ScalarGridType::template ValueConverter<VectorValueT>::Type
Type;
81 template<
typename Gr
idType,
typename InterruptT>
inline
83 cpt(
const GridType& grid,
bool threaded, InterruptT* interrupt);
85 template<
typename Gr
idType,
typename MaskT,
typename InterruptT>
inline
87 cpt(
const GridType& grid,
const MaskT& mask,
bool threaded, InterruptT* interrupt);
89 template<
typename Gr
idType>
inline
91 cpt(
const GridType& grid,
bool threaded =
true)
93 return cpt<GridType, util::NullInterrupter>(grid, threaded, NULL);
96 template<
typename Gr
idType,
typename MaskT>
inline
97 typename ScalarToVectorConverter<GridType>::Type::Ptr
98 cpt(
const GridType& grid,
const MaskT& mask,
bool threaded =
true)
100 return cpt<GridType, MaskT, util::NullInterrupter>(grid, mask, threaded, NULL);
109 template<
typename Gr
idType,
typename InterruptT>
inline
110 typename GridType::Ptr
111 curl(
const GridType& grid,
bool threaded, InterruptT* interrupt);
113 template<
typename Gr
idType,
typename MaskT,
typename InterruptT>
inline
114 typename GridType::Ptr
115 curl(
const GridType& grid,
const MaskT& mask,
bool threaded, InterruptT* interrupt);
117 template<
typename Gr
idType>
inline
118 typename GridType::Ptr
119 curl(
const GridType& grid,
bool threaded =
true)
121 return curl<GridType, util::NullInterrupter>(grid, threaded, NULL);
124 template<
typename Gr
idType,
typename MaskT>
inline
125 typename GridType::Ptr
126 curl(
const GridType& grid,
const MaskT& mask,
bool threaded =
true)
128 return curl<GridType, MaskT, util::NullInterrupter>(grid, mask, threaded, NULL);
138 template<
typename Gr
idType,
typename InterruptT>
inline
139 typename VectorToScalarConverter<GridType>::Type::Ptr
140 divergence(
const GridType& grid,
bool threaded, InterruptT* interrupt);
142 template<
typename Gr
idType,
typename MaskT,
typename InterruptT>
inline
143 typename VectorToScalarConverter<GridType>::Type::Ptr
144 divergence(
const GridType& grid,
const MaskT& mask,
bool threaded, InterruptT* interrupt);
146 template<
typename Gr
idType>
inline
147 typename VectorToScalarConverter<GridType>::Type::Ptr
150 return divergence<GridType, util::NullInterrupter>(grid, threaded, NULL);
153 template<
typename Gr
idType,
typename MaskT>
inline
154 typename VectorToScalarConverter<GridType>::Type::Ptr
155 divergence(
const GridType& grid,
const MaskT& mask,
bool threaded =
true)
157 return divergence<GridType, MaskT, util::NullInterrupter>(grid, mask, threaded, NULL);
167 template<
typename Gr
idType,
typename InterruptT>
inline
168 typename ScalarToVectorConverter<GridType>::Type::Ptr
169 gradient(
const GridType& grid,
bool threaded, InterruptT* interrupt);
171 template<
typename Gr
idType,
typename MaskT,
typename InterruptT>
inline
172 typename ScalarToVectorConverter<GridType>::Type::Ptr
173 gradient(
const GridType& grid,
const MaskT& mask,
bool threaded, InterruptT* interrupt);
175 template<
typename Gr
idType>
inline
176 typename ScalarToVectorConverter<GridType>::Type::Ptr
177 gradient(
const GridType& grid,
bool threaded =
true)
179 return gradient<GridType, util::NullInterrupter>(grid, threaded, NULL);
182 template<
typename Gr
idType,
typename MaskT>
inline
183 typename ScalarToVectorConverter<GridType>::Type::Ptr
184 gradient(
const GridType& grid,
const MaskT& mask,
bool threaded =
true)
186 return gradient<GridType, MaskT, util::NullInterrupter>(grid, mask, threaded, NULL);
195 template<
typename Gr
idType,
typename InterruptT>
inline
196 typename GridType::Ptr
197 laplacian(
const GridType& grid,
bool threaded, InterruptT* interrupt);
199 template<
typename Gr
idType,
typename MaskT,
typename InterruptT>
inline
200 typename GridType::Ptr
201 laplacian(
const GridType& grid,
const MaskT& mask,
bool threaded, InterruptT* interrupt);
203 template<
typename Gr
idType>
inline
204 typename GridType::Ptr
207 return laplacian<GridType, util::NullInterrupter>(grid, threaded, NULL);
210 template<
typename Gr
idType,
typename MaskT>
inline
211 typename GridType::Ptr
212 laplacian(
const GridType& grid,
const MaskT mask,
bool threaded =
true)
214 return laplacian<GridType, MaskT, util::NullInterrupter>(grid, mask, threaded, NULL);
223 template<
typename Gr
idType,
typename InterruptT>
inline
224 typename GridType::Ptr
225 meanCurvature(
const GridType& grid,
bool threaded, InterruptT* interrupt);
227 template<
typename Gr
idType,
typename MaskT,
typename InterruptT>
inline
228 typename GridType::Ptr
229 meanCurvature(
const GridType& grid,
const MaskT& mask,
bool threaded, InterruptT* interrupt);
231 template<
typename Gr
idType>
inline
232 typename GridType::Ptr
235 return meanCurvature<GridType, util::NullInterrupter>(grid, threaded, NULL);
238 template<
typename Gr
idType,
typename MaskT>
inline
239 typename GridType::Ptr
240 meanCurvature(
const GridType& grid,
const MaskT& mask,
bool threaded =
true)
242 return meanCurvature<GridType, MaskT, util::NullInterrupter>(grid, mask, threaded, NULL);
252 template<
typename Gr
idType,
typename InterruptT>
inline
253 typename VectorToScalarConverter<GridType>::Type::Ptr
254 magnitude(
const GridType& grid,
bool threaded, InterruptT* interrupt);
256 template<
typename Gr
idType,
typename MaskT,
typename InterruptT>
inline
257 typename VectorToScalarConverter<GridType>::Type::Ptr
258 magnitude(
const GridType& grid,
const MaskT& mask,
bool threaded, InterruptT* interrupt);
260 template<
typename Gr
idType>
inline
261 typename VectorToScalarConverter<GridType>::Type::Ptr
264 return magnitude<GridType, util::NullInterrupter>(grid, threaded, NULL);
267 template<
typename Gr
idType,
typename MaskT>
inline
268 typename VectorToScalarConverter<GridType>::Type::Ptr
269 magnitude(
const GridType& grid,
const MaskT& mask,
bool threaded =
true)
271 return magnitude<GridType, MaskT, util::NullInterrupter>(grid, mask, threaded, NULL);
280 template<
typename Gr
idType,
typename InterruptT>
inline
281 typename GridType::Ptr
282 normalize(
const GridType& grid,
bool threaded, InterruptT* interrupt);
284 template<
typename Gr
idType,
typename MaskT,
typename InterruptT>
inline
285 typename GridType::Ptr
286 normalize(
const GridType& grid,
const MaskT& mask,
bool threaded, InterruptT* interrupt);
288 template<
typename Gr
idType>
inline
289 typename GridType::Ptr
292 return normalize<GridType, util::NullInterrupter>(grid, threaded, NULL);
295 template<
typename Gr
idType,
typename MaskT>
inline
296 typename GridType::Ptr
297 normalize(
const GridType& grid,
const MaskT& mask,
bool threaded =
true)
299 return normalize<GridType, MaskT, util::NullInterrupter>(grid, mask, threaded, NULL);
311 template<
typename Gr
idType>
328 typename MaskGridType,
340 GridOperator(
const InGridT& grid,
const MaskGridType* mask,
const MapT& map,
341 InterruptT* interrupt = NULL):
342 mAcc(grid.getConstAccessor()), mMap(map), mInterrupt(interrupt), mMask(mask)
347 typename OutGridT::Ptr
process(
bool threaded =
true)
349 if (mInterrupt) mInterrupt->start(
"Processing grid");
352 typename InGridT::TreeType tmp(mAcc.tree().background());
353 typename OutGridT::ValueType backg = OperatorT::result(mMap, tmp,
math::Coord(0));
356 typename OutTreeT::Ptr tree(
new OutTreeT(mAcc.tree(), backg,
TopologyCopy()));
360 typename OutGridT::Ptr result(
new OutGridT(tree));
364 result->topologyIntersection(*mMask);
370 LeafManagerT leafManager(*tree);
373 tbb::parallel_for(leafManager.
leafRange(), *
this);
378 if (mInterrupt) mInterrupt->end();
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()));
424 Cpt(
const InGridType& grid, InterruptT* interrupt = NULL):
425 mInputGrid(grid), mInterrupt(interrupt), mMask(NULL)
429 Cpt(
const InGridType& grid,
const MaskGridType& mask, InterruptT* interrupt = NULL):
430 mInputGrid(grid), mInterrupt(interrupt), mMask(&mask)
434 typename OutGridType::Ptr
process(
bool threaded =
true,
bool useWorldTransform =
true)
436 Functor functor(mInputGrid, mMask, threaded, useWorldTransform, mInterrupt);
439 return functor.mOutputGrid;
445 template<
typename MapT,
typename AccT>
446 static typename OutGridType::ValueType
447 result(
const MapT& map,
const AccT& acc,
const Coord& xyz)
454 template<
typename MapT,
typename AccT>
455 static typename OutGridType::ValueType
456 result(
const MapT& map,
const AccT& acc,
const Coord& xyz)
463 Functor(
const InGridType& grid,
const MaskGridType* mask,
464 bool threaded,
bool worldspace, InterruptT* interrupt)
465 : mThreaded(threaded)
466 , mWorldSpace(worldspace)
468 , mInterrupt(interrupt)
472 template<
typename MapT>
473 void operator()(
const MapT& map)
476 gridop::GridOperator<InGridType, MaskGridType, OutGridType, MapT, WsOpT, InterruptT>
477 op(mInputGrid, mMask, map, mInterrupt);
478 mOutputGrid = op.process(mThreaded);
480 gridop::GridOperator<InGridType, MaskGridType, OutGridType, MapT, IsOpT, InterruptT>
481 op(mInputGrid, mMask, map, mInterrupt);
482 mOutputGrid = op.process(mThreaded);
485 const bool mThreaded;
486 const bool mWorldSpace;
487 const InGridType& mInputGrid;
488 typename OutGridType::Ptr mOutputGrid;
489 InterruptT* mInterrupt;
490 const MaskGridType* mMask;
492 const InGridType& mInputGrid;
493 InterruptT* mInterrupt;
494 const MaskGridType* mMask;
504 typename MaskGridType =
typename gridop::ToBoolGrid<GridT>::Type,
505 typename InterruptT = util::NullInterrupter>
512 Curl(
const GridT& grid, InterruptT* interrupt = NULL):
513 mInputGrid(grid), mInterrupt(interrupt), mMask(NULL)
517 Curl(
const GridT& grid,
const MaskGridType& mask, InterruptT* interrupt = NULL):
518 mInputGrid(grid), mInterrupt(interrupt), mMask(&mask)
522 typename GridT::Ptr
process(
bool threaded =
true)
524 Functor functor(mInputGrid, mMask, threaded, mInterrupt);
526 if (functor.mOutputGrid) functor.mOutputGrid->setVectorType(
VEC_COVARIANT);
527 return functor.mOutputGrid;
533 Functor(
const GridT& grid,
const MaskGridType* mask,
534 bool threaded, InterruptT* interrupt):
535 mThreaded(threaded), mInputGrid(grid), mInterrupt(interrupt), mMask(mask) {}
537 template<
typename MapT>
538 void operator()(
const MapT& map)
541 gridop::GridOperator<GridT, MaskGridType, GridT, MapT, OpT, InterruptT>
542 op(mInputGrid, mMask, map, mInterrupt);
543 mOutputGrid = op.process(mThreaded);
546 const bool mThreaded;
547 const GridT& mInputGrid;
548 typename GridT::Ptr mOutputGrid;
549 InterruptT* mInterrupt;
550 const MaskGridType* mMask;
553 const GridT& mInputGrid;
554 InterruptT* mInterrupt;
555 const MaskGridType* mMask;
565 typename MaskGridType =
typename gridop::ToBoolGrid<InGridT>::Type,
566 typename InterruptT = util::NullInterrupter>
573 Divergence(
const InGridT& grid, InterruptT* interrupt = NULL):
574 mInputGrid(grid), mInterrupt(interrupt), mMask(NULL)
578 Divergence(
const InGridT& grid,
const MaskGridType& mask, InterruptT* interrupt = NULL):
579 mInputGrid(grid), mInterrupt(interrupt), mMask(&mask)
583 typename OutGridType::Ptr
process(
bool threaded =
true)
588 return functor.mOutputGrid;
592 return functor.mOutputGrid;
597 template<math::DScheme DiffScheme>
600 Functor(
const InGridT& grid,
const MaskGridType* mask,
601 bool threaded, InterruptT* interrupt):
602 mThreaded(threaded), mInputGrid(grid), mInterrupt(interrupt), mMask(mask) {}
604 template<
typename MapT>
609 op(mInputGrid, mMask, map, mInterrupt);
610 mOutputGrid = op.
process(mThreaded);
640 Gradient(
const InGridT& grid, InterruptT* interrupt = NULL):
641 mInputGrid(grid), mInterrupt(interrupt), mMask(NULL)
645 Gradient(
const InGridT& grid,
const MaskGridType& mask, InterruptT* interrupt = NULL):
646 mInputGrid(grid), mInterrupt(interrupt), mMask(&mask)
650 typename OutGridType::Ptr
process(
bool threaded =
true)
652 Functor functor(mInputGrid, mMask, threaded, mInterrupt);
654 if (functor.mOutputGrid) functor.mOutputGrid->setVectorType(
VEC_COVARIANT);
655 return functor.mOutputGrid;
661 Functor(
const InGridT& grid,
const MaskGridType* mask,
662 bool threaded, InterruptT* interrupt):
663 mThreaded(threaded), mInputGrid(grid), mInterrupt(interrupt), mMask(mask) {}
665 template<
typename MapT>
670 op(mInputGrid, mMask, map, mInterrupt);
671 mOutputGrid = op.
process(mThreaded);
700 Laplacian(
const GridT& grid, InterruptT* interrupt = NULL):
701 mInputGrid(grid), mInterrupt(interrupt), mMask(NULL)
705 Laplacian(
const GridT& grid,
const MaskGridType& mask, InterruptT* interrupt = NULL):
706 mInputGrid(grid), mInterrupt(interrupt), mMask(&mask)
710 typename GridT::Ptr
process(
bool threaded =
true)
712 Functor functor(mInputGrid, mMask, threaded, mInterrupt);
714 if (functor.mOutputGrid) functor.mOutputGrid->setVectorType(
VEC_COVARIANT);
715 return functor.mOutputGrid;
721 Functor(
const GridT& grid,
const MaskGridType* mask,
bool threaded, InterruptT* interrupt):
722 mThreaded(threaded), mInputGrid(grid), mInterrupt(interrupt), mMask(mask) {}
724 template<
typename MapT>
729 op(mInputGrid, mMask, map);
730 mOutputGrid = op.
process(mThreaded);
760 mInputGrid(grid), mInterrupt(interrupt), mMask(NULL)
764 MeanCurvature(
const GridT& grid,
const MaskGridType& mask, InterruptT* interrupt = NULL):
765 mInputGrid(grid), mInterrupt(interrupt), mMask(&mask)
769 typename GridT::Ptr
process(
bool threaded =
true)
771 Functor functor(mInputGrid, mMask, threaded, mInterrupt);
773 if (functor.mOutputGrid) functor.mOutputGrid->setVectorType(
VEC_COVARIANT);
774 return functor.mOutputGrid;
780 Functor(
const GridT& grid,
const MaskGridType* mask,
bool threaded, InterruptT* interrupt):
781 mThreaded(threaded), mInputGrid(grid), mInterrupt(interrupt), mMask(mask) {}
783 template<
typename MapT>
788 op(mInputGrid, mMask, map);
789 mOutputGrid = op.
process(mThreaded);
818 Magnitude(
const InGridType& grid, InterruptT* interrupt = NULL):
819 mInputGrid(grid), mInterrupt(interrupt), mMask(NULL)
823 Magnitude(
const InGridType& grid,
const MaskGridType& mask, InterruptT* interrupt = NULL):
824 mInputGrid(grid), mInterrupt(interrupt), mMask(&mask)
828 typename OutGridType::Ptr
process(
bool threaded =
true)
830 Functor functor(mInputGrid, mMask, threaded, mInterrupt);
832 return functor.mOutputGrid;
838 template<
typename MapT,
typename AccT>
839 static typename OutGridType::ValueType
840 result(
const MapT&,
const AccT& acc,
const Coord& xyz) {
return acc.getValue(xyz).length();}
844 Functor(
const InGridT& grid,
const MaskGridType* mask,
845 bool threaded, InterruptT* interrupt):
846 mThreaded(threaded), mInputGrid(grid), mInterrupt(interrupt), mMask(mask) {}
848 template<
typename MapT>
852 op(mInputGrid, mMask, map);
853 mOutputGrid = op.
process(mThreaded);
882 Normalize(
const GridT& grid, InterruptT* interrupt = NULL):
883 mInputGrid(grid), mInterrupt(interrupt), mMask(NULL)
887 Normalize(
const GridT& grid,
const MaskGridType& mask, InterruptT* interrupt = NULL):
888 mInputGrid(grid), mInterrupt(interrupt), mMask(&mask)
892 typename GridT::Ptr
process(
bool threaded =
true)
894 Functor functor(mInputGrid, mMask, threaded, mInterrupt);
896 if (
typename GridT::Ptr outGrid = functor.mOutputGrid) {
897 const VecType vecType = mInputGrid.getVectorType();
901 outGrid->setVectorType(vecType);
904 return functor.mOutputGrid;
910 template<
typename MapT,
typename AccT>
911 static typename OutGridType::ValueType
912 result(
const MapT&,
const AccT& acc,
const Coord& xyz)
914 typename OutGridType::ValueType vec = acc.getValue(xyz);
915 if ( !vec.normalize() ) vec.setZero();
921 Functor(
const GridT& grid,
const MaskGridType* mask,
bool threaded, InterruptT* interrupt):
922 mThreaded(threaded), mInputGrid(grid), mInterrupt(interrupt), mMask(mask) {}
924 template<
typename MapT>
928 op(mInputGrid, mMask,map);
929 mOutputGrid = op.
process(mThreaded);
948 template<
typename Gr
idType,
typename InterruptT>
inline
950 cpt(
const GridType& grid,
bool threaded, InterruptT* interrupt)
956 template<
typename Gr
idType,
typename MaskT,
typename InterruptT>
inline
957 typename ScalarToVectorConverter<GridType>::Type::Ptr
958 cpt(
const GridType& grid,
const MaskT& mask,
bool threaded, InterruptT* interrupt)
964 template<
typename Gr
idType,
typename InterruptT>
inline
965 typename GridType::Ptr
966 curl(
const GridType& grid,
bool threaded, InterruptT* interrupt)
972 template<
typename Gr
idType,
typename MaskT,
typename InterruptT>
inline
973 typename GridType::Ptr
974 curl(
const GridType& grid,
const MaskT& mask,
bool threaded, InterruptT* interrupt)
980 template<
typename Gr
idType,
typename InterruptT>
inline
981 typename VectorToScalarConverter<GridType>::Type::Ptr
982 divergence(
const GridType& grid,
bool threaded, InterruptT* interrupt)
989 template<
typename Gr
idType,
typename MaskT,
typename InterruptT>
inline
990 typename VectorToScalarConverter<GridType>::Type::Ptr
991 divergence(
const GridType& grid,
const MaskT& mask,
bool threaded, InterruptT* interrupt)
997 template<
typename Gr
idType,
typename InterruptT>
inline
998 typename ScalarToVectorConverter<GridType>::Type::Ptr
999 gradient(
const GridType& grid,
bool threaded, InterruptT* interrupt)
1002 op(grid, interrupt);
1006 template<
typename Gr
idType,
typename MaskT,
typename InterruptT>
inline
1007 typename ScalarToVectorConverter<GridType>::Type::Ptr
1008 gradient(
const GridType& grid,
const MaskT& mask,
bool threaded, InterruptT* interrupt)
1014 template<
typename Gr
idType,
typename InterruptT>
inline
1015 typename GridType::Ptr
1016 laplacian(
const GridType& grid,
bool threaded, InterruptT* interrupt)
1019 op(grid, interrupt);
1023 template<
typename Gr
idType,
typename MaskT,
typename InterruptT>
inline
1024 typename GridType::Ptr
1025 laplacian(
const GridType& grid,
const MaskT& mask,
bool threaded, InterruptT* interrupt)
1031 template<
typename Gr
idType,
typename InterruptT>
inline
1032 typename GridType::Ptr
1036 op(grid, interrupt);
1040 template<
typename Gr
idType,
typename MaskT,
typename InterruptT>
inline
1041 typename GridType::Ptr
1042 meanCurvature(
const GridType& grid,
const MaskT& mask,
bool threaded, InterruptT* interrupt)
1048 template<
typename Gr
idType,
typename InterruptT>
inline
1049 typename VectorToScalarConverter<GridType>::Type::Ptr
1050 magnitude(
const GridType& grid,
bool threaded, InterruptT* interrupt)
1053 op(grid, interrupt);
1057 template<
typename Gr
idType,
typename MaskT,
typename InterruptT>
inline
1058 typename VectorToScalarConverter<GridType>::Type::Ptr
1059 magnitude(
const GridType& grid,
const MaskT& mask,
bool threaded, InterruptT* interrupt)
1065 template<
typename Gr
idType,
typename InterruptT>
inline
1066 typename GridType::Ptr
1067 normalize(
const GridType& grid,
bool threaded, InterruptT* interrupt)
1070 op(grid, interrupt);
1074 template<
typename Gr
idType,
typename MaskT,
typename InterruptT>
inline
1075 typename GridType::Ptr
1076 normalize(
const GridType& grid,
const MaskT& mask,
bool threaded, InterruptT* interrupt)
1086 #endif // OPENVDB_TOOLS_GRID_OPERATORS_HAS_BEEN_INCLUDED
bool wasInterrupted(T *i, int percent=-1)
Definition: NullInterrupter.h:76
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:952
LeafRange leafRange(size_t grainsize=1) const
Return a TBB-compatible LeafRange.
Definition: LeafManager.h:350
This class manages a linear array of pointers to a given tree's leaf nodes, as well as optional auxil...
Definition: LeafManager.h:114
Signed (x, y, z) 32-bit integer coordinates.
Definition: Coord.h:47
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
Iterator begin() const
Definition: LeafManager.h:181
Compute the closest-point transform to a level set.
Definition: Operators.h:1656
Container class that associates a tree with a transform and metadata.
Definition: Grid.h:54
Compute the Laplacian at a given location in a grid using finite differencing of various orders...
Definition: Operators.h:1422
#define OPENVDB_VERSION_NAME
Definition: version.h:43
Dummy NOOP interrupter class defining interface.
Definition: NullInterrupter.h:52
Compute the mean curvature.
Definition: Operators.h:1751
VecType
Definition: Types.h:234
Definition: Exceptions.h:39
Compute the curl of a vector-valued grid using differencing of various orders in the space defined by...
Definition: Operators.h:1277
Compute the closest-point transform to a level set.
Definition: Operators.h:1709
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:71
A LeafManager manages a linear array of pointers to a given tree's leaf nodes, as well as optional au...
Center difference gradient operators, defined with respect to the range-space of the map...
Definition: Operators.h:642
Definition: LeafManager.h:131