GU_SDF Class Reference

#include <GU_SDF.h>

List of all members.

Public Types

enum  sdfImplicitType { SDF_EXPLICIT, SDF_SPHERE, SDF_PLANE, SDF_BOX }

Public Member Functions

 GU_SDF ()
virtual ~GU_SDF ()
void build (const GU_Detail *gdp, const GU_SDFParms &parms)
 Build from the given gdp.
void initEmpty (const UT_BoundingBox &bbox, int xres, int yres, int zres)
UT_VoxelArrayFgetFunction () const
bool isImplicit () const
sdfImplicitType getImplicitType () const
 Returns the type of implicit surface, if any.
const UT_Vector3getImplicitNormal () const
void getDivisions (int &xdiv, int &ydiv, int &zdiv) const
fpreal getDistance (const UT_Vector3 &pos) const
 Calculates the SDF field at the point.
fpreal getFastDistance (const UT_Vector3 &pos, fpreal &tol) const
UT_Vector3 getGradient (const UT_Vector3 &pos) const
 Returns the gradient of the SDF at the point.
UT_Vector3 findClosest (const UT_Vector3 &pos, fpreal iso=0.0, fpreal cfl_cond=0.9) const
UT_Vector3 advect (const UT_Vector3 &pos, fpreal dist, fpreal cfl_cond=0.9f, bool normalize_gradient=true) const
bool findSmallestOnEdge (fpreal &minvalue, UT_Vector3 &result, const UT_Vector3 &a, const UT_Vector3 &b, fpreal cutoff=FLT_MAX) const
bool findSmallestOnTri (fpreal &minValue, UT_Vector2 &resultBary, const UT_Vector3 &p0, const UT_Vector3 &p1, const UT_Vector3 &p2, fpreal cutoff=FLT_MAX) const
bool findRayIntersection (UT_Vector3 &result, const UT_Vector3 &a, const UT_Vector3 &b, fpreal boundaryvalue=0.0) const
const UT_Vector3getVoxelSize () const
fpreal getVoxelDiameter () const
const UT_Vector3getSize () const
const UT_Vector3getOrig () const
void setOrig (const UT_Vector3 &o)
void setSize (const UT_Vector3 &s)
void computeCenterOfMass (UT_Vector3 &centerofmass) const
 Computes the center of mass of the SDF.
fpreal computeVolume () const
 Computes the volume of the SDF.
void computeInertialTensor (UT_DMatrix3 &tensor, const UT_Vector3 &centerofmass) const
int64 getMemoryUsage () const
 Returns the amount of memory used by this object.
bool isInverted () const
void setInverted (bool invert)
fpreal getOffset () const
void setOffset (fpreal offset)
void save (ostream &os) const
bool load (UT_IStream &is)

Static Public Member Functions

static void expandBounds (UT_BoundingBox &bbox, int xres, int yres, int zres)

Protected Member Functions

void sendRays (const GU_Detail *gdp, bool laserscan, bool usemetafield, fpreal tol)
void fixSigns (bool forcebounds)
int findConsensus (int x, int y, int z, int iteration, fpreal alpha, fpreal beta, UT_RefArray< gu_sdf_voxpos > &flippedlist)
int fastSweepCorrect (GU_RayIntersect *isect, int axis, int dir, fpreal alpha)
void rasterize (const GEO_Primitive *prim)
 Rasterizers...
void rasterizePoly (const GEO_PrimPoly *poly)
void rasterizeRawTri (UT_Vector3 p1, UT_Vector3 p2, UT_Vector3 p3)
 This takes coordinates in cell space.
void setCellDist (int x, int y, int z, fpreal dist, fpreal maxdist=-1.0)
void setCellTentative (int x, int y, int z, fpreal tentative)
 Sets a tentative value to a given cell.
gu_sdf_qelemgetQElem (int x, int y, int z, bool create=true)
void updateQElem (gu_sdf_qelem *qelem)
 If you change the weight of the qelem, this will update the queue.
fpreal findMinDist (int x, int y, int z, fpreal olddist) const
void propagateQueue (fpreal maxdist)
void buildFromMinDist (GU_RayIntersect &isect, int x, int y, int z, int xw, int yw, int zw)
void buildFromPointCloud (const GU_Detail *gdp, const GU_SDFParms &parms)
void buildFromVolume (const UT_VoxelArrayF &src, fpreal isocontour)
UT_Plane findPlaneFromNeighbour (const UT_Vector3 &sample, const UT_PtrArray< GEO_Point * > &neighbour, int noff) const

Protected Attributes

UT_VoxelArrayFmyVoxels
sdfImplicitType myImplicitType
UT_Vector3 myImplicitNormal
bool myInvert
fpreal myOffset
 This defines how far we should shift the zero isosurface of the SDF.
UT_Vector3 myOrig
UT_Vector3 mySize
UT_Vector3 myVoxelSize
 This stores the size of a voxel along each axis.
fpreal myVoxelDiameter
 This caches the diameter of a voxel cell. Ie, myVoxelSize.length().
UT_VoxelArray< int > * myQueueIndices
UT_PtrArray< gu_sdf_qelem * > myQueueElements
UT_IntArray myQueueFreeList
gu_sdf_queuemyQueue


Detailed Description

GU_SDF This class builds a signed distance function from a given GU_Detail. Signed distance functions contain an approximate distance to the original surface in each voxel cell. If cell is inside the the geometry, it has a negative distance. Sidedness of geometry is determined by surface normals. The geometry should be relatively watertight.

Definition at line 247 of file GU_SDF.h.


Member Enumeration Documentation

Enumerator:
SDF_EXPLICIT 
SDF_SPHERE 
SDF_PLANE 
SDF_BOX 

Definition at line 253 of file GU_SDF.h.


Constructor & Destructor Documentation

GU_SDF::GU_SDF (  ) 

virtual GU_SDF::~GU_SDF (  )  [virtual]


Member Function Documentation

UT_Vector3 GU_SDF::advect ( const UT_Vector3 pos,
fpreal  dist,
fpreal  cfl_cond = 0.9f,
bool  normalize_gradient = true 
) const

Advects a point according to the SDF's gradient field. Advection continues until the point has moved the given distance. If normalize_gradient is false, it is moved until the given amount of *time* has passed.

void GU_SDF::build ( const GU_Detail gdp,
const GU_SDFParms parms 
)

Build from the given gdp.

void GU_SDF::buildFromMinDist ( GU_RayIntersect isect,
int  x,
int  y,
int  z,
int  xw,
int  yw,
int  zw 
) [protected]

Builds a shell of distance values around the geometry based on minimum distance values. We want to fill in the cell values from (x,y,z) to (x+xw-1,y+yw-1,z+zw-1) inclusive. We only fill values that are within a band about the surface, leaving the rest for FMM. This is because min distance calls are expensive!

void GU_SDF::buildFromPointCloud ( const GU_Detail gdp,
const GU_SDFParms parms 
) [protected]

Builds a shell of distance values around the geometry from the point cloud data. If normals are present, they are used to calculate sidedness. Otherwise, the SDF becomes an unsigned distance-to-implicit surface.

void GU_SDF::buildFromVolume ( const UT_VoxelArrayF src,
fpreal  isocontour 
) [protected]

Builds a shell of distance values around the given iso-contour of the volume. This allows one to then reinitialize an SDF function.

void GU_SDF::computeCenterOfMass ( UT_Vector3 centerofmass  )  const

Computes the center of mass of the SDF.

void GU_SDF::computeInertialTensor ( UT_DMatrix3 tensor,
const UT_Vector3 centerofmass 
) const

Computes the inertial tensor. You provide the center of mass for it to use. Each sample point of the SDF is treated as a point mass. The mass is 0 for cell-points outside of the object, 1 for those fully inside, and suitably scaled for others.

fpreal GU_SDF::computeVolume (  )  const

Computes the volume of the SDF.

static void GU_SDF::expandBounds ( UT_BoundingBox bbox,
int  xres,
int  yres,
int  zres 
) [static]

Expands the given bounding box so it contains a two cell border on all sides. This helps condition the SDF stuff by ensuring the outer cells are all outside.

int GU_SDF::fastSweepCorrect ( GU_RayIntersect isect,
int  axis,
int  dir,
fpreal  alpha 
) [protected]

Performs a fast sweep along the given axis. Any voxel pair that has a bad consensus will be raytested & flipped. The flip is then propagated. dir is +/-1 to represent a forward or back sweep.

UT_Vector3 GU_SDF::findClosest ( const UT_Vector3 pos,
fpreal  iso = 0.0,
fpreal  cfl_cond = 0.9 
) const

Returns the closest point on the iso surface to the given point. The Courant-Friedreichs-Lewy condition governs how carefully we step to find the solution. 0.9 is near optimal, 0.5 is conservative.

int GU_SDF::findConsensus ( int  x,
int  y,
int  z,
int  iteration,
fpreal  alpha,
fpreal  beta,
UT_RefArray< gu_sdf_voxpos > &  flippedlist 
) [protected]

This finds consensus among the neighbours of this point It may then flip this points sign. If it does so, the point and it's neighbours are added to the list to be tested in the future. This uses myQueueIndices to track if a voxel has been added before. Returns 1 if a point flipped, 0 otherwise.

fpreal GU_SDF::findMinDist ( int  x,
int  y,
int  z,
fpreal  olddist 
) const [protected]

Calculates the distance to a cell by using the finalized distances to adjacent cells. The olddistance is used to determine sign.

UT_Plane GU_SDF::findPlaneFromNeighbour ( const UT_Vector3 sample,
const UT_PtrArray< GEO_Point * > &  neighbour,
int  noff 
) const [protected]

Takes a list of GEO_Points and finds the best fititng plane which interpolates them. If noff is not -1, it will derive the normals from the point normals.

bool GU_SDF::findRayIntersection ( UT_Vector3 result,
const UT_Vector3 a,
const UT_Vector3 b,
fpreal  boundaryvalue = 0.0 
) const

Returns the point along a path where it first intersects the SDF. If the path doesn't intersect the SDF, this function returns false. If the start of the path is inside the SDF, the function returns true, and returns the starting point of the path as the intersection.

bool GU_SDF::findSmallestOnEdge ( fpreal minvalue,
UT_Vector3 result,
const UT_Vector3 a,
const UT_Vector3 b,
fpreal  cutoff = FLT_MAX 
) const

Finds the smallest value in the SDF along the given line segment. The value must be smaller than the cutoff value. Returns false if no close value found.

bool GU_SDF::findSmallestOnTri ( fpreal minValue,
UT_Vector2 resultBary,
const UT_Vector3 p0,
const UT_Vector3 p1,
const UT_Vector3 p2,
fpreal  cutoff = FLT_MAX 
) const

Finds the smallest value in the SDF inside the given triangle. The value must be smaller than the cutoff value. Returns false if no close value found.

Note: this algorithm is far from perfect. It does only a very partial scan over the interior of the triangle, and it doesn't work well with implicit box SDFs.

void GU_SDF::fixSigns ( bool  forcebounds  )  [protected]

This fixes the sign of the distance field by finding a consensus among neighbouring voxels. This requires myQueueIndices to be present. If forcebounds is set, it will make the boundary all positive in sign, making it easier to recover from holes.

fpreal GU_SDF::getDistance ( const UT_Vector3 pos  )  const

Calculates the SDF field at the point.

void GU_SDF::getDivisions ( int &  xdiv,
int &  ydiv,
int &  zdiv 
) const

Returns the divisions that the spaces is voxelized into. This is meaningful even for implicit surfaces, as they have a prefered division set for purposes like advection.

fpreal GU_SDF::getFastDistance ( const UT_Vector3 pos,
fpreal tol 
) const

UT_VoxelArrayF* GU_SDF::getFunction (  )  const [inline]

Definition at line 277 of file GU_SDF.h.

UT_Vector3 GU_SDF::getGradient ( const UT_Vector3 pos  )  const

Returns the gradient of the SDF at the point.

const UT_Vector3& GU_SDF::getImplicitNormal (  )  const [inline]

The normal definining the implicit function. This is only meaninful for half-plane implicit functions.

Definition at line 290 of file GU_SDF.h.

sdfImplicitType GU_SDF::getImplicitType (  )  const [inline]

Returns the type of implicit surface, if any.

Definition at line 285 of file GU_SDF.h.

int64 GU_SDF::getMemoryUsage (  )  const

Returns the amount of memory used by this object.

fpreal GU_SDF::getOffset (  )  const [inline]

These offset the zero isosurface of the SDF. This means that getDistance() will always return getDistance() - offset, effectively inflating (if offset is positive) or deflating (if offset is negative) the object.

Offsetting happens before inversion.

Definition at line 408 of file GU_SDF.h.

const UT_Vector3& GU_SDF::getOrig (  )  const [inline]

Definition at line 370 of file GU_SDF.h.

gu_sdf_qelem* GU_SDF::getQElem ( int  x,
int  y,
int  z,
bool  create = true 
) [protected]

Gets or creates the qelement at the given location. Returns 0 if the element has already been processed.

const UT_Vector3& GU_SDF::getSize ( void   )  const [inline]

Definition at line 369 of file GU_SDF.h.

fpreal GU_SDF::getVoxelDiameter (  )  const [inline]

Definition at line 368 of file GU_SDF.h.

const UT_Vector3& GU_SDF::getVoxelSize (  )  const [inline]

Definition at line 367 of file GU_SDF.h.

void GU_SDF::initEmpty ( const UT_BoundingBox bbox,
int  xres,
int  yres,
int  zres 
)

Initializes an empty sdf of a given resolution and from a given bounding box.

bool GU_SDF::isImplicit (  )  const [inline]

Implicit SDFs have no array of voxels, instead defining themselves as a simple atomic shape.

Definition at line 281 of file GU_SDF.h.

bool GU_SDF::isInverted (  )  const [inline]

These invert the sense of the SDF. This means the getDistance() function will always return -getDistance(), effectively turning the object inside out. This does not affect the calculation of volumes, etc! (Technically, an inverted SDF has infinite volume, which isn't all that useful anyways)

Definition at line 399 of file GU_SDF.h.

bool GU_SDF::load ( UT_IStream is  ) 

void GU_SDF::propagateQueue ( fpreal  maxdist  )  [protected]

Propagate distances from all elements in the queue until maximum distance is reached.

void GU_SDF::rasterize ( const GEO_Primitive prim  )  [protected]

Rasterizers...

void GU_SDF::rasterizePoly ( const GEO_PrimPoly poly  )  [protected]

void GU_SDF::rasterizeRawTri ( UT_Vector3  p1,
UT_Vector3  p2,
UT_Vector3  p3 
) [protected]

This takes coordinates in cell space.

void GU_SDF::save ( ostream &  os  )  const

Load and save this SDF. This occurs in binary format.

void GU_SDF::sendRays ( const GU_Detail gdp,
bool  laserscan,
bool  usemetafield,
fpreal  tol 
) [protected]

This sends rays along all the major axes. The cell distances are set to the distance along the axes to surfaces.

void GU_SDF::setCellDist ( int  x,
int  y,
int  z,
fpreal  dist,
fpreal  maxdist = -1.0 
) [protected]

This sets the given cell to a specific SDF value. This will be considered a finalized value, so it will be written to the output voxel array, any QElem will be deleted, and any neighbouring cells will get tentative values. Propagation to neighbouring cells only occurs if dist < maxdist, unless maxdist < 0

void GU_SDF::setCellTentative ( int  x,
int  y,
int  z,
fpreal  tentative 
) [protected]

Sets a tentative value to a given cell.

void GU_SDF::setInverted ( bool  invert  )  [inline]

Definition at line 400 of file GU_SDF.h.

void GU_SDF::setOffset ( fpreal  offset  )  [inline]

Definition at line 409 of file GU_SDF.h.

void GU_SDF::setOrig ( const UT_Vector3 o  ) 

void GU_SDF::setSize ( const UT_Vector3 s  ) 

void GU_SDF::updateQElem ( gu_sdf_qelem qelem  )  [protected]

If you change the weight of the qelem, this will update the queue.


Member Data Documentation

Definition at line 526 of file GU_SDF.h.

What sort of implicit representation we are using. SDF_EXPLICIT if we have none.

Definition at line 524 of file GU_SDF.h.

bool GU_SDF::myInvert [protected]

This flags whether we act as if our SDF had the opposite sign than it does.

Definition at line 530 of file GU_SDF.h.

fpreal GU_SDF::myOffset [protected]

This defines how far we should shift the zero isosurface of the SDF.

Definition at line 532 of file GU_SDF.h.

Real world coordinates are transformed into the voxel array's 0-1 space by subtracting myOrig and dividing by mySize.

Definition at line 536 of file GU_SDF.h.

Definition at line 549 of file GU_SDF.h.

Definition at line 547 of file GU_SDF.h.

Definition at line 548 of file GU_SDF.h.

These are used in the building stage to rasterize to, and in the expansion stage as the priority queues.

Definition at line 546 of file GU_SDF.h.

Definition at line 536 of file GU_SDF.h.

This caches the diameter of a voxel cell. Ie, myVoxelSize.length().

Definition at line 542 of file GU_SDF.h.

This is the actual explicit array of voxels. It is not present if the SDF array is implicit. It does not incorporate the offset or inversion.

Definition at line 520 of file GU_SDF.h.

This stores the size of a voxel along each axis.

Definition at line 539 of file GU_SDF.h.


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

Generated on Fri May 25 00:10:29 2012 for HDK by  doxygen 1.5.9