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> 70 template<
typename Gr
idT = MaskGr
id,
typename InterrupterT = util::NullInterrupter>
77 template<
typename Po
intListT,
typename Gr
idT>
92 template<
typename Po
intListT>
97 grid->setTransform( xform.
copy() );
105 template<
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>
127 void addPoints(
const PointListT& points,
size_t grainSize = 1024)
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;
142 points.getPos(i, wPos);
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;
177 template<
typename Gr
idT,
typename InterrupterT>
178 template<
typename Po
intListT,
typename VecT>
181 AddPoints(
const PointListT& points,
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();
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);
203 const PointListT* mPoints;
210 template<
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) );
256 #endif // OPENVDB_TOOLS_POINTSTOMASK_HAS_BEEN_INCLUDED bool wasInterrupted(T *i, int percent=-1)
Definition: NullInterrupter.h:49
SharedPtr< Grid > Ptr
Definition: Grid.h:579
Definition: Exceptions.h:13
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition: version.h.in:116
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h.in:202