diff --git a/src/main/java/org/orekit/rugged/api/Rugged.java b/src/main/java/org/orekit/rugged/api/Rugged.java index 008a0bbd05b6ad07d2c03ba2db7aeb765f511575..0e23ae861ca8329116f016eb3faf64bb67af00bf 100644 --- a/src/main/java/org/orekit/rugged/api/Rugged.java +++ b/src/main/java/org/orekit/rugged/api/Rugged.java @@ -248,6 +248,8 @@ public class Rugged { algorithm.intersection(ellipsoid, pBody, lBody)); } + DumpManager.dumpDirectLocationResult(gp[i]); + } return gp; @@ -297,6 +299,7 @@ public class Rugged { lInert = obsLInert; } + final NormalizedGeodeticPoint result; if (lightTimeCorrection) { // compute DEM intersection with light time correction final Vector3D sP = approximate.transformPosition(position); @@ -311,19 +314,22 @@ public class Rugged { final Vector3D eP2 = ellipsoid.transform(gp1); final double deltaT2 = eP2.distance(sP) / Constants.SPEED_OF_LIGHT; final Transform shifted2 = inertToBody.shiftedBy(-deltaT2); - return algorithm.refineIntersection(ellipsoid, - shifted2.transformPosition(pInert), - shifted2.transformVector(lInert), - gp1); + result = algorithm.refineIntersection(ellipsoid, + shifted2.transformPosition(pInert), + shifted2.transformVector(lInert), + gp1); } else { // compute DEM intersection without light time correction final Vector3D pBody = inertToBody.transformPosition(pInert); final Vector3D lBody = inertToBody.transformVector(lInert); - return algorithm.refineIntersection(ellipsoid, pBody, lBody, - algorithm.intersection(ellipsoid, pBody, lBody)); + result = algorithm.refineIntersection(ellipsoid, pBody, lBody, + algorithm.intersection(ellipsoid, pBody, lBody)); } + DumpManager.dumpDirectLocationResult(result); + return result; + } /** Find the date at which sensor sees a ground point. diff --git a/src/main/java/org/orekit/rugged/errors/DumpReplayer.java b/src/main/java/org/orekit/rugged/errors/DumpReplayer.java index 10cfc31e39473939fb2e22108cd48e39c782a53c..589a63f69c208cd0dbe5b200a2ac2aea4594517c 100644 --- a/src/main/java/org/orekit/rugged/errors/DumpReplayer.java +++ b/src/main/java/org/orekit/rugged/errors/DumpReplayer.java @@ -20,8 +20,9 @@ import java.io.BufferedReader; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.File; -import java.io.FileReader; +import java.io.FileInputStream; import java.io.IOException; +import java.io.InputStreamReader; import java.io.ObjectOutputStream; import java.util.ArrayList; import java.util.List; @@ -34,6 +35,7 @@ import org.apache.commons.math3.geometry.euclidean.threed.Rotation; import org.apache.commons.math3.geometry.euclidean.threed.Vector3D; import org.apache.commons.math3.util.FastMath; import org.apache.commons.math3.util.OpenIntToDoubleHashMap; +import org.orekit.bodies.GeodeticPoint; import org.orekit.bodies.OneAxisEllipsoid; import org.orekit.errors.OrekitException; import org.orekit.frames.Frame; @@ -59,6 +61,12 @@ public class DumpReplayer { /** Comment start marker. */ private static final String COMMENT_START = "#"; + /** Keyword for latitude fields. */ + private static final String LATITUDE = "latitude"; + + /** Keyword for longitude fields. */ + private static final String LONGITUDE = "longitude"; + /** Keyword for elevation fields. */ private static final String ELEVATION = "elevation"; @@ -207,11 +215,11 @@ public class DumpReplayer { */ public void parse(final File file) throws RuggedException { try { - final BufferedReader reader = new BufferedReader(new FileReader(file)); + final BufferedReader reader = + new BufferedReader(new InputStreamReader(new FileInputStream(file), "UTF-8")); int l = 0; for (String line = reader.readLine(); line != null; line = reader.readLine()) { - ++l; - LineParser.parse(l, file, line, this); + LineParser.parse(++l, file, line, this); } reader.close(); } catch (IOException ioe) { @@ -308,14 +316,49 @@ public class DumpReplayer { * @return results of all dumped calls * @exception RuggedException if a call fails */ - public Object[] execute(final Rugged rugged) throws RuggedException { - final Object[] results = new Object[calls.size()]; + public Result[] execute(final Rugged rugged) throws RuggedException { + final Result[] results = new Result[calls.size()]; for (int i = 0; i < calls.size(); ++i) { - results[i] = calls.get(i).execute(rugged); + results[i] = new Result(calls.get(i).expected, + calls.get(i).execute(rugged)); } return results; } + /** Container for replay results. */ + public static class Result { + + /** Expected result. */ + private final Object expected; + + /** Replayed result. */ + private final Object replayed; + + /** Simple constructor. + * @param expected expected result + * @param replayed replayed result + */ + private Result(final Object expected, final Object replayed) { + this.expected = expected; + this.replayed = replayed; + } + + /** Get the expected result. + * @return expected result + */ + public Object getExpected() { + return expected; + } + + /** Get the replayed result. + * @return replayed result + */ + public Object getReplayed() { + return replayed; + } + + } + /** Line parsers. */ private enum LineParser { @@ -419,6 +462,26 @@ public class DumpReplayer { }, + /** Parser for direct location result dump lines. */ + DIRECT_LOCATION_RESULT() { + + /** {@inheritDoc} */ + @Override + public void parse(final int l, final File file, final String line, final String[] fields, final DumpReplayer global) + throws RuggedException { + if (fields.length < 6 || !fields[0].equals(LATITUDE) || + !fields[2].equals(LONGITUDE) || !fields[4].equals(ELEVATION)) { + throw new RuggedException(RuggedMessages.CANNOT_PARSE_LINE, l, file, line); + } + final GeodeticPoint gp = new GeodeticPoint(Double.parseDouble(fields[1]), + Double.parseDouble(fields[3]), + Double.parseDouble(fields[5])); + final DumpedCall last = global.calls.get(global.calls.size() - 1); + last.expected = gp; + } + + }, + /** Parser for search span dump lines. */ SPAN() { @@ -549,7 +612,7 @@ public class DumpReplayer { public void parse(final int l, final File file, final String line, final String[] fields, final DumpReplayer global) throws RuggedException { if (fields.length < 7 || - !fields[1].equals(LAT_INDEX) || !fields[3].equals(LON_INDEX) || !fields[5].equals(ELEVATION)) { + !fields[1].equals(LAT_INDEX) || !fields[3].equals(LON_INDEX) || !fields[5].equals(ELEVATION)) { throw new RuggedException(RuggedMessages.CANNOT_PARSE_LINE, l, file, line); } final String name = fields[0]; @@ -699,13 +762,18 @@ public class DumpReplayer { } /** Local interface for dumped calls. */ - private interface DumpedCall { + private abstract static class DumpedCall { + + /** Expected result. */ + private Object expected; + /** Execute a call. * @param rugged Rugged instance on which called should be performed * @return result of the call * @exception RuggedException if the call fails */ - Object execute(Rugged rugged) throws RuggedException; + public abstract Object execute(Rugged rugged) throws RuggedException; + } } diff --git a/src/test/java/org/orekit/rugged/errors/DumpManagerTest.java b/src/test/java/org/orekit/rugged/errors/DumpManagerTest.java index 356c6ea1f1e03fb30ea88f81c286f585cf9dfc76..f073cbe36a648a65dc89f6558fd5ab945806202c 100644 --- a/src/test/java/org/orekit/rugged/errors/DumpManagerTest.java +++ b/src/test/java/org/orekit/rugged/errors/DumpManagerTest.java @@ -68,13 +68,14 @@ public class DumpManagerTest { locationsinglePoint(); DumpManager.deactivate(); - int countAlgorithm = 0; - int countEllipsoid = 0; - int countSpan = 0; - int countTransform = 0; - int countDEMTile = 0; - int countDEMCell = 0; - int countDirectLoc = 0; + int countAlgorithm = 0; + int countEllipsoid = 0; + int countSpan = 0; + int countTransform = 0; + int countDEMTile = 0; + int countDEMCell = 0; + int countDirectLoc = 0; + int countDirectLocResult = 0; BufferedReader br = new BufferedReader(new FileReader(dump)); for (String line = br.readLine(); line != null; line = br.readLine()) { String trimmed = line.trim(); @@ -93,6 +94,8 @@ public class DumpManagerTest { ++countDEMCell; } else if (trimmed.startsWith("direct location:")) { ++countDirectLoc; + } else if (trimmed.startsWith("direct location result:")) { + ++countDirectLocResult; } else { Assert.fail(line); } @@ -104,8 +107,9 @@ public class DumpManagerTest { Assert.assertEquals(1, countSpan); Assert.assertEquals(1, countTransform); Assert.assertEquals(2, countDEMTile); - Assert.assertEquals(884, countDEMCell); + Assert.assertEquals(887, countDEMCell); Assert.assertEquals(400, countDirectLoc); + Assert.assertEquals(400, countDirectLocResult); } diff --git a/src/test/java/org/orekit/rugged/errors/DumpReplayerTest.java b/src/test/java/org/orekit/rugged/errors/DumpReplayerTest.java index ee1087f511a5f93b806f3c9c10cd2797ecefabc3..2ab2bf16ca3fbc645bf63e0ace7f41d2a8a53b75 100644 --- a/src/test/java/org/orekit/rugged/errors/DumpReplayerTest.java +++ b/src/test/java/org/orekit/rugged/errors/DumpReplayerTest.java @@ -41,11 +41,17 @@ public class DumpReplayerTest { DumpReplayer replayer = new DumpReplayer(); replayer.parse(new File(dumpPath)); Rugged rugged = replayer.createRugged(); - Object[] results = replayer.execute(rugged); - Assert.assertEquals(3, results.length); - Assert.assertTrue(results[0] instanceof GeodeticPoint); - Assert.assertTrue(results[1] instanceof GeodeticPoint); - Assert.assertTrue(results[2] instanceof GeodeticPoint); + DumpReplayer.Result[] results = replayer.execute(rugged); + + Assert.assertEquals(5, results.length); + for (final DumpReplayer.Result result : results) { + GeodeticPoint expectedGP = (GeodeticPoint) result.getExpected(); + GeodeticPoint replayedGP = (GeodeticPoint) result.getReplayed(); + Assert.assertEquals(expectedGP.getLatitude(), replayedGP.getLatitude(), 1.0e-12); + Assert.assertEquals(expectedGP.getLongitude(), replayedGP.getLongitude(), 1.0e-12); + Assert.assertEquals(expectedGP.getAltitude(), replayedGP.getAltitude(), 1.0e-6); + } + } } diff --git a/src/test/resources/replay/replay-direct-loc-01.txt b/src/test/resources/replay/replay-direct-loc-01.txt index 3c686c2ac3b9346dba42ff16607562aef51b36e8..610b02746f73dd34b7c6a87235e19eb4d17d4cc5 100644 --- a/src/test/resources/replay/replay-direct-loc-01.txt +++ b/src/test/resources/replay/replay-direct-loc-01.txt @@ -1,11 +1,13 @@ -# Rugged library dump file, created on 2015-02-10T13:52:19Z +# Rugged library dump file, created on 2015-02-10T16:00:15Z # all units are SI units (m, m/s, rad ...) +direct location: date 2012-01-01T12:30:00.00000000000000Z position 1.500000000000000e+00 0.000000000000000e+00 -2.000000000000000e-01 los 0.000000000000000e+00 -7.547095802227720e-01 6.560590289905073e-01 lightTime true aberration true span: minDate 2012-01-01T12:29:59.85000000000000Z maxDate 2012-01-01T12:30:00.15000000000000Z tStep 1.000000000000000e-03 tolerance 5.000000000000000e+00 inertialFrame EME2000 transform: index 150 body r -8.085963389171905e-01 -3.465415132416125e-04 4.896468952533137e-04 -5.883634938068593e-01 Ω -8.740475534355122e-08 1.215132763920864e-09 -7.292109805268457e-05 ΩDot -1.642299174832679e-16 8.973031065665686e-17 1.983408395824453e-19 spacecraft p 1.384771423708159e+04 3.157872644483112e+03 -7.179504513218164e+06 v -3.193269831348565e+01 -8.025700179158079e+00 8.276060585645734e+00 a -9.306388141791047e-01 -8.320023410534990e+00 1.352798021525103e-03 r -6.828948932066574e-01 4.142451147005848e-01 -3.878489669799004e-01 4.600312256701621e-01 Ω -1.009835959093257e-03 1.982938126604663e-04 1.645927204535755e-04 ΩDot -3.647403055483546e-07 2.008714378022283e-07 -1.257148591486377e-06 -direct location: date 2012-01-01T12:30:00.00000000000000Z position 1.500000000000000e+00 0.000000000000000e+00 -2.000000000000000e-01 los 0.000000000000000e+00 -7.547095802227720e-01 6.560590289905073e-01 lightTime true aberration true ellipsoid: ae 6.378137000000000e+06 f 3.352810664747481e-03 frame ITRF_CIO_CONV_2010_SIMPLE_EOP algorithm: DUVENHAGE DEM tile: t0 latMin -4.014257279586958e-01 latStep 6.817692390602850e-05 latRows 257 lonMin 2.495820830351891e+00 lonStep 6.817692390602850e-05 lonCols 257 +DEM cell: t0 latIndex 192 lonIndex 0 elevation -1.282721242683617e+03 +DEM cell: t0 latIndex 80 lonIndex 192 elevation 3.211682285355159e+03 DEM cell: t0 latIndex 96 lonIndex 64 elevation 1.075720914066972e+03 DEM cell: t0 latIndex 97 lonIndex 64 elevation 9.498384803599795e+02 DEM cell: t0 latIndex 96 lonIndex 65 elevation 1.001623033275892e+03 @@ -27,6 +29,7 @@ DEM cell: t0 latIndex 98 lonIndex 50 elevation 7.769426987315585e+01 DEM cell: t0 latIndex 99 lonIndex 50 elevation 4.265142906455210e+01 DEM cell: t0 latIndex 97 lonIndex 50 elevation 4.500756443755694e+01 DEM cell: t0 latIndex 97 lonIndex 51 elevation 7.421501844304876e+01 +direct location result: latitude -3.947445425992010e-01 longitude 2.499243584750142e+00 elevation 8.434706922629509e+01 direct location: date 2012-01-01T12:30:00.00000000000000Z position 1.500000000000000e+00 0.000000000000000e+00 -2.000000000000000e-01 los 0.000000000000000e+00 -7.548246479094037e-01 6.559266353095021e-01 lightTime true aberration true DEM cell: t0 latIndex 96 lonIndex 52 elevation 1.110753711365716e+02 DEM cell: t0 latIndex 97 lonIndex 52 elevation 8.027308091623061e+01 @@ -36,19 +39,44 @@ DEM cell: t0 latIndex 97 lonIndex 49 elevation -1.609219755441909e+01 DEM cell: t0 latIndex 98 lonIndex 49 elevation -2.653137720265925e+01 DEM cell: t0 latIndex 97 lonIndex 48 elevation -9.460844691182658e+01 DEM cell: t0 latIndex 98 lonIndex 48 elevation -6.303622859747302e+01 +direct location result: latitude -3.947611273580563e-01 longitude 2.499133846389992e+00 elevation -4.295871413137783e+01 +DEM cell: t0 latIndex 91 lonIndex 0 elevation -4.644285910379659e+02 +DEM cell: t0 latIndex 92 lonIndex 0 elevation -6.361521230433466e+02 +DEM cell: t0 latIndex 91 lonIndex 1 elevation -6.695324221432916e+02 +DEM cell: t0 latIndex 92 lonIndex 1 elevation -6.941696826528058e+02 +DEM cell: t0 latIndex 91 lonIndex 2 elevation -7.590003401646543e+02 +DEM cell: t0 latIndex 90 lonIndex 3 elevation -8.207436833089408e+02 +DEM cell: t0 latIndex 90 lonIndex 4 elevation -8.534523757445398e+02 +DEM cell: t0 latIndex 90 lonIndex 2 elevation -7.924361301694835e+02 +DEM cell: t0 latIndex 90 lonIndex 1 elevation -7.251222469503653e+02 +direct location: date 2012-01-01T12:30:00.00000000000000Z position 1.500000000000000e+00 0.000000000000000e+00 -2.000000000000000e-01 los 0.000000000000000e+00 -7.595223858294946e-01 6.504811645419663e-01 lightTime true aberration true +DEM cell: t0 latIndex 90 lonIndex 0 elevation -5.786400093316511e+02 +direct location result: latitude -3.952555711362365e-01 longitude 2.495847653590435e+00 elevation -5.905034290161145e+02 direct location: date 2012-01-01T12:30:00.00000000000000Z position 1.500000000000000e+00 0.000000000000000e+00 -2.000000000000000e-01 los 0.000000000000000e+00 -7.596364750290255e-01 6.503479267326657e-01 lightTime true aberration true DEM tile: t1 latMin -4.014257279586958e-01 latStep 6.817692390602850e-05 latRows 257 lonMin 2.478367537831948e+00 lonStep 6.817692390602850e-05 lonCols 257 +DEM cell: t1 latIndex 192 lonIndex 0 elevation -1.282721242683617e+03 +DEM cell: t1 latIndex 80 lonIndex 192 elevation 3.211682285355159e+03 DEM cell: t1 latIndex 90 lonIndex 255 elevation -6.028136533065612e+02 DEM cell: t1 latIndex 90 lonIndex 256 elevation -5.786400093316511e+02 DEM cell: t1 latIndex 91 lonIndex 255 elevation -6.221990476940956e+02 DEM cell: t1 latIndex 91 lonIndex 256 elevation -4.644285910379659e+02 +DEM cell: t1 latIndex 88 lonIndex 252 elevation 0.000000000000000e+00 +DEM cell: t1 latIndex 89 lonIndex 252 elevation -4.877794667497003e+02 +DEM cell: t1 latIndex 88 lonIndex 253 elevation 0.000000000000000e+00 +DEM cell: t1 latIndex 89 lonIndex 253 elevation -5.757446064041551e+02 +DEM cell: t1 latIndex 91 lonIndex 252 elevation 0.000000000000000e+00 +DEM cell: t1 latIndex 92 lonIndex 252 elevation 0.000000000000000e+00 +DEM cell: t1 latIndex 91 lonIndex 253 elevation -6.152228016740617e+02 +DEM cell: t1 latIndex 92 lonIndex 253 elevation 0.000000000000000e+00 DEM cell: t1 latIndex 92 lonIndex 256 elevation -6.361521230433466e+02 DEM cell: t1 latIndex 91 lonIndex 257 elevation -6.361521230433466e+02 DEM cell: t1 latIndex 92 lonIndex 257 elevation -5.119072938899205e+02 +direct location result: latitude -3.952672865845636e-01 longitude 2.495769458919830e+00 elevation -5.923807760050810e+02 direct location: date 2012-01-01T12:30:00.00000000000000Z position 1.500000000000000e+00 0.000000000000000e+00 -2.000000000000000e-01 los 0.000000000000000e+00 -7.597505408555608e-01 6.502146689130315e-01 lightTime true aberration true -DEM cell: t1 latIndex 92 lonIndex 248 elevation -1.470524675650724e+02 -DEM cell: t1 latIndex 93 lonIndex 248 elevation -1.448837787295385e+02 -DEM cell: t1 latIndex 92 lonIndex 249 elevation -2.503632800423777e+02 -DEM cell: t1 latIndex 93 lonIndex 249 elevation -2.077565123004881e+02 +DEM cell: t1 latIndex 88 lonIndex 248 elevation 0.000000000000000e+00 +DEM cell: t1 latIndex 89 lonIndex 248 elevation -2.769462712597335e+02 +DEM cell: t1 latIndex 88 lonIndex 249 elevation 0.000000000000000e+00 +DEM cell: t1 latIndex 89 lonIndex 249 elevation -3.314207112316006e+02 DEM cell: t1 latIndex 90 lonIndex 254 elevation -5.859504161342276e+02 DEM cell: t1 latIndex 91 lonIndex 254 elevation -6.458840770174961e+02 +direct location result: latitude -3.952790935038382e-01 longitude 2.495690638626864e+00 elevation -5.963149908542051e+02