maspack.geometry
Class PolygonalMesh

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

public class PolygonalMesh
extends MeshBase

Implements a polygonal mesh consisting of vertices, faces, and half-edges.


Field Summary
 boolean canSelfIntersect
           
static int computedFaceNormals
           
 
Fields inherited from class maspack.geometry.MeshBase
isFixed, myDisplayListValid, myUseDisplayList, useVertexColoring, XMeshToWorld
 
Fields inherited from interface maspack.render.GLRenderable
TRANSLUCENT, TWO_DIMENSIONAL
 
Constructor Summary
PolygonalMesh()
          Creates an empty polygonal mesh.
PolygonalMesh(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).
PolygonalMesh(PolygonalMesh old)
           
PolygonalMesh(java.lang.String fileName)
          Creates a polygonal mesh and initializes it from an file in Alias Wavefront obj format, as decribed for the method write(PrintWriter,NumberFormat,boolean).
 
Method Summary
 Face addFace(int[] indices)
          Adds a face to this mesh.
 Face addFace(Vertex3d[] vertices)
          Adds a face to this mesh.
 Face addFace(Vertex3d v0, Vertex3d v1, Vertex3d v2)
          Adds a triangular face to this mesh.
 Face addFace(Vertex3d v0, Vertex3d v1, Vertex3d v2, Vertex3d v3)
           
 void addMesh(PolygonalMesh mesh)
          Adds copies of the vertices and faces of another mesh to this mesh.
 void checkConsistency()
          Make sure that this mesh is consistent, by checking that: (1) vertex and face indices are consistent (2) every face half edge is registered with it's head vertex (3) every half edge's opposite, if non-null, points back to itself (4) every half edge's head is the next half-edge's tail (5) every half edge's face is valid (6) every half edge's head and tail are different (7) every vertex indicent half edge refers to a valid face
 double checkFaceNormals()
           
 void checkForDegenerateFaces()
           
 void clear()
          Clears this mesh (makes it empty).
 void clearBVTree()
           
 double computeArea()
          Computes the surface area of this mesh.
 double computeAverageEdgeLength()
          Computes the average edge length for this mesh.
 double computeCentreOfVolume(Point3d c)
          Computes the centre of volume of the mesh
 double computeInertia(SpatialInertia M, double density)
          Computes a spatial inertia for volume defined by this mesh, assuming a constant density.
 void computeVertexNormals()
          Computes vertex normals using an area-weighted average of the triangles formed by the half edges incident of each vertex.
 double computeVolume()
          Computes the volume of this mesh, on the assumption that it is manifold and closed.
 double computeVolumeIntegrals(Vector3d mov1, Vector3d mov2, Vector3d pov)
          Computes the volume integrals of this mesh, on the assumption that it is manifold and closed.
 PolygonalMesh copy()
          Creates a copy of this mesh.
 PolygonalMesh copyWithVertices(java.util.ArrayList<? extends Vertex3d> vtxs)
          Creates a copy of this mesh using a specific set of vertices.
 int countBorders()
           
 int countConnected()
           
 int countEdges()
           
 double countGenus()
           
 SpatialInertia createInertia(double density)
          Creates a spatial inertia for the volume defined by this mesh, assuming a constant density.
 RenderProps createRenderProps(HasProperties host)
          Creates an appropriate RenderProps for this Mesh.
 int doMergeCloseVertices(double dsqr)
           
 void dumpToFile(java.lang.String str)
           
 boolean epsilonEquals(MeshBase base, double eps)
          Tests to see if a mesh equals this one.
 void extendOpenEdges(double amount)
          Extends the first open edge loop found.
 boolean faceNormalsValid()
          Returns true if face normals are currently valid.
 java.util.ArrayList<HalfEdge> findBorderEdges()
           
 java.util.ArrayList<Face> findBorderFaces()
           
 Material getBackMaterial()
           
 BVTree getBVTree()
           
 Material getFaceMaterial()
           
 int[] getFaceOrder()
          Returns the order of sorted faces, or null if faces have never been sorted.
 java.util.ArrayList<Face> getFaces()
          Returns this mesh's faces.
 Vector3d getNormal(int idx)
          Returns the idx-th normal in this mesh.
 java.util.ArrayList<int[]> getNormalIndices()
           
 java.util.ArrayList<Vector3d> getNormalList()
           
 int getNumFaces()
          Returns the number of face in this mesh.
 int getNumNormals()
          Returns the number of normals in this mesh.
 int getRenderHints()
          Returns a bit code giving rendering hints about this renderable.
 SignedDistanceGrid getSignedDistanceGrid()
           
 SignedDistanceGrid getSignedDistanceGrid(double margin, Vector3d cellDivisions)
           
 PolygonalMesh getSubdivisionMesh()
          Generates and returns a subdivided version of this mesh interpolated using cubic patches.
 int getSubdivisions()
           
 java.util.ArrayList<int[]> getTextureIndices()
           
 java.util.ArrayList<Vector3d> getTextureVertices()
           
 void interpolate(Point3d p, Face f, double u, double v)
          Smoothly interpolate a face using barycentric coordinates.
 void inverseTransform(AffineTransform3dBase X)
          Applies an inverse affine transformation to the vertices of this mesh.
 boolean isBorderVertex(Vertex3d vtx)
           
 boolean isClosed()
          Returns true if the mesh is closed.
 boolean isManifold()
          Returns true if this mesh is manifold.
 boolean isQuad()
          Returns true if this is a quad mesh.
 boolean isTriangular()
          Returns true if this mesh is triangular.
 int mergeCloseVertices(double dist)
          Merge vertices that are within a prescribed distance of each other.
 void notifyVertexPositionsModified()
          Notifies this mesh that vertex positions have been modified, and cached data dependent on these positions should be invalidated.
 int numDegenerateFaces()
           
 int numDisconnectedVertices()
           
 PolygonalMesh[] partitionIntoConnectedMeshes()
          Copies this mesh into a set of connected meshes and returns these as an array.
 void read(java.io.Reader reader)
          Reads the contents of this mesh from a Reader.
 void read(ReaderTokenizer rtok, boolean zeroIndexed)
          Reads the contents of this mesh from a ReaderTokenizer.
 int removeDisconnectedFaces()
           
 int removeDisconnectedVertices()
           
 boolean removeFace(Face face)
          Removes a face from this mesh.
 boolean removeFaces(java.util.Collection<Face> faces)
          Removes a set of faces from this mesh, as indicated by a collection.
 void render(GLRenderer renderer, RenderProps props, int flags)
           
 void set(Point3d[] pnts, int[][] faceIndices)
          Sets the vertex points and faces associated with this mesh.
 void setBackMaterial(Material mat)
           
 void setFaceMaterial(Material mat)
           
 void setHardEdge(Vertex3d v0, Vertex3d v1, boolean hard)
           
 void setMeshToWorld(RigidTransform3d X)
          Sets the spatial transform this mesh.
 void setNormalIndices(int[][] indices)
          Sets normal indices for this mesh.
 void setNormalList(java.util.ArrayList<Vector3d> normals)
          Sets list of normals
 void setSubdivisions(int subdivisions)
          Setting this generates a new mesh therefore any previous meshes are invalidated and should be discarded.
 void setTextureIndices(int[][] indices)
          Sets texture indices for this mesh.
 void setTextureVertices(java.util.ArrayList<Vector3d> textureVertices)
          Sets texture mapping vertices.
 int[] sortFaces(Vector3d zdir)
          "Sorts" faces according to the direction provided.
 void transform(AffineTransform3dBase X)
          Applies an affine transformation to the vertices of this mesh.
 void triangulate()
          Modifies this mesh to ensure that all faces are triangles.
 void updateFaceNormals()
          Updates face normals if necessary.
 void updateRenderNormals()
          Updates face rendering normals if necessary.
 void updateSubdivisionMesh(PolygonalMesh mesh)
          Updates a subdivision mesh.
 void write(java.io.File file, java.lang.String fmtStr)
          Writes this mesh to a File, using an Alias Wavefront "obj" file format.
 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, NumberFormat fmt, boolean zeroIndexed, boolean facesClockwise)
          Writes this mesh to a PrintWriter, using an Alias Wavefront "obj" file format.
 void writePoly(java.io.PrintStream ps)
           
 void writePoly(java.lang.String nodeString)
           
 void writeWorld(java.io.PrintStream ps)
           
 
Methods inherited from class maspack.geometry.MeshBase
addVertex, addVertex, addVertex, addVertex, clearDisplayList, clearDisplayList, computeAverageRadius, computeCentroid, computeRadius, containsVertex, createRenderProps, getLocalBounds, getMeshToWorld, getMeshToWorld, getName, getNumVertices, getRadius, getRenderProps, getSelection, getVertex, getVertexColor, getVertexColorArray, getVertices, getWorldBounds, isDisplayListValid, isEmpty, isFastRemoval, isFixed, isRenderBuffered, isSelectable, isUsingDisplayList, isUsingVertexColoring, meshToWorldIsIdentity, numSelectionQueriesNeeded, prerender, read, removeVertex, removeVertices, render, saveRenderInfo, scale, scale, setFastRemoval, setFixed, setName, setRenderBuffered, setRenderProps, setUseDisplayList, setUseVertexColoring, setVertexColor, setVertexColor, setVertexColor, setVertexColor, setVertexColor, setVertexColor, setVertexColorHSV, setVertexColorHSV, size, translate, updateBounds, write
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

canSelfIntersect

public boolean canSelfIntersect

computedFaceNormals

public static int computedFaceNormals
Constructor Detail

PolygonalMesh

public PolygonalMesh()
Creates an empty polygonal mesh.


PolygonalMesh

public PolygonalMesh(java.lang.String fileName)
              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:
fileName - name of the file containing the mesh description
Throws:
java.io.IOException

PolygonalMesh

public PolygonalMesh(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

PolygonalMesh

public PolygonalMesh(PolygonalMesh old)
Method Detail

notifyVertexPositionsModified

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

Overrides:
notifyVertexPositionsModified in class MeshBase

updateFaceNormals

public void updateFaceNormals()
Updates face normals if necessary.


updateRenderNormals

public void updateRenderNormals()
Updates face rendering normals if necessary.


faceNormalsValid

public boolean faceNormalsValid()
Returns true if face normals are currently valid.


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

isTriangular

public boolean isTriangular()
Returns true if this mesh is triangular. A mesh is triangular if all its faces are triangles.

Returns:
true if this mesh is triangular

isQuad

public boolean isQuad()
Returns true if this is a quad mesh. A mesh is quad if all its faces have four sides.

Returns:
true if this is a quad mesh

isManifold

public boolean isManifold()
Returns true if this mesh is manifold. A mesh is manifold if each edge is adjacent to at most two faces; i.e., there are no redundant half-edges, and all the faces connected to each vertex form a fan.

Returns:
true if this mesh is manifold

getFaces

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

Returns:
list of this mesh's faces.

getNumFaces

public int getNumFaces()
Returns the number of face in this mesh.

Returns:
number of faces in this mesh

countEdges

public int countEdges()

getSignedDistanceGrid

public SignedDistanceGrid getSignedDistanceGrid()

getSignedDistanceGrid

public SignedDistanceGrid getSignedDistanceGrid(double margin,
                                                Vector3d cellDivisions)

setMeshToWorld

public void setMeshToWorld(RigidTransform3d X)
Description copied from class: MeshBase
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.

Overrides:
setMeshToWorld in class MeshBase
Parameters:
X - transform from mesh to world coordinates

read

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

Overrides:
read in class MeshBase
Parameters:
reader - supplied the input description of the mesh
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,
                int[][] faceIndices)
Sets the vertex points and faces associated with this mesh.

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

addFace

public Face addFace(int[] indices)
Adds a face to this mesh. A face is described by indices which specify, in counter-clockwise order, the vertices which describe this face.

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

addFace

public Face addFace(Vertex3d[] vertices)
Adds a face to this mesh. A face is described by an array of vertices arranged in counter-clockwise order with respect to the face's normal.

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

addFace

public Face addFace(Vertex3d v0,
                    Vertex3d v1,
                    Vertex3d v2)
Adds a triangular face to this mesh. The face is described by three vertices arranged in counter-clockwise order with respect to the face's normal.

Parameters:
v0 - first vertex
v1 - second vertex
v2 - third vertex
Returns:
the created Face object
Throws:
java.lang.IllegalArgumentException - if any vertices are not contained within this mesh

addFace

public Face addFace(Vertex3d v0,
                    Vertex3d v1,
                    Vertex3d v2,
                    Vertex3d v3)

removeFace

public boolean removeFace(Face face)
Removes a face from this mesh.

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

removeFaces

public boolean removeFaces(java.util.Collection<Face> faces)
Removes a set of faces from this mesh, as indicated by a collection.

Parameters:
faces - Collection of faces to remove

doMergeCloseVertices

public int doMergeCloseVertices(double dsqr)

mergeCloseVertices

public int mergeCloseVertices(double dist)
Merge vertices that are within a prescribed distance of each other. Setting this distance to zero will cause only duplicate vertices to be merge. The algorithm used by this method determines vertex distances by examining edge lengths, and then collapsing edges whose distances are less than or equal to dist. Thus vertices which are isolated, or not otherwise connected by edges, will be unaffected.

The implementation of this algorithm is not perfect. If the mesh is not closed, and merging results in the alignment of one or more boundary edges, these edges will not be connected. Moreover, the mesh topology may sometimes may it impossible to merge an adjacent vertex without corrupting the mesh topology; in these cases, merges will not be done and a warning will be printed.

Parameters:
dist - distance within which vertices should be merged.

numDisconnectedVertices

public int numDisconnectedVertices()

removeDisconnectedVertices

public int removeDisconnectedVertices()

removeDisconnectedFaces

public int removeDisconnectedFaces()

partitionIntoConnectedMeshes

public PolygonalMesh[] partitionIntoConnectedMeshes()
Copies this mesh into a set of connected meshes and returns these as an array. If this mesh is already fully connected, no meshes are produced and null is returned. At present, the copied meshes do not preserve face normal or texture information.


checkConsistency

public void checkConsistency()
Make sure that this mesh is consistent, by checking that: (1) vertex and face indices are consistent (2) every face half edge is registered with it's head vertex (3) every half edge's opposite, if non-null, points back to itself (4) every half edge's head is the next half-edge's tail (5) every half edge's face is valid (6) every half edge's head and tail are different (7) every vertex indicent half edge refers to a valid face


write

public void write(java.io.File file,
                  java.lang.String fmtStr)
           throws java.io.IOException
Writes this mesh to a File, using an Alias Wavefront "obj" file format. Behaves the same as write(java.io.PrintWriter,maspack.util.NumberFormat,boolean,boolean) with zeroIndexed and facesClockwise set to false.

Parameters:
file - File to write this mesh to
fmtStr - format string for writing the vertex coordinates. If null, a format of "%.8g" is assumed.
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. Behaves the same as write(java.io.PrintWriter,maspack.util.NumberFormat,boolean,boolean) with facesClockwise set to false.

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

write

public void write(java.io.PrintWriter pw,
                  NumberFormat fmt,
                  boolean zeroIndexed,
                  boolean facesClockwise)
           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. Faces are printed next, starting with the letter "f" and followed by a list of integers which gives the indices of that face's vertices in counter-clockwise order. For example, a mesh consisting of a simple tetrahedron might be written like this:
    v 0.0 0.0 0.0
    v 1.0 0.0 0.0
    v 0.0 1.0 0.0
    v 0.0 0.0 1.0
    f 1 2 3
    f 0 2 1
    f 0 3 2
    f 0 1 3
 

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

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.
facesClockwise - if true, face indices are written clockwise instead of the usual counter-clockwise convention.
Throws:
java.io.IOException

writePoly

public void writePoly(java.lang.String nodeString)
               throws java.lang.Exception
Throws:
java.lang.Exception

writePoly

public void writePoly(java.io.PrintStream ps)
               throws java.lang.Exception
Throws:
java.lang.Exception

transform

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

Overrides:
transform in class MeshBase
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.

Overrides:
inverseTransform in class MeshBase
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
Overrides:
getRenderHints in class MeshBase
Returns:
bit code of rendering hints.

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

getSubdivisionMesh

public PolygonalMesh getSubdivisionMesh()
Generates and returns a subdivided version of this mesh interpolated using cubic patches.

Returns:
The subdivision mesh. Null is returned

updateSubdivisionMesh

public void updateSubdivisionMesh(PolygonalMesh mesh)
Updates a subdivision mesh.

Parameters:
mesh - Must be a mesh generated by calling getSubdivisionMesh on this mesh.

interpolate

public void interpolate(Point3d p,
                        Face f,
                        double u,
                        double v)
Smoothly interpolate a face using barycentric coordinates.

Parameters:
f - The face to interpolate.
u - The weighting of the first vertice.
v - The weighting of the second vertice.

getSubdivisions

public int getSubdivisions()

setSubdivisions

public void setSubdivisions(int subdivisions)
Setting this generates a new mesh therefore any previous meshes are invalidated and should be discarded.

Parameters:
subdivisions - The number of times to subdivide each triangle.

setNormalIndices

public void setNormalIndices(int[][] indices)
Sets normal indices for this mesh. If indices is not null, it is assumed to supply one set of normal indices per face, each with the same number of indices as the face itself. Otherwise, if indices is null, the normal information is cleared.

Parameters:
indices - indices is matrix NxV, where N is number of faces and V is number of vertices in one face.

getNormalIndices

public java.util.ArrayList<int[]> getNormalIndices()

computeVertexNormals

public void computeVertexNormals()
Computes vertex normals using an area-weighted average of the triangles formed by the half edges incident of each vertex. The normals and normal indices for this mesh will be reset. One normal will be computed per vertex, except in situations where the vertex has incident half edges that are open or hard, in which case extra normals will be computed.


setNormalList

public void setNormalList(java.util.ArrayList<Vector3d> normals)
Sets list of normals

Parameters:
normals -

getNormalList

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

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

setTextureIndices

public void setTextureIndices(int[][] indices)
Sets texture indices for this mesh. If indices is not null, it is assumed to supply one set of texture indices per face, each with the same number of indices as the face itself. Otherwise, if indices is null, the texture information is cleared.

Parameters:
indices - indices is matrix NxV, where N is number of faces and V is number of vertices in one face.

getTextureIndices

public java.util.ArrayList<int[]> getTextureIndices()

setTextureVertices

public void setTextureVertices(java.util.ArrayList<Vector3d> textureVertices)
Sets texture mapping vertices.

Parameters:
textureVertices -

getTextureVertices

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

extendOpenEdges

public void extendOpenEdges(double amount)
Extends the first open edge loop found.

Parameters:
amount - The amount to extend it by.

getFaceMaterial

public Material getFaceMaterial()

setFaceMaterial

public void setFaceMaterial(Material mat)

getBackMaterial

public Material getBackMaterial()

setBackMaterial

public void setBackMaterial(Material mat)

triangulate

public void triangulate()
Modifies this mesh to ensure that all faces are triangles.


setHardEdge

public void setHardEdge(Vertex3d v0,
                        Vertex3d v1,
                        boolean hard)

checkFaceNormals

public double checkFaceNormals()

numDegenerateFaces

public int numDegenerateFaces()

checkForDegenerateFaces

public void checkForDegenerateFaces()

copy

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

Overrides:
copy in class MeshBase

copyWithVertices

public PolygonalMesh 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(PolygonalMesh mesh)
Adds copies of the vertices and faces 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. The same behavior is observed for texture information.

Parameters:
mesh - Mesh to be added to this mesh

computeVolume

public double computeVolume()
Computes the volume of this mesh, on the assumption that it is manifold and closed. The code for this was taken from vclip, by Brian Mirtich. See "Fast and Accurate Computation of Polyhedral Mass Properties," Brian Mirtich, journal of graphics tools, volume 1, number 2, 1996.

Returns:
closed volume of the mesh

computeArea

public double computeArea()
Computes the surface area of this mesh.

Returns:
surface area of the mesh

computeAverageEdgeLength

public double computeAverageEdgeLength()
Computes the average edge length for this mesh.

Returns:
average edge length of the mesh

isClosed

public boolean isClosed()
Returns true if the mesh is closed. This is determined by checking that all edges have a corresponding opposite edge. The mesh also needs to be manifold.

Returns:
true if the mesh is closed

findBorderFaces

public java.util.ArrayList<Face> findBorderFaces()

findBorderEdges

public java.util.ArrayList<HalfEdge> findBorderEdges()

computeVolumeIntegrals

public double computeVolumeIntegrals(Vector3d mov1,
                                     Vector3d mov2,
                                     Vector3d pov)
Computes the volume integrals of this mesh, on the assumption that it is manifold and closed. The code for this was taken from vclip, by Brian Mirtich. See "Fast and Accurate Computation of Polyhedral Mass Properties," Brian Mirtich, journal of graphics tools, volume 1, number 2, 1996.

Parameters:
mov1 - if non-null, returns the first moment of volume
mov2 - if non-null, returns the second moment of volume
pov - if non-null, returns the product of volume
Returns:
closed volume of the mesh

getBVTree

public BVTree getBVTree()

clearBVTree

public void clearBVTree()

writeWorld

public void writeWorld(java.io.PrintStream ps)
                throws java.io.IOException
Throws:
java.io.IOException

dumpToFile

public void dumpToFile(java.lang.String str)

getFaceOrder

public int[] getFaceOrder()
Returns the order of sorted faces, or null if faces have never been sorted.


sortFaces

public int[] sortFaces(Vector3d zdir)
"Sorts" faces according to the direction provided. Note that the order of faces is not actually changed. Instead, an index array is created that holds the sorted order.


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 PolygonalMeshes, and their transforms, vertices, faces, normals and texture coordinates are equal (within eps).

Overrides:
epsilonEquals in class MeshBase

computeInertia

public double computeInertia(SpatialInertia M,
                             double density)
Computes a spatial inertia for volume defined by this mesh, assuming a constant density. It is assumed that the mesh is closed, although small holes in the mesh should not affect the calculation that much. Is is also assumed that the faces are oriented counter-clockwise about their outward-facing normal. The code for this was taken from vclip, by Brian Mirtich. See "Fast and Accurate Computation of Polyhedral Mass Properties," Brian Mirtich, journal of graphics tools, volume 1, number 2, 1996.

Parameters:
M - returns the computed spatial inertia
density - density of the volume
Returns:
the volume of the mesh

computeCentreOfVolume

public double computeCentreOfVolume(Point3d c)
Computes the centre of volume of the mesh


createInertia

public SpatialInertia createInertia(double density)
Creates a spatial inertia for the volume defined by this mesh, assuming a constant density. It is assumed that the mesh is closed, although small holes in the mesh should not affect the calculation that much. Is is also assumed that the faces are oriented counter-clockwise about their outward-facing normal.

Parameters:
density - density of the volume

isBorderVertex

public boolean isBorderVertex(Vertex3d vtx)

countConnected

public int countConnected()

countBorders

public int countBorders()

countGenus

public double countGenus()