public class TransformSeparator extends Object
MathTransform
and source or target dimension indices.
Given an arbitrary MathTransform
, this class tries to return a new math transform that operates
only on a given set of source or target dimensions.
transform
has (x,y,z) inputs
and (λ,φ,h) outputs, then the following code:
TransformSeparator s = new TransformSeparator(theTransform); s.addSourceDimensionRange(0, 2); MathTransform mt = s.separate();will return a transform with (x,y) inputs and (probably) (λ,φ) outputs. The output dimensions can be verified with a call to
getTargetDimensions()
.Defined in the sis-referencing
module
Modifier and Type | Field and Description |
---|---|
protected MathTransformFactory |
factory
The factory to use for creating new math transforms.
|
protected int[] |
sourceDimensions
Indices of transform input dimensions to keep, or
null if not yet defined. |
protected int[] |
targetDimensions
Indices of transform output dimensions to keep, or
null if not yet defined. |
protected MathTransform |
transform
The transform to separate.
|
Constructor and Description |
---|
TransformSeparator(MathTransform transform)
Constructs a separator for the given transform.
|
TransformSeparator(MathTransform transform,
MathTransformFactory factory)
Constructs a separator for the given transform and using the given factory.
|
Modifier and Type | Method and Description |
---|---|
void |
addSourceDimensionRange(int lower,
int upper)
Adds a range of input dimensions to keep in the separated transform.
|
void |
addSourceDimensions(int... dimensions)
Adds input dimensions to keep in the separated transform.
|
void |
addTargetDimensionRange(int lower,
int upper)
Adds a range of output dimensions to keep in the separated transform.
|
void |
addTargetDimensions(int... dimensions)
Adds output dimensions to keep in the separated transform.
|
void |
clear()
Clears any source and target dimension
settings.
|
protected MathTransform |
filterSourceDimensions(MathTransform step,
int[] dimensions)
Creates a transform for the same mathematic than the given
step
but expecting only the given dimensions as inputs. |
protected MathTransform |
filterTargetDimensions(MathTransform step,
int[] dimensions)
Creates a transform for the same mathematic than the given
step
but producing only the given dimensions as outputs. |
int[] |
getSourceDimensions()
Returns the input dimensions to keep or kept in the separated transform.
|
int[] |
getTargetDimensions()
Returns the output dimensions to keep or kept in the separated transform.
|
MathTransform |
separate()
Separates the math transform specified at construction time for given dimension indices.
|
protected final MathTransform transform
protected int[] sourceDimensions
null
if not yet defined.
If non-null, the indices in the array must be sorted in strictly increasing order.
This sequence can contain any integers in the range 0 inclusive to
MathTransform.getSourceDimensions()
exclusive.
Values in this array should never be modified. For adding, removing or editing indices,
new arrays should be created and assigned to this field. This approach makes easier to keep snapshots
of indices arrays at various stages during the process of separating a MathTransform
.
protected int[] targetDimensions
null
if not yet defined.
If non-null, the indices in the array must be sorted in strictly increasing order.
This sequence can contain any integers in the range 0 inclusive to
MathTransform.getTargetDimensions()
exclusive.
Values in this array should never be modified. For adding, removing or editing indices,
new arrays should be created and assigned to this field. This approach makes easier to keep snapshots
of indices arrays at various stages during the process of separating a MathTransform
.
protected final MathTransformFactory factory
public TransformSeparator(MathTransform transform)
transform
- the transform to separate.public TransformSeparator(MathTransform transform, MathTransformFactory factory)
transform
- the transform to separate.factory
- the factory to use for creating new math transforms.public void clear()
MathTransform
needs to be separated in more than one
part, for example an horizontal and a vertical component.public void addSourceDimensions(int... dimensions) throws IllegalArgumentException
Constraints:
MathTransform.getSourceDimensions()
exclusive.dimensions
values shall be in strictly increasing order.dimensions
values shall be greater than all values specified by all previous calls
of this method since construction or since the last call to clear()
.dimensions
- a sequence of source dimensions to keep, in strictly increasing order.IllegalArgumentException
- if dimensions
contains negative values
or if values are not in a strictly increasing order.public void addSourceDimensionRange(int lower, int upper) throws IllegalArgumentException
lower
and upper
values define a range of source dimension indices
of the transform given to the constructor.lower
- the lower dimension, inclusive. Shall not be smaller than 0.upper
- the upper dimension, exclusive. Shall be smaller than MathTransform.getSourceDimensions()
.IllegalArgumentException
- if lower
or upper
are out of bounds.public int[] getSourceDimensions() throws IllegalStateException
addSourceDimensions(int...)
or addSourceDimensionRange(int, int)
since construction or since last call to clear()
.
In such case, this method returns all specified source dimensions.separate()
has been invoked.
In such case, this method returns the sequence of source dimensions that separate()
chooses to retain.
It is often, but not necessarily, all source dimensions of the transform given at construction time.IllegalStateException
- if input dimensions have not been set and
separate()
has not yet been invoked.public void addTargetDimensions(int... dimensions) throws IllegalArgumentException
Constraints:
MathTransform.getTargetDimensions()
exclusive.dimensions
values shall be in strictly increasing order.dimensions
values shall be greater than all values specified by all previous calls
of this method since construction or since the last call to clear()
.dimensions
- a sequence of target dimensions to keep, in strictly increasing order.IllegalArgumentException
- if dimensions
contains negative values
or if values are not in a strictly increasing order.public void addTargetDimensionRange(int lower, int upper) throws IllegalArgumentException
lower
and upper
values define a range of target dimension indices
of the transform given to the constructor.lower
- the lower dimension, inclusive. Shall not be smaller than 0.upper
- the upper dimension, exclusive. Shall be smaller than MathTransform.getTargetDimensions()
.IllegalArgumentException
- if lower
or upper
are out of bounds.public int[] getTargetDimensions() throws IllegalStateException
addTargetDimensions(int...)
or addTargetDimensionRange(int, int)
since construction or since last call to clear()
.
In such case, this method returns all specified target dimensions.separate()
has been invoked.
In such case, the target dimensions are inferred automatically from the source dimensions and the transform.IllegalStateException
- if output dimensions have not been set and
separate()
has not yet been invoked.public MathTransform separate() throws FactoryException
getSourceDimensions()
or getTargetDimensions()
after this separate()
method.FactoryException
- if the transform can not be separated.protected MathTransform filterSourceDimensions(MathTransform step, int[] dimensions) throws FactoryException
step
but expecting only the given dimensions as inputs.
This method is invoked by separate()
when user-specified source dimensions need to be taken in account.
The given step
and dimensions
are typically the values of
transform
and sourceDimensions
fields respectively, but not necessarily.
In particular those arguments will differ when this method is invoked recursively for processing
concatenated or sub-transforms.
Subclasses can override this method if they need to handle some MathTransform
implementations
in a special way. However all implementations of this method shall obey to the following contract:
sourceDimensions
and targetDimensions
should not be assumed accurate
since they may be temporarily outdated or modified during recursive calls to this method.sourceDimensions
should not be modified by this method.targetDimensions
must be overwritten (not updated) by this method to the
sequence of all target dimensions of step
that are also target dimensions of the returned transform.
The indices shall be in strictly increasing order from 0 inclusive to
step.getTargetDimensions()
exclusive.step
- the transform for which to retain only a subset of the source dimensions.dimensions
- indices of the source dimensions of step
to retain.FactoryException
- if the given transform is not separable.protected MathTransform filterTargetDimensions(MathTransform step, int[] dimensions) throws FactoryException
step
but producing only the given dimensions as outputs.
This method is invoked by separate()
when user-specified target dimensions need to be taken in account.
The given step
and dimensions
are typically the values of
transform
and targetDimensions
fields respectively, but not necessarily.
Subclasses can override this method if they need to handle some MathTransform
implementations
in a special way. However all implementations of this method shall obey to the following contract:
sourceDimensions
and targetDimensions
should not be assumed accurate.sourceDimensions
should not be modified by this method.targetDimensions
should not be modified by this method.transform
has (longitude, latitude, height) outputs, then a filtered
transform may keep only the (longitude, latitude) part for the same inputs.
In most cases, the filtered transform is non-invertible since it loose informations.step
- the transform for which to retain only a subset of the target dimensions.dimensions
- indices of the target dimensions of step
to retain.FactoryException
- if the given transform is not separable.Copyright © 2010–2017 The Apache Software Foundation. All rights reserved.