ini.trakem2.utils
Class M

java.lang.Object
  extended by ini.trakem2.utils.M

public final class M
extends java.lang.Object

TrakEM2's mathematician.


Constructor Summary
M()
           
 
Method Summary
static void appendShortest(float f, float precision, java.lang.StringBuilder sb)
          Appends to @param sb the shortest possible String representation of a float number, according to the desired decimal @param precision.
static void apply(mpicbg.models.CoordinateTransform ict, java.awt.geom.Area roi, java.awt.geom.Area a)
          Apply in place the @param ict to the Area @param a, but only for the part that intersects the roi.
static void apply(mpicbg.models.CoordinateTransform ict, double[][] p, int i, float[] fp)
          Reuses the @param fp to apply in place.
static void apply(VectorDataTransform vdt, java.awt.geom.Area a)
           
static void apply(VectorDataTransform vdt, java.awt.geom.Area a, boolean remove_outside)
          Parts of @param a not intersected by any of @param vdt rois will be left untouched if @param remove_outside is false.
static java.awt.geom.Area areaInInts(java.awt.geom.Area area)
          Converts all points in @param area to ints by casting.
static java.awt.geom.Area areaInIntsByRounding(java.awt.geom.Area area)
          Converts all points in @param area to ints by rounding.
static VectorString2D asVectorString2D(java.awt.Polygon pol, double z)
           
static float[] computeSegmentsIntersection(float ax0, float ay0, float ax1, float ay1, float bx0, float by0, float bx1, float by1)
           
static java.awt.Shape createArrowhead(double x1, double y1, double x2, double y2)
          Create an arrowhead at the end of the line segment defined by x1,y1 and x2,y2.
static java.awt.Shape createArrowhead(double x1, double y1, double x2, double y2, double magnification)
           
static java.util.List<javax.vecmath.Point3f> createIcosahedron(int subdivisions, float radius)
          Returns a "3D Viewer"-ready list mesh, centered at 0,0,0 and with radius as the radius of the enclosing sphere.
static double distance(double x1, double y1, double x2, double y2)
           
static double distance(double x1, double y1, double z1, double x2, double y2, double z2)
           
static double distance(javax.vecmath.Tuple3d t1, javax.vecmath.Tuple3d t2)
           
static double distancePointToLine(double px, double py, double lx1, double ly1, double lx2, double ly2)
          For a point px,py return its distance to a line defined by points lx1,ly1 and lx2,ly2.
static double distancePointToLine(double px, double py, double pz, double lx1, double ly1, double lz1, double lx2, double ly2, double lz2)
          In 3D
static double distancePointToSegment(double px, double py, double lx1, double ly1, double lx2, double ly2)
          For a point px,py return its distance to a line SEGMENT defined by points lx1,ly1 and lx2,ly2.
static double distancePointToSegment(double px, double py, double pz, double lx1, double ly1, double lz1, double lx2, double ly2, double lz2)
           
static double distancePointToSegment(javax.vecmath.Vector3d p, javax.vecmath.Vector3d v1, javax.vecmath.Vector3d v2)
          Minimum distance between point v0 and a line segment defined by points v1 and v2.
static double distancePointToSegmentSq(double px, double py, double pz, double lx1, double ly1, double lz1, double lx2, double ly2, double lz2)
           
static double distancePointToSegmentSq(javax.vecmath.Vector3d p, javax.vecmath.Vector3d v1, javax.vecmath.Vector3d v2)
           
static double distanceSq(double x1, double y1, double z1, double x2, double y2, double z2)
           
static double distanceSq(javax.vecmath.Tuple3d t1, javax.vecmath.Tuple3d t2)
           
static boolean equals(double a, double b)
           
static java.awt.Polygon findPath(java.awt.geom.Area area, int x, int y)
          Detect if a point is not in the area, but lays inside one of its path, which is returned as a Polygon.
static double getAngle(double x, double y)
          Returns the angle in radians of the given polar coordinates, correcting the Math.atan2 output.
static java.awt.geom.Area getArea(ij.gui.Roi roi)
           
static java.awt.geom.Area getArea(ij.gui.ShapeRoi sroi)
           
static java.util.Collection<java.awt.Polygon> getPolygons(java.awt.geom.Area area)
           
static java.util.Collection<java.awt.Polygon> getPolygonsByRounding(java.awt.geom.Area area)
           
static java.awt.Shape getShape(ij.gui.ShapeRoi roi)
           
static boolean intersects(java.awt.geom.Area a1, java.awt.geom.Area a2)
          Test whether the areas intersect each other.
static java.awt.geom.Point2D.Double inverseTransform(java.awt.geom.AffineTransform affine, double x, double y)
           
static boolean isAreaROI(ij.gui.Roi roi)
          Returns true if the roi is of closed shape type like an OvalRoi, ShapeRoi, a Roi rectangle, etc.
static boolean isEmpty(java.awt.geom.Area area)
           
static double measureArea(java.awt.geom.Area area, Loader loader)
          Returns the approximated area of the given Area object; Loader can be null; if not, it's used to secure memory space.
static double measureArea(javax.vecmath.Point3f p1, javax.vecmath.Point3f p2, javax.vecmath.Point3f p3)
          Compute the area of the triangle defined by 3 points in 3D space, returning half of the length of the vector resulting from the cross product of vectors p1p2 and p1p3.
static void quicksort(float[] data, java.lang.Object[] sortAlso)
           
static void quicksort(float[] data, java.lang.Object[] sortAlso, int left, int right)
          Adapted from Stephan Preibisch's mpi.fruitfly.math.General homonimous method.
static java.lang.String shortest(float f, float precision)
          Returns the shortest possible String representation of a float number, according to the desired decimal @param precision.
static java.awt.geom.Area[] splitArea(java.awt.geom.Area a, ij.gui.PolygonRoi proi, java.awt.Rectangle world)
          Returns an array of two Area objects, or of 1 if the @param proi doesn't intersect @param a.
static java.awt.geom.Point2D.Double transform(java.awt.geom.AffineTransform affine, double x, double y)
           
static java.awt.geom.Area transform(mpicbg.models.CoordinateTransform ict, java.awt.geom.Area a)
          Return a new Area resulting from applying @param ict to @param a; assumes areas consists of paths with moveTo, lineTo and close operations.
static mpicbg.models.CoordinateTransform wrap(java.awt.geom.AffineTransform to_world, mpicbg.models.CoordinateTransform ict, java.awt.geom.AffineTransform to_local)
          The @param ict is expected to transform the data as if this data was expressed in world coordinates, so this method returns a transformation list that prepends the transform from local to world, then the @param ict, then from world to local.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

M

public M()
Method Detail

distancePointToSegment

public static final double distancePointToSegment(double px,
                                                  double py,
                                                  double pz,
                                                  double lx1,
                                                  double ly1,
                                                  double lz1,
                                                  double lx2,
                                                  double ly2,
                                                  double lz2)

distancePointToSegmentSq

public static final double distancePointToSegmentSq(double px,
                                                    double py,
                                                    double pz,
                                                    double lx1,
                                                    double ly1,
                                                    double lz1,
                                                    double lx2,
                                                    double ly2,
                                                    double lz2)

distancePointToSegment

public static final double distancePointToSegment(javax.vecmath.Vector3d p,
                                                  javax.vecmath.Vector3d v1,
                                                  javax.vecmath.Vector3d v2)
Minimum distance between point v0 and a line segment defined by points v1 and v2.


distancePointToSegmentSq

public static final double distancePointToSegmentSq(javax.vecmath.Vector3d p,
                                                    javax.vecmath.Vector3d v1,
                                                    javax.vecmath.Vector3d v2)

distance

public static final double distance(javax.vecmath.Tuple3d t1,
                                    javax.vecmath.Tuple3d t2)

distanceSq

public static final double distanceSq(javax.vecmath.Tuple3d t1,
                                      javax.vecmath.Tuple3d t2)

distance

public static final double distance(double x1,
                                    double y1,
                                    double z1,
                                    double x2,
                                    double y2,
                                    double z2)

distance

public static final double distance(double x1,
                                    double y1,
                                    double x2,
                                    double y2)

distanceSq

public static final double distanceSq(double x1,
                                      double y1,
                                      double z1,
                                      double x2,
                                      double y2,
                                      double z2)

distancePointToLine

public static double distancePointToLine(double px,
                                         double py,
                                         double pz,
                                         double lx1,
                                         double ly1,
                                         double lz1,
                                         double lx2,
                                         double ly2,
                                         double lz2)
In 3D


distancePointToLine

public static double distancePointToLine(double px,
                                         double py,
                                         double lx1,
                                         double ly1,
                                         double lx2,
                                         double ly2)
For a point px,py return its distance to a line defined by points lx1,ly1 and lx2,ly2. Formula as in http://mathworld.wolfram.com/Point-LineDistance2-Dimensional.html at 2008-11-11 20:19 Zurich time.


distancePointToSegment

public static double distancePointToSegment(double px,
                                            double py,
                                            double lx1,
                                            double ly1,
                                            double lx2,
                                            double ly2)
For a point px,py return its distance to a line SEGMENT defined by points lx1,ly1 and lx2,ly2.


equals

public static final boolean equals(double a,
                                   double b)

transform

public static final java.awt.geom.Point2D.Double transform(java.awt.geom.AffineTransform affine,
                                                           double x,
                                                           double y)

inverseTransform

public static final java.awt.geom.Point2D.Double inverseTransform(java.awt.geom.AffineTransform affine,
                                                                  double x,
                                                                  double y)

getAngle

public static final double getAngle(double x,
                                    double y)
Returns the angle in radians of the given polar coordinates, correcting the Math.atan2 output. Adjusting so that 0 is 3 o'clock, PI+PI/2 is 12 o'clock, PI is 9 o'clock, and PI/2 is 6 o'clock (why atan2 doesn't output angles this way? I remember I had the same problem for Pipe.java in the A_3D_editing plugin)


isEmpty

public static final boolean isEmpty(java.awt.geom.Area area)

intersects

public static final boolean intersects(java.awt.geom.Area a1,
                                       java.awt.geom.Area a2)
Test whether the areas intersect each other.


getArea

public static final java.awt.geom.Area getArea(ij.gui.Roi roi)

getArea

public static final java.awt.geom.Area getArea(ij.gui.ShapeRoi sroi)

measureArea

public static final double measureArea(java.awt.geom.Area area,
                                       Loader loader)
Returns the approximated area of the given Area object; Loader can be null; if not, it's used to secure memory space.


measureArea

public static final double measureArea(javax.vecmath.Point3f p1,
                                       javax.vecmath.Point3f p2,
                                       javax.vecmath.Point3f p3)
Compute the area of the triangle defined by 3 points in 3D space, returning half of the length of the vector resulting from the cross product of vectors p1p2 and p1p3.


isAreaROI

public static final boolean isAreaROI(ij.gui.Roi roi)
Returns true if the roi is of closed shape type like an OvalRoi, ShapeRoi, a Roi rectangle, etc.


getPolygons

public static final java.util.Collection<java.awt.Polygon> getPolygons(java.awt.geom.Area area)

getPolygonsByRounding

public static final java.util.Collection<java.awt.Polygon> getPolygonsByRounding(java.awt.geom.Area area)

transform

public static final java.awt.geom.Area transform(mpicbg.models.CoordinateTransform ict,
                                                 java.awt.geom.Area a)
Return a new Area resulting from applying @param ict to @param a; assumes areas consists of paths with moveTo, lineTo and close operations.


apply

public static final void apply(mpicbg.models.CoordinateTransform ict,
                               java.awt.geom.Area roi,
                               java.awt.geom.Area a)
Apply in place the @param ict to the Area @param a, but only for the part that intersects the roi.


apply

public static final void apply(VectorDataTransform vdt,
                               java.awt.geom.Area a)

apply

public static final void apply(VectorDataTransform vdt,
                               java.awt.geom.Area a,
                               boolean remove_outside)
Parts of @param a not intersected by any of @param vdt rois will be left untouched if @param remove_outside is false.


getShape

public static final java.awt.Shape getShape(ij.gui.ShapeRoi roi)

findPath

public static final java.awt.Polygon findPath(java.awt.geom.Area area,
                                              int x,
                                              int y)
Detect if a point is not in the area, but lays inside one of its path, which is returned as a Polygon. Otherwise returns null. The given x,y must be already in the Area's coordinate system.


areaInInts

public static final java.awt.geom.Area areaInInts(java.awt.geom.Area area)
Converts all points in @param area to ints by casting.


areaInIntsByRounding

public static final java.awt.geom.Area areaInIntsByRounding(java.awt.geom.Area area)
Converts all points in @param area to ints by rounding.


quicksort

public static void quicksort(float[] data,
                             java.lang.Object[] sortAlso)
                      throws java.lang.IllegalArgumentException
Throws:
java.lang.IllegalArgumentException

quicksort

public static void quicksort(float[] data,
                             java.lang.Object[] sortAlso,
                             int left,
                             int right)
Adapted from Stephan Preibisch's mpi.fruitfly.math.General homonimous method.


createArrowhead

public static final java.awt.Shape createArrowhead(double x1,
                                                   double y1,
                                                   double x2,
                                                   double y2)
Create an arrowhead at the end of the line segment defined by x1,y1 and x2,y2.


createArrowhead

public static final java.awt.Shape createArrowhead(double x1,
                                                   double y1,
                                                   double x2,
                                                   double y2,
                                                   double magnification)

createIcosahedron

public static final java.util.List<javax.vecmath.Point3f> createIcosahedron(int subdivisions,
                                                                            float radius)
Returns a "3D Viewer"-ready list mesh, centered at 0,0,0 and with radius as the radius of the enclosing sphere.


apply

public static final void apply(mpicbg.models.CoordinateTransform ict,
                               double[][] p,
                               int i,
                               float[] fp)
Reuses the @param fp to apply in place.


wrap

public static final mpicbg.models.CoordinateTransform wrap(java.awt.geom.AffineTransform to_world,
                                                           mpicbg.models.CoordinateTransform ict,
                                                           java.awt.geom.AffineTransform to_local)
                                                    throws java.lang.Exception
The @param ict is expected to transform the data as if this data was expressed in world coordinates, so this method returns a transformation list that prepends the transform from local to world, then the @param ict, then from world to local.

Throws:
java.lang.Exception

shortest

public static final java.lang.String shortest(float f,
                                              float precision)
Returns the shortest possible String representation of a float number, according to the desired decimal @param precision.


appendShortest

public static final void appendShortest(float f,
                                        float precision,
                                        java.lang.StringBuilder sb)
Appends to @param sb the shortest possible String representation of a float number, according to the desired decimal @param precision.


computeSegmentsIntersection

public static final float[] computeSegmentsIntersection(float ax0,
                                                        float ay0,
                                                        float ax1,
                                                        float ay1,
                                                        float bx0,
                                                        float by0,
                                                        float bx1,
                                                        float by1)

splitArea

public static final java.awt.geom.Area[] splitArea(java.awt.geom.Area a,
                                                   ij.gui.PolygonRoi proi,
                                                   java.awt.Rectangle world)
Returns an array of two Area objects, or of 1 if the @param proi doesn't intersect @param a.


asVectorString2D

public static VectorString2D asVectorString2D(java.awt.Polygon pol,
                                              double z)
                                       throws java.lang.Exception
Throws:
java.lang.Exception