Class Meshes


  • public class Meshes
    extends Object
    Utility methods for working with Mesh objects.
    Author:
    Curtis Rueden, Kyle Harrington
    • Method Detail

      • center

        public static RealPoint center​(Mesh m)
        Finds the center of a mesh using vertices.
        Returns:
        a RealPoint representing the mesh's center
      • boundingBox

        public static RealInterval boundingBox​(Mesh mesh)
        Computes and returns an oriented bounding box RealInterval
        Parameters:
        mesh -
        Returns:
        the output Mesh
        Implementation Note:
        op names="geom.boundingBox"
      • boundingBoxMesh

        public static Mesh boundingBoxMesh​(Mesh input)
        Computes and returns an oriented bounding box Mesh
        Parameters:
        input -
        Returns:
        the output Mesh
        Implementation Note:
        op names="geom.boundingBox"
      • copy

        public static void copy​(Mesh src,
                                Mesh dest)
        Copies a mesh into another mesh.
        Parameters:
        src - Source mesh, from which data will be copied.
        dest - Destination mesh, into which source will be copied. (container)
        Implementation Note:
        op names="engine.copy, copy.mesh"
      • calculateNormals

        public static void calculateNormals​(Mesh src,
                                            Mesh dest)
        Calculates the normals for a mesh. Creates a new mesh with the calculated normals. Assumes CCW winding order.
        Parameters:
        src - Source mesh, used for vertex and triangle info
        dest - Destination mesh, will be populated with src's info plus the calculated normals
      • simplify

        public static Mesh simplify​(Mesh mesh,
                                    float target_percent,
                                    float agressiveness)
        Simplifies a given mesh. Normals and uv coordinates will be ignored and not added to the output mesh.
        Parameters:
        mesh - Source mesh
        target_percent - the amount in percent to attempt to achieve. For example: 0.25f would result in creating a mesh with 25% of triangles contained in the original.
        agressiveness - sharpness to increase the threshold. 5..8 are good numbers. more iterations yield higher quality. Minimum 4 and maximum 20 are recommended.
        Returns:
        the simplified mesh The result will not include normals or uv coordinates.
      • removeDuplicateVertices

        public static BufferMesh removeDuplicateVertices​(Mesh mesh,
                                                         int precision)
        Creates a new mesh from a given mesh without any duplicate vertices. Normals and uv coordinates will be ignored and not added to the output mesh.
        Parameters:
        mesh - Source mesh
        precision - decimal digits to take into account when comparing mesh vertices
        Returns:
        new mesh without duplicate vertices. The result will not include normals or uv coordinates.
      • marchingCubes

        public static <T extends BooleanType<T>> Mesh marchingCubes​(RandomAccessibleInterval<T> source)
        Creates mesh e.g. from IterableRegion by using the marching cubes algorithm.
        Parameters:
        source - The binary input image for the marching cubes algorithm.
        Returns:
        The result mesh of the marching cubes algorithm.
      • marchingCubes

        public static <T extends RealType<T>> Mesh marchingCubes​(RandomAccessibleInterval<T> source,
                                                                 double isoLevel)
        Creates mesh e.g. from IterableRegion by using the marching cubes algorithm.
        Parameters:
        source - The input image for the marching cubes algorithm.
        isoLevel - The threshold to distinguish between foreground and background values.
        Returns:
        The result mesh of the marching cubes algorithm.
      • nConnectedComponents

        public static int nConnectedComponents​(Mesh mesh)
        Returns the number of connected components in the specified mesh.
        Parameters:
        mesh - the mesh.
        Returns:
        the number of connected components.
      • connectedComponents

        public static Iterable<BufferMesh> connectedComponents​(Mesh mesh)
        Returns an iterable over the connected components of the specified mesh.
        Parameters:
        mesh - the mesh.
        Returns:
        an iterable.
      • scale

        public static void scale​(Mesh mesh,
                                 double[] scale)
        Scales the vertices position by the amount specified by the array.

        Note that the position are simply multiplied by the specified scale, so they are scaled with respect to (0,0,0) which makes this method useful mainly to have a mesh generated by marching-cube algorithm have coordinates in physical units.

        Parameters:
        mesh - the mesh to scale.
        scale - a double array of at least 3 elements.
      • translate

        public static void translate​(Mesh mesh,
                                     double[] translate)
        Translates the vertices position by the amount specified by the array.

        The positions are equal to new_pos[d] = old_pos[d] + translate[d].

        Parameters:
        mesh - the mesh to translate.
        translate - a double array of at least 3 elements.
      • translateScale

        public static void translateScale​(Mesh mesh,
                                          double[] translate,
                                          double[] scale)
        Translates the vertices position by the amount specified by the array, then scales the coordinates.

        The positions are equal to new_pos[d] = (old_pos[d] + translate[d]) * scale[d].

        Parameters:
        mesh - the mesh to translate.
        translate - a double array of at least 3 elements.
        scale - a double array of at least 3 elements.