maspack.geometry
Class PolylineMesh

java.lang.Object
  extended by maspack.geometry.MeshBase
      extended by maspack.geometry.PolylineMesh
All Implemented Interfaces:
GLRenderable, GLSelectable, HasRenderProps, Renderable

public class PolylineMesh
extends MeshBase

Implements a mesh consisting of a set of polylines.


Field Summary
static boolean useDisplayListsIfPossible
           
 
Fields inherited from class maspack.geometry.MeshBase
isFixed, myDisplayListValid, myUseDisplayList, useVertexColoring, XMeshToWorld
 
Fields inherited from interface maspack.render.GLRenderable
TRANSLUCENT, TWO_DIMENSIONAL
 
Constructor Summary
PolylineMesh()
          Creates an empty polyline mesh.
PolylineMesh(java.io.File file)
          Creates a polygonal mesh and initializes it from an file in Alias Wavefront obj format, as decribed for the method write(PrintWriter,NumberFormat,boolean).
PolylineMesh(PolylineMesh old)
           
 
Method Summary
 Polyline addLine(int[] indices)
          Adds a line to this mesh.
 Polyline addLine(Polyline line)
          Adds a line to this mesh.
 Polyline addLine(Vertex3d[] vertices)
          Adds a line to this mesh.
 void addMesh(PolylineMesh mesh)
          Adds copies of the vertices and lines of another mesh to this mesh.
 void clear()
          Clears this mesh (makes it empty).
 void clearBoundingInfo()
          Invalidates bounding box information.
 PolylineMesh copy()
          Creates a copy of this mesh.
 PolylineMesh copyWithVertices(java.util.ArrayList<? extends Vertex3d> vtxs)
          Creates a copy of this mesh using a specific set of vertices.
 RenderProps createRenderProps(HasProperties host)
          Creates an appropriate RenderProps for this Mesh.
 void drawColoredCylinder(javax.media.opengl.GL2 gl, int nslices, double base, double top, float[] coords0, float[] color0, float[] coords1, float[] color1, boolean capped)
           
 boolean epsilonEquals(MeshBase base, double eps)
          Tests to see if a mesh equals this one.
 AABBTree getBVTree()
           
 java.util.ArrayList<Polyline> getLines()
          Returns this mesh's lines.
 Vector3d getNormal(int idx)
          Returns the idx-th normal in this mesh.
 int getNumLines()
          Returns the number of lines in this mesh.
 int getNumNormals()
          Returns the number of normals in this mesh.
 int getRenderSkip()
           
 void invalidateBoundingInfo()
          Invalidates bounding box information.
 void read(ReaderTokenizer rtok, boolean zeroIndexed)
          Reads the contents of this mesh from a ReaderTokenizer.
 boolean removeLine(Polyline line)
          Removes a line from this mesh.
 void render(GLRenderer renderer, RenderProps props, int flags)
           
 void set(Point3d[] pnts, int[][] lineIndices)
          Sets the vertex points and line associated with this mesh.
 void setRenderSkip(int skip)
          Number of lines to skip while rendering
 void write(java.io.PrintWriter pw, NumberFormat fmt, boolean zeroIndexed)
          Writes this mesh to a PrintWriter, using an Alias Wavefront "obj" file format.
 void write(java.io.PrintWriter pw, java.lang.String fmtStr)
          Writes this mesh to a PrintWriter, using an Alias Wavefront "obj" file as described for write(PrintWriter,NumberFormat,boolean).
 
Methods inherited from class maspack.geometry.MeshBase
addVertex, addVertex, addVertex, addVertex, clearDisplayList, clearDisplayList, computeAverageRadius, computeCentroid, computeRadius, containsVertex, createRenderProps, getLocalBounds, getMeshToWorld, getMeshToWorld, getName, getNumVertices, getRadius, getRenderHints, getRenderProps, getSelection, getVertex, getVertexColor, getVertexColorArray, getVertices, getWorldBounds, inverseTransform, isDisplayListValid, isEmpty, isFastRemoval, isFixed, isRenderBuffered, isSelectable, isUsingDisplayList, isUsingVertexColoring, meshToWorldIsIdentity, notifyVertexPositionsModified, numSelectionQueriesNeeded, prerender, read, read, removeVertex, removeVertices, render, saveRenderInfo, scale, scale, setFastRemoval, setFixed, setMeshToWorld, setName, setRenderBuffered, setRenderProps, setUseDisplayList, setUseVertexColoring, setVertexColor, setVertexColor, setVertexColor, setVertexColor, setVertexColor, setVertexColor, setVertexColorHSV, setVertexColorHSV, size, transform, translate, updateBounds
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

useDisplayListsIfPossible

public static boolean useDisplayListsIfPossible
Constructor Detail

PolylineMesh

public PolylineMesh()
Creates an empty polyline mesh.


PolylineMesh

public PolylineMesh(java.io.File file)
             throws java.io.IOException
Creates a polygonal mesh and initializes it from an file in Alias Wavefront obj format, as decribed for the method write(PrintWriter,NumberFormat,boolean).

Parameters:
file - file containing the mesh description
Throws:
java.io.IOException

PolylineMesh

public PolylineMesh(PolylineMesh old)
Method Detail

invalidateBoundingInfo

public void invalidateBoundingInfo()
Description copied from class: MeshBase
Invalidates bounding box information. Can also be overriden to mark any bounding volume hierarchies as invalid and in need of updating.


clearBoundingInfo

public void clearBoundingInfo()
Description copied from class: MeshBase
Invalidates bounding box information. Can also be overriden to clear any bounding volume hierarchies so that they need to be rebuilt.


createRenderProps

public 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".

Specified by:
createRenderProps in class MeshBase
Parameters:
host - if non-null, is used to initialize inherited values
Returns:
render properties appropriate for this mesh

getNumNormals

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

Specified by:
getNumNormals in class MeshBase
Returns:
number of normals in this mesh

getNormal

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

Specified by:
getNormal in class MeshBase
Parameters:
idx - index of the desired normal
Returns:
idx-th normal

getLines

public java.util.ArrayList<Polyline> getLines()
Returns this mesh's lines. The line are contained within an ArrayList, each element of which is an array giving the vertex indices for the line.

Returns:
list of this mesh's lines.

getNumLines

public int getNumLines()
Returns the number of lines in this mesh.

Returns:
number of lines in this mesh

read

public void read(ReaderTokenizer rtok,
                 boolean zeroIndexed)
          throws java.io.IOException
Reads the contents of this mesh from a ReaderTokenizer. The input is assumed to be supplied in Alias Wavefront obj format, as described for the method write(PrintWriter,NumberFormat,boolean).

Specified by:
read in class MeshBase
Parameters:
rtok - tokenizer supplying 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

set

public void set(Point3d[] pnts,
                int[][] lineIndices)
Sets the vertex points and line associated with this mesh.

Parameters:
pnts - points from which the vertices are formed
lineIndices - integer arrays giving the indices of each line. Each index should correspond to a particular point in pnts.
Throws:
java.lang.IllegalArgumentException - if a vertex index is out of bounds

addLine

public Polyline addLine(int[] indices)
Adds a line to this mesh. A line is described by indices which specify its vertices.

Parameters:
indices - integer array giving the vertex indices of the line. Each index should correspond to a vertex presently associated with this mesh.
Returns:
the created line object
Throws:
java.lang.IllegalArgumentException - if a vertex index is out of bounds

addLine

public Polyline addLine(Vertex3d[] vertices)
Adds a line to this mesh. A face is described by an array of vertices which comprise the line.

Parameters:
vertices - vertices comprising this line. Each vertex should be presently contained in this mesh.
Returns:
the created line object
Throws:
java.lang.IllegalArgumentException - if any vertices are not contained within this mesh

addLine

public Polyline addLine(Polyline line)
Adds a line to this mesh.

Parameters:
line - Polyline to add to the mesh
Returns:
the created line object

removeLine

public boolean removeLine(Polyline line)
Removes a line from this mesh.

Parameters:
line - line to remove
Returns:
false if the line does not belong to this mesh.

write

public void write(java.io.PrintWriter pw,
                  java.lang.String fmtStr)
           throws java.io.IOException
Writes this mesh to a PrintWriter, using an Alias Wavefront "obj" file as described for write(PrintWriter,NumberFormat,boolean). 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.

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

write

public void write(java.io.PrintWriter pw,
                  NumberFormat fmt,
                  boolean zeroIndexed)
           throws java.io.IOException
Writes this mesh to a PrintWriter, using an Alias Wavefront "obj" file format. Vertices are printed first, each starting with the letter "v" and followed by x, y, and z coordinates. Lines are printed next, starting with the letter "f" and followed by a list of integers which gives the indices of that line's vertices. An example of a simple three point line is:
    v 1.0 0.0 0.0
    v 0.0 1.0 0.0
    v 0.0 0.0 1.0
    l 0 1 2
 

The format used to print vertex coordinates is specified by a NumberFormat.

Specified by:
write in class MeshBase
Parameters:
pw - PrintWriter to write this mesh to
fmt - format for writing the vertex coordinates. If null, a format of "%.8g" is assumed.
zeroIndexed - if true, index numbering for mesh vertices starts at 0. Otherwise, numbering starts at 1.
Throws:
java.io.IOException

clear

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

Overrides:
clear in class MeshBase

render

public void render(GLRenderer renderer,
                   RenderProps props,
                   int flags)
Specified by:
render in class MeshBase

drawColoredCylinder

public void drawColoredCylinder(javax.media.opengl.GL2 gl,
                                int nslices,
                                double base,
                                double top,
                                float[] coords0,
                                float[] color0,
                                float[] coords1,
                                float[] color1,
                                boolean capped)

copy

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

Overrides:
copy in class MeshBase

copyWithVertices

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

Specified by:
copyWithVertices in class MeshBase

addMesh

public void addMesh(PolylineMesh mesh)
Adds copies of the vertices and lines of another mesh to this mesh.

Parameters:
mesh - Mesh to be added to this mesh

getBVTree

public AABBTree getBVTree()

setRenderSkip

public void setRenderSkip(int skip)
Number of lines to skip while rendering


getRenderSkip

public int getRenderSkip()

epsilonEquals

public boolean epsilonEquals(MeshBase base,
                             double eps)
Tests to see if a mesh equals this one. The meshes are equal if they are both PolylineMeshes, and their transforms, vertices, and lines are equal (within eps).

Overrides:
epsilonEquals in class MeshBase