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> 92 template<
typename Gr
idT = MaskGr
id,
typename InterrupterT = util::NullInterrupter>
99 template<
typename Po
intListT,
typename Gr
idT>
114 template<
typename Po
intListT>
119 grid->setTransform( xform.
copy() );
127 template<
typename Gr
idT,
typename InterrupterT>
131 typedef typename GridT::ValueType
ValueT;
137 explicit PointsToMask(GridT& grid, InterrupterT* interrupter =
nullptr)
139 , mInterrupter(interrupter)
148 template<
typename Po
intListT>
149 void addPoints(
const PointListT& points,
size_t grainSize = 1024)
151 if (mInterrupter) mInterrupter->start(
"PointsToMask: adding points");
153 #ifdef OPENVDB_3_ABI_COMPATIBLE 154 typename GridT::Ptr examplar = mGrid->copy(CP_NEW);
156 typename GridT::Ptr examplar = mGrid->copyWithNewTree();
158 PoolType pool( *examplar );
159 AddPoints<PointListT> tmp(points, pool, grainSize, *
this );
160 if ( this->interrupt() )
return;
161 ReducePool reducePool(pool, mGrid,
size_t(0));
164 typename GridT::Accessor acc = mGrid->getAccessor();
166 for (
size_t i = 0, n = points.size(); i < n; ++i) {
167 if ( this->interrupt() )
break;
168 points.getPos(i, wPos);
172 if (mInterrupter) mInterrupter->end();
180 bool interrupt()
const 183 tbb::task::self().cancel_group_execution();
191 typedef tbb::enumerable_thread_specific<GridT> PoolType;
192 template<
typename Po
intListT>
struct AddPoints;
198 InterrupterT* mInterrupter;
203 template<
typename Gr
idT,
typename InterrupterT>
204 template<
typename Po
intListT>
207 AddPoints(
const PointListT& points,
215 tbb::parallel_for(tbb::blocked_range<size_t>(0, mPoints->size(), grainSize), *
this);
217 void operator()(
const tbb::blocked_range<size_t>& range)
const 219 if (mParent->interrupt())
return;
220 GridT& grid = mPool->local();
222 typename GridT::Accessor acc = grid.getAccessor();
224 for (
size_t i=range.begin(), n=range.end(); i!=n; ++i) {
225 mPoints->getPos(i, wPos);
229 const PointListT* mPoints;
236 template<
typename Gr
idT,
typename InterrupterT>
239 typedef std::vector<GridT*>
VecT;
240 typedef typename VecT::iterator
IterT;
241 typedef tbb::blocked_range<IterT>
RangeT;
243 ReducePool(PoolType& pool, GridT* grid,
size_t grainSize = 1)
247 if ( grainSize == 0 ) {
248 typedef typename PoolType::const_iterator IterT;
249 for (IterT i=pool.begin(); i!=pool.end(); ++i) mGrid->topologyUnion( *i );
251 VecT grids( pool.size() );
252 typename PoolType::iterator i = pool.begin();
253 for (
size_t j=0; j != pool.size(); ++i, ++j) grids[j] = &(*i);
254 tbb::parallel_reduce( RangeT( grids.begin(), grids.end(), grainSize ), *
this );
268 for (IterT i=r.begin(); i!=r.end(); ++i) mGrid->topologyUnion( *(*i) );
281 #endif // OPENVDB_TOOLS_POINTSTOMASK_HAS_BEEN_INCLUDED
#define OPENVDB_VERSION_NAME
Definition: version.h:43
Definition: Exceptions.h:39
bool wasInterrupted(T *i, int percent=-1)
Definition: NullInterrupter.h:76
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:71
SharedPtr< Grid > Ptr
Definition: Grid.h:501