Class ShapeFunctions

java.lang.Object
mgui.interfaces.Utility
mgui.interfaces.shapes.util.ShapeFunctions

public class ShapeFunctions
extends Utility
Utility class which provides functions related to InterfaceShape objects generally.
Since:
1.0
Version:
1.0
Author:
Andrew Reid
  • Field Details

  • Constructor Details

    • ShapeFunctions

      public ShapeFunctions()
  • Method Details

    • getShape

      public static Shape3DInt getShape​(org.jogamp.java3d.Shape3D shape)
    • getShapeVertexObject

      public static Shape3DInt getShapeVertexObject​(org.jogamp.java3d.Shape3D shape, MguiInteger index)
    • setAttributesFrom3DParent

      public static void setAttributesFrom3DParent​(Shape2DInt child, Shape3DInt parent, boolean inherit)
      Sets a 2D child's attributes from its parent. If inherit is true, Sets all 2D attributes to the 3D attribute values.
      Parameters:
      child_attributes -
      parent_attributes -
      inherit -
    • transformWithMatrix

      public static Shape3D transformWithMatrix​(Shape3D shape_in, org.jogamp.vecmath.Matrix4d matrix, ProgressUpdater progress)
      Transform shape_in with matrix and returns the result. Does not alter shape_in. If progress is not null, this method starts a worker thread; otherwise, it blocks.
      Parameters:
      shape_in - the shape to transform
      matrix - matrix specifying an affine transformation
      progress - option progress monitor
      Returns:
      a shape which is the transformed copy of shape_in
    • transformWithMatrixBlocking

      protected static Shape3D transformWithMatrixBlocking​(Shape3D shape_in, org.jogamp.vecmath.Matrix4d matrix, ProgressUpdater progress)
      Transform shape_in with matrix and returns the result. Does not alter shape_in. This method blocks until complete; to run in a worker thread, call transformWithMatrix(..)
      Parameters:
      shape_in - the shape to transform
      matrix - matrix specifying an affine transformation
      progress - option progress monitor
      Returns:
      a shape which is the transformed copy of shape_in
    • getConvexHull

      public static Mesh3D getConvexHull​(Shape3DInt shape)
      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​(Shape3DInt shape, ProgressUpdater progress)
    • getConvexHull

      public static Mesh3D getConvexHull​(Shape3DInt shape, java.lang.String method)
    • getConvexHull

      public static Mesh3D getConvexHull​(Shape3DInt shape, 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.
    • getConvexHullBlocking

      protected static Mesh3D getConvexHullBlocking​(Shape3DInt shape, java.lang.String method, ProgressUpdater progress)
    • getPickedShape

      public static Shape3DInt getPickedShape​(org.jogamp.java3d.utils.pickfast.PickCanvas pickNode, org.jogamp.java3d.utils.pickfast.PickCanvas pickGeom, java.awt.Point click_point, MguiInteger node)
      Return the shape picked by a mouse click at the screen location defined by click_point. Optionally sets the value of node to the selected node index of the picked shape, if node is not null.

      TODO: return a list of picked shapes, ordered from closest to farthest

      Parameters:
      pickNode -
      pickGeom -
      click_point -
      node -
      Returns:
    • getSphereAtPoint

      public static org.jogamp.java3d.TransformGroup getSphereAtPoint​(float radius, org.jogamp.vecmath.Point3f point)
      Returns a TransformGroup with a sphere at the specified point, with the specified radius.
      Parameters:
      radius -
      point -
      Returns:
    • getSphereAtPoint

      public static org.jogamp.java3d.TransformGroup getSphereAtPoint​(float radius, org.jogamp.vecmath.Point3d point)
      Returns a TransformGroup with a sphere at the specified point, with the specified radius. Uses a default Appearance with red colour.
      Parameters:
      radius -
      point -
      Returns:
    • getSphereAtPoint

      public static org.jogamp.java3d.TransformGroup getSphereAtPoint​(float radius, org.jogamp.vecmath.Point3d point, boolean pickable)
      Returns a TransformGroup with a sphere at the specified point, with the specified radius. Uses a default Appearance with red colour.
      Parameters:
      radius - Radius of the sphere
      point - Center point of the sphere
      pickable - Determines whether the sphere is pickable
      Returns:
    • getSphereAtPoint

      public static org.jogamp.java3d.TransformGroup getSphereAtPoint​(float radius, org.jogamp.vecmath.Point3d point, org.jogamp.java3d.Appearance app, boolean pickable)
      Returns a TransformGroup with a sphere at the specified point, with the specified radius and Appearance.
      Parameters:
      radius - Radius of the sphere
      point - Center point of the sphere
      pickable - Determines whether the sphere is pickable
      Returns:
    • getBoolCornerPoints

      public static BoolPolygon2DInt getBoolCornerPoints​(Polygon2DInt thePoly, double length_threshold, double angle_threshold)
    • getIntCornerPoints

      public static IntPolygon2DInt getIntCornerPoints​(Polygon2DInt thePoly, double length_threshold, double angle_threshold)
    • nodeHasChild

      public static boolean nodeHasChild​(org.jogamp.java3d.BranchGroup parent, org.jogamp.java3d.Node child) throws org.jogamp.java3d.CapabilityNotSetException
      Determines whether child is a child of parent in the Scene Graph
      Parameters:
      parent -
      child -
      Returns:
      Throws:
      org.jogamp.java3d.CapabilityNotSetException
    • getGroomedPolygon

      public static Polygon2DInt getGroomedPolygon​(Polygon2DInt thisPoly, float minLen, boolean blnMin, float maxLen, boolean blnMax, float minAngle)
    • getShapeSet3DFromSection

      public static ShapeSet3DInt getShapeSet3DFromSection​(Plane3D refPlane, float dist, ShapeSet2DInt shapes, ShapeSelectionSet selSet)
    • getShape3DIntFromSection

      public static Shape3DInt getShape3DIntFromSection​(Plane3D refPlane, float dist, Shape2DInt shape2D)
    • getShape3DIntFromSection

      public static Shape3DInt getShape3DIntFromSection​(Plane3D refPlane, float dist, Shape2DInt shape2D, boolean set_parent)
    • getIntersectionPolygon

      public static Polygon2D getIntersectionPolygon​(Box3D box, Plane3D plane)
      Returns a 2D polygon in section coordinates representing the intersection of a Box3D object with the plane. Returns null if the box does not intersect the plane.
      Parameters:
      box -
      plane -
      Returns:
      Polygon2D object, in plane coordinates relative to its reference point
    • getIntersectionPolygon2

      public static Polygon2D getIntersectionPolygon2​(Box3D box, Plane3D plane)
      Returns a 2D polygon in section coordinates representing the intersection of a Box3D object with the plane. Returns null if the box does not intersect the plane.
      Parameters:
      box -
      plane -
      Returns:
      Polygon2D object, in plane coordinates relative to its reference point
    • getProjectedPolygon

      public static Polygon2DInt getProjectedPolygon​(Polygon3D polygon, Plane3D plane, float above_dist, float below_dist)
      Returns a 2D polygon in section coordinates representing the projection of polygon onto plane, within the specified clipping distances.
      Parameters:
      box -
      plane -
      Returns:
      Polygon2D object, in plane coordinates relative to its reference point
    • getProjectedPolygon

      public static Polygon2DInt getProjectedPolygon​(Polygon3D polygon, Plane3D plane, float above_dist, float below_dist, VertexDataColumn v_column)
      Returns a 2D polygon in section coordinates representing the projection of polygon onto plane, within the specified clipping distances.
      Parameters:
      polygon - The shape to project
      plane -
      above_dist -
      below_dist -
      v_column - Vertex data column from which to derive vertex-wise values for the new polygon shape
      Returns:
      Polygon2DInt object, in plane coordinates relative to its reference point
    • getProjectedPolygon_bak

      public static Polygon2DInt getProjectedPolygon_bak​(Polygon3D polygon, Plane3D plane, float above_dist, float below_dist, VertexDataColumn v_column)
      Returns a 2D polygon in section coordinates representing the projection of polygon onto plane, within the specified clipping distances.
      Parameters:
      polygon - The shape to project
      plane -
      above_dist -
      below_dist -
      v_column - Vertex data column from which to derive vertex-wise values for the new polygon shape
      Returns:
      Polygon2DInt object, in plane coordinates relative to its reference point
    • getIntersectionMesh

      public static Mesh2DInt getIntersectionMesh​(Mesh3D mesh, Plane3D plane)
      Returns a Mesh2DInt object representing the intersection of the given 3D mesh with plane p. Returns null if this mesh does not intersect the plane. TODO: add functionality to project mesh onto plane within a given spacing.
      Parameters:
      mesh - mesh to intersect
      plane - plane of intersection
      Returns:
      Mesh2DInt object representing the intersection of the surface with the plane
    • getIntersectionMesh

      public static Mesh2DInt getIntersectionMesh​(Mesh3D mesh, Plane3D plane, java.util.ArrayList<MguiNumber> data, ColourMap cmap)
      Returns a Mesh2DInt object representing the intersection of the given 3D mesh with plane p. Returns null if this mesh does not intersect the plane. If data and cmap are not null, also assigns colours to the segments based upon their interpolated values. TODO: add functionality to project mesh onto plane within a given spacing.
      Parameters:
      mesh - mesh to intersect
      plane - plane of intersection
      data - list of node data from which to colour the lines. If null, lines are coloured according to surface fill colour.
      cmap - colour map from which to set the interpolated line colours
      Returns:
      Mesh2DInt object representing the intersection of the surface with the plane, or null if the plane doesn't intersect the mesh
    • getIntersectedGraph

      public static Graph2DInt getIntersectedGraph​(InterfaceAbstractGraph graph3d, java.util.HashMap<AbstractGraphNode,​java.lang.Integer> node_map, Plane3D plane, float above_dist, float below_dist)
      Returns a Graph2DInt object derived from the plane and 3D graph.
      Parameters:
      graph3d -
      plane -
      above_dist -
      below_dist -
      Returns:
    • getIntersectedGraph

      public static Graph2DInt getIntersectedGraph​(InterfaceAbstractGraph graph3d, java.util.HashMap<AbstractGraphNode,​java.lang.Integer> node_map, Plane3D plane, float above_dist, float below_dist, org.jogamp.vecmath.Matrix4d transform)
      Returns a Graph2DInt object derived from the plane and 3D graph.
      Parameters:
      graph3d -
      plane -
      above_dist -
      below_dist -
      Returns:
    • getIntersectionPointSet

      public static PointSet2DInt getIntersectionPointSet​(PointSet3D point_set, Plane3D plane, float above_dist, float below_dist, java.util.HashMap<java.lang.String,​java.util.ArrayList<MguiNumber>> data, ColourMap cmap)
      Returns a PointSet2DInt object representing the points within spacing of the plane plane. Returns null if this set does not intersect the plane. If data and cmap are not null, also sets these attributes.
      Parameters:
      point_set - point set to intersect
      plane - plane of intersection
      data - list of node data from which to colour the lines. If null, lines are coloured according to surface fill colour.
      cmap - colour map from which to set the interpolated line colours
      Returns:
      Mesh2DInt object representing the intersection of the surface with the plane
    • getIntersectionVector

      public static Vector2DInt getIntersectionVector​(Vector3DInt v_int, Plane3D plane, float above_dist, float below_dist)
      Returns a Vector2DInt object which is the projection of vector onto plane, if and only if some part of vector is within the distance boundary specified by above_dist and below_dist. Truncates vector at this boundary if it does not lie completely within it.
      Parameters:
      volume -
      plane -
      spacing -
      Returns:
      Image3DInt object, in plane coordinates relative to its reference point
    • getIntersectionVector

      public static Vector2DInt getIntersectionVector​(Vector3DInt v_int, Plane3D plane, float above_dist, float below_dist, org.jogamp.vecmath.Matrix4d transform)
      Returns a Vector2DInt object which is the projection of vector onto plane, if and only if some part of vector is within the distance boundary specified by above_dist and below_dist. Truncates vector at this boundary if it does not lie completely within it.
      Parameters:
      volume -
      plane -
      spacing -
      Returns:
      Image3DInt object, in plane coordinates relative to its reference point
    • setMeshConstraints

      public static void setMeshConstraints​(Mesh3DInt mesh, java.util.ArrayList<org.jogamp.vecmath.Point3f> constraints)
    • getMergedPolygons

      public static java.util.ArrayList<Polygon2D> getMergedPolygons​(java.util.ArrayList<Polygon2D> polygons)
    • getMergedPolygonsbak

      public static java.util.ArrayList<Polygon2D> getMergedPolygonsbak​(java.util.ArrayList<Polygon2D> polygons)
    • getPolygonAngles

      public static java.util.List<java.lang.Float> getPolygonAngles​(Polygon3D polygon)
      Returns a list of angles corresponding to the nodes of polygon. End points will have the angle between the first and last segment.
      Parameters:
      polygon -
      Returns:
    • getCylinderPolygon

      public static org.jogamp.java3d.BranchGroup getCylinderPolygon​(Polygon3D polygon, float radius, int res, org.jogamp.java3d.Appearance app)
      Returns a set of cylindrical segments which follow the path of the given polygon. Parameters specify its appearance. TODO: fix junction artifacts
      Parameters:
      poly -
      radius -
      res -
      closed -
      app -
      Returns:
    • getCylinderPolygon

      public static org.jogamp.java3d.BranchGroup getCylinderPolygon​(Polygon3D polygon, float radius, int res, org.jogamp.java3d.Appearance app, java.util.List<java.awt.Color> vertex_colours)
      Returns a set of cylindrical segments which follow the path of the given polygon. Parameters specify its appearance. TODO: fix junction artifacts
      Parameters:
      poly -
      radius -
      res -
      closed -
      app -
      vertex_colours - Colors for each vertex
      Returns:
    • getCylinderSegment

      public static org.jogamp.java3d.BranchGroup getCylinderSegment​(org.jogamp.vecmath.Point3f p1, org.jogamp.vecmath.Point3f p2, float radius, int res, org.jogamp.java3d.Appearance app)
    • getDataMaskedDoubleValues

      public static java.util.ArrayList<MguiNumber> getDataMaskedDoubleValues​(java.util.ArrayList<MguiNumber> input, MeshDataMaskOptions options)
    • getDataMaskedDoubleValues

      public static java.util.ArrayList<MguiNumber> getDataMaskedDoubleValues​(java.util.ArrayList<MguiNumber> input, MeshDataMaskOptions options, VertexSelection selection)
    • getDataMaskedIntegerValues

      public static java.util.ArrayList<MguiNumber> getDataMaskedIntegerValues​(java.util.ArrayList<MguiNumber> input, MeshDataMaskOptions options)
    • getDataMaskedIntegerValues

      public static java.util.ArrayList<MguiNumber> getDataMaskedIntegerValues​(java.util.ArrayList<MguiNumber> input, MeshDataMaskOptions options, VertexSelection selection)
    • getNormalizedValues

      public static java.util.ArrayList<MguiNumber> getNormalizedValues​(InterfaceShape shape, java.lang.String source_column, double source_min, double source_max, double target_min, double target_max)
      Normalize values in source_column to from the range [source_min, source_max] to the range [target_min, target_max]
      Parameters:
      volume -
      source_column -
      source_min -
      source_max -
      target_min -
      target_max -
      Returns:
    • getMaskNormalizedValues

      public static java.util.ArrayList<MguiNumber> getMaskNormalizedValues​(InterfaceShape shape, java.lang.String source_column, java.lang.String normalize_column, java.lang.String mask_column)
      Normalize values in source_column by the mean of values in normalize_column which lie in the mask mask_column. source_column and normalize_column can be the same. Elements are considered to in the mask if their value in mask_column is >= zero.

      Returned values are of the same type as source_column.

      Parameters:
      volume -
      source_column -
      normalize_column -
      mask_column -
      Returns:
    • getMaskNormalizedValues

      public static java.util.ArrayList<MguiNumber> getMaskNormalizedValues​(InterfaceShape shape, java.lang.String source_column, java.lang.String normalize_column, java.lang.String mask_column, java.lang.String statistic)
      Normalize values in source_column by the statistic of values in normalize_column which lie in the mask mask_column. source_column and normalize_column can be the same. Elements are considered to in the mask if their value in mask_column is >= zero.

      Returned values are of the same type as source_column.

      Valid values of statistic are:

      • mean
      • max
      • min
      • sum
      Parameters:
      volume -
      source_column -
      normalize_column -
      mask_column -
      statistic -
      Returns:
    • getModelClip

      public static org.jogamp.java3d.ModelClip getModelClip​(Plane3D plane, float up, float down, boolean invert)
      Returns the up and down clipping planes for this plane
      Parameters:
      plane -
      Returns:
    • setModelClip

      public static void setModelClip​(org.jogamp.java3d.ModelClip clip, Plane3D plane, float up, float down, boolean invert)
      Sets clip to match the specified plane and clipping distances.
      Parameters:
      clip -
      plane -
      up -
      down -
      invert -
    • unionMaskVolumeWithPlane

      public static void unionMaskVolumeWithPlane​(boolean[][][] mask, Volume3DInt volume, Plane3D plane, boolean is_above)
      Returns a mask for volume which is above or below plane.
      Parameters:
      volume -
      plane -
      is_above -
    • getNearestNeighbours

      public static java.util.ArrayList<java.lang.Integer> getNearestNeighbours​(InterfaceShape source, InterfaceShape target)
      Returns a list of vertex indices from source which are nearest neighbours of the corresponding vertices of target.
      Parameters:
      source -
      target -
      search_max - The maximum search radius; if no neighbours are found, the corresponding value is -1
      Returns:
      a list of indices, of size target.size() corresponding to the nearest neighbours in source.
    • getNearestNeighbour3DBlocking

      protected static java.util.ArrayList<java.lang.Integer> getNearestNeighbour3DBlocking​(Shape3DInt source, Shape3DInt target)
    • getDefaultShapeAttributes2D

      public static AttributeList getDefaultShapeAttributes2D()
    • getDefaultShapeAttributes3D

      public static AttributeList getDefaultShapeAttributes3D()