Package qupath.lib.awt.common
Class AffineTransforms
java.lang.Object
qupath.lib.awt.common.AffineTransforms
Helper class for working with affine transforms.
QuPath's core dependencies have two affine transform implementations: AffineTransform
from Java itself
and AffineTransformation
from Java Topology Suite.
Inconveniently, both are initialized from flattened double arrays using a different ordering (assuming
columns-first or rows-first) - so it is easy to make mistakes.
QuPath primarily uses AffineTransform
from Java.
This class exists to make creating a transform more explicit, and facilitate conversion when needed.
- Author:
- Pete Bankhead
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic AffineTransform
from2D
(double[][] mat) Create an affine transform from a 2x3 double array, or 3x3 if the last row has the values [0, 0, 1] only.static AffineTransform
fromColumns
(double... mat) Create an affine transform from a flat matrix with 6 elements, assumed to be in the order[[0, 2, 4], [1, 3, 5]]
.static AffineTransform
fromJTS
(AffineTransformation transform) Create a Java affine transform from a Java Topology Suite representation.static AffineTransform
fromRows
(double... mat) Create an affine transform from a flat matrix with 6 elements, assumed to be in the order[[0, 1, 2], [3, 4, 5]]
.static AffineTransform
fromScale
(double scale) Create an affine transform representing scaling, using the same scale for x and y.static AffineTransform
fromScale
(double scaleX, double scaleY) Create an affine transform representing scaling, optionally using a different scale for x and y.static AffineTransform
identity()
Create an affine transform representing the identity transform.static AffineTransformation
toJTS
(AffineTransform transform) Create a Java Topology Suite affine transformation from a Java affine transform.
-
Constructor Details
-
AffineTransforms
public AffineTransforms()
-
-
Method Details
-
from2D
Create an affine transform from a 2x3 double array, or 3x3 if the last row has the values [0, 0, 1] only.- Parameters:
mat
-- Returns:
- Throws:
IllegalArgumentException
- if the input has the wrong shape
-
fromRows
Create an affine transform from a flat matrix with 6 elements, assumed to be in the order[[0, 1, 2], [3, 4, 5]]
.- Parameters:
mat
-- Returns:
- Throws:
IllegalArgumentException
- if the input has the wrong length
-
fromColumns
Create an affine transform from a flat matrix with 6 elements, assumed to be in the order[[0, 2, 4], [1, 3, 5]]
.- Parameters:
mat
-- Returns:
- Throws:
IllegalArgumentException
- if the input has the wrong length
-
fromScale
Create an affine transform representing scaling, optionally using a different scale for x and y.- Parameters:
scaleX
-scaleY
-- Returns:
-
fromScale
Create an affine transform representing scaling, using the same scale for x and y.- Parameters:
scale
-- Returns:
-
identity
Create an affine transform representing the identity transform.- Returns:
-
fromJTS
Create a Java affine transform from a Java Topology Suite representation.- Parameters:
transform
-- Returns:
-
toJTS
Create a Java Topology Suite affine transformation from a Java affine transform.- Parameters:
transform
-- Returns:
-