maspack.geometry
Class PointMesh

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

public class PointMesh
extends MeshBase

Implements a mesh consisting of a set of points and possibly normals.


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
PointMesh()
          Creates an empty point mesh.
PointMesh(java.io.File file)
          Creates a point mesh and initializes it from an file in Alias Wavefront obj format, as decribed for the method write(PrintWriter,NumberFormat,boolean).
PointMesh(PointMesh old)
           
 
Method Summary
 void addMesh(PointMesh mesh)
          Adds copies of the vertices of another mesh to this mesh.
 void clear()
          Clears this mesh (makes it empty).
 void clearNormals()
           
 PointMesh copy()
          Creates a copy of this mesh.
 PointMesh 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.
 boolean epsilonEquals(MeshBase base, double eps)
          Tests to see if a mesh equals this one.
 AABBTree getBVTree()
           
 Vector3d getNormal(int idx)
          Returns the idx-th normal in this mesh.
 double getNormalRenderLen()
           
 java.util.ArrayList<Vector3d> getNormals()
           
 int getNumNormals()
          Returns the number of normals in this mesh.
 void read(ReaderTokenizer rtok, boolean zeroIndexed)
          Reads the contents of this mesh from a ReaderTokenizer.
 void readBinary(java.io.File file)
           
 void render(GLRenderer renderer, RenderProps props, int flags)
           
 void set(Point3d[] pnts, Vector3d[] nrms)
          Sets the vertex points and normals associated with this mesh.
 void setNormalRenderLen(double len)
           
 void setNormals(java.util.ArrayList<Vector3d> normals)
           
 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

PointMesh

public PointMesh()
Creates an empty point mesh.


PointMesh

public PointMesh(java.io.File file)
          throws java.io.IOException
Creates a point 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

PointMesh

public PointMesh(PointMesh old)
Method Detail

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

getNormals

public java.util.ArrayList<Vector3d> getNormals()

setNormals

public void setNormals(java.util.ArrayList<Vector3d> normals)

clearNormals

public void clearNormals()

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

getNormalRenderLen

public double getNormalRenderLen()

setNormalRenderLen

public void setNormalRenderLen(double len)

readBinary

public void readBinary(java.io.File file)
                throws java.io.IOException
Throws:
java.io.IOException

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,
                Vector3d[] nrms)
Sets the vertex points and normals associated with this mesh.

Parameters:
pnts - points from which the vertices are formed
nrms - (optional) if non-null, gives vectors from which the normals are formed.
Throws:
java.lang.IllegalArgumentException - if nrms is non-null and does not have the same size as pnts.

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. Normals, if present, are printed next, starting with the letter "vn" and followed by x, y, and z coordinates.

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 - (optional) format for writing the vertex and normals 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

copy

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

Overrides:
copy in class MeshBase

copyWithVertices

public PointMesh 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(PointMesh mesh)
Adds copies of the vertices of another mesh to this mesh. If the other mesh contains normal information, this will be added as well providing this mesh already contains normal information or is empty. Otherwise, normal information for this mesh will be cleared.

Parameters:
mesh - Mesh to be added to this mesh

getBVTree

public AABBTree getBVTree()

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 normals are equal (within eps).

Overrides:
epsilonEquals in class MeshBase