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;
 
 
   54template<
typename Gr
idType, 
typename InterruptT>
 
   56cpt(
const GridType& grid, 
bool threaded, InterruptT* interrupt);
 
   58template<
typename Gr
idType, 
typename MaskT, 
typename InterruptT>
 
   60cpt(
const GridType& grid, 
const MaskT& mask, 
bool threaded, InterruptT* interrupt);
 
   62template<
typename Gr
idType>
 
   69template<
typename Gr
idType, 
typename MaskT>
 
   70typename ScalarToVectorConverter<GridType>::Type::Ptr
 
   71cpt(
const GridType& grid, 
const MaskT& mask, 
bool threaded = 
true)
 
 
   82template<
typename Gr
idType, 
typename InterruptT>
 
   84curl(
const GridType& grid, 
bool threaded, InterruptT* interrupt);
 
   86template<
typename Gr
idType, 
typename MaskT, 
typename InterruptT>
 
   88curl(
const GridType& grid, 
const MaskT& mask, 
bool threaded, InterruptT* interrupt);
 
   90template<
typename Gr
idType>
 
   97template<
typename Gr
idType, 
typename MaskT>
 
  111template<
typename Gr
idType, 
typename InterruptT>
 
  112typename VectorToScalarConverter<GridType>::Type::Ptr
 
  113divergence(
const GridType& grid, 
bool threaded, InterruptT* interrupt);
 
  115template<
typename Gr
idType, 
typename MaskT, 
typename InterruptT>
 
  116typename VectorToScalarConverter<GridType>::Type::Ptr
 
  117divergence(
const GridType& grid, 
const MaskT& mask, 
bool threaded, InterruptT* interrupt);
 
  119template<
typename Gr
idType>
 
  120typename VectorToScalarConverter<GridType>::Type::Ptr
 
  126template<
typename Gr
idType, 
typename MaskT>
 
  127typename VectorToScalarConverter<GridType>::Type::Ptr
 
  140template<
typename Gr
idType, 
typename InterruptT>
 
  141typename ScalarToVectorConverter<GridType>::Type::Ptr
 
  142gradient(
const GridType& grid, 
bool threaded, InterruptT* interrupt);
 
  144template<
typename Gr
idType, 
typename MaskT, 
typename InterruptT>
 
  145typename ScalarToVectorConverter<GridType>::Type::Ptr
 
  146gradient(
const GridType& grid, 
const MaskT& mask, 
bool threaded, InterruptT* interrupt);
 
  148template<
typename Gr
idType>
 
  149typename ScalarToVectorConverter<GridType>::Type::Ptr
 
  155template<
typename Gr
idType, 
typename MaskT>
 
  156typename ScalarToVectorConverter<GridType>::Type::Ptr
 
  168template<
typename Gr
idType, 
typename InterruptT>
 
  169typename GridType::Ptr
 
  170laplacian(
const GridType& grid, 
bool threaded, InterruptT* interrupt);
 
  172template<
typename Gr
idType, 
typename MaskT, 
typename InterruptT>
 
  173typename GridType::Ptr
 
  174laplacian(
const GridType& grid, 
const MaskT& mask, 
bool threaded, InterruptT* interrupt);
 
  176template<
typename Gr
idType>
 
  177typename GridType::Ptr
 
  183template<
typename Gr
idType, 
typename MaskT>
 
  184typename GridType::Ptr
 
  196template<
typename Gr
idType, 
typename InterruptT>
 
  197typename GridType::Ptr
 
  198meanCurvature(
const GridType& grid, 
bool threaded, InterruptT* interrupt);
 
  200template<
typename Gr
idType, 
typename MaskT, 
typename InterruptT>
 
  201typename GridType::Ptr
 
  202meanCurvature(
const GridType& grid, 
const MaskT& mask, 
bool threaded, InterruptT* interrupt);
 
  204template<
typename Gr
idType>
 
  205typename GridType::Ptr
 
  211template<
typename Gr
idType, 
typename MaskT>
 
  212typename GridType::Ptr
 
  225template<
typename Gr
idType, 
typename InterruptT>
 
  226typename VectorToScalarConverter<GridType>::Type::Ptr
 
  227magnitude(
const GridType& grid, 
bool threaded, InterruptT* interrupt);
 
  229template<
typename Gr
idType, 
typename MaskT, 
typename InterruptT>
 
  230typename VectorToScalarConverter<GridType>::Type::Ptr
 
  231magnitude(
const GridType& grid, 
const MaskT& mask, 
bool threaded, InterruptT* interrupt);
 
  233template<
typename Gr
idType>
 
  234typename VectorToScalarConverter<GridType>::Type::Ptr
 
  240template<
typename Gr
idType, 
typename MaskT>
 
  241typename VectorToScalarConverter<GridType>::Type::Ptr
 
  253template<
typename Gr
idType, 
typename InterruptT>
 
  254typename GridType::Ptr
 
  255normalize(
const GridType& grid, 
bool threaded, InterruptT* interrupt);
 
  257template<
typename Gr
idType, 
typename MaskT, 
typename InterruptT>
 
  258typename GridType::Ptr
 
  259normalize(
const GridType& grid, 
const MaskT& mask, 
bool threaded, InterruptT* interrupt);
 
  261template<
typename Gr
idType>
 
  262typename GridType::Ptr
 
  268template<
typename Gr
idType, 
typename MaskT>
 
  269typename GridType::Ptr
 
  284template<
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())
 
 
  327        typename InGridT::TreeType tmp(
mAcc.tree().background());
 
  328        typename OutGridT::ValueType backg = OperatorT::result(
mMap, tmp, 
math::Coord(0));
 
  339        typename OutGridT::Ptr result(
new OutGridT(
tree));
 
  343            result->topologyIntersection(*
mMask);
 
  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()));
 
 
  387    void operator()(
const typename LeafManagerT::LeafRange& range)
 const 
  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()));
 
 
 
 
  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);
 
  439        processTypedMap(mInputGrid.transform(), functor);
 
  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)
 
  468        , mWorldSpace(worldspace)
 
  470        , mInterrupt(interrupt)
 
  474        template<
typename MapT>
 
  475        void operator()(
const MapT& map)
 
  478                gridop::GridOperator<InGridType, MaskGridType, OutGridType, MapT, WsOpT, InterruptT>
 
  479                    op(mInputGrid, mMask, map, mInterrupt, 
false);
 
  480                mOutputGrid = 
op.process(mThreaded); 
 
  482                gridop::GridOperator<InGridType, MaskGridType, OutGridType, MapT, IsOpT, InterruptT>
 
  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;
 
 
  506    typename MaskGridType = 
typename gridop::ToMaskGrid<GridT>::Type,
 
  507    typename InterruptT = util::NullInterrupter>
 
  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)
 
 
  526        Functor functor(mInputGrid, mMask, 
threaded, mInterrupt);
 
  527        processTypedMap(mInputGrid.transform(), functor);
 
  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)
 
  543            gridop::GridOperator<GridT, MaskGridType, GridT, MapT, OpT, InterruptT>
 
  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;
 
 
  567    typename MaskGridType = 
typename gridop::ToMaskGrid<InGridT>::Type,
 
  568    typename InterruptT = util::NullInterrupter>
 
  575    Divergence(
const InGridT& grid, InterruptT* interrupt = 
nullptr):
 
 
  580    Divergence(
const InGridT& grid, 
const MaskGridType& mask, InterruptT* interrupt = 
nullptr):
 
 
  589            processTypedMap(
mInputGrid.transform(), functor);
 
  590            return functor.mOutputGrid;
 
  593            processTypedMap(
mInputGrid.transform(), functor);
 
  594            return functor.mOutputGrid;
 
 
  599    template<math::DScheme DiffScheme>
 
  602        Functor(
const InGridT& grid, 
const MaskGridType* mask,
 
  603            bool threaded, InterruptT* interrupt):
 
 
  606        template<
typename MapT>
 
 
 
  642    Gradient(
const InGridT& grid, InterruptT* interrupt = 
nullptr):
 
 
  647    Gradient(
const InGridT& grid, 
const MaskGridType& mask, InterruptT* interrupt = 
nullptr):
 
 
  655        processTypedMap(
mInputGrid.transform(), functor);
 
  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):
 
 
  667        template<
typename MapT>
 
 
 
  702    Laplacian(
const GridT& grid, InterruptT* interrupt = 
nullptr):
 
 
  707    Laplacian(
const GridT& grid, 
const MaskGridType& mask, InterruptT* interrupt = 
nullptr):
 
 
  715        processTypedMap(
mInputGrid.transform(), functor);
 
  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):
 
 
  726        template<
typename MapT>
 
 
 
  766    MeanCurvature(
const GridT& grid, 
const MaskGridType& mask, InterruptT* interrupt = 
nullptr):
 
 
  774        processTypedMap(
mInputGrid.transform(), functor);
 
  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):
 
 
  785        template<
typename MapT>
 
 
 
  833        processTypedMap(
mInputGrid.transform(), functor);
 
  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):
 
 
  850        template<
typename MapT>
 
 
 
  884    Normalize(
const GridT& grid, InterruptT* interrupt = 
nullptr):
 
 
  889    Normalize(
const GridT& grid, 
const MaskGridType& mask, InterruptT* interrupt = 
nullptr):
 
 
  897        processTypedMap(
mInputGrid.transform(), functor);
 
  898        if (
typename GridT::Ptr 
outGrid = functor.mOutputGrid) {
 
  903                outGrid->setVectorType(vecType);
 
  906        return functor.mOutputGrid;
 
 
  912        template<
typename MapT, 
typename AccT>
 
  913        static typename OutGridType::ValueType
 
  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):
 
 
  926        template<
typename MapT>
 
 
 
  950template<
typename Gr
idType, 
typename InterruptT>
 
  958template<
typename Gr
idType, 
typename MaskT, 
typename InterruptT>
 
  959typename ScalarToVectorConverter<GridType>::Type::Ptr
 
  960cpt(
const GridType& grid, 
const MaskT& mask, 
bool threaded, InterruptT* interrupt)
 
 
  966template<
typename Gr
idType, 
typename InterruptT>
 
  967typename GridType::Ptr
 
  974template<
typename Gr
idType, 
typename MaskT, 
typename InterruptT>
 
  975typename GridType::Ptr
 
  976curl(
const GridType& grid, 
const MaskT& mask, 
bool threaded, InterruptT* interrupt)
 
 
  982template<
typename Gr
idType, 
typename InterruptT>
 
  983typename VectorToScalarConverter<GridType>::Type::Ptr
 
  991template<
typename Gr
idType, 
typename MaskT, 
typename InterruptT>
 
  992typename VectorToScalarConverter<GridType>::Type::Ptr
 
  999template<
typename Gr
idType, 
typename InterruptT>
 
 1000typename ScalarToVectorConverter<GridType>::Type::Ptr
 
 1004        op(grid, interrupt);
 
 
 1008template<
typename Gr
idType, 
typename MaskT, 
typename InterruptT>
 
 1009typename ScalarToVectorConverter<GridType>::Type::Ptr
 
 1016template<
typename Gr
idType, 
typename InterruptT>
 
 1017typename GridType::Ptr
 
 1021        op(grid, interrupt);
 
 
 1025template<
typename Gr
idType, 
typename MaskT, 
typename InterruptT>
 
 1026typename GridType::Ptr
 
 1033template<
typename Gr
idType, 
typename InterruptT>
 
 1034typename GridType::Ptr
 
 1038        op(grid, interrupt);
 
 
 1042template<
typename Gr
idType, 
typename MaskT, 
typename InterruptT>
 
 1043typename GridType::Ptr
 
 1050template<
typename Gr
idType, 
typename InterruptT>
 
 1051typename VectorToScalarConverter<GridType>::Type::Ptr
 
 1055        op(grid, interrupt);
 
 
 1059template<
typename Gr
idType, 
typename MaskT, 
typename InterruptT>
 
 1060typename VectorToScalarConverter<GridType>::Type::Ptr
 
 1067template<
typename Gr
idType, 
typename InterruptT>
 
 1068typename GridType::Ptr
 
 1072        op(grid, interrupt);
 
 
 1076template<
typename Gr
idType, 
typename MaskT, 
typename InterruptT>
 
 1077typename 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*) 
A LeafManager manages a linear array of pointers to a given tree's leaf nodes, as well as optional au...
ValueAccessors are designed to help accelerate accesses into the OpenVDB Tree structures by storing c...
Container class that associates a tree with a transform and metadata.
Definition Grid.h:571
Tag dispatch class that distinguishes topology copy constructors from deep copy constructors.
Definition Types.h:683
Signed (x, y, z) 32-bit integer coordinates.
Definition Coord.h:26
This class manages a linear array of pointers to a given tree's leaf nodes, as well as optional auxil...
Definition LeafManager.h:86
LeafRange leafRange(size_t grainsize=1) const
Return a TBB-compatible LeafRange.
Definition LeafManager.h:346
Definition PointDataGrid.h:170
bool wasInterrupted(T *i, int percent=-1)
Definition NullInterrupter.h:49
@ GRID_STAGGERED
Definition Types.h:457
VecType
Definition Types.h:483
@ VEC_CONTRAVARIANT_ABSOLUTE
Definition Types.h:488
@ VEC_COVARIANT
Definition Types.h:485
@ VEC_COVARIANT_NORMALIZE
Definition Types.h:486
Definition Exceptions.h:13
static Vec3< typename Accessor::ValueType > result(const MapType &map, const Accessor &grid, const Coord &ijk)
Definition Operators.h:1722
static math::Vec3< typename Accessor::ValueType > result(const MapType &map, const Accessor &grid, const Coord &ijk)
Definition Operators.h:1669
Compute the curl of a vector-valued grid using differencing of various orders in the space defined by...
Definition Operators.h:1275
Compute the divergence of a vector-valued grid using differencing of various orders,...
Definition Operators.h:950
Center difference gradient operators, defined with respect to the range-space of the map.
Definition Operators.h:620
Compute the Laplacian at a given location in a grid using finite differencing of various orders....
Definition Operators.h:1420
Compute the mean curvature.
Definition Operators.h:1762
Base class for interrupters.
Definition NullInterrupter.h:26
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition version.h.in:121
#define OPENVDB_USE_VERSION_NAMESPACE
Definition version.h.in:218
#define OPENVDB_NUMERIC_TREE_INSTANTIATE(Function)
Definition version.h.in:163
#define OPENVDB_REAL_TREE_INSTANTIATE(Function)
Definition version.h.in:162
#define OPENVDB_VEC3_TREE_INSTANTIATE(Function)
Definition version.h.in:164