|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
ObjectFormattableObject
AbstractMathTransform
@ThreadSafe public abstract class AbstractMathTransform
Provides a default implementation for most methods required by the MathTransform
interface. AbstractMathTransform provides a convenient base class from which
transform implementations can be easily derived. It also defines a few additional
Geotk-specific methods for convenience of performance.
The simplest way to implement this abstract class is to provide an implementation for the following methods only:
However more performance may be gained by overriding the other transform method as well.
Two-dimensional transforms
AbstractMathTransform implements also the methods required by the MathTransform2D
interface, but does not implements that interface directly. Subclasses must add
the "implements MathTransform2D" clause themselves, or extend the AbstractMathTransform2D
base class, if they know to map two-dimensional coordinate systems.
| referencing/geotk-referencing (download) | View source code for this class |
| Nested Class Summary | |
|---|---|
protected class |
AbstractMathTransform.Inverse
Default implementation for inverse math transform. |
| Constructor Summary | |
|---|---|
protected |
AbstractMathTransform()
Constructs a math transform. |
| Method Summary | |
|---|---|
protected int |
computeHashCode()
Computes a hash value for this transform. |
Shape |
createTransformedShape(Shape shape)
Transform the specified shape. |
Matrix |
derivative(DirectPosition point)
Gets the derivative of this transform at a point. |
Matrix |
derivative(Point2D point)
Gets the derivative of this transform at a point. |
protected static void |
ensureNonNull(String name,
Object object)
Makes sure that an argument is non-null. |
boolean |
equals(Object object)
Compares the specified object with this math transform for strict equality. |
boolean |
equals(Object object,
ComparisonMode mode)
Compares the specified object with this math transform for equality. |
String |
formatWKT(Formatter formatter)
Formats the inner part of a Well Known Text (WKT) element. |
String |
getName()
Returns a name for this math transform (never null). |
ParameterDescriptorGroup |
getParameterDescriptors()
Returns the parameter descriptors for this math transform, or null if unknown. |
ParameterValueGroup |
getParameterValues()
Returns a copy of the parameter values for this math transform, or null if unknown. |
abstract int |
getSourceDimensions()
Gets the dimension of input points. |
abstract int |
getTargetDimensions()
Gets the dimension of output points. |
int |
hashCode()
Returns a hash value for this transform. |
MathTransform |
inverse()
Returns the inverse transform of this object. |
boolean |
isIdentity()
Tests whether this transform does not move any points. |
protected static double |
rollLongitude(double x,
double bound)
Ensures that the specified longitude stay within the [-bound … bound] range. |
DirectPosition |
transform(DirectPosition ptSrc,
DirectPosition ptDst)
Transforms the specified ptSrc and stores the result in ptDst. |
abstract Matrix |
transform(double[] srcPts,
int srcOff,
double[] dstPts,
int dstOff,
boolean derivate)
Transforms a single coordinate point in an array, and optionally computes the transform derivative at that location. |
void |
transform(double[] srcPts,
int srcOff,
double[] dstPts,
int dstOff,
int numPts)
Transforms a list of coordinate point ordinal values. |
void |
transform(double[] srcPts,
int srcOff,
float[] dstPts,
int dstOff,
int numPts)
Transforms a list of coordinate point ordinal values. |
void |
transform(float[] srcPts,
int srcOff,
double[] dstPts,
int dstOff,
int numPts)
Transforms a list of coordinate point ordinal values. |
void |
transform(float[] srcPts,
int srcOff,
float[] dstPts,
int dstOff,
int numPts)
Transforms a list of coordinate point ordinal values. |
Point2D |
transform(Point2D ptSrc,
Point2D ptDst)
Transforms the specified ptSrc and stores the result in ptDst. |
| Methods inherited from class FormattableObject |
|---|
print, toString, toWKT, toWKT |
| Methods inherited from class Object |
|---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
| Methods inherited from interface MathTransform |
|---|
toWKT |
| Constructor Detail |
|---|
protected AbstractMathTransform()
| Method Detail |
|---|
public String getName()
null). This convenience methods
returns the name of the parameter descriptors if
any, or the short class name otherwise.
null).public abstract int getSourceDimensions()
getSourceDimensions in interface MathTransformpublic abstract int getTargetDimensions()
getTargetDimensions in interface MathTransformpublic ParameterDescriptorGroup getParameterDescriptors()
null if unknown.
This method is similar to OperationMethod.getParameters(), except that typical
MathTransform implementations return parameters in standard units (usually
metres or decimal degrees).
getParameterDescriptors in interface Parameterizednull.OperationMethod.getParameters()public ParameterValueGroup getParameterValues()
null if unknown.
This method is similar to SingleOperation.getParameterValues(), except that typical
MathTransform implementations return parameters in standard units (usually
metres or decimal degrees).
getParameterValues in interface Parameterizednull.
Since this method returns a copy of the parameter values, any change to
a value will have no effect on this math transform.SingleOperation.getParameterValues()public boolean isIdentity()
false.
isIdentity in interface MathTransform
public Point2D transform(Point2D ptSrc,
Point2D ptDst)
throws TransformException
ptSrc and stores the result in ptDst.
The default implementation performs the following steps:
transform(double[],int,double[],int,boolean)
method using a temporary array of doubles.
ptSrc - The coordinate point to be transformed.ptDst - The coordinate point that stores the result of transforming ptSrc,
or null if a new point should be created.
ptSrc and storing the result in
ptDst, or in a new point if ptDst was null.
MismatchedDimensionException - If this transform doesn't map two-dimensional
coordinate systems.
TransformException - If the point can't be transformed.MathTransform2D.transform(Point2D,Point2D)
public DirectPosition transform(DirectPosition ptSrc,
DirectPosition ptDst)
throws TransformException
ptSrc and stores the result in ptDst.
The default implementation performs the following steps:
transform(double[],int,double[],int,boolean) method.
transform in interface MathTransformptSrc - the coordinate point to be transformed.ptDst - the coordinate point that stores the result of transforming ptSrc,
or null.
ptSrc and storing the result
in ptDst, or a newly created point if ptDst was null.
MismatchedDimensionException - if ptSrc or
ptDst doesn't have the expected dimension.
TransformException - if the point can't be transformed.
public abstract Matrix transform(double[] srcPts,
int srcOff,
double[] dstPts,
int dstOff,
boolean derivate)
throws TransformException
Matrix derivative = null;
if (derivate) {
double[] ordinates = Arrays.copyOfRange(srcPts, srcOff, srcOff + getSourceDimensions());
derivative = this.derivative(new GeneralDirectPosition(ordinates));
}
this.transform(srcPts, srcOff, dstPts, dstOff, 1); // May overwrite srcPts.
return derivative;
However this method provides two advantages:
AbstractMathTransform subclasses.
The default transform(double[],int,double[],int,int) method implementation
will invoke this method in a loop, taking care of the iteration strategy depending on the argument value.transform and derivative methods
separately because many internal calculations are the same. Computing those two information
in a single step can help to reduce redundant calculation.
Implementation note
The source and destination may overlap. Consequently, implementors must read all source
ordinate values before to start writing the transformed ordinates in the destination array.
srcPts - The array containing the source coordinate (can not be null).srcOff - The offset to the point to be transformed in the source array.dstPts - the array into which the transformed coordinate 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.
null
if the derivate argument is false.
TransformException - If the point can't be transformed or if a problem occurred while
calculating the derivative.derivative(DirectPosition),
transform(DirectPosition, DirectPosition),
MathTransforms.derivativeAndTransform(MathTransform, double[], int, double[], int)
public void transform(double[] srcPts,
int srcOff,
double[] dstPts,
int dstOff,
int numPts)
throws TransformException
(x0,y0,z0, x1,y1,z1 ...).The default implementation invokes
transform(double[],int,double[],int,boolean)
in a loop, using an iteration strategy determined from the
arguments for iterating over the points.
transform in interface MathTransformsrcPts - 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.
TransformException - if a point can't be transformed. Some implementations will stop
at the first failure, wile some other implementations will fill the un-transformable
points with NaN values, continue and throw the exception
only at end. Implementations that fall in the later case should set the last completed transform to this.
public void transform(float[] srcPts,
int srcOff,
float[] dstPts,
int dstOff,
int numPts)
throws TransformException
transform(double[],int,double[],int,int) using a temporary
array of doubles.
transform in interface MathTransformsrcPts - 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.
TransformException - if a point can't be transformed. Some implementations will stop
at the first failure, wile some other implementations will fill the un-transformable
points with NaN values, continue and throw the exception
only at end. Implementations that fall in the later case should set the last completed transform to this.
public void transform(double[] srcPts,
int srcOff,
float[] dstPts,
int dstOff,
int numPts)
throws TransformException
transform(double[],int,double[],int,int) using a temporary
array of doubles.
transform in interface MathTransformsrcPts - 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.
TransformException - if a point can't be transformed. Some implementations will stop
at the first failure, wile some other implementations will fill the un-transformable
points with NaN values, continue and throw the exception
only at end. Implementations that fall in the later case should set the last completed transform to this.
public void transform(float[] srcPts,
int srcOff,
double[] dstPts,
int dstOff,
int numPts)
throws TransformException
transform(double[],int,double[],int,int) using a temporary
array of doubles if necessary.
transform in interface MathTransformsrcPts - 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.
TransformException - if a point can't be transformed. Some implementations will stop
at the first failure, wile some other implementations will fill the un-transformable
points with NaN values, continue and throw the exception
only at end. Implementations that fall in the later case should set the last completed transform to this.
public Shape createTransformedShape(Shape shape)
throws TransformException
Path2D, but may also be a Line2D or a QuadCurve2D if such
simplification is possible.
shape - Shape to transform.
shape if this transform is the identity transform.
IllegalStateException - if this transform doesn't map 2D coordinate systems.
TransformException - if a transform failed.MathTransform2D.createTransformedShape(Shape)
public Matrix derivative(Point2D point)
throws TransformException
MathTransform2D interface).transform(double[], int, double[], int, boolean) method,
with the derivate boolean argument set to true.TransformException.
point - The coordinate point where to evaluate the derivative.
MismatchedDimensionException - if the input dimension is not 2.
TransformException - if the derivative can't be evaluated at the specified point.MathTransform2D.derivative(Point2D)
public Matrix derivative(DirectPosition point)
throws TransformException
point dimension is equals to this math transform
source dimensions.transform(double[], int, double[], int, boolean) method,
with the derivate boolean argument set to true.TransformException.
derivative in interface MathTransformpoint - The coordinate point where to evaluate the derivative.
null).
NullPointerException - if the derivative dependents on coordinate
and point is null.
MismatchedDimensionException - if point doesn't have the expected dimension.
TransformException - if the derivative can't be evaluated at the specified point.
public MathTransform inverse()
throws NoninvertibleTransformException
this if this transform is an identity transform, and throws
a NoninvertibleTransformException otherwise. Subclasses should override
this method.
inverse in interface MathTransformNoninvertibleTransformExceptionpublic final int hashCode()
computeHashCode()
when first needed and caches the value for future invocations. Subclasses should override
computeHashCode() instead than this method.
hashCode in class Objectprotected int computeHashCode()
hashCode()
when first needed.
public final boolean equals(Object object)
return equals(other, ComparisonMode.STRICT);
equals in interface LenientComparableequals in class Objectobject - The object to compare with this transform.
true if the given object is a transform of the same class and using
the same parameter values.ComparisonMode.STRICT
public boolean equals(Object object,
ComparisonMode mode)
true if the following conditions are meet:
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.The parameter values are not compared because subclasses can typically compare those values more efficiently by accessing to their member fields.
equals in interface LenientComparableobject - The object to compare with this transform.mode - The strictness level of the comparison. Default to STRICT.
true if the given object is a transform of the same class and if, given
identical source position, the transformed position would be the equals.Utilities.deepEquals(Object, Object, ComparisonMode)public String formatWKT(Formatter formatter)
getParameterValues(). The parameter group name is used as the math
transform name.
formatWKT in interface FormattableformatWKT in class FormattableObjectformatter - The formatter to use.
"PARAM_MT" in the default implementation.FormattableObject.toWKT(),
FormattableObject.toString()
protected static void ensureNonNull(String name,
Object object)
throws InvalidParameterValueException
name - Argument name.object - User argument.
InvalidParameterValueException - if object is null.
protected static double rollLongitude(double x,
double bound)
The bound value is typically 180 if the longitude is express in degrees,
or Math.PI it the longitude is express in radians. But it can also be some
other value if the longitude has already been multiplied by a scale factor before
this method is invoked.
x - The longitude.bound - The absolute value of the minimal and maximal allowed value, or
Double.POSITIVE_INFINITY if no rolling should be applied.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||