Class SimpleTriangleMesh.Builder

java.lang.Object
org.apache.commons.geometry.euclidean.threed.mesh.SimpleTriangleMesh.Builder
Enclosing class:
SimpleTriangleMesh

public static final class SimpleTriangleMesh.Builder extends Object
Builder class for creating mesh instances.
  • Method Details

    • useVertex

      public int useVertex(Vector3D vertex)
      Use a vertex in the constructed mesh. If an equivalent vertex already exist, as determined by the configured Precision.DoubleEquivalence, then the index of the previously added vertex is returned. Otherwise, the given vertex is added to the vertex list and the index of the new entry is returned. This is in contrast with the addVertex(Vector3D), which always adds a new entry to the vertex list.
      Parameters:
      vertex - vertex to use
      Returns:
      the index of the added vertex or an equivalent vertex that was added previously
      See Also:
    • addVertex

      public int addVertex(Vector3D vertex)
      Add a vertex directly to the vertex list, returning the index of the added vertex. The vertex is added regardless of whether or not an equivalent vertex already exists in the list. This is in contrast with the useVertex(Vector3D) method, which only adds a new entry to the vertex list if an equivalent one does not already exist.
      Parameters:
      vertex - the vertex to append
      Returns:
      the index of the appended vertex in the vertex list
    • addVertices

      Add a group of vertices directly to the vertex list. No equivalent vertices are reused.
      Parameters:
      newVertices - vertices to append
      Returns:
      this instance
      See Also:
    • addVertices

      public SimpleTriangleMesh.Builder addVertices(Collection<? extends Vector3D> newVertices)
      Add a group of vertices directly to the vertex list. No equivalent vertices are reused.
      Parameters:
      newVertices - vertices to append
      Returns:
      this instance
      See Also:
    • ensureVertexCapacity

      Ensure that this instance has enough capacity to store at least numVertices number of vertices without reallocating space. This can be used to help improve performance and memory usage when creating meshes with large numbers of vertices.
      Parameters:
      numVertices - the number of vertices to ensure that this instance can contain
      Returns:
      this instance
    • getVertexCount

      public int getVertexCount()
      Get the current number of vertices in this mesh.
      Returns:
      the current number of vertices in this mesh
    • getVertex

      public Vector3D getVertex(int index)
      Get the vertex at the given index.
      Parameters:
      index - index of the vertex to retrieve
      Returns:
      vertex at the given index
      Throws:
      IndexOutOfBoundsException - if the index is out of bounds of the mesh vertex list
    • addFace

      public SimpleTriangleMesh.Builder addFace(int index1, int index2, int index3)
      Append a face to this mesh.
      Parameters:
      index1 - index of the first vertex in the face
      index2 - index of the second vertex in the face
      index3 - index of the third vertex in the face
      Returns:
      this instance
      Throws:
      IllegalArgumentException - if any of the arguments is not a valid index into the current vertex list
    • addFace

      public SimpleTriangleMesh.Builder addFace(int[] face)
      Append a face to this mesh.
      Parameters:
      face - array containing the 3 vertex indices defining the face
      Returns:
      this instance
      Throws:
      IllegalArgumentException - if face does not contain exactly 3 elements or if any of the vertex indices is not a valid index into the current vertex list
    • addFaces

      public SimpleTriangleMesh.Builder addFaces(int[][] faceIndices)
      Append a group of faces to this mesh.
      Parameters:
      faceIndices - faces to append
      Returns:
      this instance
      Throws:
      IllegalArgumentException - if any of the face index arrays does not have exactly 3 elements or if any index is not a valid index into the current vertex list
    • addFaces

      public SimpleTriangleMesh.Builder addFaces(Collection<int[]> faceIndices)
      Append a group of faces to this mesh.
      Parameters:
      faceIndices - faces to append
      Returns:
      this instance
      Throws:
      IllegalArgumentException - if any of the face index arrays does not have exactly 3 elements or if any index is not a valid index into the current vertex list
    • addFaceUsingVertices

      Add a face to this mesh, only adding vertices to the vertex list if equivalent vertices are not found.
      Parameters:
      p1 - first face vertex
      p2 - second face vertex
      p3 - third face vertex
      Returns:
      this instance
      See Also:
    • addFaceAndVertices

      Add a face and its vertices to this mesh. The vertices are always added to the vertex list, regardless of whether or not equivalent vertices exist in the vertex list.
      Parameters:
      p1 - first face vertex
      p2 - second face vertex
      p3 - third face vertex
      Returns:
      this instance
      See Also:
    • ensureFaceCapacity

      Ensure that this instance has enough capacity to store at least numFaces number of faces without reallocating space. This can be used to help improve performance and memory usage when creating meshes with large numbers of faces.
      Parameters:
      numFaces - the number of faces to ensure that this instance can contain
      Returns:
      this instance
    • getFaceCount

      public int getFaceCount()
      Get the current number of faces in this mesh.
      Returns:
      the current number of faces in this meshr
    • build

      Build a triangle mesh containing the vertices and faces in this builder.
      Returns:
      a triangle mesh containing the vertices and faces in this builder