/** * Returns the sample dimension that describes real values. This method establishes a unidirectional navigation * from sample values to real values. This is in contrast to {@link #converse}, which establish a bidirectional * navigation. * * @see #forConvertedValues(boolean) */ private SampleDimension converted() { // Transfer function shall never be null if 'converse' is non-null. return (converse != null && !transferFunction.isIdentity()) ? converse : this; }
public boolean isIdentity() { return transform.isIdentity(); }
/** * Returns a sample dimension that describes real values or sample values, depending if {@code converted} is {@code true} * or {@code false} respectively. If there is no {@linkplain #getTransferFunction() transfer function}, then this method * returns {@code this}. * * @param converted {@code true} for a sample dimension representing converted values, * or {@code false} for a sample dimension representing sample values. * @return a sample dimension representing converted or sample values, depending on {@code converted} argument value. * May be {@code this} but never {@code null}. */ public SampleDimension forConvertedValues(final boolean converted) { // Transfer function shall never be null if 'converse' is non-null. if (converse != null && transferFunction.isIdentity() != converted) { return converse; } return this; }
/** * Returns {@code true} if at least one of the specified sample dimensions has a * {@linkplain SampleDimension#getSampleToGeophysics sample to geophysics} transform * which is not the identity transform. */ public static boolean hasTransform(final SampleDimension[] sampleDimensions) { for (int i=sampleDimensions.length; --i>=0;) { SampleDimension sd = sampleDimensions[i]; if (sd instanceof GridSampleDimension) { sd = ((GridSampleDimension) sd).geophysics(false); } MathTransform1D tr = sd.getSampleToGeophysics(); return tr!=null && !tr.isIdentity(); } return false; }
/** * Returns {@code true} if at least one of the specified sample dimensions has a * {@linkplain SampleDimension#getSampleToGeophysics sample to geophysics} transform * which is not the identity transform. */ public static boolean hasTransform(final SampleDimension[] sampleDimensions) { for (int i=sampleDimensions.length; --i>=0;) { SampleDimension sd = sampleDimensions[i]; if (sd instanceof GridSampleDimension) { sd = ((GridSampleDimension) sd).geophysics(false); } MathTransform1D tr = sd.getSampleToGeophysics(); if (tr!=null && !tr.isIdentity()) { return true; } } return false; }
/** * Changes the mapping from sample to geophysics values. */ public Category rescale(MathTransform1D sampleToGeophysics) { if (sampleToGeophysics.isIdentity()) { return this; } sampleToGeophysics = (MathTransform1D) ConcatenatedTransform.create( inverse.getSampleToGeophysics(), sampleToGeophysics); return inverse.rescale(sampleToGeophysics).inverse; }
/** * Changes the mapping from sample to geophysics values. */ @Override public Category rescale(MathTransform1D sampleToGeophysics) { if (sampleToGeophysics.isIdentity()) { return this; } sampleToGeophysics = (MathTransform1D) ConcatenatedTransform.create( inverse.getSampleToGeophysics(), sampleToGeophysics); return inverse.rescale(sampleToGeophysics).inverse; }
/** * Returns the conversion from the given CRS to the CRS of this extent, or {@code null} if none or unknown. * The returned {@code MathTransform1D} may apply unit conversions or axis direction reversal, but usually * not datum shift. * * @param source the CRS from which to perform the conversions, or {@code null} if unknown. * @return the conversion from {@code source}, or {@code null} if none or unknown. * @throws UnsupportedOperationException if the {@code sis-referencing} module is not on the classpath. * @throws FactoryException if the coordinate operation factory is not available. * @throws ClassCastException if the conversion is not an instance of {@link MathTransform1D}. */ private MathTransform1D getConversionFrom(final VerticalCRS source) throws FactoryException { if (!Utilities.equalsIgnoreMetadata(verticalCRS, source) && verticalCRS != null && source != null) { final MathTransform1D cv = (MathTransform1D) ReferencingServices.getInstance() .getCoordinateOperationFactory(null, null, null, null) .createOperation(source, verticalCRS).getMathTransform(); if (!cv.isIdentity()) { return cv; } } return null; }
/** * Returns the conversion from the given CRS to the CRS of this extent, or {@code null} if none or unknown. * The returned {@code MathTransform1D} may apply unit conversions or axis direction reversal, but usually * not datum shift. * * @param source the CRS from which to perform the conversions, or {@code null} if unknown. * @return the conversion from {@code source}, or {@code null} if none or unknown. * @throws UnsupportedOperationException if the {@code sis-referencing} module is not on the classpath. * @throws FactoryException if the coordinate operation factory is not available. * @throws ClassCastException if the conversion is not an instance of {@link MathTransform1D}. */ private MathTransform1D getConversionFrom(final VerticalCRS source) throws FactoryException { if (!Utilities.equalsIgnoreMetadata(verticalCRS, source) && verticalCRS != null && source != null) { final MathTransform1D cv = (MathTransform1D) ReferencingServices.getInstance() .getCoordinateOperationFactory(null, null, null, null) .createOperation(source, verticalCRS).getMathTransform(); if (!cv.isIdentity()) { return cv; } } return null; }
if (sampleToGeophysics.isIdentity()) { inverse = this; } else {
if (sampleToGeophysics.isIdentity()) { inverse = this; } else {
if (toUnits != null) { toConverse = toUnits; if (toUnits.isIdentity()) { converse = this; if (!(samples instanceof MeasurementRange<?>)) {
if (!Double.isNaN(offset)) tr.setOffset(offset); final MathTransform1D mt = tr.getTransform(); if (!mt.isIdentity()) {
/** * Creates a category for data that are already real values. */ @Test public void testConvertedCategory() { final Random random = TestUtilities.createRandomNumberGenerator(); for (int pass=0; pass<3; pass++) { final double lower = random.nextDouble() * 5; final double upper = random.nextDouble() * 10 + lower; final Category category = new Category("Random", NumberRange.create(lower, true, upper, true), (MathTransform1D) MathTransforms.identity(1), null, null); assertSame ("converse", category, category.converse); assertEquals ("name", "Random", String.valueOf(category.name)); assertEquals ("name", "Random", String.valueOf(category.getName())); assertEquals ("minimum", lower, category.minimum, STRICT); assertEquals ("maximum", upper, category.maximum, STRICT); assertBoundEquals("range.minValue", lower, category.range.getMinValue()); assertBoundEquals("range.maxValue", upper, category.range.getMaxValue()); assertSame ("sampleRange", category.range, category.getSampleRange()); assertSame ("measurementRange", category.range, category.getMeasurementRange().get()); assertSame ("transferFunction", category.toConverse, category.getTransferFunction().get()); assertTrue ("toConverse.isIdentity", category.toConverse.isIdentity()); assertTrue ("isQuantitative", category.isQuantitative()); } }
assertFalse ("identity", dimension.getTransferFunction().get().isIdentity()); assertFalse ("identity", tr.getTransform().isIdentity()); assertEquals("scale", scale, tr.getScale(), STRICT); assertEquals("offset", offset, tr.getOffset(), STRICT); assertSame (dimension, converted.forConvertedValues(false)); assertSame (converted, converted.forConvertedValues(true)); assertTrue ("identity", converted.getTransferFunction().get().isIdentity()); assertTrue ("background", Double.isNaN(converted.getBackground().get().doubleValue()));
assertTrue("identity", tr.isIdentity());
/** * Tests construction from categories that already describe real values. * The constructor should have replaced {@link ConvertedCategory} instances * by plain {@link Category} instances without relationship with the sample values. */ @Test public void testFromConvertedCategories() { final Category[] categories = categories(); for (int i=0; i<categories.length; i++) { categories[i] = categories[i].converse; } final CategoryList list = new CategoryList(categories, null); assertSorted(list); for (int i=list.size(); --i >= 0;) { final Category category = list.get(i); assertSame(category, category.converse); assertTrue(category.toConverse.isIdentity()); } } }
/** * Tests a category with a NaN value. */ @Test public void testCategoryNaN() { final Category category = new Category("NaN", new NumberRange<>(Float.class, Float.NaN, true, Float.NaN, true), null, null, null); final NumberRange<?> range = category.getSampleRange(); assertSame ("converse", category, category.converse); assertEquals("name", "NaN", String.valueOf(category.name)); assertEquals("name", "NaN", String.valueOf(category.getName())); assertEquals("minimum", Double.NaN, category.minimum, STRICT); assertEquals("maximum", Double.NaN, category.maximum, STRICT); assertNull ("sampleRange", category.range); assertEquals("range.minValue", Float.NaN, range.getMinValue()); assertEquals("range.maxValue", Float.NaN, range.getMaxValue()); assertFalse ("measurementRange", category.getMeasurementRange().isPresent()); assertFalse ("transferFunction", category.getTransferFunction().isPresent()); assertTrue ("toConverse.isIdentity", category.toConverse.isIdentity()); assertFalse ("isQuantitative", category.isQuantitative()); } }
assertSame ("transferFunction", category.toConverse, category.getTransferFunction().get()); assertNotSame ("transferFunction", converse.toConverse, converse.getTransferFunction().get()); assertTrue ("transferFunction", converse.getTransferFunction().get().isIdentity()); assertFalse ("toConverse.isIdentity", category.toConverse.isIdentity()); assertFalse ("toConverse.isIdentity", converse.toConverse.isIdentity()); assertTrue ("isQuantitative", category.isQuantitative()); assertTrue ("isQuantitative", converse.isQuantitative());
assertSame ("sampleRange", category.range, category.getSampleRange()); assertFalse ("measurementRange", category.getMeasurementRange().isPresent()); assertFalse ("toConverse.isIdentity", category.toConverse.isIdentity()); assertFalse ("transferFunction", category.getTransferFunction().isPresent()); assertFalse ("isQuantitative", category.isQuantitative()); assertNotNull("sampleRange", converse.getSampleRange()); assertFalse ("measurementRange", category.getMeasurementRange().isPresent()); assertFalse ("toConverse.isIdentity", converse.toConverse.isIdentity()); assertFalse ("transferFunction", converse.getTransferFunction().isPresent()); assertFalse ("isQuantitative", converse.isQuantitative());