Class LinearTransform1D

All Implemented Interfaces:
Serializable, Parameterized, LinearTransform, LenientComparable, org.opengis.referencing.operation.MathTransform, org.opengis.referencing.operation.MathTransform1D
Direct Known Subclasses:
ConstantTransform1D, IdentityTransform1D

class LinearTransform1D extends AbstractMathTransform1D implements LinearTransform, Serializable
A one dimensional, linear transform. Input values x are converted into output values y using the following equation:
y  =  x × scale + offset
This 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

    Fields
    Modifier and Type
    Field
    Description
    private 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

    Constructors
    Modifier
    Constructor
    Description
    protected
    LinearTransform1D(double scale, double offset)
    Constructs a new linear transform.
  • Method Summary

    Modifier and Type
    Method
    Description
    protected 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.
    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.
    Creates the inverse transform of this object.
    boolean
    Returns true since this transform is affine.
    boolean
    Tests whether this transform does not move any points.
    Returns a string representation of this transform as a matrix, for consistency with other LinearTransform 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 serialVersionUID
      Serial number for inter-operability with different versions.
      See Also:
    • NEGATE

      static final LinearTransform1D NEGATE
      A transform that just reverse the sign of input values.
    • scale

      final double scale
      The value which is multiplied to input values.
    • offset

      final double offset
      The value to add to input values.
    • inverse

      private transient org.opengis.referencing.operation.MathTransform1D inverse
      The 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 - the scale term in the linear equation.
      offset - the offset term in the linear equation.
      See Also:
  • Method Details

    • create

      public static LinearTransform1D create(double scale, double offset)
      Constructs a new linear transform.
      Parameters:
      scale - the scale term in the linear equation.
      offset - the offset term in the linear equation.
      Returns:
      the linear transform for the given scale and offset.
      See Also:
    • constant

      static LinearTransform1D constant(double x, double y)
      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 interface Parameterized
      Overrides:
      getParameterDescriptors in class AbstractMathTransform
      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 interface Parameterized
      Overrides:
      getParameterValues in class AbstractMathTransform
      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 interface LinearTransform
      Returns:
      the coefficients of this linear transform as a matrix.
      See Also:
    • inverse

      public LinearTransform1D inverse() throws org.opengis.referencing.operation.NoninvertibleTransformException
      Creates the inverse transform of this object.
      Specified by:
      inverse in interface LinearTransform
      Specified by:
      inverse in interface org.opengis.referencing.operation.MathTransform
      Specified by:
      inverse in interface org.opengis.referencing.operation.MathTransform1D
      Overrides:
      inverse in class AbstractMathTransform1D
      Returns:
      the inverse transform.
      Throws:
      org.opengis.referencing.operation.NoninvertibleTransformException - if the transform cannot be inverted.
      See Also:
    • isAffine

      public boolean isAffine()
      Returns true since this transform is affine.
      Specified by:
      isAffine in interface LinearTransform
      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 returns false, since MathTransforms.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 interface org.opengis.referencing.operation.MathTransform
      Overrides:
      isIdentity in class AbstractMathTransform
    • 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 interface org.opengis.referencing.operation.MathTransform
      Overrides:
      derivative in class AbstractMathTransform1D
      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 interface org.opengis.referencing.operation.MathTransform1D
      Specified by:
      derivative in class AbstractMathTransform1D
      Parameters:
      value - ignored for a linear transform. Can be NaN.
      Returns:
      the derivative at the given point.
    • transform

      public double transform(double value)
      Transforms the specified value.
      Specified by:
      transform in interface org.opengis.referencing.operation.MathTransform1D
      Specified by:
      transform in class AbstractMathTransform1D
      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 the scale and offset coefficients.
      Overrides:
      transform in class AbstractMathTransform1D
      Parameters:
      srcPts - the array containing the source coordinates (cannot be null).
      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 than srcPts. May be null 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, or false if not needed.
      Returns:
      the matrix of the transform derivative at the given source position, or null if the derivate argument is false.
      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 the scale and offset coefficients.
      Specified by:
      transform in interface org.opengis.referencing.operation.MathTransform
      Overrides:
      transform in class AbstractMathTransform
      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 than srcPts.
      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 the scale and offset coefficients using the double precision, then casts the result to the float type.
      Specified by:
      transform in interface org.opengis.referencing.operation.MathTransform
      Overrides:
      transform in class AbstractMathTransform
      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 than srcPts.
      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 the scale and offset coefficients using the double precision, then casts the result to the float type.
      Specified by:
      transform in interface org.opengis.referencing.operation.MathTransform
      Overrides:
      transform in class AbstractMathTransform
      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 the scale and offset coefficients.
      Specified by:
      transform in interface org.opengis.referencing.operation.MathTransform
      Overrides:
      transform in class AbstractMathTransform
      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 the scale coefficient only.
      Specified by:
      deltaTransform in interface LinearTransform
      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 than srcPts.
      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 by AbstractMathTransform.hashCode() when first needed.
      Overrides:
      computeHashCode in class AbstractMathTransform
      Returns:
      the hash code value. This value may change between different execution of the Apache SIS library.
    • equals

      public boolean equals(Object object, ComparisonMode mode)
      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 or approximately equal. This method may conservatively returns false if unsure.

      The default implementation returns true if the following conditions are met:

      • object is an instance of the same class than this. 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 interface LenientComparable
      Overrides:
      equals in class AbstractMathTransform
      Parameters:
      object - the object to compare with this transform.
      mode - the strictness level of the comparison. Default to STRICT.
      Returns:
      true if the given object is considered equals to this math transform.
      See Also:
    • toString

      public String toString()
      Returns a string representation of this transform as a matrix, for consistency with other LinearTransform implementations in Apache SIS.
      Overrides:
      toString in class FormattableObject
      Returns:
      the Well Known Text (WKT) or an alternative representation of this object.