Package mgui.geometry
Class Mesh3D
java.lang.Object
mgui.geometry.Shape3D
mgui.geometry.Mesh3D
public class Mesh3D extends Shape3D
Geometry class to represent a 3D triangular mesh. This is implemented as an array
of nodes and an array of MeshFace3D objects, which hold the indices of the three nodes
of the triangular face. Normals are generated here, as in Java3D, by the policy that
clockwise triangles have up-facing normals.
- Since:
- 1.0
- Version:
- 1.0
- Author:
- Andrew Reid
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
Mesh3D.MeshFace3D
Inner class which defines a face in a meshNested classes/interfaces inherited from interface mgui.interfaces.xml.XMLObject
XMLObject.XMLEncoding, XMLObject.XMLType
-
Field Summary
Fields inherited from class mgui.geometry.Shape3D
xml_count, xml_current_block, xml_encoding, xml_itr, xml_vertices
-
Constructor Summary
-
Method Summary
Modifier and Type Method Description boolean
addFace(int a, int b, int c)
Add a triangular face to this mesh.void
addFace(Mesh3D.MeshFace3D face)
Adds a face to this mesh.void
addFaces(java.util.ArrayList<Mesh3D.MeshFace3D> list)
boolean
addVertex(org.jogamp.vecmath.Point3f node)
void
addVertices(java.util.ArrayList<org.jogamp.vecmath.Point3f> list)
void
clear()
java.lang.Object
clone()
void
finalize()
void
flipFace(int i)
Flips face ifloat[]
getCoords()
Mesh3D.MeshFace3D
getFace(int i)
Returns the face at indexi
.double
getFaceAngle(int i, int face)
Returns the angle in faceface
at vertexi
.int
getFaceCount()
Returns the number of faces in this mesh.int[]
getFaceIndexArray()
java.util.ArrayList<org.jogamp.vecmath.Point3f>
getFaceNodes(int i)
Returns this face's vertices asPoint3f
objects.java.util.ArrayList<Mesh3D.MeshFace3D>
getFaces()
Triangle3D
getFaceTriangle(int i)
Returns a 3D triangle for facei
.java.lang.String
getLocalName()
Returns the local name associated with this XML object.org.jogamp.vecmath.Vector3f
getNormalAtFace(int i)
java.util.ArrayList<org.jogamp.vecmath.Vector3f>
getNormals()
int
getSize()
Returns the number of vertices in this shape.org.jogamp.vecmath.Point3f
getVertex(int i)
Returns the vertex at the specified index as aPoint3f
.int
getVertexCount()
java.util.ArrayList<org.jogamp.vecmath.Point3f>
getVertices()
Returns a list of this shape's nodes asPoint3f
's.java.lang.String
getXML(int tab)
Returns this object's XML representation as a single string.void
handleXMLString(java.lang.String s)
Handles a string within an XML element.boolean
isClockwiseFace(int i)
protected void
loadAsciiFaces(java.lang.String data)
Load vertices from Ascii encoded dataprotected void
loadBinaryFaces(java.lang.String data, int compression)
Load vertices from Base64 binary encoded data.void
removeAllFaces()
void
removeAllVertices()
Removes all vertices in this mesh.void
removeAllVertices(boolean remove_faces)
Removes all vertices in this mesh.void
removeFace(int i)
void
removeFaces(java.util.TreeSet<java.lang.Integer> removed)
Remove a list of faces.void
removeVertex(int i)
Remove a vertex from this mesh, and any faces including it.void
removeVertex(int i, boolean remove_faces)
Remove a vertex from this mesh.java.util.HashMap<java.lang.Integer,java.lang.Integer>
removeVertices(java.util.TreeSet<java.lang.Integer> removed)
Remove a list of vertices.void
setCoords(float[] coords)
void
setFaces(java.util.ArrayList<Mesh3D.MeshFace3D> list)
void
setFromMesh(Mesh3D mesh)
Set this mesh from another mesh.void
setVertex(int i, org.jogamp.vecmath.Point3f p)
void
setVertices(java.util.ArrayList<org.jogamp.vecmath.Point3f> list)
protected void
writeAsciiFaces(java.io.Writer writer, java.lang.String tab)
Write faces as ASCII data to an XML writer; formats todecimals
decimal places.protected void
writeBinaryFaces(java.io.Writer writer, int compress)
Write mesh faces as Base64 encoded binary data to an XML writer, in row major order.void
writeXML(int tab, java.io.Writer writer, XMLOutputOptions options, ProgressUpdater progress_bar)
Writes the XML representation of this object to file.Methods inherited from class mgui.geometry.Shape3D
contains, getBoundBox, getCenter, getDTD, getProximity, getProximityPoint, getShortXML, getXML, getXMLSchema, handleXMLElementEnd, handleXMLElementStart, loadAsciiCoords, loadBinaryCoords, loadCoords, loadXMLCoord, setVertices, transform, transform, writeAsciiCoords, writeBinaryCoords, writeCoords, writeXML, writeXML
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Field Details
-
nodes
public float[] nodes -
faces
public int[] faces -
n
public int n -
f
public int f
-
-
Constructor Details
-
Mesh3D
public Mesh3D() -
Mesh3D
-
-
Method Details
-
addVertex
public boolean addVertex(org.jogamp.vecmath.Point3f node) -
getFaceCount
public int getFaceCount()Returns the number of faces in this mesh.- Returns:
-
getVertexCount
public int getVertexCount() -
clear
public void clear() -
getSize
public int getSize()Description copied from class:Shape3D
Returns the number of vertices in this shape. Subclasses can provide more efficient implementations. -
setFromMesh
Set this mesh from another mesh.- Parameters:
mesh
-
-
addFace
public boolean addFace(int a, int b, int c)Add a triangular face to this mesh.- Parameters:
a
-b
-c
-- Returns:
-
removeVertex
public void removeVertex(int i)Remove a vertex from this mesh, and any faces including it.- Parameters:
i
-
-
removeVertex
public void removeVertex(int i, boolean remove_faces)Remove a vertex from this mesh.- Parameters:
i
-remove_faces
- Also remove faces including this vertex?
-
removeAllVertices
public void removeAllVertices(boolean remove_faces)Removes all vertices in this mesh.- Parameters:
remove_faces
- - Also removes the faces
-
removeAllVertices
public void removeAllVertices()Removes all vertices in this mesh. Also removes the faces. -
removeVertices
public java.util.HashMap<java.lang.Integer,java.lang.Integer> removeVertices(java.util.TreeSet<java.lang.Integer> removed)Remove a list of vertices.removed
must be sorted ascending.- Parameters:
removed
-
-
removeFaces
public void removeFaces(java.util.TreeSet<java.lang.Integer> removed)Remove a list of faces.removed
must be sorted ascending.- Parameters:
removed
-
-
removeFace
public void removeFace(int i) -
getVertices
public java.util.ArrayList<org.jogamp.vecmath.Point3f> getVertices()Description copied from class:Shape3D
Returns a list of this shape's nodes asPoint3f
's. This list is a copy, so operations performed on these nodes will not affect this shape.- Specified by:
getVertices
in classShape3D
- Returns:
-
getCoords
public float[] getCoords() -
getFaceNodes
public java.util.ArrayList<org.jogamp.vecmath.Point3f> getFaceNodes(int i)Returns this face's vertices asPoint3f
objects.- Parameters:
n
-- Returns:
-
getFaceTriangle
Returns a 3D triangle for facei
.- Parameters:
i
-- Returns:
-
setVertices
public void setVertices(java.util.ArrayList<org.jogamp.vecmath.Point3f> list)- Specified by:
setVertices
in classShape3D
-
setCoords
public void setCoords(float[] coords) -
setFaces
-
getFaceIndexArray
public int[] getFaceIndexArray() -
getFaces
-
removeAllFaces
public void removeAllFaces() -
finalize
public void finalize()- Overrides:
finalize
in classjava.lang.Object
-
isClockwiseFace
public boolean isClockwiseFace(int i) -
getVertex
public org.jogamp.vecmath.Point3f getVertex(int i)Description copied from class:Shape3D
Returns the vertex at the specified index as aPoint3f
. This vertex is a copy, so operations performed on it will not affect this shape.Note: subclasses may want to provide a more efficient implementation of this method.
-
setVertex
public void setVertex(int i, org.jogamp.vecmath.Point3f p) -
flipFace
public void flipFace(int i)Flips face i- Parameters:
i
-
-
getFace
Returns the face at indexi
.- Parameters:
i
-- Returns:
-
getFaceAngle
public double getFaceAngle(int i, int face)Returns the angle in faceface
at vertexi
. ReturnsDouble.NaN
if the vertex or face indices are invalid, or if the vertex is not in this face- Parameters:
vertex
-face
-- Returns:
-
addFace
Adds a face to this mesh.- Parameters:
face
-
-
addVertices
public void addVertices(java.util.ArrayList<org.jogamp.vecmath.Point3f> list) -
addFaces
-
getNormals
public java.util.ArrayList<org.jogamp.vecmath.Vector3f> getNormals() -
getNormalAtFace
public org.jogamp.vecmath.Vector3f getNormalAtFace(int i) -
clone
public java.lang.Object clone() -
getLocalName
public java.lang.String getLocalName()Description copied from interface:XMLObject
Returns the local name associated with this XML object.- Specified by:
getLocalName
in interfaceXMLObject
- Overrides:
getLocalName
in classShape3D
- Returns:
-
getXML
public java.lang.String getXML(int tab)Description copied from interface:XMLObject
Returns this object's XML representation as a single string. NOTE: this is not feasible for larger objects and containers, thus may not be implemented for these objects. Use theXMLObject.writeXML(int,java.io.Writer,mgui.io.standard.xml.XMLOutputOptions,mgui.interfaces.ProgressUpdater)
functions to write larger objects to file. -
writeXML
public void writeXML(int tab, java.io.Writer writer, XMLOutputOptions options, ProgressUpdater progress_bar) throws java.io.IOExceptionDescription copied from interface:XMLObject
Writes the XML representation of this object to file. The basic contract for this method is that it should not write a newline character at its start or end. The default format ofXMLFormat.Ascii
will be used.- Specified by:
writeXML
in interfaceXMLObject
- Overrides:
writeXML
in classShape3D
- Parameters:
tab
- The number of tabs to place before the XML textwriter
- The writeroptions
- XMLOutputOptions defining the write parametersprogress_bar
- Optional progress updater (may benull
)- Throws:
java.io.IOException
-
handleXMLString
public void handleXMLString(java.lang.String s) throws org.xml.sax.SAXExceptionDescription copied from interface:XMLObject
Handles a string within an XML element.- Specified by:
handleXMLString
in interfaceXMLObject
- Overrides:
handleXMLString
in classShape3D
- Parameters:
s
- String to handle- Throws:
org.xml.sax.SAXException
-
writeBinaryFaces
protected void writeBinaryFaces(java.io.Writer writer, int compress) throws java.io.IOExceptionWrite mesh faces as Base64 encoded binary data to an XML writer, in row major order.- Parameters:
mesh
-encoding
-compress
- Compression; 0 for none, 1 for zip, 2 for gzip- Throws:
java.io.IOException
-
writeAsciiFaces
protected void writeAsciiFaces(java.io.Writer writer, java.lang.String tab) throws java.io.IOExceptionWrite faces as ASCII data to an XML writer; formats todecimals
decimal places. Wraps line when it exceeds 76 characters.- Parameters:
mesh
-encoding
-- Throws:
java.io.IOException
-
loadBinaryFaces
protected void loadBinaryFaces(java.lang.String data, int compression)Load vertices from Base64 binary encoded data.- Parameters:
data
-compression
- Compression; 0 for none, 1 for zip, 2 for gzip
-
loadAsciiFaces
protected void loadAsciiFaces(java.lang.String data)Load vertices from Ascii encoded data- Parameters:
data
-
-