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