Package gov.nih.mipav.model.algorithms
Class ContourPlot.Utils
- java.lang.Object
-
- gov.nih.mipav.model.algorithms.ContourPlot.Utils
-
- Enclosing class:
- ContourPlot
public static class ContourPlot.Utils extends java.lang.Object
Class containing utility methods- Author:
- hageldave
-
-
Constructor Summary
Constructors Constructor Description Utils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static double
clamp(double lower, double v, double upper)
Clamps value between specified boundsstatic float
clamp(float lower, float v, float upper)
Clamps value between specified boundsstatic int
clamp(int lower, int v, int upper)
Clamps value between specified boundsstatic <T extends java.awt.geom.Point2D>
Tcopy(T p)
Copies the specifiedPoint2D
(calls clone) and casts the copy to the class of the original.static double
hypot(double x, double y)
Calculates sqrt(x*x + y*y) which is the hypotenuse length given catheti x and y.static java.awt.image.ImageObserver
imageObserver(int flags)
Creates anImageObserver
that checks the for the specified infoflags.static <T extends java.lang.Comparable<T>>
booleanisSorted(java.util.Iterator<T> iter)
Checks if specified iterator is sorted according to natural ordering.static double
max3(double v0, double v1, double v2)
Returns the maximum of 3 valuesstatic double
min3(double v0, double v1, double v2)
Returns the minimum of 3 valuesstatic <T> java.util.stream.Stream<T>
parallelize(java.util.stream.Stream<T> stream, boolean parallel)
Syntactic sugar for conditional stream.parallel().private static boolean
pointInTri(double px, double py, double x0, double y0, double x1, double y1, double x2, double y2)
static boolean
rectIntersectsOrIsContainedInTri(java.awt.geom.Rectangle2D rect, double x0, double y0, double x1, double y1, double x2, double y2)
tests intersection or containment of rectangle and triangle.private static double
sign(double x1, double y1, double x2, double y2, double x3, double y3)
static <P extends java.awt.geom.Point2D>
PswapYAxis(P point, int height)
Swaps between GL and AWT coordinates, AWT coordinate system has its origin in the top left corner of a component and downwards pointing y axis, whereas GL has its origin in the bottom left corner of the viewport (at least in JPlotter) and upwards pointing y axis.
-
-
-
Method Detail
-
copy
public static <T extends java.awt.geom.Point2D> T copy(T p)
Copies the specifiedPoint2D
(calls clone) and casts the copy to the class of the original.- Type Parameters:
T
- type of Point2D- Parameters:
p
- point to copy- Returns:
- the copied point
-
copy
public static <T extends java.awt.geom.RectangularShape> T copy(T r)
Copies the specifiedRectangularShape
(calls clone) and casts the copy to the class of the original.- Type Parameters:
T
- type of RectangularShape- Parameters:
r
- rectangle to copy- Returns:
- the copied rectangle
-
isSorted
public static <T extends java.lang.Comparable<T>> boolean isSorted(java.util.Iterator<T> iter)
Checks if specified iterator is sorted according to natural ordering.- Type Parameters:
T
- element type that implementsComparable
- Parameters:
iter
- iterator- Returns:
- true if sorted, false otherwise
-
parallelize
public static <T> java.util.stream.Stream<T> parallelize(java.util.stream.Stream<T> stream, boolean parallel)
Syntactic sugar for conditional stream.parallel().- Type Parameters:
T
- element type of stream- Parameters:
stream
- to make parallelparallel
- whether to make parallel or not- Returns:
- stream.parallel() if true
-
clamp
public static double clamp(double lower, double v, double upper)
Clamps value between specified bounds- Parameters:
lower
- minimum valuev
- value to clampupper
- maximum value- Returns:
- max(lower,min(upper,v))
-
clamp
public static float clamp(float lower, float v, float upper)
Clamps value between specified bounds- Parameters:
lower
- minimum valuev
- value to clampupper
- maximum value- Returns:
- max(lower,min(upper,v))
-
clamp
public static int clamp(int lower, int v, int upper)
Clamps value between specified bounds- Parameters:
lower
- minimum valuev
- value to clampupper
- maximum value- Returns:
- max(lower,min(upper,v))
-
min3
public static double min3(double v0, double v1, double v2)
Returns the minimum of 3 values- Parameters:
v0
- valuev1
- valuev2
- value- Returns:
- minimum
-
max3
public static double max3(double v0, double v1, double v2)
Returns the maximum of 3 values- Parameters:
v0
- valuev1
- valuev2
- value- Returns:
- maximum
-
rectIntersectsOrIsContainedInTri
public static boolean rectIntersectsOrIsContainedInTri(java.awt.geom.Rectangle2D rect, double x0, double y0, double x1, double y1, double x2, double y2)
tests intersection or containment of rectangle and triangle.- Parameters:
rect
- rectangle to testx0
- x coordinate of 0th triangle vertexy0
- y coordinate of 0th triangle vertexx1
- x coordinate of 1st triangle vertexy1
- y coordinate of 1st triangle vertexx2
- x coordinate of 2nd triangle vertexy2
- y coordinate of 2nd triangle vertex- Returns:
- true when intersecting
-
sign
private static double sign(double x1, double y1, double x2, double y2, double x3, double y3)
-
pointInTri
private static boolean pointInTri(double px, double py, double x0, double y0, double x1, double y1, double x2, double y2)
-
imageObserver
public static java.awt.image.ImageObserver imageObserver(int flags)
Creates anImageObserver
that checks the for the specified infoflags. SeeImageObserver.imageUpdate(java.awt.Image, int, int, int, int, int)
.- Parameters:
flags
- infoflags to check- Returns:
- a new ImageObserver
-
hypot
public static final double hypot(double x, double y)
Calculates sqrt(x*x + y*y) which is the hypotenuse length given catheti x and y.- Parameters:
x
- a valuey
- a value- Returns:
- hypotenuse length
-
swapYAxis
public static <P extends java.awt.geom.Point2D> P swapYAxis(P point, int height)
Swaps between GL and AWT coordinates, AWT coordinate system has its origin in the top left corner of a component and downwards pointing y axis, whereas GL has its origin in the bottom left corner of the viewport (at least in JPlotter) and upwards pointing y axis.- Type Parameters:
P
- type of Point2D- Parameters:
point
- to swap the y axis ofheight
- of the component or viewport- Returns:
- point in coordinates of the other reference coordinate system.
-
-