Class SimpleTriangleMesh

    • Field Detail

      • vertices

        private final java.util.List<Vector3D> vertices
        Vertices in the mesh.
      • faces

        private final java.util.List<int[]> faces
        Faces in the mesh.
      • bounds

        private final Bounds3D bounds
        The bounds of the mesh.
      • precision

        private final org.apache.commons.numbers.core.Precision.DoubleEquivalence precision
        Object used for floating point comparisons.
    • Constructor Detail

      • SimpleTriangleMesh

        private SimpleTriangleMesh​(java.util.List<Vector3D> vertices,
                                   java.util.List<int[]> faces,
                                   Bounds3D bounds,
                                   org.apache.commons.numbers.core.Precision.DoubleEquivalence precision)
        Construct a new instance from a vertex list and set of faces. No validation is performed on the input.
        Parameters:
        vertices - vertex list
        faces - face indices list
        bounds - mesh bounds
        precision - precision context used when creating face polygons
    • Method Detail

      • vertices

        public java.lang.Iterable<Vector3D> vertices()
        Get an iterable containing the vertices in the mesh.
        Specified by:
        vertices in interface Mesh<TriangleMesh.Face>
        Returns:
        an iterable containing the vertices in the mesh
      • getVertices

        public java.util.List<Vector3D> getVertices()
        Get a list containing all vertices in the mesh.
        Specified by:
        getVertices in interface Mesh<TriangleMesh.Face>
        Returns:
        a list containing all vertices in the mesh
      • getVertexCount

        public int getVertexCount()
        Get the number of vertices in the mesh.
        Specified by:
        getVertexCount in interface Mesh<TriangleMesh.Face>
        Returns:
        the number of vertices in the mesh
      • faces

        public java.lang.Iterable<TriangleMesh.Face> faces()
        Get an iterable containing all faces in the mesh.
        Specified by:
        faces in interface Mesh<TriangleMesh.Face>
        Returns:
        an iterable containing all faces in the mesh
      • getFaceCount

        public int getFaceCount()
        Get the number of faces in the mesh.
        Specified by:
        getFaceCount in interface Mesh<TriangleMesh.Face>
        Returns:
        the number of faces in the mesh
      • getFace

        public TriangleMesh.Face getFace​(int index)
        Get a face from the mesh by its index.
        Specified by:
        getFace in interface Mesh<TriangleMesh.Face>
        Parameters:
        index - the index of the mesh to retrieve
        Returns:
        the face at the given index
      • getBounds

        public Bounds3D getBounds()
        Get a Bounds3D object defining the axis-aligned box containing all vertices in the boundaries for this instance. Null is returned if any boundary is infinite or no vertices are found.
        Specified by:
        getBounds in interface BoundarySource3D
        Returns:
        the bounding box for this instance or null if no valid bounds could be determined
      • getPrecision

        public org.apache.commons.numbers.core.Precision.DoubleEquivalence getPrecision()
        Get the precision context for the mesh. This context is used during construction of face Triangle3D instances.
        Returns:
        the precision context for the mesh
      • triangleStream

        public java.util.stream.Stream<Triangle3D> triangleStream()
        Return the boundaries of this instance as a stream of Triangle3D instances. An IllegalStateException exception is thrown while reading from the stream if any boundary cannot be converted to a triangle (i.e. if it has infinite size).
        Specified by:
        triangleStream in interface BoundarySource3D
        Returns:
        a stream of triangles representing the instance boundaries
        See Also:
        PlaneSubset.toTriangles()
      • toTriangleMesh

        public SimpleTriangleMesh toTriangleMesh​(org.apache.commons.numbers.core.Precision.DoubleEquivalence meshPrecision)
        Return this instance if the given precision context is equal to the current precision context. Otherwise, create a new mesh with the given precision context but the same vertices, faces, and bounds.
        Specified by:
        toTriangleMesh in interface BoundarySource3D
        Parameters:
        meshPrecision - precision context to use when generating face polygons
        Returns:
        a mesh instance with the given precision context and the same mesh structure as the current instance
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • createFaceStream

        private <T> java.util.stream.Stream<T> createFaceStream​(java.util.function.Function<TriangleMesh.Face,​T> fn)
        Create a stream containing the results of applying fn to each face in the mesh.
        Type Parameters:
        T - Stream element type
        Parameters:
        fn - function used to extract the stream values from each face
        Returns:
        a stream containing the results of applying fn to each face in the mesh
      • builder

        public static SimpleTriangleMesh.Builder builder​(org.apache.commons.numbers.core.Precision.DoubleEquivalence precision)
        Return a builder for creating new triangle mesh objects.
        Parameters:
        precision - precision object used for floating point comparisons
        Returns:
        a builder for creating new triangle mesh objects
      • from

        public static SimpleTriangleMesh from​(Vector3D[] vertices,
                                              int[][] faces,
                                              org.apache.commons.numbers.core.Precision.DoubleEquivalence precision)
        Construct a new triangle mesh from the given vertices and face indices.
        Parameters:
        vertices - vertices for the mesh
        faces - face indices for the mesh
        precision - precision context used for floating point comparisons
        Returns:
        a new triangle mesh instance
        Throws:
        java.lang.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 vertex list
      • from

        public static SimpleTriangleMesh from​(java.util.Collection<Vector3D> vertices,
                                              java.util.Collection<int[]> faces,
                                              org.apache.commons.numbers.core.Precision.DoubleEquivalence precision)
        Construct a new triangle mesh from the given vertices and face indices.
        Parameters:
        vertices - vertices for the mesh
        faces - face indices for the mesh
        precision - precision context used for floating point comparisons
        Returns:
        a new triangle mesh instance
        Throws:
        java.lang.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 vertex list
      • from

        public static SimpleTriangleMesh from​(BoundarySource3D boundarySrc,
                                              org.apache.commons.numbers.core.Precision.DoubleEquivalence precision)
        Construct a new mesh instance containing all triangles from the given boundary source. Equivalent vertices are reused wherever possible.
        Parameters:
        boundarySrc - boundary source to construct a mesh from
        precision - precision context used for floating point comparisons
        Returns:
        new mesh instance containing all triangles from the given boundary source
        Throws:
        java.lang.IllegalStateException - if any boundary in the boundary source has infinite size and cannot be converted to triangles