12 #ifndef OPENVDB_TOOLS_LEVELSETSPHERE_HAS_BEEN_INCLUDED 13 #define OPENVDB_TOOLS_LEVELSETSPHERE_HAS_BEEN_INCLUDED 21 #include <type_traits> 23 #include <tbb/enumerable_thread_specific.h> 24 #include <tbb/parallel_for.h> 25 #include <tbb/parallel_reduce.h> 26 #include <tbb/blocked_range.h> 48 template<
typename Gr
idType,
typename InterruptT>
49 typename GridType::Ptr
52 InterruptT* interrupt =
nullptr,
bool threaded =
true);
67 template<
typename Gr
idType>
68 typename GridType::Ptr
72 return createLevelSetSphere<GridType, util::NullInterrupter>(radius,center,voxelSize,halfWidth,
nullptr,threaded);
85 template<
typename Gr
idT,
typename InterruptT = util::NullInterrupter>
89 using TreeT =
typename GridT::TreeType;
90 using ValueT =
typename GridT::ValueType;
93 "level set grids must have scalar, floating-point value types");
106 : mRadius(radius), mCenter(center), mInterrupt(interrupt)
118 mGrid = createLevelSet<GridT>(voxelSize, halfWidth);
119 this->rasterSphere(voxelSize, halfWidth, threaded);
131 const ValueT r0 = mRadius/dx, rmax = r0 + w;
134 if (r0 < 1.5f)
return;
137 const Vec3T c(mCenter[0]/dx, mCenter[1]/dx, mCenter[2]/dx);
145 typename GridT::Accessor accessor = mGrid->getAccessor();
147 if (mInterrupt) mInterrupt->start(
"Generating level set of sphere");
149 tbb::enumerable_thread_specific<TreeT> pool(mGrid->tree());
151 auto kernel = [&](
const tbb::blocked_range<int>& r) {
153 int &i = ijk[0], &j = ijk[1], &k = ijk[2], m=1;
154 TreeT &tree = pool.local();
155 typename GridT::Accessor acc(tree);
157 for (i = r.begin(); i != r.end(); ++i) {
160 for (j = jmin; j <= jmax; ++j) {
162 for (k = kmin; k <= kmax; k += m) {
168 acc.setValue(ijk, dx*v);
182 tbb::parallel_for(tbb::blocked_range<int>(imin, imax, 128), kernel);
183 using RangeT = tbb::blocked_range<typename tbb::enumerable_thread_specific<TreeT>::iterator>;
187 Op(
TreeT &tree) : mDelete(
false), mTree(&tree) {}
188 Op(
const Op& other, tbb::split) : mDelete(
true), mTree(
new TreeT(other.mTree->background())) {}
189 ~Op() {
if (mDelete)
delete mTree; }
190 void operator()(RangeT &r) {
for (
auto i=r.begin(); i!=r.end(); ++i) this->merge(*i);}
191 void join(Op &other) { this->merge(*(other.mTree)); }
193 } op( mGrid->tree() );
194 tbb::parallel_reduce(RangeT(pool.begin(), pool.end(), 4), op);
196 kernel(tbb::blocked_range<int>(imin, imax));
203 if (mInterrupt) mInterrupt->end();
208 InterruptT* mInterrupt;
209 typename GridT::Ptr mGrid;
216 template<
typename Gr
idType,
typename InterruptT>
217 typename GridType::Ptr
219 float halfWidth, InterruptT* interrupt,
bool threaded)
223 "level set grids must have scalar, floating-point value types");
225 using ValueT =
typename GridType::ValueType;
227 return factory.
getLevelSet(ValueT(voxelSize), ValueT(halfWidth), threaded);
236 #ifdef OPENVDB_USE_EXPLICIT_INSTANTIATION 238 #ifdef OPENVDB_INSTANTIATE_LEVELSETSPHERE 242 #define _FUNCTION(TreeT) \ 243 Grid<TreeT>::Ptr createLevelSetSphere<Grid<TreeT>>(float, const openvdb::Vec3f&, float, float, \ 244 util::NullInterrupter*, bool) 248 #endif // OPENVDB_USE_EXPLICIT_INSTANTIATION 255 #endif // OPENVDB_TOOLS_LEVELSETSPHERE_HAS_BEEN_INCLUDED bool wasInterrupted(T *i, int percent=-1)
Definition: NullInterrupter.h:49
#define OPENVDB_THROW(exception, message)
Definition: Exceptions.h:74
General-purpose arithmetic and comparison routines, most of which accept arbitrary value types (or at...
Definition: Exceptions.h:65
int Ceil(float x)
Return the ceiling of x.
Definition: Math.h:859
int Floor(float x)
Return the floor of x.
Definition: Math.h:851
float Sqrt(float x)
Return the square root of a floating-point value.
Definition: Math.h:764
Propagate the signs of distance values from the active voxels in the narrow band to the inactive valu...
Definition: Exceptions.h:13
ValueT value
Definition: GridBuilder.h:1287
#define OPENVDB_REAL_TREE_INSTANTIATE(Function)
Definition: version.h.in:147
Coord Abs(const Coord &xyz)
Definition: Coord.h:514
Type Pow2(Type x)
Return x2.
Definition: Math.h:551
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition: version.h.in:116
static const Real LEVEL_SET_HALF_WIDTH
Definition: Types.h:422
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h.in:202