73 #ifndef OPENVDB_TOOLS_POINT_MASK_GRID_HAS_BEEN_INCLUDED 74 #define OPENVDB_TOOLS_POINT_MASK_GRID_HAS_BEEN_INCLUDED 76 #include <tbb/tbb_thread.h> 77 #include <tbb/task_scheduler_init.h> 78 #include <tbb/enumerable_thread_specific.h> 79 #include <tbb/parallel_for.h> 80 #include <tbb/parallel_reduce.h> 81 #include <tbb/blocked_range.h> 94 template<
typename Gr
idT = MaskGr
id,
typename InterrupterT = util::NullInterrupter>
101 template<
typename Po
intListT,
typename Gr
idT>
116 template<
typename Po
intListT>
121 grid->setTransform( xform.
copy() );
129 template<
typename Gr
idT,
typename InterrupterT>
133 typedef typename GridT::ValueType
ValueT;
141 , mInterrupter(interrupter)
150 template<
typename Po
intListT>
151 void addPoints(
const PointListT& points,
size_t grainSize = 1024)
153 if (mInterrupter) mInterrupter->start(
"PointsToMask: adding points");
155 typename GridT::Ptr examplar = mGrid->copy(
CP_NEW );
156 PoolType pool( *examplar );
157 AddPoints<PointListT> tmp(points, pool, grainSize, *
this );
158 if ( this->interrupt() )
return;
159 ReducePool reducePool(pool, mGrid,
size_t(0));
162 typename GridT::Accessor acc = mGrid->getAccessor();
164 for (
size_t i = 0, n = points.size(); i < n; ++i) {
165 if ( this->interrupt() )
break;
166 points.getPos(i, wPos);
170 if (mInterrupter) mInterrupter->end();
178 bool interrupt()
const 181 tbb::task::self().cancel_group_execution();
189 typedef tbb::enumerable_thread_specific<GridT> PoolType;
190 template<
typename Po
intListT>
struct AddPoints;
196 InterrupterT* mInterrupter;
201 template<
typename Gr
idT,
typename InterrupterT>
202 template<
typename Po
intListT>
205 AddPoints(
const PointListT& points,
213 tbb::parallel_for(tbb::blocked_range<size_t>(0, mPoints->size(), grainSize), *
this);
215 void operator()(
const tbb::blocked_range<size_t>& range)
const 217 if (mParent->interrupt())
return;
218 GridT& grid = mPool->local();
220 typename GridT::Accessor acc = grid.getAccessor();
222 for (
size_t i=range.begin(), n=range.end(); i!=n; ++i) {
223 mPoints->getPos(i, wPos);
227 const PointListT* mPoints;
234 template<
typename Gr
idT,
typename InterrupterT>
237 typedef std::vector<GridT*>
VecT;
238 typedef typename VecT::iterator
IterT;
239 typedef tbb::blocked_range<IterT>
RangeT;
241 ReducePool(PoolType& pool, GridT* grid,
size_t grainSize = 1)
245 if ( grainSize == 0 ) {
246 typedef typename PoolType::const_iterator IterT;
247 for (IterT i=pool.begin(); i!=pool.end(); ++i) mGrid->topologyUnion( *i );
249 VecT grids( pool.size() );
250 typename PoolType::iterator i = pool.begin();
251 for (
size_t j=0; j != pool.size(); ++i, ++j) grids[j] = &(*i);
252 tbb::parallel_reduce( RangeT( grids.begin(), grids.end(), grainSize ), *
this );
266 for (IterT i=r.begin(); i!=r.end(); ++i) mGrid->topologyUnion( *(*i) );
279 #endif //OPENVDB_TOOLS_POINT_MASK_GRID_HAS_BEEN_INCLUDED
boost::shared_ptr< Grid > Ptr
Definition: Grid.h:485
#define OPENVDB_VERSION_NAME
Definition: version.h:43
Definition: Exceptions.h:39
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:71
bool wasInterrupted(T *i, int percent=-1)
Definition: NullInterrupter.h:76