Class MeshFunctions

java.lang.Object
mgui.interfaces.Utility
mgui.geometry.mesh.MeshFunctions

public class MeshFunctions
extends Utility
Utility class containing static methods that perform some operation upon Mesh3D shape objects. This class should contain all methods for mesh functions, which may or may not reference more specialized mesh algorithm classes. I.e., it is intended as the standard interface for mesh operations within mgui.

Policy: See ProgressUpdater for details on how to incorporate progress updaters into your methods. In general, if progress updating is desired, functions must be able to handle null updater arguments, and preferably provide a second method with no updater which calls the first with a null updater (thus allowing stand-alone calls to blocking methods). TODO: Remove all calls to Worker in this class. All functions should block.

Since:
1.0
Version:
1.0
Author:
Andrew Reid
See Also:
ProgressUpdater, InterfaceProgressBar
  • Nested Class Summary

    Nested Classes
    Modifier and Type Class Description
    protected static class  MeshFunctions.IndexedPoint3f  
  • Field Summary

    Fields
    Modifier and Type Field Description
    static javax.swing.JProgressBar progressBar  
    static double tolerance  
  • Constructor Summary

    Constructors
    Constructor Description
    MeshFunctions()  
  • Method Summary

    Modifier and Type Method Description
    static void addIndexedTriangleArray​(Mesh3D mesh, org.jogamp.java3d.IndexedTriangleArray tris)
    Adds an IndexedTriangleArray to the current mesh.
    static void cleanMesh​(Mesh3D mesh)  
    static Mesh3D combine​(Mesh3D mesh1, Mesh3D mesh2)
    Combines mesh1 and mesh2 and returns the result.
    static boolean computeVertexWiseCurvature​(Mesh3DInt mesh3D, java.lang.String target_column, ProgressUpdater progress)
    Computes the curvature of a mesh at each of its nodes, as the magnitude of the sum of surface normals of the triangles of which it is a node.
    static Mesh3D condenseMesh​(Mesh3D mesh)
    Condenses a mesh by removing all coincident nodes.
    static void correctOrientation​(Mesh3D mesh)
    Orients all faces with each other, starting with the first face
    static void correctOrientation​(Mesh3D mesh, boolean reverse)
    Orients all faces with each other (starting with face 0)
    static java.util.ArrayList<Mesh3D> cutMeshWithPlane​(Mesh3D mesh, Plane3D plane, InterfaceProgressBar progress_bar)
    Cuts mesh with plane, creating new faces along the cut seam.
    static java.util.ArrayList<Mesh3D> cutMeshWithPlane3​(Mesh3D mesh, Plane3D plane)
    Cuts mesh with plane, creating new faces along the cut seam.
    static void decimateByDistance​(Mesh3D mesh, Mesh3D newmesh, double threshold)
    Decimates this mesh by merging multiple nodes into a single node if they are separated by less than .
    static org.jogamp.vecmath.Vector3f[] flipNormals​(org.jogamp.vecmath.Vector3f[] normals)  
    protected static java.util.ArrayList<MguiInteger> getAllNeighbours​(int n, NeighbourhoodMesh nmesh, boolean[] removed, int[] added, boolean[] processed)
    Searches for all neighbours of n in nmesh.
    static double getArea​(Mesh3D mesh)
    Returns the surface area of the given mesh
    static double getAverageEdgeLength​(Mesh3D mesh)
    Returns the average edge length keyin a mesh.
    static java.util.ArrayList<java.lang.Integer> getBoundaryNodeIndices​(Mesh3D mesh)  
    static boolean[] getBoundaryNodes​(Mesh3D mesh)
    Determine which nodes are boundary nodes, return an array of booleans.
    static int getClosestVertex​(Mesh3D mesh, int idx, java.util.ArrayList<java.lang.Integer> search_vertices, MguiDouble distance)
    Returns the closest vertex in a list of vertices, or from all vertices if the list is empty.
    static java.util.ArrayList<java.lang.Integer> getClosestVertices​(Mesh3D mesh)
    Returns a list of size mesh.n integers, such that list(i) = the index of the closest vertex j from vertex i.
    static java.util.ArrayList<java.lang.Integer> getClosestVertices​(Mesh3D mesh, java.util.ArrayList<java.lang.Double> distances)
    Returns a list of size mesh.n integers, such that list(i) = the index of the closest vertex j from vertex i.
    static Mesh3D getConvexHull​(Mesh3D mesh)
    Returns a new mesh which is the convex hull of the given mesh.
    static Mesh3D getConvexHull​(Mesh3D mesh, java.lang.String method)  
    static Mesh3D getConvexHull​(Mesh3D mesh, java.lang.String method, ProgressUpdater progress)
    Returns a new mesh which is the convex hull of the given mesh.
    static Mesh3D getConvexHull​(Mesh3D mesh, ProgressUpdater progress)  
    static java.util.ArrayList<java.lang.Boolean> getDuplicateFaces​(Mesh3D mesh)
    Returns an array of booleans where true indicates a duplicate face
    static java.util.List<java.lang.Integer> getDuplicateNodes​(Mesh3D mesh)
    Returns an array of booleans where true indicates a duplicate node
    static java.util.ArrayList<MguiDouble> getEdgeLengths​(Mesh3D mesh, java.util.ArrayList<MeshEdge> edges)
    Returns a list of edge lengths for the given set of edges
    static java.util.ArrayList<java.lang.Integer> getFarthestVertices​(Mesh3D mesh)
    Returns a list of size mesh.n integers, such that list(i) = the index of the farthest vertex j from vertex i.
    static java.util.ArrayList<java.lang.Integer> getFarthestVertices​(Mesh3D mesh, java.util.ArrayList<java.lang.Double> distances)
    Returns a list of size mesh.n integers, such that list(i) = the index of the farthest vertex j from vertex i.
    static java.util.ArrayList<java.lang.Integer> getFarthestVertices​(Mesh3D mesh, java.util.ArrayList<java.lang.Double> distances, java.util.ArrayList<java.lang.Integer> vertices)
    Returns a list of size mesh.n integers, such that list(i) = the index of the farthest vertex j from vertex i.
    static Mesh3D getFractalSphereMesh​(org.jogamp.vecmath.Point3f center, float radius, int min_nodes)  
    static Mesh3D getGlobeSphereMesh​(org.jogamp.vecmath.Point3f center, float radius, int n_nodes)  
    static java.util.ArrayList<java.util.ArrayList<java.lang.Integer>> getIntersectingFaces​(Mesh3D mesh1, Mesh3D mesh2, float search_max)
    Returns a list of face indices indicating which faces intersect between mesh1 and mesh2.
    static java.util.ArrayList<java.util.ArrayList<java.lang.Integer>> getIntersectingFaces​(Mesh3D mesh_1, Mesh3D mesh_2, float search_max, ProgressUpdater progress)
    Returns two lists of face indices indicating which faces intersect between mesh1 and mesh2.
    static java.util.ArrayList<java.util.ArrayList<java.lang.Integer>> getIntersectingFacesBlocking​(Mesh3D mesh_1, Mesh3D mesh_2, float search_max, ProgressUpdater progress)
    Returns two lists of face indices indicating which faces intersect between mesh1 and mesh2.
    static org.jogamp.vecmath.Point3f getIntersectionPoint​(Mesh3D mesh, org.jogamp.vecmath.Point3f p, org.jogamp.vecmath.Vector3f v)
    Finds the point from the first face in the nodes list which intersects the line segment defined by p and v.
    static java.util.ArrayList<Polygon3D> getIntersectionSegments​(Mesh3D mesh1, Mesh3D mesh2, InterfaceProgressBar progress_bar)
    Return a set of line segments which represent the intersection of one mesh with another.
    static Mesh3D getIsosurfaceFromVolume​(Volume3DInt volume, java.lang.String column, double iso_level)
    Constructs an isosurface from volume; i.e., computes a mesh which represents the location where values in the 3D scalar field in volume are equal to iso_level.
    static java.util.HashMap<java.lang.Integer,​java.lang.Integer> getJaggedEdgeNodes​(Mesh3D mesh, java.util.ArrayList<MguiNumber> values, int min_nbrs, int max_nbrs, boolean islands)
    Detects nodes corresponding to "jagged" edges; a jagged edge node is defined as one which has only max_nbrs neighbours with the same value as itself, and at least min_nbrs neighbours which are the same value.
    static java.util.ArrayList<java.lang.Double> getLaplacian​(Mesh3D mesh)
    Computes the discrete Laplacian for each vertex in mesh.
    static java.util.ArrayList<MguiNumber> getLargestContiguousRois​(Mesh3D mesh, java.util.ArrayList<MguiNumber> rois, int out_value)
    Retains only the largest contiguous ROIs in the given set of values; all others are set to out_value.
    static float getMaximumEdgeLength​(Mesh3D mesh)
    Searches all edges and returns the maximum length
    static float getMeanCurvature​(Mesh3D mesh)  
    static Mesh3D getMeanSphereMesh​(org.jogamp.vecmath.Point3f center, float radius, int n_nodes, float stop_delta, long max_itrs)  
    static Mesh3D getMeshExpandedAlongNormals​(Mesh3D mesh, float expansion)
    Expands mesh along its vertex normals by a distance of expansion.
    static java.util.ArrayList<Mesh3D> getMeshParts​(Mesh3D mesh)  
    static java.util.ArrayList<Mesh3D> getMeshParts​(Mesh3D mesh, java.util.HashMap<java.lang.String,​java.util.ArrayList<MguiNumber>> old_data, java.util.ArrayList<java.util.HashMap<java.lang.String,​java.util.ArrayList<MguiNumber>>> parts_data)  
    static java.util.ArrayList<Mesh3D> getMeshParts​(Mesh3D mesh, java.util.HashMap<java.lang.String,​java.util.ArrayList<MguiNumber>> old_data, java.util.ArrayList<java.util.HashMap<java.lang.String,​java.util.ArrayList<MguiNumber>>> parts_data, ProgressUpdater updater)
    Returns a set of non-contiguous meshes from mesh.
    static float getMinimumEdgeLength​(Mesh3D mesh)
    Searches all edges and returns the minimum length
    protected static void getNeighbourhoodPoints​(java.util.TreeSet<org.jogamp.vecmath.Point3f> points, Mesh3D mesh, NeighbourhoodMesh neighbourhoods, int node, int levels)  
    static java.util.ArrayList<org.jogamp.vecmath.Point3f> getNeighbourhoodPoints​(Mesh3D mesh, NeighbourhoodMesh neighbourhoods, int node)
    Returns a list of points corresponding to the immediate (1st level) neighbourhood of node node.
    static java.util.ArrayList<org.jogamp.vecmath.Point3f> getNeighbourhoodPoints​(Mesh3D mesh, NeighbourhoodMesh neighbourhoods, int node, int levels)
    Returns a list of points corresponding to the n-th level neighbourhood of node node, where n is specified by the parameter levels
    static Mesh3D getNeighbourhoodSubmesh​(Mesh3D mesh, int i)
    Gets a submesh from mesh consisting of the neighbourhood of vertex i.
    static Mesh3D getOptimalSubmesh​(Mesh3D mesh, java.util.ArrayList<MguiInteger> ring)
    Returns the optimal submesh defined by the connect ring ring.
    static Mesh3D getOptimizedSphereMesh​(org.jogamp.vecmath.Point3f center, float radius, int n_nodes, double stop_value, long max_iter, float entropy)  
    static java.util.ArrayList<java.lang.Integer> getRegionBoundaryNodeIndices​(Mesh3D mesh, java.util.ArrayList<MguiNumber> values, int value)
    Returns a list of nodes which form the boundary of all regions defined by value, specified by the vertex-wise list values.
    static java.util.ArrayList<java.lang.Integer> getRoiIndices​(Mesh3D mesh, java.util.ArrayList<MguiNumber> rois, int roi)
    Returns a list of indices corresponding to rois == roi.
    static VertexSelection getRoiSelection​(Mesh3D mesh, java.util.ArrayList<MguiNumber> rois, int roi)
    Returns a vertex selection corresponding to rois == roi.
    static Mesh3D getRoiSubmesh​(Mesh3D mesh, java.util.ArrayList<MguiNumber> rois, int roi)
    Returns a submesh of mesh including all vertices corresponding to rois == roi.
    static java.util.ArrayList<java.lang.Integer> getSelfIntersections​(Mesh3D mesh, float search_max)
    Returns a list of face indices indicating which faces intersect within mesh.
    static java.util.ArrayList<java.lang.Integer> getSelfIntersections​(Mesh3D mesh, float search_max, ProgressUpdater progress)  
    protected static java.util.ArrayList<java.lang.Integer> getSelfIntersectionsBlocking​(Mesh3D mesh, float search_max, ProgressUpdater progress)
    Returns a list of face indices indicating which faces intersect within mesh.
    static Mesh3D getSubMesh​(Mesh3D mesh, java.util.ArrayList<java.lang.Integer> ring)
    Returns a submesh defined by the connect ring ring.
    static Mesh3D getSubMesh​(Mesh3D mesh_old, java.util.ArrayList<MguiNumber> mask, int value, boolean retain)
    Returns a submesh comprised of all unmasked (mask != 0) vertices and all faces whose vertices are retained.
    static Mesh3D getSubMesh​(Mesh3D mesh_old, java.util.ArrayList<MguiNumber> mask, int value, boolean retain, boolean any_in_face, java.util.HashMap<java.lang.String,​java.util.ArrayList<MguiNumber>> data_old, java.util.HashMap<java.lang.String,​java.util.ArrayList<MguiNumber>> data_new)
    Returns a submesh based upon a mask.
    static Mesh3D getSubMesh​(Mesh3D mesh_old, java.util.ArrayList<MguiNumber> mask, int value, boolean retain, java.util.HashMap<java.lang.String,​java.util.ArrayList<MguiNumber>> data_old, java.util.HashMap<java.lang.String,​java.util.ArrayList<MguiNumber>> data_new)  
    static Mesh3D getSubMesh​(Mesh3D mesh_old, java.util.ArrayList<MguiNumber> mask, int value_from, int value_to, boolean retain, boolean any_in_face, java.util.HashMap<java.lang.String,​java.util.ArrayList<MguiNumber>> data_old, java.util.HashMap<java.lang.String,​java.util.ArrayList<MguiNumber>> data_new)
    Returns a submesh comprised of all unmasked (mask != 0) vertices and all faces whose vertices are retained.
    static Mesh3D getSubMesh​(Mesh3D mesh_old, VertexSelection selection, boolean retain)
    Returns a sub-mesh of mesh_old containing all vertices and associated faces in selection.
    static Mesh3D getSubMesh​(Mesh3D mesh_old, VertexSelection selection, boolean retain, boolean any_in_face, java.util.HashMap<java.lang.String,​java.util.ArrayList<MguiNumber>> data_old, java.util.HashMap<java.lang.String,​java.util.ArrayList<MguiNumber>> data_new)
    Returns a sub-mesh of mesh_old containing all vertices and associated faces in selection.
    static java.util.ArrayList<org.jogamp.vecmath.Vector3f> getSurfaceNormals​(Mesh3D mesh)
    Returns surface normals for all vertices of mesh, determined as the average vector of all triangular face normals.
    static Mesh3D getTriangulation​(org.jogamp.vecmath.Point3f[] nodes)
    Triangulates a set of nodes that form a ring.
    static java.util.ArrayList<MguiNumber> getVertexWiseCurvature​(Mesh3D mesh, ProgressUpdater progress)
    Computes the mean curvature at each node in the mesh.
    static java.util.ArrayList<MguiNumber> getVertexWiseCurvature_bak​(Mesh3D mesh, ProgressUpdater progress)
    Computes the mean curvature at each node in the mesh.
    static java.util.ArrayList<MguiFloat> getVertexWiseCurvatureBak​(Mesh3D mesh)  
    static double[] getVolumeAndArea​(Mesh3D mesh, java.util.ArrayList<MguiNumber> thickness, java.util.ArrayList<MguiNumber> filter, double cutoff)
    Given a mesh and a set of thickness values, returns an area and a volume calculation (in that order).
    static Mesh3D inflateMeshTRP​(Mesh3DInt mesh3D, double lambda, double beta, long max_itr, ProgressUpdater progress)
    Inflate this mesh using the TRP method.
    static boolean intersects​(Mesh3D mesh, org.jogamp.vecmath.Point3f p, org.jogamp.vecmath.Vector3f v)
    Determines whether a vector defined by p and v intersects mesh.
    static boolean isBadFace​(Mesh3D.MeshFace3D face)  
    static Volume3DInt mapMeshToVolumeGaussian​(Mesh3DInt mesh_int, Volume3DInt volume, java.lang.String mesh_column, java.lang.String grid_channel, double sigma_normal, double sigma_tangent, double sigma_max_normal, double sigma_max_tangent, boolean normalize, boolean is_discrete, ProgressUpdater progress)
    Projects vertex-wise data from a given Mesh3DInt data column to a Grid3D channel, normal and transverse (tangent) Gaussian functions.
    static java.util.ArrayList<MguiNumber> mapVolumeToMeshEV​(Mesh3D mesh, Volume3DInt volume, java.lang.String column, double no_value, float radius, int stat, ProgressUpdater progress)
    Maps the values in channel of grid, an instance of Grid3D, to the vertices of mesh, using a containing-voxel(s) approach.
    static java.util.ArrayList<MguiNumber> mapVolumeToMeshEV​(Mesh3D mesh, Volume3DInt volume, java.lang.String column, double no_value, ProgressUpdater progress)
    Maps the values in channel of grid, an instance of Grid3D, to the vertices of mesh, using a containing-voxel approach.
    protected static java.util.ArrayList<MguiNumber> mapVolumeToMeshEVBlocking​(Mesh3D mesh, Volume3DInt volume, java.lang.String column, double no_value, float radius, int stat, ProgressUpdater progress)
    Maps the values in channel of grid, an instance of Grid3D, to the vertices of mesh, using a containing-voxel(s) approach.
    static java.util.ArrayList<MguiNumber> mapVolumeToMeshGaussian​(Mesh3D mesh, Volume3DInt volume, java.lang.String channel, double sigma_normal, double sigma_tangent, double sigma_max_normal, double sigma_max_tangent, java.lang.String setSigmaT, boolean normalize)  
    static java.util.ArrayList<MguiNumber> mapVolumeToMeshGaussian​(Mesh3D mesh, Volume3DInt volume, java.lang.String channel, double sigma_normal, double sigma_tangent, double sigma_max_normal, double sigma_max_tangent, java.lang.String setSigmaT, boolean normalize, ProgressUpdater progress, boolean output_matrix, double normal_set_max_sigma, double tangent_set_max_sigma, java.lang.String matrix_file)
    Maps values from a Grid3D object to a mesh object by applying a Gaussian kernal to voxels in the vicinity of each mesh vertex.
    static java.util.ArrayList<MguiNumber> maskMeshWithPlane​(Mesh3D mesh, Plane3D plane, double above_val, double below_val)  
    static java.util.ArrayList<MguiNumber> maskMeshWithPlane​(Mesh3D mesh, Plane3D plane, double above_val, double below_val, double contained_val)  
    static java.util.ArrayList<MguiNumber> maskMeshWithPlane​(Mesh3D mesh, Plane3D plane, double above_val, double below_val, double contained_val, VertexSelection selection)
    Masks a mesh with a plane.
    static Mesh3D mergeMeshes​(java.util.ArrayList<Mesh3D> mesh_list)
    Merges the mesh shapes in list and returns the resulting single mesh.
    static Mesh3D mergeMeshes​(java.util.ArrayList<Mesh3D> mesh_list, java.util.ArrayList<java.util.HashMap<java.lang.Integer,​java.lang.Integer>> index_map)
    Merges the mesh shapes in list and returns the resulting single mesh.
    protected void orderNeighbours​(java.util.ArrayList<MguiInteger> list, NeighbourhoodMesh nmesh)  
    protected static int polygonizeCell​(org.jogamp.vecmath.Point3f[] gridcell, double[] values, java.util.ArrayList<org.jogamp.vecmath.Point3f> triangles, double isolevel)
    Uses the marching cubes lookup tables to find triangular faces intersecting the given grid cell at the given isolevel
    static boolean removeBadFaces​(Mesh3D mesh)  
    static boolean removeDuplicateFaces​(Mesh3D mesh)  
    static boolean removeDuplicateNodes​(Mesh3D mesh)
    Removes all duplicate vertices from mesh, and changes mesh in place.
    static void removeNodes​(Mesh3D mesh, boolean[] removed)
    Removes all nodes specified in nodes from mesh, and retriangulates the remaining nodes.
    static void removeNodes​(Mesh3D mesh, boolean[] removed, NeighbourhoodMesh nmesh)
    Removes all nodes specified in nodes from mesh, and retriangulates the remaining nodes.
    static void removeStrandedNodes​(Mesh3D mesh)
    Removes all nodes from mesh which do not have a corresponding face.
    static void selectFloodFill​(Mesh3D mesh, VertexSelection selection, int seed_node, ProgressUpdater progress)
    Selects all nodes surrounding a seed node in a region enclosed by selected nodes; if seed node is not fully enclosed, this will select the entire mesh.
    static void smoothEM​(Mesh3DInt mesh)  
    static void smoothLR​(Mesh3D mesh)  
    static java.util.ArrayList<MguiNumber> smoothVertexValuesIsotropicGaussian​(Mesh3D mesh, java.util.ArrayList<MguiNumber> values, double sigma, double sigma_max, ProgressUpdater progress)
    Smooths values with an isotropic Gaussian kernel, along the surface of mesh.
    static java.util.ArrayList<MguiNumber> splitRoiWithPlane​(Mesh3D mesh, Plane3D plane, java.util.ArrayList<MguiNumber> rois, int roi, int new_roi, ProgressUpdater progress)
    Splits the ROI defined by roi into two parts, on either side of plane.
    static void subdivideMesh​(Mesh3D mesh, int iter)  
    static void subdivideMesh​(Mesh3DInt mesh, int iter)
    Subdivides iter times, for all triangle in mesh.
    static void subdivideMesh​(Mesh3DInt mesh, int iter, double edgeThreshold, double areaThreshold)
    Subdivides iter times, for triangles which meet the criteria specified by and .
    static java.util.ArrayList<MguiNumber> subdivideRois​(Mesh3D mesh, java.util.ArrayList<MguiNumber> old_rois, int min_size, int target_rois, int min_roi, int max_roi, ProgressUpdater progress)
    Subdivides a mesh into (roughly) equally sized ROIs, with the final number equal or close to target_rois.
    static java.util.ArrayList<MguiNumber> subdivideRois​(Mesh3D mesh, java.util.ArrayList<MguiNumber> old_rois, int min_size, int target_rois, ProgressUpdater progress)
    Subdivides a mesh into (roughly) equally sized ROIs, with the final number equal or close to target_rois.
    static java.util.ArrayList<MguiNumber> subdivideRoisBlocking​(Mesh3D mesh, java.util.ArrayList<MguiNumber> old_rois, int min_size, int target_rois, int min_roi, int max_roi, ProgressUpdater progress)
    Subdivides a mesh into (roughly) equally sized ROIs, with the final number equal or close to target_rois.
    static Mesh3D transformWithMatrix​(Mesh3D mesh_in, org.jogamp.vecmath.Matrix4d matrix, InterfaceProgressBar progress_bar)  
    static void triangulate​(Mesh3D mesh, java.util.ArrayList<MguiInteger> neighbours)
    Triangulates the given neighbourhood by adding faces using recursive loop splitting
    static boolean validateSurface​(Mesh3D mesh)  

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • tolerance

      public static double tolerance
    • progressBar

      public static javax.swing.JProgressBar progressBar
  • Constructor Details

    • MeshFunctions

      public MeshFunctions()
  • Method Details

    • getConvexHull

      public static Mesh3D getConvexHull​(Mesh3D mesh)
      Returns a new mesh which is the convex hull of the given mesh. Defaults to the "Giftwrap" algorithm, by Tim Lambert:

      http://www.cse.unsw.edu.au/~lambert/java/3d/implementation.html

      Parameters:
      mesh - Mesh for which to compute a convex hull.
      method - The method to use
    • getConvexHull

      public static Mesh3D getConvexHull​(Mesh3D mesh, ProgressUpdater progress)
    • getConvexHull

      public static Mesh3D getConvexHull​(Mesh3D mesh, java.lang.String method)
    • combine

      public static Mesh3D combine​(Mesh3D mesh1, Mesh3D mesh2)
      Combines mesh1 and mesh2 and returns the result.
      Parameters:
      mesh1 -
      mesh2 -
      Returns:
    • getConvexHull

      public static Mesh3D getConvexHull​(Mesh3D mesh, java.lang.String method, ProgressUpdater progress)
      Returns a new mesh which is the convex hull of the given mesh. Algorithms provided by Joseph O'Rourke et al:

      http://maven.smith.edu/~orourke/books/ftp.html

      and Tim Lambert:

      http://www.cse.unsw.edu.au/~lambert/java/3d/implementation.html

      Parameters:
      mesh - Mesh for which to compute a convex hull
      method - The method to use
      bar - Optional progress bar
      Returns:
      the convex hull, or null if method failed or was cancelled.
    • getSubMesh

      public static Mesh3D getSubMesh​(Mesh3D mesh_old, VertexSelection selection, boolean retain)
      Returns a sub-mesh of mesh_old containing all vertices and associated faces in selection.
      Parameters:
      mesh_old - Mesh from which to obtain sub-mesh
      selection - Selected vertices for sub-mesh
      retain - Whether to retain the selection (otherwise it is removed)
      Returns:
      Newly created sub-mesh
    • getSubMesh

      public static Mesh3D getSubMesh​(Mesh3D mesh_old, VertexSelection selection, boolean retain, boolean any_in_face, java.util.HashMap<java.lang.String,​java.util.ArrayList<MguiNumber>> data_old, java.util.HashMap<java.lang.String,​java.util.ArrayList<MguiNumber>> data_new)
      Returns a sub-mesh of mesh_old containing all vertices and associated faces in selection.
      Parameters:
      mesh_old - Mesh from which to obtain sub-mesh
      selection - Selected vertices for sub-mesh
      retain - Whether to retain the selection (otherwise it is removed)
      any_in_face - Include faces with any vertices in selection? Otherwise, requires all vertices to be in the selection.
      data_old - Data from mesh_old to transfer to mesh_new (can be null)
      data_new - New data for the sub-mesh; this should be a reference to an empty HashMap
      Returns:
      Newly created sub-mesh
    • getLargestContiguousRois

      public static java.util.ArrayList<MguiNumber> getLargestContiguousRois​(Mesh3D mesh, java.util.ArrayList<MguiNumber> rois, int out_value)
      Retains only the largest contiguous ROIs in the given set of values; all others are set to out_value.
      Parameters:
      mesh -
      rois -
      out_value -
      Returns:
    • splitRoiWithPlane

      public static java.util.ArrayList<MguiNumber> splitRoiWithPlane​(Mesh3D mesh, Plane3D plane, java.util.ArrayList<MguiNumber> rois, int roi, int new_roi, ProgressUpdater progress)
      Splits the ROI defined by roi into two parts, on either side of plane.
      Parameters:
      mesh -
      plane -
      rois -
      roi -
      new_roi -
      progress -
      Returns:
      The new ROIs; or null if the plane does not intersect the ROI
    • subdivideRois

      public static java.util.ArrayList<MguiNumber> subdivideRois​(Mesh3D mesh, java.util.ArrayList<MguiNumber> old_rois, int min_size, int target_rois, ProgressUpdater progress) throws MeshFunctionException
      Subdivides a mesh into (roughly) equally sized ROIs, with the final number equal or close to target_rois. Generation is constrained by the min/max parameters.

      A starting parcellation can be specified using the old_rois parameter; this can also be null to start from a random seed.

      Parameters:
      mesh -
      old_rois -
      min_rois -
      max_rois -
      max_size -
      min_size -
      target_rois -
      Returns:
      Throws:
      MeshFunctionException
    • subdivideRois

      public static java.util.ArrayList<MguiNumber> subdivideRois​(Mesh3D mesh, java.util.ArrayList<MguiNumber> old_rois, int min_size, int target_rois, int min_roi, int max_roi, ProgressUpdater progress) throws MeshFunctionException
      Subdivides a mesh into (roughly) equally sized ROIs, with the final number equal or close to target_rois. Generation is constrained by the min/max parameters.

      A starting parcellation can be specified using the old_rois parameter; this can also be null to start from a random seed.

      Parameters:
      mesh -
      old_rois -
      min_rois -
      max_rois -
      max_size -
      min_size -
      target_rois -
      min_roi - Minimum roi value to include
      max_roi - Maximum roi value to include
      Returns:
      Throws:
      MeshFunctionException
    • subdivideRoisBlocking

      public static java.util.ArrayList<MguiNumber> subdivideRoisBlocking​(Mesh3D mesh, java.util.ArrayList<MguiNumber> old_rois, int min_size, int target_rois, int min_roi, int max_roi, ProgressUpdater progress) throws MeshFunctionException
      Subdivides a mesh into (roughly) equally sized ROIs, with the final number equal or close to target_rois. Generation is constrained by the min/max parameters.

      A starting parcellation can be specified using the old_rois parameter; this can also be null, in which case the mesh will first be split by the median x coordinate and then subdivided.

      Parameters:
      mesh -
      old_rois -
      min_rois -
      max_rois -
      max_size -
      min_size -
      target_rois -
      min_roi - Minimum roi value to include
      max_roi - Maximum roi value to include
      Returns:
      Throws:
      MeshFunctionException
    • getFarthestVertices

      public static java.util.ArrayList<java.lang.Integer> getFarthestVertices​(Mesh3D mesh)
      Returns a list of size mesh.n integers, such that list(i) = the index of the farthest vertex j from vertex i.
      Parameters:
      mesh -
      Returns:
    • getFarthestVertices

      public static java.util.ArrayList<java.lang.Integer> getFarthestVertices​(Mesh3D mesh, java.util.ArrayList<java.lang.Double> distances)
      Returns a list of size mesh.n integers, such that list(i) = the index of the farthest vertex j from vertex i.
      Parameters:
      mesh -
      distances - Stores the corresponding distances; can be null.
      Returns:
    • getFarthestVertices

      public static java.util.ArrayList<java.lang.Integer> getFarthestVertices​(Mesh3D mesh, java.util.ArrayList<java.lang.Double> distances, java.util.ArrayList<java.lang.Integer> vertices)
      Returns a list of size mesh.n integers, such that list(i) = the index of the farthest vertex j from vertex i.
      Parameters:
      mesh -
      distances - Stores the corresponding distances; can be null.
      n_vertex - Number of vertices to sample from mesh. n_vertex <= 0 samples from entire mesh (default). This should be specified for very large graphs to avoid resource issues.
      Returns:
    • getClosestVertices

      public static java.util.ArrayList<java.lang.Integer> getClosestVertices​(Mesh3D mesh)
      Returns a list of size mesh.n integers, such that list(i) = the index of the closest vertex j from vertex i.
      Parameters:
      mesh -
      Returns:
    • getClosestVertices

      public static java.util.ArrayList<java.lang.Integer> getClosestVertices​(Mesh3D mesh, java.util.ArrayList<java.lang.Double> distances)
      Returns a list of size mesh.n integers, such that list(i) = the index of the closest vertex j from vertex i.
      Parameters:
      mesh -
      distances - Stores the corresponding distances; can be null.
      Returns:
    • getRoiSubmesh

      public static Mesh3D getRoiSubmesh​(Mesh3D mesh, java.util.ArrayList<MguiNumber> rois, int roi)
      Returns a submesh of mesh including all vertices corresponding to rois == roi.
      Parameters:
      mesh -
      rois -
      roi -
      Returns:
    • getRoiSelection

      public static VertexSelection getRoiSelection​(Mesh3D mesh, java.util.ArrayList<MguiNumber> rois, int roi)
      Returns a vertex selection corresponding to rois == roi.
      Parameters:
      mesh -
      rois -
      roi -
      Returns:
    • getRoiIndices

      public static java.util.ArrayList<java.lang.Integer> getRoiIndices​(Mesh3D mesh, java.util.ArrayList<MguiNumber> rois, int roi)
      Returns a list of indices corresponding to rois == roi.
      Parameters:
      mesh -
      rois -
      roi -
      Returns:
    • getClosestVertex

      public static int getClosestVertex​(Mesh3D mesh, int idx, java.util.ArrayList<java.lang.Integer> search_vertices, MguiDouble distance)
      Returns the closest vertex in a list of vertices, or from all vertices if the list is empty. This searches links and accumulates distance along the links, rather than using Euclidean distance. If the vertex is unconnected to any of the target vertices, returns null. The distance parameter (if not null) stores the actual link-wise distance.
      Parameters:
      mesh -
      idx -
      search_vertices -
      distance -
      Returns:
    • getRegionBoundaryNodeIndices

      public static java.util.ArrayList<java.lang.Integer> getRegionBoundaryNodeIndices​(Mesh3D mesh, java.util.ArrayList<MguiNumber> values, int value)
      Returns a list of nodes which form the boundary of all regions defined by value, specified by the vertex-wise list values.
      Parameters:
      mesh -
      values -
      value -
      Returns:
    • selectFloodFill

      public static void selectFloodFill​(Mesh3D mesh, VertexSelection selection, int seed_node, ProgressUpdater progress)
      Selects all nodes surrounding a seed node in a region enclosed by selected nodes; if seed node is not fully enclosed, this will select the entire mesh.
      Parameters:
      mesh -
      selection -
      seed_node -
    • getSubMesh

      public static Mesh3D getSubMesh​(Mesh3D mesh_old, java.util.ArrayList<MguiNumber> mask, int value, boolean retain)
      Returns a submesh comprised of all unmasked (mask != 0) vertices and all faces whose vertices are retained.
      Parameters:
      mesh -
      mask -
      value -
      retain -
      Returns:
      submesh
    • getSubMesh

      public static Mesh3D getSubMesh​(Mesh3D mesh_old, java.util.ArrayList<MguiNumber> mask, int value, boolean retain, java.util.HashMap<java.lang.String,​java.util.ArrayList<MguiNumber>> data_old, java.util.HashMap<java.lang.String,​java.util.ArrayList<MguiNumber>> data_new)
    • getSubMesh

      public static Mesh3D getSubMesh​(Mesh3D mesh_old, java.util.ArrayList<MguiNumber> mask, int value, boolean retain, boolean any_in_face, java.util.HashMap<java.lang.String,​java.util.ArrayList<MguiNumber>> data_old, java.util.HashMap<java.lang.String,​java.util.ArrayList<MguiNumber>> data_new)
      Returns a submesh based upon a mask. If retain is true, retains all vertices where mask == value; otherwise retains the inverse. Removes all faces containing removed vertices. If data_old and data_new are non-null, populates data_new with the retained values from data_old.
      Parameters:
      mesh -
      mask -
      value -
      retain -
      any_in_face - retains a face if any of its vertices are retained
      data -
      Returns:
      submesh
    • getSubMesh

      public static Mesh3D getSubMesh​(Mesh3D mesh_old, java.util.ArrayList<MguiNumber> mask, int value_from, int value_to, boolean retain, boolean any_in_face, java.util.HashMap<java.lang.String,​java.util.ArrayList<MguiNumber>> data_old, java.util.HashMap<java.lang.String,​java.util.ArrayList<MguiNumber>> data_new)
      Returns a submesh comprised of all unmasked (mask != 0) vertices and all faces whose vertices are retained.
      Parameters:
      mesh -
      mask -
      value_from -
      value_to -
      retain -
      any_in_face - retains a face if any of its vertices are retained
      data -
      Returns:
      submesh
    • removeStrandedNodes

      public static void removeStrandedNodes​(Mesh3D mesh)
      Removes all nodes from mesh which do not have a corresponding face.
      Parameters:
      mesh -
    • validateSurface

      public static boolean validateSurface​(Mesh3D mesh)
    • removeDuplicateFaces

      public static boolean removeDuplicateFaces​(Mesh3D mesh)
    • isBadFace

      public static boolean isBadFace​(Mesh3D.MeshFace3D face)
    • removeBadFaces

      public static boolean removeBadFaces​(Mesh3D mesh)
    • getDuplicateFaces

      public static java.util.ArrayList<java.lang.Boolean> getDuplicateFaces​(Mesh3D mesh)
      Returns an array of booleans where true indicates a duplicate face
      Returns:
    • removeDuplicateNodes

      public static boolean removeDuplicateNodes​(Mesh3D mesh)
      Removes all duplicate vertices from mesh, and changes mesh in place.

      Duplicates are determined as pt1.distance(pt2) < MeshFunctions.tolerance.

      Parameters:
      mesh -
      Returns:
      true if successful
    • getDuplicateNodes

      public static java.util.List<java.lang.Integer> getDuplicateNodes​(Mesh3D mesh)
      Returns an array of booleans where true indicates a duplicate node
      Returns:
    • transformWithMatrix

      public static Mesh3D transformWithMatrix​(Mesh3D mesh_in, org.jogamp.vecmath.Matrix4d matrix, InterfaceProgressBar progress_bar)
    • subdivideMesh

      public static void subdivideMesh​(Mesh3D mesh, int iter)
    • subdivideMesh

      public static void subdivideMesh​(Mesh3DInt mesh, int iter)
      Subdivides iter times, for all triangle in mesh. Operates directly on mesh, so if user requires a retained original, he/she must make a copy before calling.
      Parameters:
      mesh - Mesh object to subdivide.
      iter - Number of times to subdivide this mesh. If <= 0, operation will do nothing.
    • subdivideMesh

      public static void subdivideMesh​(Mesh3DInt mesh, int iter, double edgeThreshold, double areaThreshold)
      Subdivides iter times, for triangles which meet the criteria specified by and . Operates directly on mesh, so if user requires a retained original, he/she must make a copy before calling.
      Parameters:
      mesh - Mesh object to subdivide
      edgeThreshold - Triangle will be subdivided if one edge is at least as long as . If edgeThreshold <= 0, edge length is not checked.
      areaThreshold - Triangle will be subdivided if its area is at least . If <= 0, area is not checked.
      iter - Number of times to subdivide this mesh. If <= 0, and either or > 0, operation will subdivide until no triangles satisfy criteria. Otherwise it will do nothing.
    • maskMeshWithPlane

      public static java.util.ArrayList<MguiNumber> maskMeshWithPlane​(Mesh3D mesh, Plane3D plane, double above_val, double below_val)
    • maskMeshWithPlane

      public static java.util.ArrayList<MguiNumber> maskMeshWithPlane​(Mesh3D mesh, Plane3D plane, double above_val, double below_val, double contained_val)
    • maskMeshWithPlane

      public static java.util.ArrayList<MguiNumber> maskMeshWithPlane​(Mesh3D mesh, Plane3D plane, double above_val, double below_val, double contained_val, VertexSelection selection)
      Masks a mesh with a plane.
    • addIndexedTriangleArray

      public static void addIndexedTriangleArray​(Mesh3D mesh, org.jogamp.java3d.IndexedTriangleArray tris)
      Adds an IndexedTriangleArray to the current mesh. Coincident nodes from either object will be represented as two seperate nodes, however. To merge these nodes into a single node, call decimateByLength with a minimal length threshold.
      Parameters:
      mesh - Mesh object to which nodes and faces will be added.
      tris - IndexedTriangleArray object from which nodes and face indices will be extracted.
    • getTriangulation

      public static Mesh3D getTriangulation​(org.jogamp.vecmath.Point3f[] nodes)
      Triangulates a set of nodes that form a ring.
      Parameters:
      mesh -
      nodes -
      Returns:
    • mergeMeshes

      public static Mesh3D mergeMeshes​(java.util.ArrayList<Mesh3D> mesh_list) throws MeshFunctionException
      Merges the mesh shapes in list and returns the resulting single mesh.
      Parameters:
      mesh_list -
      Throws:
      MeshFunctionException - If the merge failed
    • mergeMeshes

      public static Mesh3D mergeMeshes​(java.util.ArrayList<Mesh3D> mesh_list, java.util.ArrayList<java.util.HashMap<java.lang.Integer,​java.lang.Integer>> index_map) throws MeshFunctionException
      Merges the mesh shapes in list and returns the resulting single mesh. If index_map is not null, also provides a mapping of the original indices to the merged mesh indices.
      Parameters:
      mesh_list -
      index_map -
      Throws:
      MeshFunctionException - If the merge failed
    • decimateByDistance

      public static void decimateByDistance​(Mesh3D mesh, Mesh3D newmesh, double threshold)
      Decimates this mesh by merging multiple nodes into a single node if they are separated by less than .
      Parameters:
      mesh - Mesh3D object to be decimated
      threshold - Threshold separation length at which to merge two nodes
    • inflateMeshTRP

      public static Mesh3D inflateMeshTRP​(Mesh3DInt mesh3D, double lambda, double beta, long max_itr, ProgressUpdater progress)
      Inflate this mesh using the TRP method. TODO: Remove worker here
      Parameters:
      mesh3D -
      lambda -
      beta -
      max_itr -
      progress -
      Returns:
    • getMeshParts

      public static java.util.ArrayList<Mesh3D> getMeshParts​(Mesh3D mesh)
    • getMeshParts

      public static java.util.ArrayList<Mesh3D> getMeshParts​(Mesh3D mesh, java.util.HashMap<java.lang.String,​java.util.ArrayList<MguiNumber>> old_data, java.util.ArrayList<java.util.HashMap<java.lang.String,​java.util.ArrayList<MguiNumber>>> parts_data)
    • getMeshParts

      public static java.util.ArrayList<Mesh3D> getMeshParts​(Mesh3D mesh, java.util.HashMap<java.lang.String,​java.util.ArrayList<MguiNumber>> old_data, java.util.ArrayList<java.util.HashMap<java.lang.String,​java.util.ArrayList<MguiNumber>>> parts_data, ProgressUpdater updater)
      Returns a set of non-contiguous meshes from mesh. If mesh is a single contiguous surface, this method will return only that surface.
      Parameters:
      mesh - Mesh from which to extract parts
      old_data - Vertex data to be transferred to the new meshes
      new_data - Vertex data transferred to the new meshes. Should be an empty object.
      Returns:
      List of created mesh parts
    • getSubMesh

      public static Mesh3D getSubMesh​(Mesh3D mesh, java.util.ArrayList<java.lang.Integer> ring)
      Returns a submesh defined by the connect ring ring. Triangulation is performed by connecting n to n + 2, to n - 1, to n + 3, etc.
      Returns:
      optimal submesh
    • getOptimalSubmesh

      public static Mesh3D getOptimalSubmesh​(Mesh3D mesh, java.util.ArrayList<MguiInteger> ring)
      Returns the optimal submesh defined by the connect ring ring. Triangulation is optimized by minimizing the sum of angles for each permutation of possible edge configurations.
      Returns:
      optimal submesh
    • correctOrientation

      public static void correctOrientation​(Mesh3D mesh)
      Orients all faces with each other, starting with the first face
      Parameters:
      mesh -
    • correctOrientation

      public static void correctOrientation​(Mesh3D mesh, boolean reverse)
      Orients all faces with each other (starting with face 0)
      Parameters:
      mesh -
      seed -
      reverse -
    • flipNormals

      public static org.jogamp.vecmath.Vector3f[] flipNormals​(org.jogamp.vecmath.Vector3f[] normals)
    • condenseMesh

      public static Mesh3D condenseMesh​(Mesh3D mesh)
      Condenses a mesh by removing all coincident nodes.
      Parameters:
      mesh - mesh to condense
      Returns:
      condensed mesh
    • computeVertexWiseCurvature

      public static boolean computeVertexWiseCurvature​(Mesh3DInt mesh3D, java.lang.String target_column, ProgressUpdater progress)
      Computes the curvature of a mesh at each of its nodes, as the magnitude of the sum of surface normals of the triangles of which it is a node. Adds this information to mesh3D as a variable named name.
      Parameters:
      mesh3D - Mesh for which to compute curvature
      name - Name of resulting variable
    • getVertexWiseCurvature_bak

      public static java.util.ArrayList<MguiNumber> getVertexWiseCurvature_bak​(Mesh3D mesh, ProgressUpdater progress)
      Computes the mean curvature at each node in the mesh. See:

      Tosun D, Rettman ME, Prince JL (2004). Mapping techniques for aligning sulci across multiple brains. Medical Image Analysis 8:295-309.

      Meyer M, Desbrun M, Schroeder P, Barr AH (2002). Discrete differential- geometry operators for triangulated 2-manifolds. http://citeseer.ist.psu.edu/meyer02discrete.html

      Parameters:
      mesh -
      Returns:
    • getVertexWiseCurvature

      public static java.util.ArrayList<MguiNumber> getVertexWiseCurvature​(Mesh3D mesh, ProgressUpdater progress)
      Computes the mean curvature at each node in the mesh. See:

      Tosun D, Rettman ME, Prince JL (2004). Mapping techniques for aligning sulci across multiple brains. Medical Image Analysis 8:295-309.

      Meyer M, Desbrun M, Schroeder P, Barr AH (2002). Discrete differential- geometry operators for triangulated 2-manifolds. http://citeseer.ist.psu.edu/meyer02discrete.html

      Parameters:
      mesh -
      Returns:
    • getVertexWiseCurvatureBak

      public static java.util.ArrayList<MguiFloat> getVertexWiseCurvatureBak​(Mesh3D mesh)
    • getMeanCurvature

      public static float getMeanCurvature​(Mesh3D mesh)
    • smoothLR

      public static void smoothLR​(Mesh3D mesh)
    • smoothEM

      public static void smoothEM​(Mesh3DInt mesh)
    • smoothVertexValuesIsotropicGaussian

      public static java.util.ArrayList<MguiNumber> smoothVertexValuesIsotropicGaussian​(Mesh3D mesh, java.util.ArrayList<MguiNumber> values, double sigma, double sigma_max, ProgressUpdater progress)
      Smooths values with an isotropic Gaussian kernel, along the surface of mesh.
      Parameters:
      mesh -
      values -
      sigma -
      sigma_max -
      progress -
      Returns:
    • getEdgeLengths

      public static java.util.ArrayList<MguiDouble> getEdgeLengths​(Mesh3D mesh, java.util.ArrayList<MeshEdge> edges)
      Returns a list of edge lengths for the given set of edges
      Parameters:
      mesh -
      Returns:
    • getArea

      public static double getArea​(Mesh3D mesh)
      Returns the surface area of the given mesh
      Parameters:
      mesh -
      Returns:
    • getVolumeAndArea

      public static double[] getVolumeAndArea​(Mesh3D mesh, java.util.ArrayList<MguiNumber> thickness, java.util.ArrayList<MguiNumber> filter, double cutoff)
      Given a mesh and a set of thickness values, returns an area and a volume calculation (in that order). Simply sums triangle areas for area, and multiplies area by the average thickness for volume.
      Parameters:
      mesh -
      thickness -
      cutoff - value below which the area and volume are not counted.
      Returns:
      double array with area and volume, in that order
    • getNeighbourhoodPoints

      public static java.util.ArrayList<org.jogamp.vecmath.Point3f> getNeighbourhoodPoints​(Mesh3D mesh, NeighbourhoodMesh neighbourhoods, int node)
      Returns a list of points corresponding to the immediate (1st level) neighbourhood of node node.
      Parameters:
      mesh -
      neighbourhoods -
      node -
      Returns:
    • getNeighbourhoodPoints

      public static java.util.ArrayList<org.jogamp.vecmath.Point3f> getNeighbourhoodPoints​(Mesh3D mesh, NeighbourhoodMesh neighbourhoods, int node, int levels)
      Returns a list of points corresponding to the n-th level neighbourhood of node node, where n is specified by the parameter levels
      Parameters:
      mesh -
      neighbourhoods -
      node -
      Returns:
    • getNeighbourhoodPoints

      protected static void getNeighbourhoodPoints​(java.util.TreeSet<org.jogamp.vecmath.Point3f> points, Mesh3D mesh, NeighbourhoodMesh neighbourhoods, int node, int levels)
    • removeNodes

      public static void removeNodes​(Mesh3D mesh, boolean[] removed)
      Removes all nodes specified in nodes from mesh, and retriangulates the remaining nodes.
      Parameters:
      mesh -
      vertices -
    • removeNodes

      public static void removeNodes​(Mesh3D mesh, boolean[] removed, NeighbourhoodMesh nmesh)
      Removes all nodes specified in nodes from mesh, and retriangulates the remaining nodes.
      Parameters:
      mesh -
      vertices -
      nmesh - Neighbourhood mesh (in case one is already made)
    • getAllNeighbours

      protected static java.util.ArrayList<MguiInteger> getAllNeighbours​(int n, NeighbourhoodMesh nmesh, boolean[] removed, int[] added, boolean[] processed)
      Searches for all neighbours of n in nmesh. If a neighbour is removed and not yet processed, its neighbours will also be added to this list recursively, and its index in the processed array will be set to true (to prevent its being reprocessed). This continues until all n's neighbours have been processed.
    • orderNeighbours

      protected void orderNeighbours​(java.util.ArrayList<MguiInteger> list, NeighbourhoodMesh nmesh)
    • triangulate

      public static void triangulate​(Mesh3D mesh, java.util.ArrayList<MguiInteger> neighbours)
      Triangulates the given neighbourhood by adding faces using recursive loop splitting
      Parameters:
      mesh -
      n -
    • mapVolumeToMeshGaussian

      public static java.util.ArrayList<MguiNumber> mapVolumeToMeshGaussian​(Mesh3D mesh, Volume3DInt volume, java.lang.String channel, double sigma_normal, double sigma_tangent, double sigma_max_normal, double sigma_max_tangent, java.lang.String setSigmaT, boolean normalize)
    • mapVolumeToMeshGaussian

      public static java.util.ArrayList<MguiNumber> mapVolumeToMeshGaussian​(Mesh3D mesh, Volume3DInt volume, java.lang.String channel, double sigma_normal, double sigma_tangent, double sigma_max_normal, double sigma_max_tangent, java.lang.String setSigmaT, boolean normalize, ProgressUpdater progress, boolean output_matrix, double normal_set_max_sigma, double tangent_set_max_sigma, java.lang.String matrix_file)
      Maps values from a Grid3D object to a mesh object by applying a Gaussian kernal to voxels in the vicinity of each mesh vertex. The Gaussian is defined in the direction normal to the vertex, by sigma_normal (one standard deviation) and sigma_max_normal (the distance, in standard deviations, at which to stop considering voxels). It is defined in the plane tangent to the normal depending on the value of setSigmaT:

      • "Parameter": sigma_tangent is set to the passed parameter
      • "From mean area": for each vertex, sigma_tangent is set to sqrt(A_tri_mean / Pi)
      • "From mean length": for each vertex, sigma_tangent is set to the mean length of all edges connecting the vertex
      The values returned will be those obtained by the Grid3D.getDoubleValue method, but can alternatively be normalized by setting the normalized flag.
      Parameters:
      mesh - Mesh on which to project values
      grid - Input grid
      sigma_normal - Sigma defining the Gaussian in the normal direction
      sigma_tangent - Sigma defining the Gaussian in the tangent direction
      sigma_max_normal - Maximum sigma at which to obtain values in the normal direction
      sigma_max_tangent - Maximum sigma at which to obtain values in the tangent direction
      setSigmaT - How to determine the tangent sigma; one of "parameter", "area", or...
      normalize - Whether to normalize the resulting values
      normal_set_max_sigma - From all values within this proximity along the normal, set value to the maximum rather than the weighted average; set to 0 to avoid this behaviour (default)
      tangent_set_max_sigma - From all values within this proximity along the tangent, set value to the maximum rather than the weighted average; set to 0 to avoid this behaviour (default)
      Returns:
      Vertex-wise mapped values, or null if process fails or was cancelled.
    • mapMeshToVolumeGaussian

      public static Volume3DInt mapMeshToVolumeGaussian​(Mesh3DInt mesh_int, Volume3DInt volume, java.lang.String mesh_column, java.lang.String grid_channel, double sigma_normal, double sigma_tangent, double sigma_max_normal, double sigma_max_tangent, boolean normalize, boolean is_discrete, ProgressUpdater progress)
      Projects vertex-wise data from a given Mesh3DInt data column to a Grid3D channel, normal and transverse (tangent) Gaussian functions.
      Parameters:
      mesh_int - The mesh from which to project
      grid - The target 3D grid
      mesh_column - The column from which to obtain the projected data
      grid_channel - The target grid channel
      sigma_normal - The sigma defining a Gaussian normal to the vertex
      sigma_tangent - The sigma defining a Gaussian tangential to the vertex
      max_normal - The maximum distance to project data in the normal direction
      max_tangent - The maximum distance to project data in the tangential direction
      is_discrete - Indicates whether data are to be treated as discrete; if so, the mapped value will be the value of the neighbour with the highest Gaussian weight. Otherwise, value is the weighted real-valued mean.
      progress -
      Returns:
      A new Grid3D containing the projected values
    • getAverageEdgeLength

      public static double getAverageEdgeLength​(Mesh3D mesh)
      Returns the average edge length keyin a mesh.
      Parameters:
      mesh -
      Returns:
    • getSurfaceNormals

      public static java.util.ArrayList<org.jogamp.vecmath.Vector3f> getSurfaceNormals​(Mesh3D mesh)
      Returns surface normals for all vertices of mesh, determined as the average vector of all triangular face normals.
      Parameters:
      mesh -
      Returns:
    • mapVolumeToMeshEV

      public static java.util.ArrayList<MguiNumber> mapVolumeToMeshEV​(Mesh3D mesh, Volume3DInt volume, java.lang.String column, double no_value, ProgressUpdater progress)
      Maps the values in channel of grid, an instance of Grid3D, to the vertices of mesh, using a containing-voxel approach. This method essentially maps the value of the containing voxel to the vertex, ignoring all neighbours. Size is single voxel.
      Parameters:
      mesh - Mesh whose vertices are used to determine mapping
      volume - Volume to map
      column - Column to map
      no_value - Value to use when no mapping is made
      progress -
      Returns:
      A list of size n, where n = number of vertices in mesh
    • mapVolumeToMeshEV

      public static java.util.ArrayList<MguiNumber> mapVolumeToMeshEV​(Mesh3D mesh, Volume3DInt volume, java.lang.String column, double no_value, float radius, int stat, ProgressUpdater progress)
      Maps the values in channel of grid, an instance of Grid3D, to the vertices of mesh, using a containing-voxel(s) approach. This method essentially maps the value of the containing voxel to the vertex, ignoring all neighbours.
      Parameters:
      mesh - Mesh whose vertices are used to determine mapping
      volume - Volume to map
      column - Column to map
      no_value - Value to use when no mapping is made
      size - Radius of the search sphere, in voxels; <=0 is single voxel (default)
      stat - Statistic to use for summarizing values in a search sphere; only used if radius > 0; one of: 1=max, 2=min, 3=abs max, 4=abs min, 0(or other)= mean
      progress -
      Returns:
      A list of size n, where n = number of vertices in mesh
    • mapVolumeToMeshEVBlocking

      protected static java.util.ArrayList<MguiNumber> mapVolumeToMeshEVBlocking​(Mesh3D mesh, Volume3DInt volume, java.lang.String column, double no_value, float radius, int stat, ProgressUpdater progress)
      Maps the values in channel of grid, an instance of Grid3D, to the vertices of mesh, using a containing-voxel(s) approach. This method essentially maps the value of the containing voxel to the vertex, ignoring all neighbours.
      Parameters:
      mesh - Mesh whose vertices are used to determine mapping
      volume - Volume to map
      column - Column to map
      no_value - Value to use when no mapping is made
      radius - Radius of the search sphere, in voxels; <=0 is single voxel (default)
      stat - Statistic to use for summarizing values in a search sphere; only used if radius > 0; one of: 1=max, 2=min, 3=abs max, 4=abs min, 5=mode, 6=median, 0(or other)= mean
      progress -
      Returns:
      A list of size n, where n = number of vertices in mesh
    • getNeighbourhoodSubmesh

      public static Mesh3D getNeighbourhoodSubmesh​(Mesh3D mesh, int i)
      Gets a submesh from mesh consisting of the neighbourhood of vertex i.
      Parameters:
      mesh -
      i -
      Returns:
    • cleanMesh

      public static void cleanMesh​(Mesh3D mesh)
    • getMeanSphereMesh

      public static Mesh3D getMeanSphereMesh​(org.jogamp.vecmath.Point3f center, float radius, int n_nodes, float stop_delta, long max_itrs)
    • getFractalSphereMesh

      public static Mesh3D getFractalSphereMesh​(org.jogamp.vecmath.Point3f center, float radius, int min_nodes)
    • getOptimizedSphereMesh

      public static Mesh3D getOptimizedSphereMesh​(org.jogamp.vecmath.Point3f center, float radius, int n_nodes, double stop_value, long max_iter, float entropy)
    • intersects

      public static boolean intersects​(Mesh3D mesh, org.jogamp.vecmath.Point3f p, org.jogamp.vecmath.Vector3f v)
      Determines whether a vector defined by p and v intersects mesh.
      Parameters:
      mesh -
      p -
      v -
      Returns:
    • getIntersectingFaces

      public static java.util.ArrayList<java.util.ArrayList<java.lang.Integer>> getIntersectingFaces​(Mesh3D mesh1, Mesh3D mesh2, float search_max)
      Returns a list of face indices indicating which faces intersect between mesh1 and mesh2. If there are no such faces, returns an empty list.
      Parameters:
      mesh1 -
      mesh2 -
      search_max - Maximum search radius; should be similar to largest face size; larger takes longer
      Returns:
    • getIntersectingFaces

      public static java.util.ArrayList<java.util.ArrayList<java.lang.Integer>> getIntersectingFaces​(Mesh3D mesh_1, Mesh3D mesh_2, float search_max, ProgressUpdater progress)
      Returns two lists of face indices indicating which faces intersect between mesh1 and mesh2. If there are no such faces, returns an empty list.
      Parameters:
      mesh1 -
      mesh2 -
      search_max - Maximum search radius; should be similar to largest face size; larger takes longer
      progress -
      Returns:
    • getIntersectingFacesBlocking

      public static java.util.ArrayList<java.util.ArrayList<java.lang.Integer>> getIntersectingFacesBlocking​(Mesh3D mesh_1, Mesh3D mesh_2, float search_max, ProgressUpdater progress)
      Returns two lists of face indices indicating which faces intersect between mesh1 and mesh2. If there are no such faces, returns an empty list.
      Parameters:
      mesh1 -
      mesh2 -
      search_max - Maximum search radius; should be similar to largest face size; larger takes longer
      progress -
      Returns:
    • getSelfIntersections

      public static java.util.ArrayList<java.lang.Integer> getSelfIntersections​(Mesh3D mesh, float search_max)
      Returns a list of face indices indicating which faces intersect within mesh. If there are no such faces, returns an empty list.
      Parameters:
      mesh -
      search_max - Maximum search radius; should be similar to largest face size; larger takes longer
      Returns:
    • getSelfIntersections

      public static java.util.ArrayList<java.lang.Integer> getSelfIntersections​(Mesh3D mesh, float search_max, ProgressUpdater progress)
    • getSelfIntersectionsBlocking

      protected static java.util.ArrayList<java.lang.Integer> getSelfIntersectionsBlocking​(Mesh3D mesh, float search_max, ProgressUpdater progress)
      Returns a list of face indices indicating which faces intersect within mesh. If there are no such faces, returns an empty list.
      Parameters:
      mesh -
      search_max - Maximum search radius; should be similar to largest face size; larger takes longer
      progress -
      Returns:
    • getMaximumEdgeLength

      public static float getMaximumEdgeLength​(Mesh3D mesh)
      Searches all edges and returns the maximum length
      Returns:
    • getMinimumEdgeLength

      public static float getMinimumEdgeLength​(Mesh3D mesh)
      Searches all edges and returns the minimum length
      Returns:
    • getIntersectionPoint

      public static org.jogamp.vecmath.Point3f getIntersectionPoint​(Mesh3D mesh, org.jogamp.vecmath.Point3f p, org.jogamp.vecmath.Vector3f v)
      Finds the point from the first face in the nodes list which intersects the line segment defined by p and v. Returns null if no intersection exists.
      Parameters:
      mesh -
      p -
      v -
      Returns:
    • getLaplacian

      public static java.util.ArrayList<java.lang.Double> getLaplacian​(Mesh3D mesh)
      Computes the discrete Laplacian for each vertex in mesh. Adapted from matlab script; see

      Oostendorp, Oosterom & Huiskamp (1989), Interpolation on a triangulated 3D surface. Journal of Computational Physics, 80: 331-343

      Parameters:
      mesh -
      Returns:
      vertex-wise Laplacian values
    • cutMeshWithPlane3

      public static java.util.ArrayList<Mesh3D> cutMeshWithPlane3​(Mesh3D mesh, Plane3D plane) throws MeshFunctionException
      Cuts mesh with plane, creating new faces along the cut seam. Returns two meshes (if they exist) for above and below, respectively.
      Parameters:
      mesh -
      plane -
      as_submeshes -
      Returns:
      Throws:
      MeshFunctionException
    • cutMeshWithPlane

      public static java.util.ArrayList<Mesh3D> cutMeshWithPlane​(Mesh3D mesh, Plane3D plane, InterfaceProgressBar progress_bar) throws MeshFunctionException
      Cuts mesh with plane, creating new faces along the cut seam. Returns two meshes (if they exist) for above and below, respectively.
      Parameters:
      mesh -
      plane -
      as_submeshes -
      Returns:
      Throws:
      MeshFunctionException
    • getIntersectionSegments

      public static java.util.ArrayList<Polygon3D> getIntersectionSegments​(Mesh3D mesh1, Mesh3D mesh2, InterfaceProgressBar progress_bar) throws MeshFunctionException
      Return a set of line segments which represent the intersection of one mesh with another.
      Parameters:
      mesh1 -
      mesh2 -
      progress_bar -
      Returns:
      Throws:
      MeshFunctionException
    • getGlobeSphereMesh

      public static Mesh3D getGlobeSphereMesh​(org.jogamp.vecmath.Point3f center, float radius, int n_nodes)
    • getBoundaryNodes

      public static boolean[] getBoundaryNodes​(Mesh3D mesh)
      Determine which nodes are boundary nodes, return an array of booleans.
      Parameters:
      mesh -
      Returns:
    • getBoundaryNodeIndices

      public static java.util.ArrayList<java.lang.Integer> getBoundaryNodeIndices​(Mesh3D mesh)
    • getJaggedEdgeNodes

      public static java.util.HashMap<java.lang.Integer,​java.lang.Integer> getJaggedEdgeNodes​(Mesh3D mesh, java.util.ArrayList<MguiNumber> values, int min_nbrs, int max_nbrs, boolean islands)
      Detects nodes corresponding to "jagged" edges; a jagged edge node is defined as one which has only max_nbrs neighbours with the same value as itself, and at least min_nbrs neighbours which are the same value. Values are treated as integers. Such nodes are candidates for a value change.
      Parameters:
      mesh - Mesh to search
      regions - Vertex-wise values
      min_nbrs - The minimum # of neighbours with the same value which is different from a node's value
      max_brs - The maximum # of neighbours with the same value as a node's value
      Returns:
      A list of indices for jagged edge vertices
    • getMeshExpandedAlongNormals

      public static Mesh3D getMeshExpandedAlongNormals​(Mesh3D mesh, float expansion)
      Expands mesh along its vertex normals by a distance of expansion. This is suitable for a convex mesh; for a concave mesh there is no guarantee that the resulting mesh will be valid (i.e., faces may become crossed).
      Parameters:
      mesh -
      expansion -
      Returns:
      the expanded mesh
    • getIsosurfaceFromVolume

      public static Mesh3D getIsosurfaceFromVolume​(Volume3DInt volume, java.lang.String column, double iso_level)
      Constructs an isosurface from volume; i.e., computes a mesh which represents the location where values in the 3D scalar field in volume are equal to iso_level.
      Parameters:
      volume -
      iso_level -
      Returns:
    • polygonizeCell

      protected static int polygonizeCell​(org.jogamp.vecmath.Point3f[] gridcell, double[] values, java.util.ArrayList<org.jogamp.vecmath.Point3f> triangles, double isolevel)
      Uses the marching cubes lookup tables to find triangular faces intersecting the given grid cell at the given isolevel
      Parameters:
      grid -
      values -
      Returns: