39 #ifndef OPENVDB_TOOLS_LEVELSETSPHERE_HAS_BEEN_INCLUDED
40 #define OPENVDB_TOOLS_LEVELSETSPHERE_HAS_BEEN_INCLUDED
42 #include <openvdb/Grid.h>
43 #include <openvdb/Types.h>
44 #include <openvdb/math/Math.h>
45 #include <openvdb/util/NullInterrupter.h>
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)
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();
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);
186 mGrid->signedFloodFill();
190 const ValueT mRadius;
193 typename GridT::Ptr mGrid;
200 template<
typename Gr
idType,
typename InterruptT>
201 typename GridType::Ptr
203 float halfWidth, InterruptT* interrupt)
206 BOOST_STATIC_ASSERT(boost::is_floating_point<typename GridType::ValueType>::value);
208 typedef typename GridType::ValueType ValueT;
210 return factory.
getLevelSet(ValueT(voxelSize), ValueT(halfWidth));
217 #endif // OPENVDB_TOOLS_LEVELSETSPHERE_HAS_BEEN_INCLUDED
int Ceil(float x)
Return the ceiling of x.
Definition: Math.h:728
float Sqrt(float x)
Return the square root of a floating-point value.
Definition: Math.h:648
#define OPENVDB_THROW(exception, message)
Definition: Exceptions.h:97
Type Pow2(Type x)
Return .
Definition: Math.h:460
#define OPENVDB_VERSION_NAME
Definition: version.h:45
InterruptT * mInterrupt
Definition: GridOperators.h:261
static const Real LEVEL_SET_HALF_WIDTH
Definition: Types.h:143
Definition: Exceptions.h:88
int32_t Abs(int32_t i)
Return the absolute value of the given quantity.
Definition: Math.h:246
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:56
int Floor(float x)
Return the floor of x.
Definition: Math.h:720
bool wasInterrupted(T *i, int percent=-1)
Definition: NullInterrupter.h:76