12 #ifndef OPENVDB_TOOLS_LEVELSETSPHERE_HAS_BEEN_INCLUDED 
   13 #define OPENVDB_TOOLS_LEVELSETSPHERE_HAS_BEEN_INCLUDED 
   23 #include <type_traits> 
   25 #include <tbb/enumerable_thread_specific.h> 
   26 #include <tbb/parallel_for.h> 
   27 #include <tbb/parallel_reduce.h> 
   28 #include <tbb/blocked_range.h> 
   50 template<
typename Gr
idType, 
typename InterruptT>
 
   51 typename GridType::Ptr
 
   53                      float halfWidth = 
float(LEVEL_SET_HALF_WIDTH),
 
   54                      InterruptT* interrupt = 
nullptr, 
bool threaded = 
true);
 
   69 template<
typename Gr
idType>
 
   70 typename GridType::Ptr
 
   72                      float halfWidth = 
float(LEVEL_SET_HALF_WIDTH), 
bool threaded = 
true)
 
   74     return createLevelSetSphere<GridType, util::NullInterrupter>(radius,center,voxelSize,halfWidth,
nullptr,
threaded);
 
   87 template<
typename Gr
idT, 
typename InterruptT = util::NullInterrupter>
 
   91     using TreeT  = 
typename GridT::TreeType;
 
   95         "level set grids must have scalar, floating-point value types");
 
  108         : mRadius(radius), mCenter(center), mInterrupt(interrupt)
 
  110         if (mRadius<=0) 
OPENVDB_THROW(ValueError, 
"radius must be positive");
 
  120         mGrid = createLevelSet<GridT>(voxelSize, halfWidth);
 
  121         this->rasterSphere(voxelSize, halfWidth, 
threaded);
 
  129         if (!(dx>0.0
f)) 
OPENVDB_THROW(ValueError, 
"voxel size must be positive");
 
  130         if (!(w>1)) 
OPENVDB_THROW(ValueError, 
"half-width must be larger than one");
 
  133         const ValueT r0 = mRadius/dx, rmax = r0 + 
w;
 
  136         if (r0 < 1.5
f)  
return;
 
  139         const Vec3T c(mCenter[0]/dx, mCenter[1]/dx, mCenter[2]/dx);
 
  147         typename GridT::Accessor accessor = mGrid->getAccessor();
 
  149         if (mInterrupt) mInterrupt->start(
"Generating level set of sphere");
 
  151         tbb::enumerable_thread_specific<TreeT> 
pool(mGrid->tree());
 
  153         auto kernel = [&](
const tbb::blocked_range<int>& 
r) {
 
  155             int &i = ijk[0], &
j = ijk[1], &k = ijk[2], m=1;
 
  157             typename GridT::Accessor acc(tree);
 
  159             for (i = 
r.begin(); i != 
r.end(); ++i) {
 
  162                 for (j = jmin; j <= jmax; ++
j) {
 
  164                     for (k = kmin; k <= kmax; k += m) {
 
  170                             acc.setValue(ijk, dx*
v);
 
  185             using RangeT = tbb::blocked_range<typename tbb::enumerable_thread_specific<TreeT>::iterator>;
 
  189                 Op(
TreeT &tree) : mDelete(false), mTree(&tree) {}
 
  190                 Op(
const Op& other, 
tbb::split) : mDelete(true), mTree(new 
TreeT(other.mTree->background())) {}
 
  191                 ~
Op() { 
if (mDelete) 
delete mTree; }
 
  192                 void operator()(
const RangeT &
r) { 
for (
auto i=r.begin(); i!=r.end(); ++i) this->
merge(*i);}
 
  193                 void join(
Op &other) { this->
merge(*(other.mTree)); }
 
  195             } 
op( mGrid->tree() );
 
  196             tbb::parallel_reduce(RangeT(
pool.begin(), 
pool.end(), 4), 
op);
 
  198             kernel(tbb::blocked_range<int>(imin, imax));
 
  205         if (mInterrupt) mInterrupt->end();
 
  210     InterruptT*         mInterrupt;
 
  211     typename GridT::Ptr mGrid;
 
  218 template<
typename Gr
idType, 
typename InterruptT>
 
  219 typename GridType::Ptr
 
  221     float halfWidth, InterruptT* interrupt, 
bool threaded)
 
  225         "level set grids must have scalar, floating-point value types");
 
  229     return factory.
getLevelSet(ValueT(voxelSize), ValueT(halfWidth), threaded);
 
  238 #ifdef OPENVDB_USE_EXPLICIT_INSTANTIATION 
  240 #ifdef OPENVDB_INSTANTIATE_LEVELSETSPHERE 
  244 #define _FUNCTION(TreeT) \ 
  245     Grid<TreeT>::Ptr createLevelSetSphere<Grid<TreeT>>(float, const openvdb::Vec3f&, float, float, \ 
  246         util::NullInterrupter*, bool) 
  250 #endif // OPENVDB_USE_EXPLICIT_INSTANTIATION 
  257 #endif // OPENVDB_TOOLS_LEVELSETSPHERE_HAS_BEEN_INCLUDED 
int Ceil(float x)
Return the ceiling of x. 
 
Type Pow2(Type x)
Return x2. 
 
GLsizei const GLfloat * value
 
#define OPENVDB_REAL_TREE_INSTANTIATE(Function)
 
#define OPENVDB_USE_VERSION_NAMESPACE
 
Coord Abs(const Coord &xyz)
 
General-purpose arithmetic and comparison routines, most of which accept arbitrary value types (or at...
 
OIIO_UTIL_API void parallel_for(int32_t begin, int32_t end, function_view< void(int32_t)> task, paropt opt=0)
 
float Sqrt(float x)
Return the square root of a floating-point value. 
 
Propagate the signs of distance values from the active voxels in the narrow band to the inactive valu...
 
int Floor(float x)
Return the floor of x. 
 
GLubyte GLubyte GLubyte GLubyte w
 
void OIIO_UTIL_API split(string_view str, std::vector< string_view > &result, string_view sep=string_view(), int maxsplit=-1)
 
bool wasInterrupted(T *i, int percent=-1)
 
#define OPENVDB_VERSION_NAME
The version namespace name for this library version. 
 
#define OPENVDB_THROW(exception, message)
 
**Note that the tasks the is the thread number *for the pool