HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
openvdb::OPENVDB_VERSION_NAME::tools::ConvexVoxelizer< GridType, Derived, InterruptType > Class Template Reference

Base class used to generate a grid of type GridType containing a narrow-band level set representation of a convex region. More...

#include <ConvexVoxelizer.h>

Classes

class  XYRangeData
 Class that stores endpoints of a y range for each x value within a specified range and step size. More...
 

Public Member Functions

 ConvexVoxelizer (GridPtr &grid, const bool &threaded=false, InterruptType *interrupter=nullptr)
 Constructor. More...
 
virtual ~ConvexVoxelizer ()=default
 
ValueT voxelSize () const
 Return the voxel size of the grid. More...
 
ValueT halfWidth () const
 Return the half width of the narrow-band level set. More...
 

Protected Types

using ValueT = typename GridType::ValueType
 
using Vec3T = math::Vec3< ValueT >
 
using Vec2T = math::Vec2< ValueT >
 

Protected Member Functions

void iterate ()
 The function the derived class calls to create the level set, working in index space other than setting signed distance values. More...
 
void setXYRangeData (const Index &)
 Determines the x bounds in index space of the convex region dilated by the half width. For each x value in index space, the y range in index space of the dilated region is computed. This function should store the data in mXYData. More...
 
bool tileCanFit (const Index &) const
 Checks if the tile of a given dimension can possibly fit within the region. More...
 
ValueT signedDistance (const Vec3T &) const
 Computes the signed distance from a point to the convex region in index space. More...
 
ValueT tilePointSignedDistance (const Vec3T &p) const
 Computes the signed distance for tiles in index space, considering the center of the tile. This method is optional to override and defaults to signedDistance. More...
 

Static Protected Member Functions

static ValueT tileCeil (const ValueT &x, const ValueT &step)
 Rounds an input scalar up to the nearest valid ordinate of tile of a specified size. More...
 
template<typename T >
static ValueT tileCeil (const ValueT &x, const T &step)
 Rounds an input scalar up to the nearest valid ordinate of tile of a specified size. More...
 
static ValueT tileFloor (const ValueT &x, const ValueT &step)
 Rounds an input scalar down to the nearest valid ordinate of tile of a specified size. More...
 
template<typename T >
static ValueT tileFloor (const ValueT &x, const T &step)
 Rounds an input scalar down to the nearest valid ordinate of tile of a specified size. More...
 
static ValueT circleBottom (const ValueT &x0, const ValueT &y0, const ValueT &r, const ValueT &x)
 Computes the bottom y-coordinate of a circle at a given x position. More...
 
static ValueT circleTop (const ValueT &x0, const ValueT &y0, const ValueT &r, const ValueT &x)
 Computes the top y-coordinate of a circle at a given x position. More...
 
static ValueT sphereBottom (const ValueT &x0, const ValueT &y0, const ValueT &z0, const ValueT &r, const ValueT &x, const ValueT &y)
 Computes the bottom z-coordinate of a sphere at a given (x, y) position. More...
 
static ValueT sphereTop (const ValueT &x0, const ValueT &y0, const ValueT &z0, const ValueT &r, const ValueT &x, const ValueT &y)
 Computes the top z-coordinate of a sphere at a given (x, y) position. More...
 

Protected Attributes

std::function< bool(ValueT
&, ValueT &, const ValueT
&, const ValueT &)> 
bottomTop
 Find where a vertical infinite line intersects a convex region dilated by the half width. More...
 
XYRangeData mXYData
 

Detailed Description

template<typename GridType, typename Derived, typename InterruptType = util::NullInterrupter>
class openvdb::OPENVDB_VERSION_NAME::tools::ConvexVoxelizer< GridType, Derived, InterruptType >

Base class used to generate a grid of type GridType containing a narrow-band level set representation of a convex region.

Note
GridType::ValueType must be a floating-point scalar.
Derived is the derived class that implements the base class (curiously recurring template pattern).
Example of derived level set sphere class
template <typename GridType>
class SphereVoxelizer : public ConvexVoxelizer<GridType, SphereVoxelizer<GridType>>
{
using GridPtr = typename GridType::Ptr;
using BaseT = ConvexVoxelizer<GridType, SphereVoxelizer<GridType>>;
using BaseT::mXYData;
using BaseT::tileCeil;
using ValueT = typename BaseT::ValueT;
using Vec3T = typename BaseT::Vec3T;
public:
friend class ConvexVoxelizer<GridType, SphereVoxelizer<GridType>>;
SphereVoxelizer(GridPtr& grid, const bool& threaded = true)
: BaseT(grid, threaded)
{
}
template <typename ScalarT>
void
operator()(const math::Vec3<ScalarT>& pt, const ScalarT& r)
{
if (r <= 0)
return;
initialize<ScalarT>(pt, r);
BaseT::iterate();
}
private:
inline ValueT
signedDistance(const Vec3T& p) const
{
return (p - mPt).length() - mRad;
}
inline void
setXYRangeData(const Index& step = 1)
{
mXYData.reset(mX - mORad, mX + mORad, step);
for (ValueT x = tileCeil(mX - mORad, step); x <= mX + mORad; x += step)
mXYData.expandYRange(x, BaseT::circleBottom(mX, mY, mORad, x),
BaseT::circleTop(mX, mY, mORad, x));
}
std::function<bool(ValueT&, ValueT&, const ValueT&, const ValueT&)> sphereBottomTop =
[this](ValueT& zb, ValueT& zt, const ValueT& x, const ValueT& y)
{
zb = BaseT::sphereBottom(mX, mY, mZ, mORad, x, y);
zt = BaseT::sphereTop(mX, mY, mZ, mORad, x, y);
return std::isfinite(zb) && std::isfinite(zt);
};
template <typename ScalarT>
inline void
initialize(const math::Vec3<ScalarT>& pt, const ScalarT& r)
{
const ValueT vx = BaseT::voxelSize(),
hw = BaseT::halfWidth();
// sphere data in index space
mPt = Vec3T(pt)/vx;
mRad = ValueT(r)/vx;
mX = mPt.x(); mY = mPt.y(); mZ = mPt.z();
// padded radius used to populate the outer halfwidth of the sdf
mORad = mRad + hw;
BaseT::bottomTop = sphereBottomTop;
}
Vec3T mPt;
ValueT mRad, mORad, mX, mY, mZ;
};
// usage:
// initialize level set grid with voxel size 0.1 and half width 3.0
FloatGrid::Ptr grid = createLevelSet<GridT>(0.1f, 3.0f);
// populate grid with a sphere centered at (0, 1, 2) and radius 5
SphereVoxelizer<FloatGrid> op(grid);
op(Vec3s(0.0f, 1.0f, 2.0f), 5.0f);

Definition at line 170 of file ConvexVoxelizer.h.

Member Typedef Documentation

template<typename GridType, typename Derived, typename InterruptType = util::NullInterrupter>
using openvdb::OPENVDB_VERSION_NAME::tools::ConvexVoxelizer< GridType, Derived, InterruptType >::ValueT = typename GridType::ValueType
protected

Definition at line 184 of file ConvexVoxelizer.h.

template<typename GridType, typename Derived, typename InterruptType = util::NullInterrupter>
using openvdb::OPENVDB_VERSION_NAME::tools::ConvexVoxelizer< GridType, Derived, InterruptType >::Vec2T = math::Vec2<ValueT>
protected

Definition at line 186 of file ConvexVoxelizer.h.

template<typename GridType, typename Derived, typename InterruptType = util::NullInterrupter>
using openvdb::OPENVDB_VERSION_NAME::tools::ConvexVoxelizer< GridType, Derived, InterruptType >::Vec3T = math::Vec3<ValueT>
protected

Definition at line 185 of file ConvexVoxelizer.h.

Constructor & Destructor Documentation

template<typename GridType, typename Derived, typename InterruptType = util::NullInterrupter>
openvdb::OPENVDB_VERSION_NAME::tools::ConvexVoxelizer< GridType, Derived, InterruptType >::ConvexVoxelizer ( GridPtr &  grid,
const bool &  threaded = false,
InterruptType *  interrupter = nullptr 
)
inline

Constructor.

Parameters
gridscalar grid to populate the level set in
threadedcenter of the sphere in world units
interrupterpointer to optional interrupter. Use template argument util::NullInterrupter if no interruption is desired.
Note
The voxel size and half width are determined from the input grid, meaning the voxel size and background value need to be set prior to voxelization

Definition at line 201 of file ConvexVoxelizer.h.

template<typename GridType, typename Derived, typename InterruptType = util::NullInterrupter>
virtual openvdb::OPENVDB_VERSION_NAME::tools::ConvexVoxelizer< GridType, Derived, InterruptType >::~ConvexVoxelizer ( )
virtualdefault

Member Function Documentation

template<typename GridType, typename Derived, typename InterruptType = util::NullInterrupter>
static ValueT openvdb::OPENVDB_VERSION_NAME::tools::ConvexVoxelizer< GridType, Derived, InterruptType >::circleBottom ( const ValueT &  x0,
const ValueT &  y0,
const ValueT &  r,
const ValueT &  x 
)
inlinestaticprotected

Computes the bottom y-coordinate of a circle at a given x position.

Parameters
x0X-coordinate of the circle's center.
y0Y-coordinate of the circle's center.
rRadius of the circle.
xX-coordinate for which to compute the bottom y-coordinate.
Returns
The y-coordinate at the bottom of the circle for the given x position.

Definition at line 389 of file ConvexVoxelizer.h.

template<typename GridType, typename Derived, typename InterruptType = util::NullInterrupter>
static ValueT openvdb::OPENVDB_VERSION_NAME::tools::ConvexVoxelizer< GridType, Derived, InterruptType >::circleTop ( const ValueT &  x0,
const ValueT &  y0,
const ValueT &  r,
const ValueT &  x 
)
inlinestaticprotected

Computes the top y-coordinate of a circle at a given x position.

Parameters
x0X-coordinate of the circle's center.
y0Y-coordinate of the circle's center.
rRadius of the circle.
xX-coordinate for which to compute the top y-coordinate.
Returns
The y-coordinate at the top of the circle for the given x position.

Definition at line 402 of file ConvexVoxelizer.h.

template<typename GridType, typename Derived, typename InterruptType = util::NullInterrupter>
ValueT openvdb::OPENVDB_VERSION_NAME::tools::ConvexVoxelizer< GridType, Derived, InterruptType >::halfWidth ( ) const
inline

Return the half width of the narrow-band level set.

Definition at line 218 of file ConvexVoxelizer.h.

template<typename GridType, typename Derived, typename InterruptType = util::NullInterrupter>
void openvdb::OPENVDB_VERSION_NAME::tools::ConvexVoxelizer< GridType, Derived, InterruptType >::iterate ( )
inlineprotected

The function the derived class calls to create the level set, working in index space other than setting signed distance values.

Note
This function handles both parallel and serial iterations. If running in serial mode, it flood fills the tile topology immediately; otherwise, it avoids duplicating nontrivial tree topology over multiple threads. This method also checks for background tiles that are too thin to fit and delegates accordingly.

Definition at line 236 of file ConvexVoxelizer.h.

template<typename GridType, typename Derived, typename InterruptType = util::NullInterrupter>
void openvdb::OPENVDB_VERSION_NAME::tools::ConvexVoxelizer< GridType, Derived, InterruptType >::setXYRangeData ( const Index &  )
inlineprotected

Determines the x bounds in index space of the convex region dilated by the half width. For each x value in index space, the y range in index space of the dilated region is computed. This function should store the data in mXYData.

Parameters
stepThe step size for setting the XY range data, defaults to 1.
Note
Function to be implemented by derived classes to set XY range data. This function is called at most 4 times within iterate().

Definition at line 272 of file ConvexVoxelizer.h.

template<typename GridType, typename Derived, typename InterruptType = util::NullInterrupter>
ValueT openvdb::OPENVDB_VERSION_NAME::tools::ConvexVoxelizer< GridType, Derived, InterruptType >::signedDistance ( const Vec3T &  ) const
inlineprotected

Computes the signed distance from a point to the convex region in index space.

Parameters
pThe point in 3D space for which to compute the signed distance.

Definition at line 290 of file ConvexVoxelizer.h.

template<typename GridType, typename Derived, typename InterruptType = util::NullInterrupter>
static ValueT openvdb::OPENVDB_VERSION_NAME::tools::ConvexVoxelizer< GridType, Derived, InterruptType >::sphereBottom ( const ValueT &  x0,
const ValueT &  y0,
const ValueT &  z0,
const ValueT &  r,
const ValueT &  x,
const ValueT &  y 
)
inlinestaticprotected

Computes the bottom z-coordinate of a sphere at a given (x, y) position.

Parameters
x0X-coordinate of the sphere's center.
y0Y-coordinate of the sphere's center.
z0Z-coordinate of the sphere's center.
rRadius of the sphere.
xX-coordinate for which to compute the bottom z-coordinate.
yY-coordinate for which to compute the bottom z-coordinate.
Returns
The z-coordinate at the bottom of the sphere for the given (x, y) position.

Definition at line 417 of file ConvexVoxelizer.h.

template<typename GridType, typename Derived, typename InterruptType = util::NullInterrupter>
static ValueT openvdb::OPENVDB_VERSION_NAME::tools::ConvexVoxelizer< GridType, Derived, InterruptType >::sphereTop ( const ValueT &  x0,
const ValueT &  y0,
const ValueT &  z0,
const ValueT &  r,
const ValueT &  x,
const ValueT &  y 
)
inlinestaticprotected

Computes the top z-coordinate of a sphere at a given (x, y) position.

Parameters
x0X-coordinate of the sphere's center.
y0Y-coordinate of the sphere's center.
z0Z-coordinate of the sphere's center.
rRadius of the sphere.
xX-coordinate for which to compute the top z-coordinate.
yY-coordinate for which to compute the top z-coordinate.
Returns
The z-coordinate at the top of the sphere for the given (x, y) position.

Definition at line 432 of file ConvexVoxelizer.h.

template<typename GridType, typename Derived, typename InterruptType = util::NullInterrupter>
bool openvdb::OPENVDB_VERSION_NAME::tools::ConvexVoxelizer< GridType, Derived, InterruptType >::tileCanFit ( const Index &  ) const
inlineprotected

Checks if the tile of a given dimension can possibly fit within the region.

The derived class does not need to implement it if the default behavior is acceptable, which assumes a tile can always possibly fit.

Parameters
dimThe dimension of the tile in which to check if the tile fits.
Note
This is meant as a short-circuting method: if a tile of a given dimension can't fit then iterate will not try to populate the level set with background tiles of this dimension.
Returns
true if the tile can possibly fit; otherwise false.

Definition at line 284 of file ConvexVoxelizer.h.

template<typename GridType, typename Derived, typename InterruptType = util::NullInterrupter>
static ValueT openvdb::OPENVDB_VERSION_NAME::tools::ConvexVoxelizer< GridType, Derived, InterruptType >::tileCeil ( const ValueT &  x,
const ValueT &  step 
)
inlinestaticprotected

Rounds an input scalar up to the nearest valid ordinate of tile of a specified size.

Parameters
xInput value.
stepTile step size.
Returns
The ceiling of the value based on the tile size.

Definition at line 327 of file ConvexVoxelizer.h.

template<typename GridType, typename Derived, typename InterruptType = util::NullInterrupter>
template<typename T >
static ValueT openvdb::OPENVDB_VERSION_NAME::tools::ConvexVoxelizer< GridType, Derived, InterruptType >::tileCeil ( const ValueT &  x,
const T &  step 
)
inlinestaticprotected

Rounds an input scalar up to the nearest valid ordinate of tile of a specified size.

Template Parameters
TAny integral type (int, unsigned int, size_t, etc.)
Parameters
xInput value.
stepTile step size.
Returns
The ceiling of the value based on the tile size.

Definition at line 343 of file ConvexVoxelizer.h.

template<typename GridType, typename Derived, typename InterruptType = util::NullInterrupter>
static ValueT openvdb::OPENVDB_VERSION_NAME::tools::ConvexVoxelizer< GridType, Derived, InterruptType >::tileFloor ( const ValueT &  x,
const ValueT &  step 
)
inlinestaticprotected

Rounds an input scalar down to the nearest valid ordinate of tile of a specified size.

Parameters
xInput value.
stepTile step size.
Returns
The ceiling of the value based on the tile size.

Definition at line 357 of file ConvexVoxelizer.h.

template<typename GridType, typename Derived, typename InterruptType = util::NullInterrupter>
template<typename T >
static ValueT openvdb::OPENVDB_VERSION_NAME::tools::ConvexVoxelizer< GridType, Derived, InterruptType >::tileFloor ( const ValueT &  x,
const T &  step 
)
inlinestaticprotected

Rounds an input scalar down to the nearest valid ordinate of tile of a specified size.

Template Parameters
TAny integral type (int, unsigned int, size_t, etc.)
Parameters
xInput value.
stepTile step size.
Returns
The ceiling of the value based on the tile size.

Definition at line 373 of file ConvexVoxelizer.h.

template<typename GridType, typename Derived, typename InterruptType = util::NullInterrupter>
ValueT openvdb::OPENVDB_VERSION_NAME::tools::ConvexVoxelizer< GridType, Derived, InterruptType >::tilePointSignedDistance ( const Vec3T &  p) const
inlineprotected

Computes the signed distance for tiles in index space, considering the center of the tile. This method is optional to override and defaults to signedDistance.

Parameters
pThe point at the center of the tile in 3D space.
Note
This can be useful for cases that build objects from multiple primitives, e.g. dilated mesh is built by constructing and unioning open prisms and open tube wedges. A tile might not fully fit in an open prism but might fit in the union of a prism and wedge, and so in this case it might make sense to use the sdf for an offset triangle on tiles during the open prism scan.

Definition at line 303 of file ConvexVoxelizer.h.

template<typename GridType, typename Derived, typename InterruptType = util::NullInterrupter>
ValueT openvdb::OPENVDB_VERSION_NAME::tools::ConvexVoxelizer< GridType, Derived, InterruptType >::voxelSize ( ) const
inline

Return the voxel size of the grid.

Definition at line 215 of file ConvexVoxelizer.h.

Member Data Documentation

template<typename GridType, typename Derived, typename InterruptType = util::NullInterrupter>
std::function<bool(ValueT&, ValueT&, const ValueT&, const ValueT&)> openvdb::OPENVDB_VERSION_NAME::tools::ConvexVoxelizer< GridType, Derived, InterruptType >::bottomTop
protected
Initial value:
=
[](ValueT&, ValueT&, const ValueT&, const ValueT&) { return false; }

Find where a vertical infinite line intersects a convex region dilated by the half width.

Parameters
[out]zbReference to the z ordinate where the bottom intersection occurs.
[out]ztReference to the z ordinate where the top intersection occurs.
[in]xThe x ordinate of the infinite line.
[in]yThe y ordinate of the infinite line.
Returns
true if an intersection occurs; otherwise false.
Note
The derived class can override this lambda to implement different behavior for degenerate cases.

Definition at line 317 of file ConvexVoxelizer.h.

template<typename GridType, typename Derived, typename InterruptType = util::NullInterrupter>
XYRangeData openvdb::OPENVDB_VERSION_NAME::tools::ConvexVoxelizer< GridType, Derived, InterruptType >::mXYData
protected

Definition at line 780 of file ConvexVoxelizer.h.


The documentation for this class was generated from the following file: