39 #ifndef OPENVDB_TOOLS_LEVELSETSPHERE_HAS_BEEN_INCLUDED 40 #define OPENVDB_TOOLS_LEVELSETSPHERE_HAS_BEEN_INCLUDED 47 #include <type_traits> 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 using ValueT =
typename GridT::ValueType;
109 static_assert(std::is_floating_point<ValueT>::value,
110 "level set grids must have scalar, floating-point value types");
123 : mRadius(radius), mCenter(center), mInterrupt(interrupt)
134 mGrid = createLevelSet<GridT>(voxelSize, halfWidth);
135 this->rasterSphere(voxelSize, halfWidth);
141 void rasterSphere(ValueT dx, ValueT w)
147 const ValueT r0 = mRadius/dx, rmax = r0 + w;
150 if (r0 < 1.5f)
return;
153 const Vec3T c(mCenter[0]/dx, mCenter[1]/dx, mCenter[2]/dx);
157 int &i = ijk[0], &j = ijk[1], &k = ijk[2], m=1;
163 typename GridT::Accessor accessor = mGrid->getAccessor();
165 if (mInterrupt) mInterrupt->start(
"Generating level set of sphere");
167 for (i = imin; i <= imax; ++i) {
170 for (j = jmin; j <= jmax; ++j) {
172 for (k = kmin; k <= kmax; k += m) {
178 accessor.setValue(ijk, dx*v);
189 if (mInterrupt) mInterrupt->end();
192 const ValueT mRadius;
194 InterruptT* mInterrupt;
195 typename GridT::Ptr mGrid;
202 template<
typename Gr
idType,
typename InterruptT>
203 typename GridType::Ptr
205 float halfWidth, InterruptT* interrupt)
208 static_assert(std::is_floating_point<typename GridType::ValueType>::value,
209 "level set grids must have scalar, floating-point value types");
211 using ValueT =
typename GridType::ValueType;
213 return factory.
getLevelSet(ValueT(voxelSize), ValueT(halfWidth));
220 #endif // OPENVDB_TOOLS_LEVELSETSPHERE_HAS_BEEN_INCLUDED int Ceil(float x)
Return the ceiling of x.
Definition: Math.h:810
General-purpose arithmetic and comparison routines, most of which accept arbitrary value types (or at...
float Sqrt(float x)
Return the square root of a floating-point value.
Definition: Math.h:715
#define OPENVDB_THROW(exception, message)
Definition: Exceptions.h:109
bool wasInterrupted(T *i, int percent=-1)
Definition: NullInterrupter.h:76
Signed (x, y, z) 32-bit integer coordinates.
Definition: Coord.h:51
int Floor(float x)
Return the floor of x.
Definition: Math.h:802
static const Real LEVEL_SET_HALF_WIDTH
Definition: Types.h:283
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition: version.h:136
Propagate the signs of distance values from the active voxels in the narrow band to the inactive valu...
Definition: Exceptions.h:40
Coord Abs(const Coord &xyz)
Definition: Coord.h:513
Definition: Exceptions.h:92
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:188
Type Pow2(Type x)
Return x2.
Definition: Math.h:502