From 5161a0b4fea3df2b18c9afc5f02e37db42773de5 Mon Sep 17 00:00:00 2001
From: Luc Maisonobe <luc@orekit.org>
Date: Wed, 23 Apr 2014 10:53:23 +0200
Subject: [PATCH] Moved light travel compensation setting out of construction.

This setting is not intended to be used often (in fact it should be used
only for validation against other systems), so forcing user to set it in
all cases was a bad idea. Now the default configuration is to compensate
and if user does not want to compensate, he can inhibate it by calling a
separate method after construction.
---
 .../java/org/orekit/rugged/api/Rugged.java    | 53 +++++++++++++------
 .../org/orekit/rugged/api/RuggedTest.java     | 12 +++--
 2 files changed, 46 insertions(+), 19 deletions(-)

diff --git a/src/main/java/org/orekit/rugged/api/Rugged.java b/src/main/java/org/orekit/rugged/api/Rugged.java
index 64770f43..89d8e96c 100644
--- a/src/main/java/org/orekit/rugged/api/Rugged.java
+++ b/src/main/java/org/orekit/rugged/api/Rugged.java
@@ -73,12 +73,13 @@ public class Rugged {
     private final IntersectionAlgorithm algorithm;
 
     /** Flag for fixing light travel time. */
-    private final boolean fixLightTravelTime;
+    private boolean lightTravelTimeCompensated;
 
     /** Build a configured instance.
      * <p>
-     * This method is the first one that must be called, otherwise the
-     * other methods will fail due to uninitialized context.
+     * By default, the instance compensates light travel time, an explicit call
+     * to {@link #setLightTravelTimeCompensated(boolean) setLightTravelTimeCompensated}
+     * can be made after construction if it should not be compensated.
      * </p>
      * @param referenceDate reference date from which all other dates are computed
      * @param updater updater used to load Digital Elevation Model tiles
@@ -87,8 +88,6 @@ public class Rugged {
      * @param ellipsoidID identifier of reference ellipsoid
      * @param inertialFrameID identifier of inertial frame
      * @param bodyRotatingFrameID identifier of body rotating frame
-     * @param fixLightTravelTime if true, light travel time should be fixed when computing
-     * direct and inverse localization
      * @param positionsVelocities satellite position and velocity
      * @param pvInterpolationOrder order to use for position/velocity interpolation
      * @param quaternions satellite quaternions
@@ -99,9 +98,9 @@ public class Rugged {
                   final TileUpdater updater, final int maxCachedTiles,
                   final AlgorithmId algorithmID, final EllipsoidId ellipsoidID,
                   final InertialFrameId inertialFrameID, final BodyRotatingFrameId bodyRotatingFrameID,
-                  final boolean fixLightTravelTime,
-                  final List<Pair<AbsoluteDate, PVCoordinates>> positionsVelocities, final int pvInterpolationOrder,
-                  final List<Pair<AbsoluteDate, Rotation>> quaternions, final int aInterpolationOrder)
+                  final List<Pair<AbsoluteDate, PVCoordinates>> positionsVelocities,
+                  final int pvInterpolationOrder, final List<Pair<AbsoluteDate, Rotation>> quaternions,
+                  final int aInterpolationOrder)
         throws RuggedException {
         try {
 
@@ -119,9 +118,9 @@ public class Rugged {
 
             // intersection algorithm
             algorithm = selectAlgorithm(algorithmID, updater, maxCachedTiles);
-            this.fixLightTravelTime = fixLightTravelTime;
 
             sensors = new HashMap<String, Sensor>();
+            setLightTravelTimeCompensated(true);
 
         } catch (OrekitException oe) {
             throw new RuggedException(oe, oe.getSpecifier(), oe.getParts().clone());
@@ -130,8 +129,9 @@ public class Rugged {
 
     /** Build a configured instance.
      * <p>
-     * This method is the first one that must be called, otherwise the
-     * other methods will fail due to uninitialized context.
+     * By default, the instance compensates light travel time, an explicit call
+     * to {@link #setLightTravelTimeCompensated(boolean) setLightTravelTimeCompensated}
+     * can be made after construction if it should not be compensated.
      * </p>
      * @param newReferenceDate reference date from which all other dates are computed
      * @param updater updater used to load Digital Elevation Model tiles
@@ -140,8 +140,6 @@ public class Rugged {
      * @param ellipsoidID identifier of reference ellipsoid
      * @param inertialFrameID identifier of inertial frame
      * @param bodyRotatingFrameID identifier of body rotating frame
-     * @param fixLightTravelTime if true, light travel time should be fixed when computing
-     * direct and inverse localization
      * @param propagator global propagator
      * @exception RuggedException if data needed for some frame cannot be loaded
      */
@@ -149,7 +147,6 @@ public class Rugged {
                   final TileUpdater updater, final int maxCachedTiles,
                   final AlgorithmId algorithmID, final EllipsoidId ellipsoidID,
                   final InertialFrameId inertialFrameID, final BodyRotatingFrameId bodyRotatingFrameID,
-                  final boolean fixLightTravelTime,
                   final Propagator propagator)
         throws RuggedException {
         try {
@@ -167,9 +164,9 @@ public class Rugged {
 
             // intersection algorithm
             algorithm = selectAlgorithm(algorithmID, updater, maxCachedTiles);
-            this.fixLightTravelTime = fixLightTravelTime;
 
             sensors = new HashMap<String, Sensor>();
+            setLightTravelTimeCompensated(true);
 
         } catch (OrekitException oe) {
             throw new RuggedException(oe, oe.getSpecifier(), oe.getParts().clone());
@@ -183,6 +180,30 @@ public class Rugged {
         return referenceDate;
     }
 
+    /** Set flag for compensating light travel time.
+     * <p>
+     * This methods set the flag for compensating or not light travel time
+     * between ground and spacecraft. Compensating this delay improves localization
+     * accuracy and is enabled by default. Not compensating it is mainly useful
+     * for validation purposes against system that do not compensate it.
+     * </p>
+     * @param lightTravelTimeCompensated if true, the light travel time between ground
+     * and spacecraft is compensated for more accurate localization
+     * @see #isLightTravelTimeCompensated()
+     */
+    public void setLightTravelTimeCompensated(final boolean lightTravelTimeCompensated) {
+        this.lightTravelTimeCompensated = lightTravelTimeCompensated;
+    }
+
+    /** Get flag for compensating light travel time.
+     * @return true if the light travel time between ground
+     * and spacecraft is compensated for more accurate localization
+     * @see #setLightTravelTimeCompensated(boolean)
+     */
+    public boolean isLightTravelTimeCompensated() {
+        return lightTravelTimeCompensated;
+    }
+
     /** Set up line sensor model.
      * @param sensorName name of the line sensor.
      * @param linesOfSigth lines of sight for each pixels
@@ -383,7 +404,7 @@ public class Rugged {
             for (int i = 0; i < gp.length; ++i) {
 
                 final Transform fixed;
-                if (fixLightTravelTime) {
+                if (lightTravelTimeCompensated) {
                     // fix light travel time
                     final Vector3D sP     = approximate.transformPosition(sensor.getPosition(i));
                     final Vector3D sL     = approximate.transformVector(sensor.getLos(i));
diff --git a/src/test/java/org/orekit/rugged/api/RuggedTest.java b/src/test/java/org/orekit/rugged/api/RuggedTest.java
index 0dd75371..8cbb7de8 100644
--- a/src/test/java/org/orekit/rugged/api/RuggedTest.java
+++ b/src/test/java/org/orekit/rugged/api/RuggedTest.java
@@ -148,10 +148,13 @@ public class RuggedTest {
                                    EllipsoidId.WGS84,
                                    InertialFrameId.EME2000,
                                    BodyRotatingFrameId.ITRF,
-                                   true, pv, 8, q, 8);
+                                   pv, 8, q, 8);
 
         Assert.assertEquals(new AbsoluteDate("2012-01-01T00:00:00", TimeScalesFactory.getUTC()),
                             rugged.getReferenceDate());
+        Assert.assertTrue(rugged.isLightTravelTimeCompensated());
+        rugged.setLightTravelTimeCompensated(false);
+        Assert.assertFalse(rugged.isLightTravelTimeCompensated());
 
     }
 
@@ -176,9 +179,12 @@ public class RuggedTest {
                                    EllipsoidId.WGS84,
                                    InertialFrameId.EME2000,
                                    BodyRotatingFrameId.ITRF,
-                                   true, propagator);
+                                   propagator);
 
         Assert.assertEquals(propagator.getInitialState().getDate(), rugged.getReferenceDate());
+        Assert.assertTrue(rugged.isLightTravelTimeCompensated());
+        rugged.setLightTravelTimeCompensated(false);
+        Assert.assertFalse(rugged.isLightTravelTimeCompensated());
 
     }
 
@@ -226,7 +232,7 @@ public class RuggedTest {
                                    EllipsoidId.WGS84,
                                    InertialFrameId.EME2000,
                                    BodyRotatingFrameId.ITRF,
-                                   true, ephemeris);
+                                   ephemeris);
 
         rugged.setLineSensor("line", los, lineDatation);
 
-- 
GitLab