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 classMesh3D.MeshFace3DInner 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 booleanaddFace(int a, int b, int c)Add a triangular face to this mesh.voidaddFace(Mesh3D.MeshFace3D face)Adds a face to this mesh.voidaddFaces(java.util.ArrayList<Mesh3D.MeshFace3D> list)booleanaddVertex(org.jogamp.vecmath.Point3f node)voidaddVertices(java.util.ArrayList<org.jogamp.vecmath.Point3f> list)voidclear()java.lang.Objectclone()voidfinalize()voidflipFace(int i)Flips face ifloat[]getCoords()Mesh3D.MeshFace3DgetFace(int i)Returns the face at indexi.doublegetFaceAngle(int i, int face)Returns the angle in facefaceat vertexi.intgetFaceCount()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 asPoint3fobjects.java.util.ArrayList<Mesh3D.MeshFace3D>getFaces()Triangle3DgetFaceTriangle(int i)Returns a 3D triangle for facei.java.lang.StringgetLocalName()Returns the local name associated with this XML object.org.jogamp.vecmath.Vector3fgetNormalAtFace(int i)java.util.ArrayList<org.jogamp.vecmath.Vector3f>getNormals()intgetSize()Returns the number of vertices in this shape.org.jogamp.vecmath.Point3fgetVertex(int i)Returns the vertex at the specified index as aPoint3f.intgetVertexCount()java.util.ArrayList<org.jogamp.vecmath.Point3f>getVertices()Returns a list of this shape's nodes asPoint3f's.java.lang.StringgetXML(int tab)Returns this object's XML representation as a single string.voidhandleXMLString(java.lang.String s)Handles a string within an XML element.booleanisClockwiseFace(int i)protected voidloadAsciiFaces(java.lang.String data)Load vertices from Ascii encoded dataprotected voidloadBinaryFaces(java.lang.String data, int compression)Load vertices from Base64 binary encoded data.voidremoveAllFaces()voidremoveAllVertices()Removes all vertices in this mesh.voidremoveAllVertices(boolean remove_faces)Removes all vertices in this mesh.voidremoveFace(int i)voidremoveFaces(java.util.TreeSet<java.lang.Integer> removed)Remove a list of faces.voidremoveVertex(int i)Remove a vertex from this mesh, and any faces including it.voidremoveVertex(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.voidsetCoords(float[] coords)voidsetFaces(java.util.ArrayList<Mesh3D.MeshFace3D> list)voidsetFromMesh(Mesh3D mesh)Set this mesh from another mesh.voidsetVertex(int i, org.jogamp.vecmath.Point3f p)voidsetVertices(java.util.ArrayList<org.jogamp.vecmath.Point3f> list)protected voidwriteAsciiFaces(java.io.Writer writer, java.lang.String tab)Write faces as ASCII data to an XML writer; formats todecimalsdecimal places.protected voidwriteBinaryFaces(java.io.Writer writer, int compress)Write mesh faces as Base64 encoded binary data to an XML writer, in row major order.voidwriteXML(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, writeXMLMethods 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:Shape3DReturns 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.removedmust be sorted ascending.- Parameters:
removed-
-
removeFaces
public void removeFaces(java.util.TreeSet<java.lang.Integer> removed)Remove a list of faces.removedmust 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:Shape3DReturns 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:
getVerticesin classShape3D- Returns:
-
getCoords
public float[] getCoords() -
getFaceNodes
public java.util.ArrayList<org.jogamp.vecmath.Point3f> getFaceNodes(int i)Returns this face's vertices asPoint3fobjects.- 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:
setVerticesin classShape3D
-
setCoords
public void setCoords(float[] coords) -
setFaces
-
getFaceIndexArray
public int[] getFaceIndexArray() -
getFaces
-
removeAllFaces
public void removeAllFaces() -
finalize
public void finalize()- Overrides:
finalizein classjava.lang.Object
-
isClockwiseFace
public boolean isClockwiseFace(int i) -
getVertex
public org.jogamp.vecmath.Point3f getVertex(int i)Description copied from class:Shape3DReturns 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 facefaceat vertexi. ReturnsDouble.NaNif 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:XMLObjectReturns the local name associated with this XML object.- Specified by:
getLocalNamein interfaceXMLObject- Overrides:
getLocalNamein classShape3D- Returns:
-
getXML
public java.lang.String getXML(int tab)Description copied from interface:XMLObjectReturns 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:XMLObjectWrites 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.Asciiwill be used.- Specified by:
writeXMLin interfaceXMLObject- Overrides:
writeXMLin 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:XMLObjectHandles a string within an XML element.- Specified by:
handleXMLStringin interfaceXMLObject- Overrides:
handleXMLStringin 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 todecimalsdecimal 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-
-