public class PolygonalMesh extends MeshBase
Modifier and Type | Field and Description |
---|---|
boolean |
canSelfIntersect |
static int |
computedFaceNormals |
isFixed, myDisplayListValid, myUseDisplayList, useVertexColoring, XMeshToWorld
TRANSLUCENT, TWO_DIMENSIONAL
Constructor and Description |
---|
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) . |
Modifier and Type | Method and Description |
---|---|
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.
|
RigidTransform3d |
computePrincipalAxes() |
static RigidTransform3d |
computePrincipalAxes(PolygonalMesh mesh) |
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) |
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
public boolean canSelfIntersect
public static int computedFaceNormals
public PolygonalMesh()
public PolygonalMesh(java.lang.String fileName) throws java.io.IOException
write(PrintWriter,NumberFormat,boolean)
.fileName
- name of the file containing the mesh descriptionjava.io.IOException
public PolygonalMesh(java.io.File file) throws java.io.IOException
write(PrintWriter,NumberFormat,boolean)
.file
- file containing the mesh descriptionjava.io.IOException
public PolygonalMesh(PolygonalMesh old)
public void notifyVertexPositionsModified()
notifyVertexPositionsModified
in class MeshBase
public void updateFaceNormals()
public void updateRenderNormals()
public boolean faceNormalsValid()
public RenderProps createRenderProps(HasProperties host)
createRenderProps
in class MeshBase
host
- if non-null, is used to initialize inherited valuespublic boolean isTriangular()
public boolean isQuad()
public boolean isManifold()
public java.util.ArrayList<Face> getFaces()
Face
.
Modifying these elements will modify the mesh.public int getNumFaces()
public int countEdges()
public SignedDistanceGrid getSignedDistanceGrid()
public SignedDistanceGrid getSignedDistanceGrid(double margin, Vector3d cellDivisions)
public void setMeshToWorld(RigidTransform3d X)
MeshBase
meshToWorldIsIdentity
will subsequently
return true.setMeshToWorld
in class MeshBase
X
- transform from mesh to world coordinatespublic void read(java.io.Reader reader) throws java.io.IOException
write(PrintWriter,NumberFormat,boolean)
.public void read(ReaderTokenizer rtok, boolean zeroIndexed) throws java.io.IOException
write(PrintWriter,NumberFormat,boolean)
.public void set(Point3d[] pnts, int[][] faceIndices)
pnts
- points from which the vertices are formedfaceIndices
- integer arrays giving the indices of each face. Each index should
correspond to a particular point in pnts.java.lang.IllegalArgumentException
- if a vertex index is out of boundspublic Face addFace(int[] indices)
indices
- integer array giving the vertex indices of the face. Each index should
correspond to a vertex presently associated with this mesh.java.lang.IllegalArgumentException
- if a vertex index is out of boundspublic Face addFace(Vertex3d[] vertices)
vertices
- vertices comprising this faces. Each vertex should be presently contained
in this mesh.java.lang.IllegalArgumentException
- if any vertices are not contained within this meshpublic Face addFace(Vertex3d v0, Vertex3d v1, Vertex3d v2)
v0
- first vertexv1
- second vertexv2
- third vertexjava.lang.IllegalArgumentException
- if any vertices are not contained within this meshpublic boolean removeFace(Face face)
face
- face to removepublic boolean removeFaces(java.util.Collection<Face> faces)
faces
- Collection of faces to removepublic int doMergeCloseVertices(double dsqr)
public int mergeCloseVertices(double dist)
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.
dist
- distance within which vertices should be merged.public int numDisconnectedVertices()
public int removeDisconnectedVertices()
public int removeDisconnectedFaces()
public PolygonalMesh[] partitionIntoConnectedMeshes()
null
is returned. At present, the copied meshes do not
preserve face normal or texture information.public void checkConsistency()
public void write(java.io.File file, java.lang.String fmtStr) throws java.io.IOException
write(java.io.PrintWriter,maspack.util.NumberFormat,boolean,boolean)
with zeroIndexed
and facesClockwise
set to
false.file
- File to write this mesh tofmtStr
- format string for writing the vertex coordinates. If null
,
a format of "%.8g"
is assumed.java.io.IOException
public void write(java.io.PrintWriter pw, NumberFormat fmt, boolean zeroIndexed) throws java.io.IOException
write(java.io.PrintWriter,maspack.util.NumberFormat,boolean,boolean)
with facesClockwise
set to false.write
in class MeshBase
pw
- PrintWriter to write this mesh tofmt
- 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.java.io.IOException
public void write(java.io.PrintWriter pw, NumberFormat fmt, boolean zeroIndexed, boolean facesClockwise) throws java.io.IOException
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
.
pw
- PrintWriter to write this mesh tofmt
- 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.java.io.IOException
public void writePoly(java.lang.String nodeString) throws java.lang.Exception
java.lang.Exception
public void writePoly(java.io.PrintStream ps) throws java.lang.Exception
java.lang.Exception
public void transform(AffineTransform3dBase X)
public void inverseTransform(AffineTransform3dBase X)
inverseTransform
in class MeshBase
X
- affine transformationpublic int getRenderHints()
TRANSLUCENT
.getRenderHints
in interface GLRenderable
getRenderHints
in class MeshBase
public void render(GLRenderer renderer, RenderProps props, int flags)
public PolygonalMesh getSubdivisionMesh()
public void updateSubdivisionMesh(PolygonalMesh mesh)
mesh
- Must be a mesh generated by calling getSubdivisionMesh on this mesh.public void interpolate(Point3d p, Face f, double u, double v)
f
- The face to interpolate.u
- The weighting of the first vertice.v
- The weighting of the second vertice.public int getSubdivisions()
public void setSubdivisions(int subdivisions)
subdivisions
- The number of times to subdivide each triangle.public void setNormalIndices(int[][] indices)
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.indices
- indices is matrix NxV, where N is number of faces and V is number of
vertices in one face.public java.util.ArrayList<int[]> getNormalIndices()
public void computeVertexNormals()
public void setNormalList(java.util.ArrayList<Vector3d> normals)
normals
- public java.util.ArrayList<Vector3d> getNormalList()
public int getNumNormals()
getNumNormals
in class MeshBase
public Vector3d getNormal(int idx)
public void setTextureIndices(int[][] indices)
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.indices
- indices is matrix NxV, where N is number of faces and V is number of
vertices in one face.public java.util.ArrayList<int[]> getTextureIndices()
public void setTextureVertices(java.util.ArrayList<Vector3d> textureVertices)
textureVertices
- public java.util.ArrayList<Vector3d> getTextureVertices()
public void extendOpenEdges(double amount)
amount
- The amount to extend it by.public Material getFaceMaterial()
public void setFaceMaterial(Material mat)
public Material getBackMaterial()
public void setBackMaterial(Material mat)
public void triangulate()
public double checkFaceNormals()
public int numDegenerateFaces()
public void checkForDegenerateFaces()
public PolygonalMesh copy()
public PolygonalMesh copyWithVertices(java.util.ArrayList<? extends Vertex3d> vtxs)
copyWithVertices
in class MeshBase
public void addMesh(PolygonalMesh mesh)
mesh
- Mesh to be added to this meshpublic double computeVolume()
public double computeArea()
public double computeAverageEdgeLength()
public boolean isClosed()
public java.util.ArrayList<Face> findBorderFaces()
public java.util.ArrayList<HalfEdge> findBorderEdges()
public double computeVolumeIntegrals(Vector3d mov1, Vector3d mov2, Vector3d pov)
mov1
- if non-null, returns the first moment of volumemov2
- if non-null, returns the second moment of volumepov
- if non-null, returns the product of volumepublic RigidTransform3d computePrincipalAxes()
public static RigidTransform3d computePrincipalAxes(PolygonalMesh mesh)
public BVTree getBVTree()
public void clearBVTree()
public void writeWorld(java.io.PrintStream ps) throws java.io.IOException
java.io.IOException
public void dumpToFile(java.lang.String str)
public int[] getFaceOrder()
public int[] sortFaces(Vector3d zdir)
public boolean epsilonEquals(MeshBase base, double eps)
eps
).epsilonEquals
in class MeshBase
public double computeInertia(SpatialInertia M, double density)
M
- returns the computed spatial inertiadensity
- density of the volumepublic double computeCentreOfVolume(Point3d c)
public SpatialInertia createInertia(double density)
density
- density of the volumepublic boolean isBorderVertex(Vertex3d vtx)
public int countConnected()
public int countBorders()
public double countGenus()