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)
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
Coord Abs(const Coord &xyz)
Definition: Coord.h:247
float Sqrt(float x)
Return the square root of a floating-point value.
Definition: Math.h:727
Type Pow2(Type x)
Return .
Definition: Math.h:514
#define OPENVDB_THROW(exception, message)
Definition: Exceptions.h:97
static const Real LEVEL_SET_HALF_WIDTH
Definition: Types.h:219
int Ceil(float x)
Return the ceiling of x.
Definition: Math.h:822
#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
int Floor(float x)
Return the floor of x.
Definition: Math.h:814
Definition: Exceptions.h:88
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:71
bool wasInterrupted(T *i, int percent=-1)
Definition: NullInterrupter.h:76