maspack.geometry
Class MeshBase

java.lang.Object
  extended by maspack.geometry.MeshBase
All Implemented Interfaces:
GLRenderable, GLSelectable, HasRenderProps, Renderable
Direct Known Subclasses:
PointMesh, PolygonalMesh, PolylineMesh

public abstract class MeshBase
extends java.lang.Object
implements Renderable

A "mesh" is a geometric object defined by a set of vertices, which are then connected in some specific way.


Field Summary
 boolean isFixed
           
 boolean myDisplayListValid
           
 boolean myUseDisplayList
           
 boolean useVertexColoring
           
 RigidTransform3d XMeshToWorld
           
 
Fields inherited from interface maspack.render.GLRenderable
TRANSLUCENT, TWO_DIMENSIONAL
 
Constructor Summary
MeshBase()
          Creates an empty polyline mesh.
 
Method Summary
 Vertex3d addVertex(double x, double y, double z)
          Adds a point to the set of vertices associated with this mesh.
 Vertex3d addVertex(Point3d pnt)
          Adds a point to the set of vertices associated with this mesh.
 Vertex3d addVertex(Point3d pnt, boolean byReference)
          Adds a point to the set of vertices associated with this mesh.
 void addVertex(Vertex3d vtx)
          Adds a vertex to the set of vertices associated with this mesh.
 void clear()
          Clears this mesh (makes it empty).
 void clearDisplayList()
           
 void clearDisplayList(RenderProps props)
           
 double computeAverageRadius()
           
 void computeCentroid(Vector3d centroid)
           
 double computeRadius()
          Returns the radius of this mesh.
 boolean containsVertex(Vertex3d vtx)
           
 MeshBase copy()
          Creates a copy of this mesh.
abstract  MeshBase copyWithVertices(java.util.ArrayList<? extends Vertex3d> vtxs)
          Creates a copy of this mesh using a specific set of vertices.
 RenderProps createRenderProps()
          Factory method to create render properties appropriate to this object.
abstract  RenderProps createRenderProps(HasProperties host)
          Creates an appropriate RenderProps for this Mesh.
 boolean epsilonEquals(MeshBase base, double eps)
          Base method for testing if two meshes are equal.
 void getLocalBounds(Vector3d pmin, Vector3d pmax)
          Returns the minimum and maximum coordinates for this mesh, in mesh local coordinates.
 RigidTransform3d getMeshToWorld()
          Returns a pointer to the current mesh to world transform.
 void getMeshToWorld(RigidTransform3d X)
          Returns the spatial transform this mesh.
 java.lang.String getName()
           
abstract  Vector3d getNormal(int idx)
          Returns the idx-th normal in this mesh.
abstract  int getNumNormals()
          Returns the number of normals in this mesh.
 int getNumVertices()
          Returns the number of vertices in this mesh.
 double getRadius()
          Computes an approximate radius for this mesh, determined as half the diagonal of the corners of its bounding box.
 int getRenderHints()
          Returns a bit code giving rendering hints about this renderable.
 RenderProps getRenderProps()
          Returns the render properities for this object.
 void getSelection(java.util.LinkedList<java.lang.Object> list, int qid)
          Append to list the component (or components) associated with the qid-th selection query issued by this component's render method.
 Vertex3d getVertex(int idx)
          Returns the idx-th vertex in this mesh.
 java.awt.Color getVertexColor(int i)
           
 float[] getVertexColorArray(int i)
           
 java.util.ArrayList<Vertex3d> getVertices()
          Returns this mesh's vertices.
 void getWorldBounds(Vector3d pmin, Vector3d pmax)
          Returns the minimum and maximum coordinates for this mesh, in world coordinates.
 void inverseTransform(AffineTransform3dBase X)
          Applies an inverse affine transformation to the vertices of this mesh.
 boolean isDisplayListValid(RenderProps rprops)
           
 boolean isEmpty()
          Returns true if this mesh is empty.
 boolean isFastRemoval()
           
 boolean isFixed()
          Returns whether or not this mesh is considered ``fixed'', as described in setFixed.
 boolean isRenderBuffered()
           
 boolean isSelectable()
          Returns true if this object is in fact selectable.
 boolean isUsingDisplayList()
           
 boolean isUsingVertexColoring()
          Returns whether or not this mesh is using per-vertex coloring, as described in setUseVertexColoring.
 boolean meshToWorldIsIdentity()
          Returns true if the mesh to world transform is the identity.
 void notifyVertexPositionsModified()
          Notifies this mesh that vertex positions have been modified, and cached data dependent on these positions should be invalidated.
 int numSelectionQueriesNeeded()
          If this selectable manages its own selection (by issuing selection queries within its render method), then this method should return the maximum number of selection queries that will be required.
 void prerender(RenderList list)
          Prepare for rendering, and potentially add itself to a list to be drawn by a GLRenderer.
 void read(java.io.Reader reader)
          Reads the contents of this mesh from a Reader.
 void read(java.io.Reader reader, boolean zeroIndexed)
          Reads the contents of this mesh from a Reader.
abstract  void read(ReaderTokenizer rtok, boolean zeroIndexed)
          Reads the contents of this mesh from a ReaderTokenizer.
 boolean removeVertex(Vertex3d vtx)
          Removes a vertex from this mesh.
 boolean removeVertices(java.util.Collection<Vertex3d> vertices)
          Removes a set of vertices from this mesh, as indicated by a collection.
 void render(GLRenderer renderer, int flags)
          Render this object using Open GL via the JOGL.
abstract  void render(GLRenderer renderer, RenderProps props, int flags)
           
 void saveRenderInfo()
           
 void scale(double s)
          Scales the vertices of this mesh.
 void scale(double sx, double sy, double sz)
          Scales the vertices of this mesh in the given directions.
 void setFastRemoval(boolean set)
           
 void setFixed(boolean fixed)
          Sets whether or not this mesh to is to be considered ``fixed''.
 void setMeshToWorld(RigidTransform3d X)
          Sets the spatial transform this mesh.
 void setName(java.lang.String name)
           
 void setRenderBuffered(boolean enable)
           
 void setRenderProps(RenderProps props)
          Assigns a new set of render properties to this object.
 void setUseDisplayList(boolean set)
          Gives control over display lists even if not fixed mesh (for rendering while paused and mesh isn't changing)
 void setUseVertexColoring(boolean vertexColoring)
          Sets whether or not this mesh to is to use per-vertex coloring.
 void setVertexColor(int i, java.awt.Color color)
           
 void setVertexColor(int i, java.awt.Color color, float alpha)
           
 void setVertexColor(int i, double r, double g, double b)
           
 void setVertexColor(int i, double r, double g, double b, double a)
           
 void setVertexColor(int i, float r, float g, float b)
           
 void setVertexColor(int i, float r, float g, float b, float a)
           
 void setVertexColorHSV(int i, double h, double s, double b)
           
 void setVertexColorHSV(int i, double h, double s, double b, double a)
           
 Point3d size()
           
 void transform(AffineTransform3dBase X)
          Applies an affine transformation to the vertices of this mesh.
 void translate(Vector3d off)
          Translates the vertices of this mesh.
 void updateBounds(Point3d pmin, Point3d pmax)
          Update the minimum and maximum points for this object.
abstract  void write(java.io.PrintWriter pw, NumberFormat fmt, boolean zeroIndexed)
          Writes this mesh to a PrintWriter.
 void write(java.io.PrintWriter pw, java.lang.String fmtStr)
          Writes this mesh to a PrintWriter.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

XMeshToWorld

public RigidTransform3d XMeshToWorld

isFixed

public boolean isFixed

useVertexColoring

public boolean useVertexColoring

myUseDisplayList

public boolean myUseDisplayList

myDisplayListValid

public boolean myDisplayListValid
Constructor Detail

MeshBase

public MeshBase()
Creates an empty polyline mesh.

Method Detail

setName

public void setName(java.lang.String name)

getName

public java.lang.String getName()

notifyVertexPositionsModified

public void notifyVertexPositionsModified()
Notifies this mesh that vertex positions have been modified, and cached data dependent on these positions should be invalidated.


setFixed

public void setFixed(boolean fixed)
Sets whether or not this mesh to is to be considered ``fixed''. A fixed mesh is one for which the vertex coordinate values are considered constant. Rendering speeds can therefore be improved by pre-allocating appropriate graphical display buffers.

By default, a mesh is set to be fixed unless the vertices are created using referenced points (see addVertex).

Parameters:
fixed - if true, sets this mesh to be considered fixed.
See Also:
isFixed

isFixed

public boolean isFixed()
Returns whether or not this mesh is considered ``fixed'', as described in setFixed.

Returns:
true if this mesh is fixed.

setUseVertexColoring

public void setUseVertexColoring(boolean vertexColoring)
Sets whether or not this mesh to is to use per-vertex coloring.

By default, a mesh is set not to use per-vertex coloring.

Parameters:
vertexColoring - if true, sets this mesh to use per-vertex coloring.
See Also:
isUsingVertexColoring()

isUsingVertexColoring

public boolean isUsingVertexColoring()
Returns whether or not this mesh is using per-vertex coloring, as described in setUseVertexColoring.

Returns:
true if this mesh is using per-vertex coloring.

getRenderProps

public RenderProps getRenderProps()
Returns the render properities for this object. If no render properties are assigned, this routines returns null.

Specified by:
getRenderProps in interface HasRenderProps
Returns:
current render properties for this object

createRenderProps

public abstract RenderProps createRenderProps(HasProperties host)
Creates an appropriate RenderProps for this Mesh. If the supplied host is non-null, then it is used to initialize any inherited properties. The property name associated with the host is assumed to be "renderProps".

Parameters:
host - if non-null, is used to initialize inherited values
Returns:
render properties appropriate for this mesh

createRenderProps

public RenderProps createRenderProps()
Factory method to create render properties appropriate to this object.

Specified by:
createRenderProps in interface HasRenderProps
Returns:
new render properties for this object

setRenderProps

public void setRenderProps(RenderProps props)
Assigns a new set of render properties to this object. An argument of null will remove render properties from this object.

Specified by:
setRenderProps in interface HasRenderProps
Parameters:
props - new render properties for this object

getMeshToWorld

public void getMeshToWorld(RigidTransform3d X)
Returns the spatial transform this mesh. At present, the spatial transform is used only for rendering.

Parameters:
X - returns the transform from mesh to world coordinates

meshToWorldIsIdentity

public boolean meshToWorldIsIdentity()
Returns true if the mesh to world transform is the identity.

Returns:
true if the spatial transform is the identity.

getMeshToWorld

public RigidTransform3d getMeshToWorld()
Returns a pointer to the current mesh to world transform. This should not be modified by the caller.

Returns:
current mesh to world transform

setMeshToWorld

public void setMeshToWorld(RigidTransform3d X)
Sets the spatial transform this mesh. At present, the spatial transform is used only for rendering. If the transform is the identity, then meshToWorldIsIdentity will subsequently return true.

Parameters:
X - transform from mesh to world coordinates

getVertices

public java.util.ArrayList<Vertex3d> getVertices()
Returns this mesh's vertices. The vertices are contained within an ArrayList, each element of which is of type Vertex3d. Modifying these elements will modify the mesh.

Returns:
list of this mesh's vertices.

getNumVertices

public int getNumVertices()
Returns the number of vertices in this mesh.

Returns:
number of vertices in this mesh

getNumNormals

public abstract int getNumNormals()
Returns the number of normals in this mesh.

Returns:
number of normals in this mesh

getNormal

public abstract Vector3d getNormal(int idx)
Returns the idx-th normal in this mesh.

Parameters:
idx - index of the desired normal
Returns:
idx-th normal

getVertex

public Vertex3d getVertex(int idx)
Returns the idx-th vertex in this mesh.

Parameters:
idx - index of the desired vertex
Returns:
idx-th vertex

getLocalBounds

public void getLocalBounds(Vector3d pmin,
                           Vector3d pmax)
Returns the minimum and maximum coordinates for this mesh, in mesh local coordinates.

Parameters:
pmin - (optional) minimum point of the bounding box
pmax - (optional) maximum point of the bounding box

getWorldBounds

public void getWorldBounds(Vector3d pmin,
                           Vector3d pmax)
Returns the minimum and maximum coordinates for this mesh, in world coordinates.

Parameters:
pmin - (optional) minimum point of the bounding box
pmax - (optional) maximum point of the bounding box

read

public void read(java.io.Reader reader)
          throws java.io.IOException
Reads the contents of this mesh from a Reader. The input format depends on the specific mesh type.

Parameters:
reader - supplies the input description of the mesh
Throws:
java.io.IOException

read

public void read(java.io.Reader reader,
                 boolean zeroIndexed)
          throws java.io.IOException
Reads the contents of this mesh from a Reader. The input format depends on the specific mesh type.

Parameters:
reader - supplies the input description of the mesh
zeroIndexed - if true, the index numbering for mesh vertices starts at 0. Otherwise, numbering starts at 1.
Throws:
java.io.IOException

read

public abstract void read(ReaderTokenizer rtok,
                          boolean zeroIndexed)
                   throws java.io.IOException
Reads the contents of this mesh from a ReaderTokenizer. The input format depends on the specific mesh type.

Parameters:
rtok - tokenizer providing the input
zeroIndexed - if true, the index numbering for mesh vertices starts at 0. Otherwise, numbering starts at 1.
Throws:
java.io.IOException

addVertex

public void addVertex(Vertex3d vtx)
Adds a vertex to the set of vertices associated with this mesh. The pnt field of the vertex should be non-null. The index of the vertex will be set to reflect it's position in the list of vertices.

Parameters:
vtx - vertex to add
See Also:
addVertex(Point3d,boolean), addVertex(Point3d)

removeVertex

public boolean removeVertex(Vertex3d vtx)
Removes a vertex from this mesh.

Parameters:
vtx - vertex to remove
Returns:
true if the vertex was present

removeVertices

public boolean removeVertices(java.util.Collection<Vertex3d> vertices)
Removes a set of vertices from this mesh, as indicated by a collection.

Parameters:
vertices - Collection of vertices to remove

containsVertex

public boolean containsVertex(Vertex3d vtx)

addVertex

public Vertex3d addVertex(Point3d pnt)
Adds a point to the set of vertices associated with this mesh. Equivalent to calling addVertex(pnt,false).

Parameters:
pnt - vertex point to add
Returns:
vertex object containing the point
See Also:
addVertex(Point3d,boolean)

addVertex

public Vertex3d addVertex(double x,
                          double y,
                          double z)
Adds a point to the set of vertices associated with this mesh.

Parameters:
x - vertex x coordinate
y - vertex y coordinate
z - vertex z coordinate
Returns:
vertex object containing the point

addVertex

public Vertex3d addVertex(Point3d pnt,
                          boolean byReference)
Adds a point to the set of vertices associated with this mesh.

Parameters:
pnt - vertex point to add
byReference - if true, then the supplied Point3d argument is not copied but is referred to directly by the vertex structure. The mesh will track any changes to this point and isFixed will return false.
Returns:
vertex object containing the point
See Also:
addVertex(Point3d)

write

public void write(java.io.PrintWriter pw,
                  java.lang.String fmtStr)
           throws java.io.IOException
Writes this mesh to a PrintWriter. The exact output format will depend on the specific mesh type. Index numbering starts at one, and the format used to print vertex coordinates is specified by a C printf style format string contained in the parameter fmtStr. For a description of the format string syntax, see NumberFormat. Good default choices for fmtStr are either "%g" (full precision), or "%.Ng", where N is the number of desired significant figures.

Parameters:
pw - PrintWriter to write this mesh to
fmtStr - string specifying the format for writing the vertex coordinates
Throws:
java.io.IOException

write

public abstract void write(java.io.PrintWriter pw,
                           NumberFormat fmt,
                           boolean zeroIndexed)
                    throws java.io.IOException
Writes this mesh to a PrintWriter. The exact output format will depend on the specific mesh type.

Parameters:
pw - PrintWriter to write this mesh to
fmt - format for writing the vertex coordinates
zeroIndexed - if true, index numbering for mesh vertices starts at 0. Otherwise, numbering starts at 1.
Throws:
java.io.IOException

scale

public void scale(double s)
Scales the vertices of this mesh. The topology remains unchanged.

Parameters:
s - scale factor

scale

public void scale(double sx,
                  double sy,
                  double sz)
Scales the vertices of this mesh in the given directions. The topology remains unchanged.

Parameters:
sx - scaling factor in the x direction
sy - scaling factor in the y direction
sz - scaling factor in the z direction

size

public Point3d size()

getRadius

public double getRadius()
Computes an approximate radius for this mesh, determined as half the diagonal of the corners of its bounding box.

Returns:
approximate radius for this mesh

updateBounds

public void updateBounds(Point3d pmin,
                         Point3d pmax)
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

translate

public void translate(Vector3d off)
Translates the vertices of this mesh. The topology of the mesh remains unchanged.

Parameters:
off - offset to add to the mesh vertices

transform

public void transform(AffineTransform3dBase X)
Applies an affine transformation to the vertices of this mesh. The topology of the mesh remains unchanged.

Parameters:
X - affine transformation

inverseTransform

public void inverseTransform(AffineTransform3dBase X)
Applies an inverse affine transformation to the vertices of this mesh. The topology of the mesh remains unchanged.

Parameters:
X - affine transformation

getRenderHints

public int getRenderHints()
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.

clear

public void clear()
Clears this mesh (makes it empty).


isEmpty

public boolean isEmpty()
Returns true if this mesh is empty.

Returns:
true if mesh is empty

getSelection

public void getSelection(java.util.LinkedList<java.lang.Object> list,
                         int qid)
Description copied from interface: GLSelectable
Append to list the component (or components) associated with the qid-th selection query issued by this component's render method. This will only be called if this component manages its own selection (i.e., the number nums returned by GLSelectable.numSelectionQueriesNeeded() is positive), and qid will in turn be a number between 0 and nums-1.

Specified by:
getSelection in interface GLSelectable
Parameters:
list - selected objects are appended to the end of this list
qid - index of the selection query

isSelectable

public boolean isSelectable()
Description copied from interface: GLSelectable
Returns true if this object is in fact selectable.

Specified by:
isSelectable in interface GLSelectable
Returns:
true if this object is selectable

numSelectionQueriesNeeded

public int numSelectionQueriesNeeded()
Description copied from interface: GLSelectable
If this selectable manages its own selection (by issuing selection queries within its render method), then this method should return the maximum number of selection queries that will be required. Otherwise, this method should return -1.

Specified by:
numSelectionQueriesNeeded in interface GLSelectable
Returns:
maximum number of selection queries needed by this component, or -1 if this component does not manage its own selection.

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

setUseDisplayList

public void setUseDisplayList(boolean set)
Gives control over display lists even if not fixed mesh (for rendering while paused and mesh isn't changing)


clearDisplayList

public void clearDisplayList()

clearDisplayList

public void clearDisplayList(RenderProps props)

isDisplayListValid

public boolean isDisplayListValid(RenderProps rprops)

isUsingDisplayList

public boolean isUsingDisplayList()

setRenderBuffered

public void setRenderBuffered(boolean enable)

isRenderBuffered

public boolean isRenderBuffered()

saveRenderInfo

public void saveRenderInfo()

copy

public MeshBase copy()
Creates a copy of this mesh.


copyWithVertices

public abstract MeshBase copyWithVertices(java.util.ArrayList<? extends Vertex3d> vtxs)
Creates a copy of this mesh using a specific set of vertices.


computeCentroid

public void computeCentroid(Vector3d centroid)

computeRadius

public double computeRadius()
Returns the radius of this mesh. This is defined to be the maximum distance of any vertex from the mesh's centroid.


computeAverageRadius

public double computeAverageRadius()

render

public void render(GLRenderer renderer,
                   int flags)
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.

render

public abstract void render(GLRenderer renderer,
                            RenderProps props,
                            int flags)

epsilonEquals

public boolean epsilonEquals(MeshBase base,
                             double eps)
Base method for testing if two meshes are equal. Two MeshBase objects are considered equal if their vertex coordinates and transforms are equal within eps. This method, and its overrides, is used in mesh unit tests.


setFastRemoval

public void setFastRemoval(boolean set)

isFastRemoval

public boolean isFastRemoval()

setVertexColor

public void setVertexColor(int i,
                           java.awt.Color color)

setVertexColor

public void setVertexColor(int i,
                           java.awt.Color color,
                           float alpha)

setVertexColor

public void setVertexColor(int i,
                           double r,
                           double g,
                           double b)

setVertexColor

public void setVertexColor(int i,
                           double r,
                           double g,
                           double b,
                           double a)

setVertexColor

public void setVertexColor(int i,
                           float r,
                           float g,
                           float b)

setVertexColor

public void setVertexColor(int i,
                           float r,
                           float g,
                           float b,
                           float a)

setVertexColorHSV

public void setVertexColorHSV(int i,
                              double h,
                              double s,
                              double b)

setVertexColorHSV

public void setVertexColorHSV(int i,
                              double h,
                              double s,
                              double b,
                              double a)

getVertexColor

public java.awt.Color getVertexColor(int i)

getVertexColorArray

public float[] getVertexColorArray(int i)