Package mgui.geometry

Class Mesh3D

java.lang.Object
mgui.geometry.Shape3D
mgui.geometry.Mesh3D
All Implemented Interfaces:
java.lang.Cloneable, Shape, XMLObject

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
  • Field Details

    • nodes

      public float[] nodes
    • faces

      public int[] faces
    • n

      public int n
    • f

      public int f
  • Constructor Details

    • Mesh3D

      public Mesh3D()
    • Mesh3D

      public Mesh3D​(Mesh3D mesh_to_copy)
  • 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.
      Specified by:
      getSize in interface Shape
      Overrides:
      getSize in class Shape3D
      Returns:
      the number of vertices
    • setFromMesh

      public void setFromMesh​(Mesh3D mesh)
      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 as Point3f's. This list is a copy, so operations performed on these nodes will not affect this shape.
      Specified by:
      getVertices in class Shape3D
      Returns:
    • getCoords

      public float[] getCoords()
      Specified by:
      getCoords in interface Shape
      Specified by:
      getCoords in class Shape3D
    • getFaceNodes

      public java.util.ArrayList<org.jogamp.vecmath.Point3f> getFaceNodes​(int i)
      Returns this face's vertices as Point3f objects.
      Parameters:
      n -
      Returns:
    • getFaceTriangle

      public Triangle3D getFaceTriangle​(int i)
      Returns a 3D triangle for face i.
      Parameters:
      i -
      Returns:
    • setVertices

      public void setVertices​(java.util.ArrayList<org.jogamp.vecmath.Point3f> list)
      Specified by:
      setVertices in class Shape3D
    • setCoords

      public void setCoords​(float[] coords)
      Specified by:
      setCoords in interface Shape
      Specified by:
      setCoords in class Shape3D
    • setFaces

      public void setFaces​(java.util.ArrayList<Mesh3D.MeshFace3D> list)
    • getFaceIndexArray

      public int[] getFaceIndexArray()
    • getFaces

      public java.util.ArrayList<Mesh3D.MeshFace3D> getFaces()
    • removeAllFaces

      public void removeAllFaces()
    • finalize

      public void finalize()
      Overrides:
      finalize in class java.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 a Point3f. 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.

      Specified by:
      getVertex in class Shape3D
      Returns:
    • setVertex

      public void setVertex​(int i, org.jogamp.vecmath.Point3f p)
    • flipFace

      public void flipFace​(int i)
      Flips face i
      Parameters:
      i -
    • getFace

      public Mesh3D.MeshFace3D getFace​(int i)
      Returns the face at index i.
      Parameters:
      i -
      Returns:
    • getFaceAngle

      public double getFaceAngle​(int i, int face)
      Returns the angle in face face at vertex i. Returns Double.NaN if the vertex or face indices are invalid, or if the vertex is not in this face
      Parameters:
      vertex -
      face -
      Returns:
    • addFace

      public void addFace​(Mesh3D.MeshFace3D face)
      Adds a face to this mesh.
      Parameters:
      face -
    • addVertices

      public void addVertices​(java.util.ArrayList<org.jogamp.vecmath.Point3f> list)
    • addFaces

      public void addFaces​(java.util.ArrayList<Mesh3D.MeshFace3D> list)
    • 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()
      Overrides:
      clone in class Shape3D
    • getLocalName

      public java.lang.String getLocalName()
      Description copied from interface: XMLObject
      Returns the local name associated with this XML object.
      Specified by:
      getLocalName in interface XMLObject
      Overrides:
      getLocalName in class Shape3D
      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 the XMLObject.writeXML(int,java.io.Writer,mgui.io.standard.xml.XMLOutputOptions,mgui.interfaces.ProgressUpdater) functions to write larger objects to file.
      Specified by:
      getXML in interface XMLObject
      Overrides:
      getXML in class Shape3D
      Parameters:
      tab - The number of tabs to place before the opening XML wrapper
      Returns:
    • writeXML

      public void writeXML​(int tab, java.io.Writer writer, XMLOutputOptions options, ProgressUpdater progress_bar) throws java.io.IOException
      Description 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 of XMLFormat.Ascii will be used.
      Specified by:
      writeXML in interface XMLObject
      Overrides:
      writeXML in class Shape3D
      Parameters:
      tab - The number of tabs to place before the XML text
      writer - The writer
      options - XMLOutputOptions defining the write parameters
      progress_bar - Optional progress updater (may be null)
      Throws:
      java.io.IOException
    • handleXMLString

      public void handleXMLString​(java.lang.String s) throws org.xml.sax.SAXException
      Description copied from interface: XMLObject
      Handles a string within an XML element.
      Specified by:
      handleXMLString in interface XMLObject
      Overrides:
      handleXMLString in class Shape3D
      Parameters:
      s - String to handle
      Throws:
      org.xml.sax.SAXException
    • writeBinaryFaces

      protected void writeBinaryFaces​(java.io.Writer writer, int compress) throws java.io.IOException
      Write 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.IOException
      Write faces as ASCII data to an XML writer; formats to decimals 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 -