diff --git a/src/main/java/org/orekit/rugged/los/FixedZHomothety.java b/src/main/java/org/orekit/rugged/los/FixedZHomothety.java new file mode 100644 index 0000000000000000000000000000000000000000..f2d76bea0a330518c34b59f052bddb37b8d26f43 --- /dev/null +++ b/src/main/java/org/orekit/rugged/los/FixedZHomothety.java @@ -0,0 +1,110 @@ +/* Copyright 2013-2016 CS Systèmes d'Information + * Licensed to CS Systèmes d'Information (CS) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * CS licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.orekit.rugged.los; + +import java.util.stream.Stream; + +import org.hipparchus.analysis.differentiation.DerivativeStructure; +import org.hipparchus.geometry.euclidean.threed.FieldVector3D; +import org.hipparchus.geometry.euclidean.threed.Vector3D; +import org.hipparchus.util.FastMath; +import org.orekit.errors.OrekitException; +import org.orekit.rugged.errors.RuggedException; +import org.orekit.rugged.utils.DSGenerator; +import org.orekit.utils.ParameterDriver; +import org.orekit.utils.ParameterObserver; + +/** {@link TimeIndependentLOSTransform LOS transform} based on a homothety along the Z axis. + * inspired from FixedZHomothety / s2geolib + * @author Lucie Labatallee + * @see LOSBuilder + */ +public class FixedZHomothety implements TimeIndependentLOSTransform { + + /** Parameters scaling factor. + * <p> + * We use a power of 2 to avoid numeric noise introduction + * in the multiplications/divisions sequences. + * </p> + */ + private final double SCALE = FastMath.scalb(1.0, -20); + + /** Homothety factor. */ + private double factor; + + /** Underlying homothety with derivatives. */ + private DerivativeStructure factorDS; + + /** Driver for homothety factor. */ + private final ParameterDriver factorDriver; + + /** Simple constructor. + * <p> + * The single parameter is the homothety factor. + * </p> + * @param name name of the homothety (used for estimated parameters identification) + * @param factor homothety factor + */ + public FixedZHomothety(final String name, final double factorvalue) { + this.factor = factorvalue; + this.factorDS = null; + try { + this.factorDriver = new ParameterDriver(name, factorvalue, SCALE, Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY); + factorDriver.addObserver(new ParameterObserver() { + @Override + public void valueChanged(final double previousValue, final ParameterDriver driver) { + // reset factor to zero, they will be evaluated lazily if needed + factor = 0.0; +// System.out.format("Value changed: %f %n", factorDriver.getValue()); + factorDS = null; + } + }); + } catch (OrekitException oe) { + // this should never happen + throw RuggedException.createInternalError(oe); + } + } + + /** {@inheritDoc} */ + @Override + public Stream<ParameterDriver> getParametersDrivers() { + return Stream.of(factorDriver); + } + + /** {@inheritDoc} */ + @Override + public Vector3D transformLOS(final int i, final Vector3D los) { + + if (factor == 0.0) { + // lazy evaluation of the homothety + factor = factorDriver.getValue(); + } + return new Vector3D(los.getX(), los.getY(), factor*los.getZ()); + } + + /** {@inheritDoc} */ + @Override + public FieldVector3D<DerivativeStructure> transformLOS(final int i, final FieldVector3D<DerivativeStructure> los, + final DSGenerator generator) { + if (factorDS == null) { + // lazy evaluation of the homothety + factorDS = generator.variable(factorDriver); + } + return new FieldVector3D<DerivativeStructure>(los.getX(), los.getY(), factorDS.multiply(los.getZ())); + } + +} diff --git a/src/tutorials/java/AffinagePleiades/AffinageRugged.java b/src/tutorials/java/AffinagePleiades/AffinageRugged.java index c1ba241675dee2f023c4e8af3ca8c8afdd485e43..198e8869f09d30a1d622779709f11946c6fed7d2 100644 --- a/src/tutorials/java/AffinagePleiades/AffinageRugged.java +++ b/src/tutorials/java/AffinagePleiades/AffinageRugged.java @@ -62,7 +62,8 @@ public class AffinageRugged { // Initialize Orekit, assuming an orekit-data folder is in user home directory File home = new File(System.getProperty("user.home")); - File orekitData = new File(home, "workspace/data/orekit-data"); + //File orekitData = new File(home, "workspace/data/orekit-data"); + File orekitData = new File(home, "COTS/orekit-data"); DataProvidersManager.getInstance().addProvider(new DirectoryCrawler(orekitData)); @@ -140,10 +141,10 @@ public class AffinageRugged { double rollValue = FastMath.toRadians( 0.1); double pitchValue = FastMath.toRadians(-0.3); + double factorValue = 0.5; + + System.out.format("roll : %3.5f pitch : %3.5f factor : %3.5f \n",rollValue,pitchValue,factorValue); - System.out.format("roll : %3.5f pitch : %3.5f \n",rollValue,pitchValue); - - rugged. getLineSensor("line"). getParametersDrivers(). @@ -155,6 +156,13 @@ public class AffinageRugged { getParametersDrivers(). filter(driver -> driver.getName().equals("pitch")). findFirst().get().setValue(pitchValue); + + rugged. + getLineSensor("line"). + getParametersDrivers(). + filter(driver -> driver.getName().equals("factor")). + findFirst().get().setValue(factorValue); + System.out.format(" **** Generate Measures **** %n"); @@ -162,7 +170,7 @@ public class AffinageRugged { MeasureGenerator measure = new MeasureGenerator(pleiadesViewingModel,rugged); measure.CreateMeasure(1000, 1000); - System.out.format(" **** Reset Roll/Pitch **** %n"); + System.out.format(" **** Reset Roll/Pitch/Factor **** %n"); rugged. getLineSensor(pleiadesViewingModel.getSensorName()). getParametersDrivers(). @@ -175,7 +183,18 @@ public class AffinageRugged { throw new OrekitExceptionWrapper(e); } }); - + rugged. + getLineSensor(pleiadesViewingModel.getSensorName()). + getParametersDrivers(). + filter(driver -> driver.getName().equals("factor")). + forEach(driver -> { + try { + driver.setSelected(true); + driver.setValue(1.0); // default value: no Z scale factor applied + } catch (OrekitException e) { + throw new OrekitExceptionWrapper(e); + } + }); System.out.format(" **** Start optimization **** %n"); @@ -204,7 +223,14 @@ public class AffinageRugged { filter(driver -> driver.getName().equals("pitch")). findFirst().get().getValue(); double pitchError = (estimatedPitch - pitchValue); - System.out.format("Estimated pitch %3.5f pitch error %3.6e %n ", estimatedPitch, pitchError); + System.out.format("Estimated pitch %3.5f pitch error %3.6e %n ", estimatedPitch, pitchError); + + double estimatedFactor = rugged.getLineSensor(pleiadesViewingModel.getSensorName()). + getParametersDrivers(). + filter(driver -> driver.getName().equals("factor")). + findFirst().get().getValue(); + double factorError = (estimatedFactor - factorValue); + System.out.format("Estimated factor %3.5f factor error %3.6e %n ", estimatedFactor, factorError); diff --git a/src/tutorials/java/AffinagePleiades/PleiadesViewingModel.java b/src/tutorials/java/AffinagePleiades/PleiadesViewingModel.java index 60b46b21bbe89465f013c2e6be4b85a49dccbc9b..5f85a0335aa3404a303baccb1dda33b91155ba70 100644 --- a/src/tutorials/java/AffinagePleiades/PleiadesViewingModel.java +++ b/src/tutorials/java/AffinagePleiades/PleiadesViewingModel.java @@ -28,6 +28,7 @@ import java.util.List; import org.orekit.rugged.los.FixedRotation; +import org.orekit.rugged.los.FixedZHomothety; import org.orekit.rugged.los.LOSBuilder; import org.orekit.rugged.los.TimeDependentLOS; import org.orekit.time.AbsoluteDate; @@ -89,6 +90,7 @@ public class PleiadesViewingModel { losBuilder.addTransform(new FixedRotation("roll", Vector3D.MINUS_I, 0.0)); losBuilder.addTransform(new FixedRotation("pitch", Vector3D.MINUS_J, 0.0)); + losBuilder.addTransform(new FixedZHomothety("factor", 1.0)); return losBuilder.build(); }