Class LinearTransform1D
java.lang.Object
org.apache.sis.io.wkt.FormattableObject
org.apache.sis.referencing.operation.transform.AbstractMathTransform
org.apache.sis.referencing.operation.transform.AbstractMathTransform1D
org.apache.sis.referencing.operation.transform.LinearTransform1D
- All Implemented Interfaces:
Serializable
,Parameterized
,LinearTransform
,LenientComparable
,org.opengis.referencing.operation.MathTransform
,org.opengis.referencing.operation.MathTransform1D
- Direct Known Subclasses:
ConstantTransform1D
,IdentityTransform1D
A one dimensional, linear transform.
Input values x are converted into output values y using the following equation:
y = x × scale + offsetThis class is the same as a 2×2 affine transform. However, this specialized
LinearTransform1D
class
is faster. This kind of transform is extensively used by org.apache.sis.coverage.grid.GridCoverage2D
.- Since:
- 0.5
- Version:
- 0.7
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class org.apache.sis.referencing.operation.transform.AbstractMathTransform1D
AbstractMathTransform1D.Inverse
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate org.opengis.referencing.operation.MathTransform1D
The inverse of this transform.(package private) static final LinearTransform1D
A transform that just reverse the sign of input values.(package private) final double
The value to add to input values.(package private) final double
The value which is multiplied to input values.private static final long
Serial number for inter-operability with different versions.Fields inherited from class org.apache.sis.referencing.operation.transform.AbstractMathTransform
MAXIMUM_BUFFER_SIZE, MAXIMUM_FAILURES
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
LinearTransform1D
(double scale, double offset) Constructs a new linear transform. -
Method Summary
Modifier and TypeMethodDescriptionprotected int
Computes a hash value for this transform.(package private) static LinearTransform1D
constant
(double x, double y) Creates a constant function having value y, and for which the inverse is x.static LinearTransform1D
create
(double scale, double offset) Constructs a new linear transform.void
deltaTransform
(double[] srcPts, int srcOff, double[] dstPts, int dstOff, int numPts) Transforms many distance vectors in a list of coordinate values.double
derivative
(double value) Gets the derivative of this function at a value.org.opengis.referencing.operation.Matrix
derivative
(org.opengis.geometry.DirectPosition point) Gets the derivative of this transform at a point.boolean
equals
(Object object, ComparisonMode mode) Compares the specified object with this math transform for equality.org.opengis.referencing.operation.Matrix
Returns this transform as an affine transform matrix.org.opengis.parameter.ParameterDescriptorGroup
Returns the parameter descriptors for this math transform.org.opengis.parameter.ParameterValueGroup
Returns the matrix elements as a group of parameter values.inverse()
Creates the inverse transform of this object.boolean
isAffine()
Returnstrue
since this transform is affine.boolean
Tests whether this transform does not move any points.toString()
Returns a string representation of this transform as a matrix, for consistency with otherLinearTransform
implementations in Apache SIS.double
transform
(double value) Transforms the specified value.org.opengis.referencing.operation.Matrix
transform
(double[] srcPts, int srcOff, double[] dstPts, int dstOff, boolean derivate) Transforms a single point in the given array and opportunistically computes its derivative if requested.void
transform
(double[] srcPts, int srcOff, double[] dstPts, int dstOff, int numPts) Transforms many positions in a list of coordinate values.void
transform
(double[] srcPts, int srcOff, float[] dstPts, int dstOff, int numPts) Transforms many positions in a list of coordinate values.void
transform
(float[] srcPts, int srcOff, double[] dstPts, int dstOff, int numPts) Transforms many positions in a list of coordinate values.void
transform
(float[] srcPts, int srcOff, float[] dstPts, int dstOff, int numPts) Transforms many positions in a list of coordinate values.Methods inherited from class org.apache.sis.referencing.operation.transform.AbstractMathTransform1D
getSourceDimensions, getTargetDimensions
Methods inherited from class org.apache.sis.referencing.operation.transform.AbstractMathTransform
beforeFormat, equals, formatTo, getContextualParameters, getDomain, hashCode, isInverseEquals, mismatchedDimension, transform, tryConcatenate
Methods inherited from class org.apache.sis.io.wkt.FormattableObject
print, toString, toWKT
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface org.opengis.referencing.operation.MathTransform
getSourceDimensions, getTargetDimensions, toWKT, transform
-
Field Details
-
serialVersionUID
private static final long serialVersionUIDSerial number for inter-operability with different versions.- See Also:
-
NEGATE
A transform that just reverse the sign of input values. -
scale
final double scaleThe value which is multiplied to input values. -
offset
final double offsetThe value to add to input values. -
inverse
private transient org.opengis.referencing.operation.MathTransform1D inverseThe inverse of this transform. Created only when first needed.
-
-
Constructor Details
-
LinearTransform1D
protected LinearTransform1D(double scale, double offset) Constructs a new linear transform. This constructor is provided for subclasses only. Instances should be created using the factory method, which may returns optimized implementations for some particular argument values.- Parameters:
scale
- thescale
term in the linear equation.offset
- theoffset
term in the linear equation.- See Also:
-
-
Method Details
-
create
Constructs a new linear transform.- Parameters:
scale
- thescale
term in the linear equation.offset
- theoffset
term in the linear equation.- Returns:
- the linear transform for the given scale and offset.
- See Also:
-
constant
Creates a constant function having value y, and for which the inverse is x.- Since:
- 0.7
-
getParameterDescriptors
public org.opengis.parameter.ParameterDescriptorGroup getParameterDescriptors()Returns the parameter descriptors for this math transform.- Specified by:
getParameterDescriptors
in interfaceParameterized
- Overrides:
getParameterDescriptors
in classAbstractMathTransform
- Returns:
- the parameter descriptors for this math transform, or
null
if unspecified. - See Also:
-
getParameterValues
public org.opengis.parameter.ParameterValueGroup getParameterValues()Returns the matrix elements as a group of parameter values. The number of parameters depends on the matrix size. Only matrix elements different from their default value will be included in this group.- Specified by:
getParameterValues
in interfaceParameterized
- Overrides:
getParameterValues
in classAbstractMathTransform
- Returns:
- the parameter values for this math transform.
- See Also:
-
getMatrix
public org.opengis.referencing.operation.Matrix getMatrix()Returns this transform as an affine transform matrix.- Specified by:
getMatrix
in interfaceLinearTransform
- Returns:
- the coefficients of this linear transform as a matrix.
- See Also:
-
inverse
public LinearTransform1D inverse() throws org.opengis.referencing.operation.NoninvertibleTransformExceptionCreates the inverse transform of this object.- Specified by:
inverse
in interfaceLinearTransform
- Specified by:
inverse
in interfaceorg.opengis.referencing.operation.MathTransform
- Specified by:
inverse
in interfaceorg.opengis.referencing.operation.MathTransform1D
- Overrides:
inverse
in classAbstractMathTransform1D
- Returns:
- the inverse transform.
- Throws:
org.opengis.referencing.operation.NoninvertibleTransformException
- if the transform cannot be inverted.- See Also:
-
isAffine
public boolean isAffine()Returnstrue
since this transform is affine.- Specified by:
isAffine
in interfaceLinearTransform
- Returns:
true
if this transform is affine.- See Also:
-
isIdentity
public boolean isIdentity()Tests whether this transform does not move any points.Note: this method should always returnsfalse
, sinceMathTransforms.linear(…)
should have created specialized implementations for identity cases. Nevertheless we perform the full check as a safety, in case someone instantiated this class directly instead of using a factory method.- Specified by:
isIdentity
in interfaceorg.opengis.referencing.operation.MathTransform
- Overrides:
isIdentity
in classAbstractMathTransform
-
derivative
public org.opengis.referencing.operation.Matrix derivative(org.opengis.geometry.DirectPosition point) throws org.opengis.referencing.operation.TransformException Gets the derivative of this transform at a point.- Specified by:
derivative
in interfaceorg.opengis.referencing.operation.MathTransform
- Overrides:
derivative
in classAbstractMathTransform1D
- Parameters:
point
- ignored for a linear transform. Can be null.- Returns:
- the derivative at the given point.
- Throws:
org.opengis.referencing.operation.TransformException
- if the derivative cannot be evaluated at the specified point.
-
derivative
public double derivative(double value) Gets the derivative of this function at a value.- Specified by:
derivative
in interfaceorg.opengis.referencing.operation.MathTransform1D
- Specified by:
derivative
in classAbstractMathTransform1D
- Parameters:
value
- ignored for a linear transform. Can beNaN
.- Returns:
- the derivative at the given point.
-
transform
public double transform(double value) Transforms the specified value.- Specified by:
transform
in interfaceorg.opengis.referencing.operation.MathTransform1D
- Specified by:
transform
in classAbstractMathTransform1D
- Parameters:
value
- the value to transform.- Returns:
- the transformed value.
-
transform
public org.opengis.referencing.operation.Matrix transform(double[] srcPts, int srcOff, double[] dstPts, int dstOff, boolean derivate) Transforms a single point in the given array and opportunistically computes its derivative if requested. The default implementation computes all those values from thescale
andoffset
coefficients.- Overrides:
transform
in classAbstractMathTransform1D
- Parameters:
srcPts
- the array containing the source coordinates (cannot benull
).srcOff
- the offset to the point to be transformed in the source array.dstPts
- the array into which the transformed coordinates is returned. May be the same thansrcPts
. May benull
if only the derivative matrix is desired.dstOff
- the offset to the location of the transformed point that is stored in the destination array.derivate
-true
for computing the derivative, orfalse
if not needed.- Returns:
- the matrix of the transform derivative at the given source position,
or
null
if thederivate
argument isfalse
. - See Also:
-
transform
public void transform(double[] srcPts, int srcOff, double[] dstPts, int dstOff, int numPts) Transforms many positions in a list of coordinate values. The default implementation computes the values from thescale
andoffset
coefficients.- Specified by:
transform
in interfaceorg.opengis.referencing.operation.MathTransform
- Overrides:
transform
in classAbstractMathTransform
- Parameters:
srcPts
- the array containing the source point coordinates.srcOff
- the offset to the first point to be transformed in the source array.dstPts
- the array into which the transformed point coordinates are returned. May be the same thansrcPts
.dstOff
- the offset to the location of the first transformed point that is stored in the destination array.numPts
- the number of point objects to be transformed.
-
transform
public void transform(float[] srcPts, int srcOff, float[] dstPts, int dstOff, int numPts) Transforms many positions in a list of coordinate values. The default implementation computes the values from thescale
andoffset
coefficients using thedouble
precision, then casts the result to thefloat
type.- Specified by:
transform
in interfaceorg.opengis.referencing.operation.MathTransform
- Overrides:
transform
in classAbstractMathTransform
- Parameters:
srcPts
- the array containing the source point coordinates.srcOff
- the offset to the first point to be transformed in the source array.dstPts
- the array into which the transformed point coordinates are returned. May be the same thansrcPts
.dstOff
- the offset to the location of the first transformed point that is stored in the destination array.numPts
- the number of point objects to be transformed.
-
transform
public void transform(double[] srcPts, int srcOff, float[] dstPts, int dstOff, int numPts) Transforms many positions in a list of coordinate values. The default implementation computes the values from thescale
andoffset
coefficients using thedouble
precision, then casts the result to thefloat
type.- Specified by:
transform
in interfaceorg.opengis.referencing.operation.MathTransform
- Overrides:
transform
in classAbstractMathTransform
- Parameters:
srcPts
- the array containing the source point coordinates.srcOff
- the offset to the first point to be transformed in the source array.dstPts
- the array into which the transformed point coordinates are returned.dstOff
- the offset to the location of the first transformed point that is stored in the destination array.numPts
- the number of point objects to be transformed.
-
transform
public void transform(float[] srcPts, int srcOff, double[] dstPts, int dstOff, int numPts) Transforms many positions in a list of coordinate values. The default implementation computes the values from thescale
andoffset
coefficients.- Specified by:
transform
in interfaceorg.opengis.referencing.operation.MathTransform
- Overrides:
transform
in classAbstractMathTransform
- Parameters:
srcPts
- the array containing the source point coordinates.srcOff
- the offset to the first point to be transformed in the source array.dstPts
- the array into which the transformed point coordinates are returned.dstOff
- the offset to the location of the first transformed point that is stored in the destination array.numPts
- the number of point objects to be transformed.
-
deltaTransform
public void deltaTransform(double[] srcPts, int srcOff, double[] dstPts, int dstOff, int numPts) Transforms many distance vectors in a list of coordinate values. The default implementation computes the values from thescale
coefficient only.- Specified by:
deltaTransform
in interfaceLinearTransform
- Parameters:
srcPts
- the array containing the source vectors.srcOff
- the offset to the first vector to be transformed in the source array.dstPts
- the array into which the transformed vectors are returned. Can be the same thansrcPts
.dstOff
- the offset to the location of the first transformed vector that is stored in the destination array.numPts
- the number of vector objects to be transformed.- Since:
- 0.7
- See Also:
-
computeHashCode
protected int computeHashCode()Computes a hash value for this transform. This method is invoked byAbstractMathTransform.hashCode()
when first needed.- Overrides:
computeHashCode
in classAbstractMathTransform
- Returns:
- the hash code value. This value may change between different execution of the Apache SIS library.
-
equals
Compares the specified object with this math transform for equality. Two math transforms are considered equal if, given identical source positions, their transformed positions would be equal orapproximately
equal. This method may conservatively returnsfalse
if unsure.The default implementation returns
true
if the following conditions are met:object
is an instance of the same class thanthis
. We require the same class because there is no interface for the various kinds of transform.- If the hash code value has already been computed for both instances, their values are the same (opportunist performance enhancement).
- The contextual parameters are equal according the given comparison mode.
- Specified by:
equals
in interfaceLenientComparable
- Overrides:
equals
in classAbstractMathTransform
- Parameters:
object
- the object to compare with this transform.mode
- the strictness level of the comparison. Default toSTRICT
.- Returns:
true
if the given object is considered equals to this math transform.- See Also:
-
toString
Returns a string representation of this transform as a matrix, for consistency with otherLinearTransform
implementations in Apache SIS.- Overrides:
toString
in classFormattableObject
- Returns:
- the Well Known Text (WKT) or an alternative representation of this object.
-