From f62b3ce9ebb8804ce5d1b3b13ba6605a7f517b95 Mon Sep 17 00:00:00 2001 From: Guylaine Prat <guylaine.prat@c-s.fr> Date: Wed, 12 Dec 2018 11:28:09 +0100 Subject: [PATCH] Remove use of OrekitExceptionWrapper. Fixes #373 --- .../rugged/adjustment/AdjustmentContext.java | 4 +-- .../GroundOptimizationProblemBuilder.java | 4 --- ...nterSensorsOptimizationProblemBuilder.java | 4 --- .../OptimizationProblemBuilder.java | 21 ++++++---------- .../org/orekit/rugged/api/RuggedTest.java | 11 +------- .../rugged/linesensor/FixedRotationTest.java | 25 ++++++++----------- .../linesensor/PolynomialRotationTest.java | 25 ++++++++----------- .../examples/refiningPleiades/Refining.java | 23 ++++++----------- 8 files changed, 36 insertions(+), 81 deletions(-) diff --git a/src/main/java/org/orekit/rugged/adjustment/AdjustmentContext.java b/src/main/java/org/orekit/rugged/adjustment/AdjustmentContext.java index f50e47c8..094bd7b5 100644 --- a/src/main/java/org/orekit/rugged/adjustment/AdjustmentContext.java +++ b/src/main/java/org/orekit/rugged/adjustment/AdjustmentContext.java @@ -26,7 +26,6 @@ import java.util.Map; import org.hipparchus.optim.nonlinear.vector.leastsquares.LeastSquaresOptimizer.Optimum; import org.hipparchus.optim.nonlinear.vector.leastsquares.LeastSquaresProblem; import org.orekit.errors.OrekitException; -import org.orekit.errors.OrekitExceptionWrapper; import org.orekit.rugged.api.Rugged; import org.orekit.rugged.errors.RuggedException; import org.orekit.rugged.errors.RuggedExceptionWrapper; @@ -163,8 +162,7 @@ public class AdjustmentContext { } catch (RuggedExceptionWrapper rew) { throw rew.getException(); - } catch (OrekitExceptionWrapper oew) { - final OrekitException oe = oew.getException(); + } catch (OrekitException oe) { throw new RuggedException(oe, oe.getSpecifier(), oe.getParts()); } } diff --git a/src/main/java/org/orekit/rugged/adjustment/GroundOptimizationProblemBuilder.java b/src/main/java/org/orekit/rugged/adjustment/GroundOptimizationProblemBuilder.java index 3773d5c7..566d791f 100644 --- a/src/main/java/org/orekit/rugged/adjustment/GroundOptimizationProblemBuilder.java +++ b/src/main/java/org/orekit/rugged/adjustment/GroundOptimizationProblemBuilder.java @@ -34,8 +34,6 @@ import org.hipparchus.optim.nonlinear.vector.leastsquares.ParameterValidator; import org.hipparchus.util.FastMath; import org.hipparchus.util.Pair; import org.orekit.bodies.GeodeticPoint; -import org.orekit.errors.OrekitException; -import org.orekit.errors.OrekitExceptionWrapper; import org.orekit.rugged.api.Rugged; import org.orekit.rugged.errors.RuggedException; import org.orekit.rugged.errors.RuggedExceptionWrapper; @@ -220,8 +218,6 @@ public class GroundOptimizationProblemBuilder extends OptimizationProblemBuilder } catch (RuggedException re) { throw new RuggedExceptionWrapper(re); - } catch (OrekitException oe) { - throw new OrekitExceptionWrapper(oe); } }; diff --git a/src/main/java/org/orekit/rugged/adjustment/InterSensorsOptimizationProblemBuilder.java b/src/main/java/org/orekit/rugged/adjustment/InterSensorsOptimizationProblemBuilder.java index 41dd778e..5da3c156 100644 --- a/src/main/java/org/orekit/rugged/adjustment/InterSensorsOptimizationProblemBuilder.java +++ b/src/main/java/org/orekit/rugged/adjustment/InterSensorsOptimizationProblemBuilder.java @@ -35,8 +35,6 @@ import org.hipparchus.optim.nonlinear.vector.leastsquares.LeastSquaresProblem; import org.hipparchus.optim.nonlinear.vector.leastsquares.MultivariateJacobianFunction; import org.hipparchus.optim.nonlinear.vector.leastsquares.ParameterValidator; import org.hipparchus.util.Pair; -import org.orekit.errors.OrekitException; -import org.orekit.errors.OrekitExceptionWrapper; import org.orekit.rugged.api.Rugged; import org.orekit.rugged.errors.RuggedException; import org.orekit.rugged.errors.RuggedExceptionWrapper; @@ -254,8 +252,6 @@ public class InterSensorsOptimizationProblemBuilder extends OptimizationProblemB } catch (RuggedException re) { throw new RuggedExceptionWrapper(re); - } catch (OrekitException oe) { - throw new OrekitExceptionWrapper(oe); } }; diff --git a/src/main/java/org/orekit/rugged/adjustment/OptimizationProblemBuilder.java b/src/main/java/org/orekit/rugged/adjustment/OptimizationProblemBuilder.java index 2c607efe..954cc914 100644 --- a/src/main/java/org/orekit/rugged/adjustment/OptimizationProblemBuilder.java +++ b/src/main/java/org/orekit/rugged/adjustment/OptimizationProblemBuilder.java @@ -30,13 +30,11 @@ import org.hipparchus.optim.ConvergenceChecker; import org.hipparchus.optim.nonlinear.vector.leastsquares.LeastSquaresProblem; import org.hipparchus.optim.nonlinear.vector.leastsquares.MultivariateJacobianFunction; import org.hipparchus.optim.nonlinear.vector.leastsquares.ParameterValidator; -import org.orekit.errors.OrekitException; -import org.orekit.errors.OrekitExceptionWrapper; +import org.orekit.rugged.adjustment.measurements.Observables; import org.orekit.rugged.errors.RuggedException; import org.orekit.rugged.errors.RuggedExceptionWrapper; import org.orekit.rugged.errors.RuggedMessages; import org.orekit.rugged.linesensor.LineSensor; -import org.orekit.rugged.adjustment.measurements.Observables; import org.orekit.rugged.utils.DSGenerator; import org.orekit.utils.ParameterDriver; @@ -151,19 +149,14 @@ abstract class OptimizationProblemBuilder { // Prevent parameters to exceed their prescribed bounds final ParameterValidator validator = params -> { - try { - int i = 0; - for (final ParameterDriver driver : this.drivers) { - - // let the parameter handle min/max clipping - driver.setNormalizedValue(params.getEntry(i)); - params.setEntry(i++, driver.getNormalizedValue()); - } - return params; + int i = 0; + for (final ParameterDriver driver : this.drivers) { - } catch (OrekitException oe) { - throw new OrekitExceptionWrapper(oe); + // let the parameter handle min/max clipping + driver.setNormalizedValue(params.getEntry(i)); + params.setEntry(i++, driver.getNormalizedValue()); } + return params; }; return validator; diff --git a/src/test/java/org/orekit/rugged/api/RuggedTest.java b/src/test/java/org/orekit/rugged/api/RuggedTest.java index 60eb4409..f258f20a 100644 --- a/src/test/java/org/orekit/rugged/api/RuggedTest.java +++ b/src/test/java/org/orekit/rugged/api/RuggedTest.java @@ -54,7 +54,6 @@ import org.orekit.bodies.GeodeticPoint; import org.orekit.data.DataProvidersManager; import org.orekit.data.DirectoryCrawler; import org.orekit.errors.OrekitException; -import org.orekit.errors.OrekitExceptionWrapper; import org.orekit.forces.gravity.potential.NormalizedSphericalHarmonicsProvider; import org.orekit.frames.Frame; import org.orekit.frames.FramesFactory; @@ -1316,8 +1315,6 @@ public class RuggedTest { rollDriver.setValue(roll); pitchDriver.setValue(0); return rugged.inverseLocation("line", gp[referencePixel], 0, dimension).getLineNumber(); - } catch (OrekitException e) { - throw new OrekitExceptionWrapper(e); } catch (RuggedException e) { throw new RuggedExceptionWrapper(e); } @@ -1331,8 +1328,6 @@ public class RuggedTest { rollDriver.setValue(0); pitchDriver.setValue(pitch); return rugged.inverseLocation("line", gp[referencePixel], 0, dimension).getLineNumber(); - } catch (OrekitException e) { - throw new OrekitExceptionWrapper(e); } catch (RuggedException e) { throw new RuggedExceptionWrapper(e); } @@ -1346,8 +1341,6 @@ public class RuggedTest { rollDriver.setValue(roll); pitchDriver.setValue(0); return rugged.inverseLocation("line", gp[referencePixel], 0, dimension).getPixelNumber(); - } catch (OrekitException e) { - throw new OrekitExceptionWrapper(e); } catch (RuggedException e) { throw new RuggedExceptionWrapper(e); } @@ -1361,8 +1354,6 @@ public class RuggedTest { rollDriver.setValue(0); pitchDriver.setValue(pitch); return rugged.inverseLocation("line", gp[referencePixel], 0, dimension).getPixelNumber(); - } catch (OrekitException e) { - throw new OrekitExceptionWrapper(e); } catch (RuggedException e) { throw new RuggedExceptionWrapper(e); } @@ -1373,7 +1364,7 @@ public class RuggedTest { } catch (InvocationTargetException | NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException | URISyntaxException | - OrekitExceptionWrapper | RuggedExceptionWrapper e) { + OrekitException | RuggedExceptionWrapper e) { Assert.fail(e.getLocalizedMessage()); } } diff --git a/src/test/java/org/orekit/rugged/linesensor/FixedRotationTest.java b/src/test/java/org/orekit/rugged/linesensor/FixedRotationTest.java index 946e1f0d..14cf298f 100644 --- a/src/test/java/org/orekit/rugged/linesensor/FixedRotationTest.java +++ b/src/test/java/org/orekit/rugged/linesensor/FixedRotationTest.java @@ -38,7 +38,6 @@ import org.junit.Assert; import org.junit.Before; import org.junit.Test; import org.orekit.errors.OrekitException; -import org.orekit.errors.OrekitExceptionWrapper; import org.orekit.rugged.errors.RuggedException; import org.orekit.rugged.los.FixedRotation; import org.orekit.rugged.los.LOSBuilder; @@ -199,20 +198,16 @@ public class FixedRotationTest { int[] orders = new int[selected.size()]; orders[index] = 1; UnivariateDifferentiableMatrixFunction f = - differentiator.differentiate((UnivariateMatrixFunction) x -> { - try { - double oldX = driver.getValue(); - double[][] matrix = new double[raw.size()][]; - driver.setValue(x); - for (int i = 0 ; i < raw.size(); ++i) { - matrix[i] = tdl.getLOS(i, AbsoluteDate.J2000_EPOCH).toArray(); - } - driver.setValue(oldX); - return matrix; - } catch (OrekitException oe) { - throw new OrekitExceptionWrapper(oe); - } - }); + differentiator.differentiate((UnivariateMatrixFunction) x -> { + double oldX = driver.getValue(); + double[][] matrix = new double[raw.size()][]; + driver.setValue(x); + for (int i = 0 ; i < raw.size(); ++i) { + matrix[i] = tdl.getLOS(i, AbsoluteDate.J2000_EPOCH).toArray(); + } + driver.setValue(oldX); + return matrix; + }); DerivativeStructure[][] mDS = f.value(factory11.variable(0, driver.getValue())); for (int i = 0; i < raw.size(); ++i) { Vector3D los = tdl.getLOS(i, AbsoluteDate.J2000_EPOCH); diff --git a/src/test/java/org/orekit/rugged/linesensor/PolynomialRotationTest.java b/src/test/java/org/orekit/rugged/linesensor/PolynomialRotationTest.java index 2734af05..cb8aed13 100644 --- a/src/test/java/org/orekit/rugged/linesensor/PolynomialRotationTest.java +++ b/src/test/java/org/orekit/rugged/linesensor/PolynomialRotationTest.java @@ -39,7 +39,6 @@ import org.junit.Assert; import org.junit.Before; import org.junit.Test; import org.orekit.errors.OrekitException; -import org.orekit.errors.OrekitExceptionWrapper; import org.orekit.rugged.errors.RuggedException; import org.orekit.rugged.los.LOSBuilder; import org.orekit.rugged.los.PolynomialRotation; @@ -216,20 +215,16 @@ public class PolynomialRotationTest { int[] orders = new int[selected.size()]; orders[index] = 1; UnivariateDifferentiableMatrixFunction f = - differentiator.differentiate((UnivariateMatrixFunction) x -> { - try { - double oldX = driver.getValue(); - double[][] matrix = new double[raw.size()][]; - driver.setValue(x); - for (int i = 0 ; i < raw.size(); ++i) { - matrix[i] = tdl.getLOS(i, date).toArray(); - } - driver.setValue(oldX); - return matrix; - } catch (OrekitException oe) { - throw new OrekitExceptionWrapper(oe); - } - }); + differentiator.differentiate((UnivariateMatrixFunction) x -> { + double oldX = driver.getValue(); + double[][] matrix = new double[raw.size()][]; + driver.setValue(x); + for (int i = 0 ; i < raw.size(); ++i) { + matrix[i] = tdl.getLOS(i, date).toArray(); + } + driver.setValue(oldX); + return matrix; + }); DerivativeStructure[][] mDS = f.value(factory11.variable(0, driver.getValue())); for (int i = 0; i < raw.size(); ++i) { Vector3D los = tdl.getLOS(i, date); diff --git a/src/tutorials/java/fr/cs/examples/refiningPleiades/Refining.java b/src/tutorials/java/fr/cs/examples/refiningPleiades/Refining.java index b5dc3072..e3e7aa0b 100644 --- a/src/tutorials/java/fr/cs/examples/refiningPleiades/Refining.java +++ b/src/tutorials/java/fr/cs/examples/refiningPleiades/Refining.java @@ -23,7 +23,6 @@ import java.util.List; import org.hipparchus.optim.nonlinear.vector.leastsquares.LeastSquaresOptimizer.Optimum; import org.orekit.errors.OrekitException; -import org.orekit.errors.OrekitExceptionWrapper; import org.orekit.rugged.adjustment.AdjustmentContext; import org.orekit.rugged.api.Rugged; import org.orekit.rugged.errors.RuggedException; @@ -271,14 +270,10 @@ public class Refining { getLineSensor(sensorName). getParametersDrivers(). filter(driver -> driver.getName().equals(sensorName + rollSuffix) - || driver.getName().equals(sensorName + pitchSuffix)). + || driver.getName().equals(sensorName + pitchSuffix)). forEach(driver -> { - try { - driver.setSelected(true); - driver.setValue(0.0); - } catch (OrekitException e) { - throw new OrekitExceptionWrapper(e); - } + driver.setSelected(true); + driver.setValue(0.0); }); rugged. @@ -286,14 +281,10 @@ public class Refining { getParametersDrivers(). filter(driver -> driver.getName().equals(factorName)). forEach(driver -> { - try { - driver.setSelected(isSelected); - - // default value: no Z scale factor applied - driver.setValue(1.0); - } catch (OrekitException e) { - throw new OrekitExceptionWrapper(e); - } + driver.setSelected(isSelected); + + // default value: no Z scale factor applied + driver.setValue(1.0); }); } -- GitLab