73 #ifndef OPENVDB_TOOLS_POINTSTOMASK_HAS_BEEN_INCLUDED 74 #define OPENVDB_TOOLS_POINTSTOMASK_HAS_BEEN_INCLUDED 76 #include <tbb/enumerable_thread_specific.h> 77 #include <tbb/parallel_for.h> 78 #include <tbb/parallel_reduce.h> 79 #include <tbb/blocked_range.h> 80 #include <openvdb/openvdb.h> 81 #include <openvdb/Grid.h> 82 #include <openvdb/Types.h> 83 #include <openvdb/util/NullInterrupter.h> 93 template<
typename Gr
idT = MaskGr
id,
typename InterrupterT = util::NullInterrupter>
100 template<
typename Po
intListT,
typename Gr
idT>
115 template<
typename Po
intListT>
120 grid->setTransform( xform.
copy() );
128 template<
typename Gr
idT,
typename InterrupterT>
132 using ValueT =
typename GridT::ValueType;
138 explicit PointsToMask(GridT& grid, InterrupterT* interrupter =
nullptr)
140 , mInterrupter(interrupter)
149 template<
typename Po
intListT>
150 void addPoints(
const PointListT& points,
size_t grainSize = 1024)
152 if (mInterrupter) mInterrupter->start(
"PointsToMask: adding points");
154 #if OPENVDB_ABI_VERSION_NUMBER <= 3 155 typename GridT::Ptr examplar = mGrid->copy(CP_NEW);
157 typename GridT::Ptr examplar = mGrid->copyWithNewTree();
159 PoolType pool( *examplar );
160 AddPoints<PointListT> tmp(points, pool, grainSize, *
this );
161 if ( this->interrupt() )
return;
162 ReducePool reducePool(pool, mGrid,
size_t(0));
165 typename GridT::Accessor acc = mGrid->getAccessor();
167 for (
size_t i = 0, n = points.size(); i < n; ++i) {
168 if ( this->interrupt() )
break;
169 points.getPos(i, wPos);
173 if (mInterrupter) mInterrupter->end();
181 bool interrupt()
const 184 tbb::task::self().cancel_group_execution();
192 using PoolType = tbb::enumerable_thread_specific<GridT>;
193 template<
typename Po
intListT>
struct AddPoints;
199 InterrupterT* mInterrupter;
204 template<
typename Gr
idT,
typename InterrupterT>
205 template<
typename Po
intListT>
208 AddPoints(
const PointListT& points,
216 tbb::parallel_for(tbb::blocked_range<size_t>(0, mPoints->size(), grainSize), *
this);
218 void operator()(
const tbb::blocked_range<size_t>& range)
const 220 if (mParent->interrupt())
return;
221 GridT& grid = mPool->local();
223 typename GridT::Accessor acc = grid.getAccessor();
225 for (
size_t i=range.begin(), n=range.end(); i!=n; ++i) {
226 mPoints->getPos(i, wPos);
230 const PointListT* mPoints;
237 template<
typename Gr
idT,
typename InterrupterT>
240 using VecT = std::vector<GridT*>;
241 using IterT =
typename VecT::iterator;
242 using RangeT = tbb::blocked_range<IterT>;
244 ReducePool(PoolType& pool, GridT* grid,
size_t grainSize = 1)
248 if ( grainSize == 0 ) {
249 using IterT =
typename PoolType::const_iterator;
250 for (
IterT i=pool.begin(); i!=pool.end(); ++i) mGrid->topologyUnion( *i );
252 VecT grids( pool.size() );
253 typename PoolType::iterator i = pool.begin();
254 for (
size_t j=0; j != pool.size(); ++i, ++j) grids[j] = &(*i);
255 tbb::parallel_reduce(
RangeT( grids.begin(), grids.end(), grainSize ), *
this );
269 for (
IterT i=r.begin(); i!=r.end(); ++i) mGrid->topologyUnion( *(*i) );
282 #endif // OPENVDB_TOOLS_POINTSTOMASK_HAS_BEEN_INCLUDED
bool wasInterrupted(T *i, int percent=-1)
Definition: NullInterrupter.h:76
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition: version.h:136
SharedPtr< Grid > Ptr
Definition: Grid.h:502
Definition: Exceptions.h:40
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:188