maspack.geometry
Class SignedDistanceGrid

java.lang.Object
  extended by maspack.geometry.SignedDistanceGrid
All Implemented Interfaces:
GLRenderable

public class SignedDistanceGrid
extends java.lang.Object
implements GLRenderable

SignedDistanceGrid is a class used to create, render, and use a signed distance field for collision detection purposes.

Author:
Bruce Haines, bruce DOT a DOT haines AT gmail.com

Field Summary
 SignedDistanceGridCell[] gridCellArray
           
static double OUTSIDE
           
 
Fields inherited from interface maspack.render.GLRenderable
TRANSLUCENT, TWO_DIMENSIONAL
 
Constructor Summary
SignedDistanceGrid()
           
SignedDistanceGrid(PolygonalMesh m, double gridSizeMargin)
           
SignedDistanceGrid(PolygonalMesh m, double gridSizeMargin, Vector3d cellDivisions)
           
 
Method Summary
 int[] getClosestFace()
           
 int getClosestFace(int idx)
          Returns the index in faces corresponding to the closest face at this point in phi.
 double getDistanceAndNormal(Vector3d norm, double x, double y, double z)
          Calculates the normal at a point in the grid in mesh coordinates.
 double getDistanceAndNormal(Vector3d norm, Vector3d point)
          Calculates the normal at a point in the grid in mesh coordinates.
 Face[] getFaces()
           
 SignedDistanceGridCell getGridCell(int idx)
           
 Vector3d getGridCellSize()
           
 int[] getGridSize()
           
 Vector3d getMax()
           
 double[] getMeshCoordinatesFromGrid(int x, int y, int z)
           
 void getMeshCoordinatesFromGrid(Point3d meshCoords, double x, double y, double z)
           
 Vector3d getMeshMax()
           
 Vector3d getMeshMin()
           
 Vector3d getMin()
           
 Vector3d getNormal(int x, int y, int z)
           
 double[] getPhi()
           
 double getPhiAtPoint(int[] point)
           
 double getPhiAtPoint(int x, int y, int z)
           
 int getRenderHints()
          Returns a bit code giving rendering hints about this renderable.
 double interpolatePhi(Vector3d point)
          Calculates the distance at a point on the grid in mesh coordinates.
 void prerender(RenderList list)
          Prepare for rendering, and potentially add itself to a list to be drawn by a GLRenderer.
 void render(GLRenderer renderer, int flags)
          Render this object using Open GL via the JOGL.
 void updateBounds(Point3d pmin, Point3d pmax)
          Update the minimum and maximum points for this object.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

OUTSIDE

public static double OUTSIDE

gridCellArray

public SignedDistanceGridCell[] gridCellArray
Constructor Detail

SignedDistanceGrid

public SignedDistanceGrid()

SignedDistanceGrid

public SignedDistanceGrid(PolygonalMesh m,
                          double gridSizeMargin)

SignedDistanceGrid

public SignedDistanceGrid(PolygonalMesh m,
                          double gridSizeMargin,
                          Vector3d cellDivisions)
Method Detail

interpolatePhi

public double interpolatePhi(Vector3d point)
Calculates the distance at a point on the grid in mesh coordinates.

Parameters:
point - The point on the grid, in the same units as the corresponding mesh.
Returns:
The normal to the mesh surface at the given point.

getDistanceAndNormal

public double getDistanceAndNormal(Vector3d norm,
                                   double x,
                                   double y,
                                   double z)
Calculates the normal at a point in the grid in mesh coordinates.

Parameters:
x - x coordinate of point in mesh coordinates.
y - y coordinate of point in mesh coordinates.
z - z coordinate of point in mesh coordinates.
Returns:
Interpolated normal to the mesh surface, in world coordinates, as well as the distance to the mesh surface.

getDistanceAndNormal

public double getDistanceAndNormal(Vector3d norm,
                                   Vector3d point)
Calculates the normal at a point in the grid in mesh coordinates.

Parameters:
norm - Used to return the normal.
point - The point at which to calculate the normal and distance in mesh coordinates.
Returns:
Interpolated normal to the mesh surface, in world coordinates, as well as the distance to the mesh surface.

getGridSize

public int[] getGridSize()

getGridCellSize

public Vector3d getGridCellSize()

getMin

public Vector3d getMin()

getMax

public Vector3d getMax()

getGridCell

public SignedDistanceGridCell getGridCell(int idx)

getNormal

public Vector3d getNormal(int x,
                          int y,
                          int z)

getPhi

public double[] getPhi()

getPhiAtPoint

public double getPhiAtPoint(int x,
                            int y,
                            int z)

getPhiAtPoint

public double getPhiAtPoint(int[] point)

prerender

public void prerender(RenderList list)
Description copied from interface: GLRenderable
Prepare for rendering, and potentially add itself to a list to be drawn by a GLRenderer.

Specified by:
prerender in interface GLRenderable

render

public void render(GLRenderer renderer,
                   int flags)
Description copied from interface: GLRenderable
Render this object using Open GL via the JOGL.

Specified by:
render in interface GLRenderable
Parameters:
renderer - renderer object which is used to perform the rendering. Provides pointers to GL and GLU, along with helper functions.
flags - supplies flags that may be used to control different aspects of the rendering. Flags are defined in GLRenderer and currently include GLRenderer.SELECTED, GLRenderer.VERTEX_COLORING, GLRenderer.HSV_COLOR_INTERPOLATION, GLRenderer.SORT_FACES, and GLRenderer.CLEAR_MESH_DISPLAY_LISTS.

updateBounds

public void updateBounds(Point3d pmin,
                         Point3d pmax)
Description copied from interface: GLRenderable
Update the minimum and maximum points for this object. In an x-y-z coordinate system with x directed to the right and y directed upwards, the minimum and maximum points can be thought of as defining the left-lower-far and right-upper-near corners of a bounding cube. This method should only reduce the elements of the minimum point and increase the elements of the maximum point, since it may be used as part of an iteration to determine the bounding cube for several different objects.

Specified by:
updateBounds in interface GLRenderable
Parameters:
pmin - minimum point
pmax - maximum point

getRenderHints

public int getRenderHints()
Description copied from interface: GLRenderable
Returns a bit code giving rendering hints about this renderable. Current bit codes include TRANSLUCENT.

Specified by:
getRenderHints in interface GLRenderable
Returns:
bit code of rendering hints.

getFaces

public Face[] getFaces()

getClosestFace

public int[] getClosestFace()

getClosestFace

public int getClosestFace(int idx)
Returns the index in faces corresponding to the closest face at this point in phi.

Parameters:
idx - The index of phi that corresponds to the point in question.

getMeshCoordinatesFromGrid

public double[] getMeshCoordinatesFromGrid(int x,
                                           int y,
                                           int z)

getMeshCoordinatesFromGrid

public void getMeshCoordinatesFromGrid(Point3d meshCoords,
                                       double x,
                                       double y,
                                       double z)

getMeshMin

public Vector3d getMeshMin()

getMeshMax

public Vector3d getMeshMax()