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>
44 #include <tbb/parallel_for.h>
58 typedef typename VectorGridType::template ValueConverter<VecComponentValueT>::Type
Type;
67 typedef typename ScalarGridType::template ValueConverter<VectorValueT>::Type
Type;
79 template<
typename Gr
idType,
typename InterruptT>
inline
81 cpt(
const GridType& grid,
bool threaded, InterruptT* interrupt);
83 template<
typename Gr
idType>
inline
85 cpt(
const GridType& grid,
bool threaded =
true)
87 return cpt<GridType, util::NullInterrupter>(grid, threaded, NULL);
93 template<
typename Gr
idType,
typename InterruptT>
inline
94 typename GridType::Ptr
95 curl(
const GridType& grid,
bool threaded, InterruptT* interrupt);
97 template<
typename Gr
idType>
inline
98 typename GridType::Ptr
99 curl(
const GridType& grid,
bool threaded =
true)
101 return curl<GridType, util::NullInterrupter>(grid, threaded, NULL);
107 template<
typename Gr
idType,
typename InterruptT>
inline
108 typename VectorToScalarConverter<GridType>::Type::Ptr
109 divergence(
const GridType& grid,
bool threaded, InterruptT* interrupt);
111 template<
typename Gr
idType>
inline
112 typename VectorToScalarConverter<GridType>::Type::Ptr
115 return divergence<GridType, util::NullInterrupter>(grid, threaded, NULL);
121 template<
typename Gr
idType,
typename InterruptT>
inline
122 typename ScalarToVectorConverter<GridType>::Type::Ptr
123 gradient(
const GridType& grid,
bool threaded, InterruptT* interrupt);
125 template<
typename Gr
idType>
inline
126 typename ScalarToVectorConverter<GridType>::Type::Ptr
127 gradient(
const GridType& grid,
bool threaded =
true)
129 return gradient<GridType, util::NullInterrupter>(grid, threaded, NULL);
135 template<
typename Gr
idType,
typename InterruptT>
inline
136 typename GridType::Ptr
137 laplacian(
const GridType& grid,
bool threaded, InterruptT* interrupt);
139 template<
typename Gr
idType>
inline
140 typename GridType::Ptr
143 return laplacian<GridType, util::NullInterrupter>(grid, threaded, NULL);
148 template<
typename Gr
idType,
typename InterruptT>
inline
149 typename GridType::Ptr
150 meanCurvature(
const GridType& grid,
bool threaded, InterruptT* interrupt);
152 template<
typename Gr
idType>
inline
153 typename GridType::Ptr
156 return meanCurvature<GridType, util::NullInterrupter>(grid, threaded, NULL);
162 template<
typename Gr
idType,
typename InterruptT>
inline
163 typename VectorToScalarConverter<GridType>::Type::Ptr
164 magnitude(
const GridType& grid,
bool threaded, InterruptT* interrupt);
166 template<
typename Gr
idType>
inline
167 typename VectorToScalarConverter<GridType>::Type::Ptr
170 return magnitude<GridType, util::NullInterrupter>(grid, threaded, NULL);
175 template<
typename Gr
idType,
typename InterruptT>
inline
176 typename GridType::Ptr
177 normalize(
const GridType& grid,
bool threaded, InterruptT* interrupt);
179 template<
typename Gr
idType>
inline
180 typename GridType::Ptr
183 return normalize<GridType, util::NullInterrupter>(grid, threaded, NULL);
200 template<
typename InGridT,
typename OutGridT,
typename MapT,
205 typedef typename OutGridT::TreeType OutTreeT;
206 typedef typename OutTreeT::LeafNodeType OutLeafT;
209 GridOperator(
const InGridT& grid,
const MapT& map, InterruptT* interrupt = NULL):
213 virtual ~GridOperator() {}
214 typename OutGridT::Ptr process(
bool threaded =
true)
218 typename InGridT::TreeType tmp(
mAcc.tree().background());
219 typename OutGridT::ValueType backg = OperatorT::result(
mMap, tmp, math::Coord(0));
221 typename OutTreeT::Ptr tree(
new OutTreeT(
mAcc.tree(), backg, TopologyCopy()));
223 typename OutGridT::Ptr result(
new OutGridT(tree));
225 result->setTransform(math::Transform::Ptr(
new math::Transform(
mMap.copy() )));
227 LeafManagerT leafManager(*tree);
230 tbb::parallel_for(leafManager.leafRange(), *
this);
232 (*this)(leafManager.leafRange());
245 void operator()(
const typename LeafManagerT::LeafRange& range)
const
249 for (
typename LeafManagerT::LeafRange::Iterator leaf=range.begin(); leaf; ++leaf) {
250 for (
typename OutLeafT::ValueOnIter value=leaf->beginValueOn(); value; ++value) {
251 value.setValue(OperatorT::result(
mMap,
mAcc, value.getCoord()));
258 typedef typename InGridT::ConstAccessor AccessorT;
271 template<
typename InGr
idT,
typename InterruptT = util::NullInterrupter>
282 typename OutGridType::Ptr
process(
bool threaded =
true,
bool useWorldTransform =
true)
284 Functor functor(mInputGrid, threaded, useWorldTransform,
mInterrupt);
286 return functor.mOutputGrid;
291 template<
typename MapT,
typename AccT>
292 static typename OutGridType::ValueType
293 result(
const MapT& map,
const AccT& acc,
const Coord& xyz)
300 template<
typename MapT,
typename AccT>
301 static typename OutGridType::ValueType
302 result(
const MapT& map,
const AccT& acc,
const Coord& xyz)
309 Functor(
const InGridType& grid,
bool threaded,
bool worldspace, InterruptT* interrupt):
310 mThreaded(threaded), mWorldSpace(worldspace), mInputGrid(grid),
mInterrupt(interrupt){}
311 template<
typename MapT>
312 void operator()(
const MapT& map)
315 GridOperator<InGridType, OutGridType, MapT, WsOpT, InterruptT> op(mInputGrid, map,
mInterrupt);
316 mOutputGrid = op.process(mThreaded);
318 GridOperator<InGridType, OutGridType, MapT, IsOpT, InterruptT> op(mInputGrid, map,
mInterrupt);
319 mOutputGrid = op.process(mThreaded);
322 const bool mThreaded;
323 const bool mWorldSpace;
324 const InGridType& mInputGrid;
325 typename OutGridType::Ptr mOutputGrid;
328 const InGridType& mInputGrid;
337 template<
typename Gr
idT,
typename InterruptT = util::NullInterrupter>
343 Curl(
const GridT& grid, InterruptT* interrupt = NULL):
347 typename GridT::Ptr
process(
bool threaded =
true)
349 Functor functor(mInputGrid, threaded,
mInterrupt);
351 return functor.mOutputGrid;
357 Functor(
const GridT& grid,
bool threaded, InterruptT* interrupt):
358 mThreaded(threaded), mInputGrid(grid),
mInterrupt(interrupt){}
359 template<
typename MapT>
360 void operator()(
const MapT& map)
363 GridOperator<GridT, GridT, MapT, OpT, InterruptT> op(mInputGrid, map,
mInterrupt);
364 mOutputGrid = op.process(mThreaded);
366 const bool mThreaded;
367 const GridT& mInputGrid;
368 typename GridT::Ptr mOutputGrid;
372 const GridT& mInputGrid;
381 template<
typename InGr
idT,
typename InterruptT = util::NullInterrupter>
388 Divergence(
const InGridT& grid, InterruptT* interrupt = NULL):
392 typename OutGridType::Ptr
process(
bool threaded =
true)
397 return functor.mOutputGrid;
402 return functor.mOutputGrid;
407 template<math::DScheme DiffScheme>
410 Functor(
const InGridT& grid,
bool threaded, InterruptT* interrupt):
411 mThreaded(threaded), mInputGrid(grid),
mInterrupt(interrupt) {}
412 template<
typename MapT>
416 GridOperator<InGridType, OutGridType, MapT, OpT, InterruptT> op(mInputGrid, map,
mInterrupt);
417 mOutputGrid = op.process(mThreaded);
434 template<
typename InGr
idT,
typename InterruptT = util::NullInterrupter>
441 Gradient(
const InGridT& grid, InterruptT* interrupt = NULL):
445 typename OutGridType::Ptr
process(
bool threaded =
true)
449 return functor.mOutputGrid;
455 Functor(
const InGridT& grid,
bool threaded, InterruptT* interrupt):
456 mThreaded(threaded), mInputGrid(grid),
mInterrupt(interrupt) {}
457 template<
typename MapT>
461 GridOperator<InGridType, OutGridType, MapT, OpT, InterruptT> op(mInputGrid, map,
mInterrupt);
462 mOutputGrid = op.process(mThreaded);
479 template<
typename Gr
idT,
typename InterruptT = util::NullInterrupter>
485 Laplacian(
const GridT& grid, InterruptT* interrupt = NULL):
489 typename GridT::Ptr
process(
bool threaded =
true)
493 return functor.mOutputGrid;
499 Functor(
const GridT& grid,
bool threaded, InterruptT* interrupt):
500 mThreaded(threaded), mInputGrid(grid),
mInterrupt(interrupt) {}
501 template<
typename MapT>
505 GridOperator<GridT, GridT, MapT, OpT, InterruptT> op(mInputGrid, map);
506 mOutputGrid = op.process(mThreaded);
522 template<
typename Gr
idT,
typename InterruptT = util::NullInterrupter>
532 typename GridT::Ptr
process(
bool threaded =
true)
536 return functor.mOutputGrid;
542 Functor(
const GridT& grid,
bool threaded, InterruptT* interrupt):
543 mThreaded(threaded), mInputGrid(grid),
mInterrupt(interrupt) {}
544 template<
typename MapT>
548 GridOperator<GridT, GridT, MapT, OpT, InterruptT> op(mInputGrid, map);
549 mOutputGrid = op.process(mThreaded);
565 template<
typename InGr
idT,
typename InterruptT = util::NullInterrupter>
575 typename OutGridType::Ptr
process(
bool threaded =
true)
579 return functor.mOutputGrid;
585 template<
typename MapT,
typename AccT>
586 static typename OutGridType::ValueType
587 result(
const MapT&,
const AccT& acc,
const Coord& xyz) {
return acc.getValue(xyz).length();}
591 Functor(
const InGridT& grid,
bool threaded, InterruptT* interrupt):
592 mThreaded(threaded), mInputGrid(grid),
mInterrupt(interrupt) {}
593 template<
typename MapT>
596 GridOperator<InGridType, OutGridType, MapT, OpT, InterruptT> op(mInputGrid, map);
597 mOutputGrid = op.process(mThreaded);
613 template<
typename Gr
idT,
typename InterruptT = util::NullInterrupter>
619 Normalize(
const GridT& grid, InterruptT* interrupt = NULL):
623 typename GridT::Ptr
process(
bool threaded =
true)
627 return functor.mOutputGrid;
633 template<
typename MapT,
typename AccT>
634 static typename OutGridType::ValueType
635 result(
const MapT&,
const AccT& acc,
const Coord& xyz)
637 typename OutGridType::ValueType vec = acc.getValue(xyz);
638 if ( !vec.normalize() ) vec.setZero();
644 Functor(
const GridT& grid,
bool threaded, InterruptT* interrupt):
645 mThreaded(threaded), mInputGrid(grid),
mInterrupt(interrupt) {}
646 template<
typename MapT>
649 GridOperator<GridT, GridT, MapT, OpT, InterruptT> op(mInputGrid, map);
650 mOutputGrid = op.process(mThreaded);
666 template<
typename Gr
idType,
typename InterruptT>
inline
668 cpt(
const GridType& grid,
bool threaded, InterruptT* interrupt)
674 template<
typename Gr
idType,
typename InterruptT>
inline
675 typename GridType::Ptr
676 curl(
const GridType& grid,
bool threaded, InterruptT* interrupt)
682 template<
typename Gr
idType,
typename InterruptT>
inline
683 typename VectorToScalarConverter<GridType>::Type::Ptr
684 divergence(
const GridType& grid,
bool threaded, InterruptT* interrupt)
690 template<
typename Gr
idType,
typename InterruptT>
inline
691 typename ScalarToVectorConverter<GridType>::Type::Ptr
692 gradient(
const GridType& grid,
bool threaded, InterruptT* interrupt)
698 template<
typename Gr
idType,
typename InterruptT>
inline
699 typename GridType::Ptr
700 laplacian(
const GridType& grid,
bool threaded, InterruptT* interrupt)
706 template<
typename Gr
idType,
typename InterruptT>
inline
707 typename GridType::Ptr
714 template<
typename Gr
idType,
typename InterruptT>
inline
715 typename VectorToScalarConverter<GridType>::Type::Ptr
716 magnitude(
const GridType& grid,
bool threaded, InterruptT* interrupt)
722 template<
typename Gr
idType,
typename InterruptT>
inline
723 typename GridType::Ptr
724 normalize(
const GridType& grid,
bool threaded, InterruptT* interrupt)
734 #endif // OPENVDB_TOOLS_GRID_OPERATORS_HAS_BEEN_INCLUDED
Compute the curl of a vector-valued grid using differencing of various orders in the space defined by...
Definition: Operators.h:1260
const MapT & mMap
Definition: GridOperators.h:260
Compute the Laplacian at a given location in a grid using finite differencing of various orders...
Definition: Operators.h:1403
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:253
AccessorT mAcc
Definition: GridOperators.h:259
Compute the closest-point transform to a level set.
Definition: Operators.h:1637
Compute the closest-point transform to a level set.
Definition: Operators.h:1690
Center difference gradient operators, defined with respect to the range-space of the map...
Definition: Operators.h:609
#define OPENVDB_VERSION_NAME
Definition: version.h:45
InterruptT * mInterrupt
Definition: GridOperators.h:261
Compute the mean curvature.
Definition: Operators.h:1732
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:56
This class manages a linear array of pointers to a given tree's leaf nodes, as well as optional auxil...
Definition: LeafManager.h:109
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:915
Dummy NOOP interrupter class defining interface.
Definition: NullInterrupter.h:52