46#ifndef OPENVDB_TOOLS_POINTSTOMASK_HAS_BEEN_INCLUDED 
   47#define OPENVDB_TOOLS_POINTSTOMASK_HAS_BEEN_INCLUDED 
   54#include <openvdb/thread/Threading.h> 
   56#include <tbb/enumerable_thread_specific.h> 
   57#include <tbb/parallel_for.h> 
   58#include <tbb/parallel_reduce.h> 
   59#include <tbb/blocked_range.h> 
   70template<
typename Gr
idT = MaskGr
id, 
typename InterrupterT = util::NullInterrupter>
 
   77template<
typename Po
intListT, 
typename Gr
idT>
 
   92template<
typename Po
intListT>
 
   97    grid->setTransform( xform.
copy() );
 
 
  105template<
typename Gr
idT, 
typename InterrupterT>
 
  109    using ValueT = 
typename GridT::ValueType;
 
  115    explicit PointsToMask(GridT& grid, InterrupterT* interrupter = 
nullptr)
 
  117        , mInterrupter(interrupter)
 
 
  126    template<
typename Po
intListT, 
typename VecT = Vec3R>
 
  129        if (mInterrupter) mInterrupter->start(
"PointsToMask: adding points");
 
  131            typename GridT::Ptr examplar = mGrid->copyWithNewTree();
 
  132            PoolType pool( *examplar );
 
  133            AddPoints<PointListT, VecT> tmp(
points, pool, grainSize, *
this );
 
  134            if ( this->interrupt() ) 
return;
 
  135            ReducePool reducePool(pool, mGrid, 
size_t(0));
 
  138            typename GridT::Accessor acc = mGrid->getAccessor();
 
  140            for (
size_t i = 0, n = 
points.size(); i < n; ++i) {
 
  141                if ( this->interrupt() ) 
break;
 
  146        if (mInterrupter) mInterrupter->end();
 
 
  154    bool interrupt()
 const 
  157            thread::cancelGroupExecution();
 
  165    using PoolType = tbb::enumerable_thread_specific<GridT>;
 
  166    template<
typename Po
intListT, 
typename VecT = Vec3R> 
struct AddPoints;
 
  172    InterrupterT* mInterrupter;
 
 
  177template<
typename Gr
idT, 
typename InterrupterT>
 
  178template<
typename Po
intListT, 
typename VecT>
 
  179struct PointsToMask<GridT, InterrupterT>::AddPoints
 
  181    AddPoints(
const PointListT& points,
 
  184              const PointsToMask& parent)
 
  189        tbb::parallel_for(tbb::blocked_range<size_t>(0, mPoints->size(), grainSize), *
this);
 
  191    void operator()(
const tbb::blocked_range<size_t>& range)
 const 
  193        if (mParent->interrupt()) 
return;
 
  194        GridT& grid = mPool->local();
 
  195        const math::Transform& xform = grid.transform();
 
  196        typename GridT::Accessor acc = grid.getAccessor();
 
  198        for (
size_t i=range.begin(), n=range.end(); i!=n; ++i) {
 
  199            mPoints->getPos(i, wPos);
 
  200            acc.setValueOn( xform.worldToIndexCellCentered( wPos ) );
 
  203    const PointListT*    mPoints;
 
  204    const PointsToMask* mParent;
 
  210template<
typename Gr
idT, 
typename InterrupterT>
 
  213    using VecT = std::vector<GridT*>;
 
  214    using IterT = 
typename VecT::iterator;
 
  215    using RangeT = tbb::blocked_range<IterT>;
 
  217    ReducePool(PoolType& pool, GridT* grid, 
size_t grainSize = 1)
 
  221        if (grainSize == 0) {
 
  222            for (
typename PoolType::const_iterator i = pool.begin(); i != pool.end(); ++i) {
 
  223                mGrid->topologyUnion(*i);
 
  226            VecT grids( pool.size() );
 
  227            typename PoolType::iterator i = pool.begin();
 
  228            for (
size_t j=0; j != pool.size(); ++i, ++j) grids[j] = &(*i);
 
  229            tbb::parallel_reduce( 
RangeT( grids.begin(), grids.end(), grainSize ), *
this );
 
 
  243        for (
IterT i=r.begin(); i!=r.end(); ++i) 
mGrid->topologyUnion( *(*i) );
 
 
 
SharedPtr< Grid > Ptr
Definition Grid.h:573
Definition AttributeArray.h:42
bool wasInterrupted(T *i, int percent=-1)
Definition NullInterrupter.h:49
GridType::Ptr createGrid(const typename GridType::ValueType &background)
Create a new grid of type GridType with a given background value.
Definition Grid.h:1757
Definition Exceptions.h:13
#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