39 #ifndef OPENVDB_TOOLS_LEVELSETSPHERE_HAS_BEEN_INCLUDED
40 #define OPENVDB_TOOLS_LEVELSETSPHERE_HAS_BEEN_INCLUDED
46 #include <boost/utility.hpp>
47 #include <boost/type_traits/is_floating_point.hpp>
68 template<
typename Gr
idType,
typename InterruptT>
69 typename GridType::Ptr
85 template<
typename Gr
idType>
86 typename GridType::Ptr
90 return createLevelSetSphere<GridType, util::NullInterrupter>(radius,center,voxelSize,halfWidth);
103 template<
typename Gr
idT,
typename InterruptT = util::NullInterrupter>
107 typedef typename GridT::ValueType
ValueT;
109 BOOST_STATIC_ASSERT(boost::is_floating_point<ValueT>::value);
122 : mRadius(radius), mCenter(center), mInterrupt(interrupt)
131 typename GridT::Ptr
getLevelSet(ValueT voxelSize, ValueT halfWidth)
133 mGrid = createLevelSet<GridT>(voxelSize, halfWidth);
134 this->rasterSphere(voxelSize, halfWidth);
140 void rasterSphere(ValueT dx, ValueT w)
146 const ValueT r0 = mRadius/dx, rmax = r0 + w;
149 if (r0 < 1.5f)
return;
152 const Vec3T c(mCenter[0]/dx, mCenter[1]/dx, mCenter[2]/dx);
156 int &i = ijk[0], &j = ijk[1], &k = ijk[2], m=1;
162 typename GridT::Accessor accessor = mGrid->getAccessor();
164 if (mInterrupt) mInterrupt->start(
"Generating level set of sphere");
166 for ( i = imin; i <= imax; ++i ) {
169 for ( j = jmin; j <= jmax; ++j ) {
171 for (k=kmin; k<=kmax; k += m) {
177 accessor.setValue(ijk, dx*v);
188 if (mInterrupt) mInterrupt->end();
191 const ValueT mRadius;
193 InterruptT* mInterrupt;
194 typename GridT::Ptr mGrid;
201 template<
typename Gr
idType,
typename InterruptT>
202 typename GridType::Ptr
204 float halfWidth, InterruptT* interrupt)
207 BOOST_STATIC_ASSERT(boost::is_floating_point<typename GridType::ValueType>::value);
209 typedef typename GridType::ValueType ValueT;
211 return factory.
getLevelSet(ValueT(voxelSize), ValueT(halfWidth));
218 #endif // OPENVDB_TOOLS_LEVELSETSPHERE_HAS_BEEN_INCLUDED
bool wasInterrupted(T *i, int percent=-1)
Definition: NullInterrupter.h:76
General-purpose arithmetic and comparison routines, most of which accept arbitrary value types (or at...
int32_t Abs(int32_t i)
Return the absolute value of the given quantity.
Definition: Math.h:293
Definition: Exceptions.h:88
#define OPENVDB_THROW(exception, message)
Definition: Exceptions.h:97
int Ceil(float x)
Return the ceiling of x.
Definition: Math.h:804
#define OPENVDB_VERSION_NAME
Definition: version.h:43
Propagates the sign of distance values from the active voxels in the narrow band to the inactive valu...
Definition: Exceptions.h:39
Type Pow2(Type x)
Return .
Definition: Math.h:514
int Floor(float x)
Return the floor of x.
Definition: Math.h:796
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:71
float Sqrt(float x)
Return the square root of a floating-point value.
Definition: Math.h:709
static const Real LEVEL_SET_HALF_WIDTH
Definition: Types.h:212