diff --git a/src/main/java/org/orekit/rugged/api/Rugged.java b/src/main/java/org/orekit/rugged/api/Rugged.java index a7f3890a9d6304ed50be475e160bb91f0e7b3fe6..6e767b1737f4b1fd7d6298e8eb9c48b0f5705def 100644 --- a/src/main/java/org/orekit/rugged/api/Rugged.java +++ b/src/main/java/org/orekit/rugged/api/Rugged.java @@ -168,6 +168,14 @@ public class Rugged { return algorithm; } + /** Get the DEM intersection algorithm identifier. + * @return DEM intersection algorithm Id + * @since 2.2 + */ + public AlgorithmId getAlgorithmId() { + return algorithm.getAlgorithmId(); + } + /** Get flag for light time correction. * @return true if the light time between ground and spacecraft is * compensated for more accurate location diff --git a/src/main/java/org/orekit/rugged/intersection/BasicScanAlgorithm.java b/src/main/java/org/orekit/rugged/intersection/BasicScanAlgorithm.java index d06beb853f0db4f1c0519ff587da8aaba7dd429b..18696efb3ad1f988aa97e157fbdc82ff45790c39 100644 --- a/src/main/java/org/orekit/rugged/intersection/BasicScanAlgorithm.java +++ b/src/main/java/org/orekit/rugged/intersection/BasicScanAlgorithm.java @@ -39,6 +39,7 @@ import org.orekit.rugged.utils.NormalizedGeodeticPoint; * corner points. It is not designed for operational use. * </p> * @author Luc Maisonobe + * @author Guylaine Prat */ public class BasicScanAlgorithm implements IntersectionAlgorithm { @@ -51,14 +52,19 @@ public class BasicScanAlgorithm implements IntersectionAlgorithm { /** Maximum altitude encountered. */ private double hMax; + /** Algorithm Id. + * @since 2.2 */ + private final AlgorithmId algorithmId; + /** Simple constructor. * @param updater updater used to load Digital Elevation Model tiles * @param maxCachedTiles maximum number of tiles stored in the cache */ public BasicScanAlgorithm(final TileUpdater updater, final int maxCachedTiles) { - cache = new TilesCache<SimpleTile>(new SimpleTileFactory(), updater, maxCachedTiles); - hMin = Double.POSITIVE_INFINITY; - hMax = Double.NEGATIVE_INFINITY; + this.cache = new TilesCache<SimpleTile>(new SimpleTileFactory(), updater, maxCachedTiles); + this.hMin = Double.POSITIVE_INFINITY; + this.hMax = Double.NEGATIVE_INFINITY; + this.algorithmId = AlgorithmId.BASIC_SLOW_EXHAUSTIVE_SCAN_FOR_TESTS_ONLY; } /** {@inheritDoc} */ @@ -66,7 +72,7 @@ public class BasicScanAlgorithm implements IntersectionAlgorithm { public NormalizedGeodeticPoint intersection(final ExtendedEllipsoid ellipsoid, final Vector3D position, final Vector3D los) { - DumpManager.dumpAlgorithm(AlgorithmId.BASIC_SLOW_EXHAUSTIVE_SCAN_FOR_TESTS_ONLY); + DumpManager.dumpAlgorithm(this.algorithmId); // find the tiles between the entry and exit point in the Digital Elevation Model NormalizedGeodeticPoint entryPoint = null; @@ -162,7 +168,7 @@ public class BasicScanAlgorithm implements IntersectionAlgorithm { public NormalizedGeodeticPoint refineIntersection(final ExtendedEllipsoid ellipsoid, final Vector3D position, final Vector3D los, final NormalizedGeodeticPoint closeGuess) { - DumpManager.dumpAlgorithm(AlgorithmId.BASIC_SLOW_EXHAUSTIVE_SCAN_FOR_TESTS_ONLY); + DumpManager.dumpAlgorithm(this.algorithmId); final Vector3D delta = ellipsoid.transform(closeGuess).subtract(position); final double s = Vector3D.dotProduct(delta, los) / los.getNormSq(); final GeodeticPoint projected = ellipsoid.transform(new Vector3D(1, position, s, los), @@ -182,11 +188,17 @@ public class BasicScanAlgorithm implements IntersectionAlgorithm { /** {@inheritDoc} */ @Override public double getElevation(final double latitude, final double longitude) { - DumpManager.dumpAlgorithm(AlgorithmId.BASIC_SLOW_EXHAUSTIVE_SCAN_FOR_TESTS_ONLY); + DumpManager.dumpAlgorithm(this.algorithmId); final Tile tile = cache.getTile(latitude, longitude); return tile.interpolateElevation(latitude, longitude); } + /** {@inheritDoc} */ + @Override + public AlgorithmId getAlgorithmId() { + return this.algorithmId; + } + /** Check the overall min and max altitudes. * @param tiles tiles to check * @return true if the tile changed either min or max altitude @@ -252,5 +264,4 @@ public class BasicScanAlgorithm implements IntersectionAlgorithm { final int rawIndex = tile.getFloorLongitudeIndex(longitude); return FastMath.min(FastMath.max(0, rawIndex), tile.getLongitudeColumns()); } - } diff --git a/src/main/java/org/orekit/rugged/intersection/ConstantElevationAlgorithm.java b/src/main/java/org/orekit/rugged/intersection/ConstantElevationAlgorithm.java index 73ab6d8fdb6160970c7015b59549101f434d983f..93a24f1e7228d80606c9fdc19239091547ad2005 100644 --- a/src/main/java/org/orekit/rugged/intersection/ConstantElevationAlgorithm.java +++ b/src/main/java/org/orekit/rugged/intersection/ConstantElevationAlgorithm.java @@ -28,24 +28,30 @@ import org.orekit.rugged.utils.NormalizedGeodeticPoint; * This implementation uses a constant elevation over the ellipsoid. * </p> * @author Luc Maisonobe + * @author Guylaine Prat */ public class ConstantElevationAlgorithm implements IntersectionAlgorithm { /** Constant elevation over ellipsoid. */ private final double constantElevation; + /** Algorithm Id. + * @since 2.2 */ + private final AlgorithmId algorithmId; + /** Simple constructor. * @param constantElevation constant elevation over ellipsoid */ public ConstantElevationAlgorithm(final double constantElevation) { this.constantElevation = constantElevation; + this.algorithmId = AlgorithmId.CONSTANT_ELEVATION_OVER_ELLIPSOID; } /** {@inheritDoc} */ @Override public NormalizedGeodeticPoint intersection(final ExtendedEllipsoid ellipsoid, final Vector3D position, final Vector3D los) { - DumpManager.dumpAlgorithm(AlgorithmId.CONSTANT_ELEVATION_OVER_ELLIPSOID, constantElevation); + DumpManager.dumpAlgorithm(this.algorithmId, constantElevation); final Vector3D p = ellipsoid.pointAtAltitude(position, los, constantElevation); final GeodeticPoint gp = ellipsoid.transform(p, ellipsoid.getFrame(), null); return new NormalizedGeodeticPoint(gp.getLatitude(), gp.getLongitude(), gp.getAltitude(), 0.0); @@ -56,7 +62,7 @@ public class ConstantElevationAlgorithm implements IntersectionAlgorithm { public NormalizedGeodeticPoint refineIntersection(final ExtendedEllipsoid ellipsoid, final Vector3D position, final Vector3D los, final NormalizedGeodeticPoint closeGuess) { - DumpManager.dumpAlgorithm(AlgorithmId.CONSTANT_ELEVATION_OVER_ELLIPSOID, constantElevation); + DumpManager.dumpAlgorithm(this.algorithmId, constantElevation); final Vector3D p = ellipsoid.pointAtAltitude(position, los, constantElevation); final GeodeticPoint gp = ellipsoid.transform(p, ellipsoid.getFrame(), null); return new NormalizedGeodeticPoint(gp.getLatitude(), gp.getLongitude(), gp.getAltitude(), @@ -71,8 +77,13 @@ public class ConstantElevationAlgorithm implements IntersectionAlgorithm { */ @Override public double getElevation(final double latitude, final double longitude) { - DumpManager.dumpAlgorithm(AlgorithmId.CONSTANT_ELEVATION_OVER_ELLIPSOID, constantElevation); + DumpManager.dumpAlgorithm(this.algorithmId, constantElevation); return constantElevation; } + /** {@inheritDoc} */ + @Override + public AlgorithmId getAlgorithmId() { + return this.algorithmId; + } } diff --git a/src/main/java/org/orekit/rugged/intersection/IgnoreDEMAlgorithm.java b/src/main/java/org/orekit/rugged/intersection/IgnoreDEMAlgorithm.java index eb96998a236fbf1ece113cf02538a91930b76e20..68f331a67ac47eb332b73466e68e20b025f1a2f5 100644 --- a/src/main/java/org/orekit/rugged/intersection/IgnoreDEMAlgorithm.java +++ b/src/main/java/org/orekit/rugged/intersection/IgnoreDEMAlgorithm.java @@ -27,19 +27,25 @@ import org.orekit.rugged.utils.NormalizedGeodeticPoint; * This dummy implementation simply uses the ellipsoid itself. * </p> * @author Luc Maisonobe + * @author Guylaine Prat */ public class IgnoreDEMAlgorithm implements IntersectionAlgorithm { + /** Algorithm Id. + * @since 2.2 */ + private final AlgorithmId algorithmId; + /** Simple constructor. */ public IgnoreDEMAlgorithm() { + this.algorithmId = AlgorithmId.IGNORE_DEM_USE_ELLIPSOID; } /** {@inheritDoc} */ @Override public NormalizedGeodeticPoint intersection(final ExtendedEllipsoid ellipsoid, final Vector3D position, final Vector3D los) { - DumpManager.dumpAlgorithm(AlgorithmId.IGNORE_DEM_USE_ELLIPSOID); + DumpManager.dumpAlgorithm(this.algorithmId); return ellipsoid.pointOnGround(position, los, 0.0); } @@ -48,7 +54,7 @@ public class IgnoreDEMAlgorithm implements IntersectionAlgorithm { public NormalizedGeodeticPoint refineIntersection(final ExtendedEllipsoid ellipsoid, final Vector3D position, final Vector3D los, final NormalizedGeodeticPoint closeGuess) { - DumpManager.dumpAlgorithm(AlgorithmId.IGNORE_DEM_USE_ELLIPSOID); + DumpManager.dumpAlgorithm(this.algorithmId); return intersection(ellipsoid, position, los); } @@ -60,8 +66,13 @@ public class IgnoreDEMAlgorithm implements IntersectionAlgorithm { */ @Override public double getElevation(final double latitude, final double longitude) { - DumpManager.dumpAlgorithm(AlgorithmId.IGNORE_DEM_USE_ELLIPSOID); + DumpManager.dumpAlgorithm(this.algorithmId); return 0.0; } + /** {@inheritDoc} */ + @Override + public AlgorithmId getAlgorithmId() { + return this.algorithmId; + } } diff --git a/src/main/java/org/orekit/rugged/intersection/IntersectionAlgorithm.java b/src/main/java/org/orekit/rugged/intersection/IntersectionAlgorithm.java index 84776a21c41038b111edcef115cf6b79c61cce18..438e7b05bdd106ed51328ca4290eb8a617b9011a 100644 --- a/src/main/java/org/orekit/rugged/intersection/IntersectionAlgorithm.java +++ b/src/main/java/org/orekit/rugged/intersection/IntersectionAlgorithm.java @@ -18,11 +18,13 @@ package org.orekit.rugged.intersection; import org.hipparchus.geometry.euclidean.threed.Vector3D; import org.orekit.bodies.GeodeticPoint; +import org.orekit.rugged.api.AlgorithmId; import org.orekit.rugged.utils.ExtendedEllipsoid; import org.orekit.rugged.utils.NormalizedGeodeticPoint; /** Interface for Digital Elevation Model intersection algorithm. * @author Luc Maisonobe + * @author Guylaine Prat */ public interface IntersectionAlgorithm { @@ -58,4 +60,9 @@ public interface IntersectionAlgorithm { */ double getElevation(double latitude, double longitude); + /** Get the algorithmId. + * @return the algorithmId + * @since 2.2 + */ + AlgorithmId getAlgorithmId(); } diff --git a/src/main/java/org/orekit/rugged/intersection/duvenhage/DuvenhageAlgorithm.java b/src/main/java/org/orekit/rugged/intersection/duvenhage/DuvenhageAlgorithm.java index 1ffb3dfcae92cdfed21d538e3b6b4459efeedfb7..1b9f23e312f54563ae80e988148f05be41db4983 100644 --- a/src/main/java/org/orekit/rugged/intersection/duvenhage/DuvenhageAlgorithm.java +++ b/src/main/java/org/orekit/rugged/intersection/duvenhage/DuvenhageAlgorithm.java @@ -58,6 +58,10 @@ public class DuvenhageAlgorithm implements IntersectionAlgorithm { /** Flag for flat-body hypothesis. */ private final boolean flatBody; + /** Algorithm Id. + * @since 2.2 */ + private final AlgorithmId algorithmId; + /** Simple constructor. * @param updater updater used to load Digital Elevation Model tiles * @param maxCachedTiles maximum number of tiles stored in the cache @@ -72,6 +76,7 @@ public class DuvenhageAlgorithm implements IntersectionAlgorithm { final boolean flatBody) { this.cache = new TilesCache<MinMaxTreeTile>(new MinMaxTreeTileFactory(), updater, maxCachedTiles); this.flatBody = flatBody; + this.algorithmId = flatBody ? AlgorithmId.DUVENHAGE_FLAT_BODY : AlgorithmId.DUVENHAGE; } /** {@inheritDoc} */ @@ -79,7 +84,7 @@ public class DuvenhageAlgorithm implements IntersectionAlgorithm { public NormalizedGeodeticPoint intersection(final ExtendedEllipsoid ellipsoid, final Vector3D position, final Vector3D los) { - DumpManager.dumpAlgorithm(flatBody ? AlgorithmId.DUVENHAGE_FLAT_BODY : AlgorithmId.DUVENHAGE); + DumpManager.dumpAlgorithm(this.algorithmId); // compute intersection with ellipsoid final NormalizedGeodeticPoint gp0 = ellipsoid.pointOnGround(position, los, 0.0); @@ -194,7 +199,7 @@ public class DuvenhageAlgorithm implements IntersectionAlgorithm { final Vector3D position, final Vector3D los, final NormalizedGeodeticPoint closeGuess) { - DumpManager.dumpAlgorithm(flatBody ? AlgorithmId.DUVENHAGE_FLAT_BODY : AlgorithmId.DUVENHAGE); + DumpManager.dumpAlgorithm(this.algorithmId); if (flatBody) { // under the (bad) flat-body assumption, the reference point must remain @@ -284,11 +289,17 @@ public class DuvenhageAlgorithm implements IntersectionAlgorithm { @Override public double getElevation(final double latitude, final double longitude) { - DumpManager.dumpAlgorithm(flatBody ? AlgorithmId.DUVENHAGE_FLAT_BODY : AlgorithmId.DUVENHAGE); + DumpManager.dumpAlgorithm(this.algorithmId); final Tile tile = cache.getTile(latitude, longitude); return tile.interpolateElevation(latitude, longitude); } + /** {@inheritDoc} */ + @Override + public AlgorithmId getAlgorithmId() { + return this.algorithmId; + } + /** Compute intersection of line with Digital Elevation Model in a sub-tile. * @param depth recursion depth * @param ellipsoid reference ellipsoid @@ -737,5 +748,4 @@ public class DuvenhageAlgorithm implements IntersectionAlgorithm { } } - } diff --git a/src/test/java/org/orekit/rugged/api/RuggedTest.java b/src/test/java/org/orekit/rugged/api/RuggedTest.java index d3938f6c4dd232b3d510de326d2d64e34a2c39d0..2709c9c8e7db94a10b8f6d1893455e04ba27e58e 100644 --- a/src/test/java/org/orekit/rugged/api/RuggedTest.java +++ b/src/test/java/org/orekit/rugged/api/RuggedTest.java @@ -1465,6 +1465,9 @@ public class RuggedTest { // Get the algorithm assertTrue(rugged.getAlgorithm().getClass().isInstance(new IgnoreDEMAlgorithm())); + // Get the algorithm Id + assertEquals(AlgorithmId.IGNORE_DEM_USE_ELLIPSOID, rugged.getAlgorithmId()); + // Change the min and max line in inverse location to update the SensorMeanPlaneCrossing when the planeCrossing is not null int minLine = firstLine; int maxLine = lastLine; diff --git a/src/test/java/org/orekit/rugged/intersection/BasicScanAlgorithmTest.java b/src/test/java/org/orekit/rugged/intersection/BasicScanAlgorithmTest.java index c235a3117d7808b6f99bc703776122eac0ceeb66..8584941939aee3ce27a9226da3304a9c64dee113 100644 --- a/src/test/java/org/orekit/rugged/intersection/BasicScanAlgorithmTest.java +++ b/src/test/java/org/orekit/rugged/intersection/BasicScanAlgorithmTest.java @@ -17,6 +17,10 @@ package org.orekit.rugged.intersection; +import static org.junit.Assert.assertEquals; + +import org.junit.Test; +import org.orekit.rugged.api.AlgorithmId; import org.orekit.rugged.raster.TileUpdater; public class BasicScanAlgorithmTest extends AbstractAlgorithmTest { @@ -25,4 +29,10 @@ public class BasicScanAlgorithmTest extends AbstractAlgorithmTest { return new BasicScanAlgorithm(updater, maxCachedTiles); } + @Test + public void testAlgorithmId() { + setUpMayonVolcanoContext(); + final IntersectionAlgorithm algorithm = createAlgorithm(updater, 8); + assertEquals(AlgorithmId.BASIC_SLOW_EXHAUSTIVE_SCAN_FOR_TESTS_ONLY, algorithm.getAlgorithmId()); + } } diff --git a/src/test/java/org/orekit/rugged/intersection/ConstantElevationAlgorithmTest.java b/src/test/java/org/orekit/rugged/intersection/ConstantElevationAlgorithmTest.java index 64077c7e031622bba5a1c6a274c1e03b025d2330..af5933c68a53a6d34a4a07586c56c826a485823d 100644 --- a/src/test/java/org/orekit/rugged/intersection/ConstantElevationAlgorithmTest.java +++ b/src/test/java/org/orekit/rugged/intersection/ConstantElevationAlgorithmTest.java @@ -17,6 +17,8 @@ package org.orekit.rugged.intersection; +import static org.junit.Assert.assertEquals; + import java.io.File; import java.net.URISyntaxException; @@ -33,6 +35,7 @@ import org.orekit.data.DirectoryCrawler; import org.orekit.frames.FramesFactory; import org.orekit.orbits.CartesianOrbit; import org.orekit.propagation.SpacecraftState; +import org.orekit.rugged.api.AlgorithmId; import org.orekit.rugged.intersection.duvenhage.DuvenhageAlgorithm; import org.orekit.rugged.raster.CheckedPatternElevationUpdater; import org.orekit.rugged.raster.TileUpdater; @@ -96,6 +99,15 @@ public class ConstantElevationAlgorithmTest { double elevation0 = ignore.getElevation(gpRef.getLatitude(), gpConst.getLatitude()); Assert.assertEquals(elevation0, 0.0, 1.e-15); } + + @Test + public void testAlgorithmId() { + IntersectionAlgorithm constantElevation = new ConstantElevationAlgorithm(0.0); + assertEquals(AlgorithmId.CONSTANT_ELEVATION_OVER_ELLIPSOID, constantElevation.getAlgorithmId()); + + IntersectionAlgorithm ignore = new IgnoreDEMAlgorithm(); + assertEquals(AlgorithmId.IGNORE_DEM_USE_ELLIPSOID, ignore.getAlgorithmId()); + } @Before public void setUp() throws URISyntaxException { diff --git a/src/test/java/org/orekit/rugged/intersection/duvenhage/DuvenhageAlgorithmTest.java b/src/test/java/org/orekit/rugged/intersection/duvenhage/DuvenhageAlgorithmTest.java index 2aa0108f341d2fd64015f6092cd442c6ee914707..55830c25d237d94f705758f75afb5b601c663fdc 100644 --- a/src/test/java/org/orekit/rugged/intersection/duvenhage/DuvenhageAlgorithmTest.java +++ b/src/test/java/org/orekit/rugged/intersection/duvenhage/DuvenhageAlgorithmTest.java @@ -19,6 +19,9 @@ package org.orekit.rugged.intersection.duvenhage; import org.hipparchus.geometry.euclidean.threed.Vector3D; import org.hipparchus.util.FastMath; + +import static org.junit.Assert.assertEquals; + import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; @@ -27,6 +30,7 @@ import org.junit.Assert; import org.junit.Test; import org.orekit.bodies.GeodeticPoint; import org.orekit.errors.OrekitException; +import org.orekit.rugged.api.AlgorithmId; import org.orekit.rugged.errors.RuggedException; import org.orekit.rugged.errors.RuggedMessages; import org.orekit.rugged.intersection.AbstractAlgorithmTest; @@ -191,6 +195,17 @@ public class DuvenhageAlgorithmTest extends AbstractAlgorithmTest { 1.0e-6); } + + @Test + public void testAlgorithmId() { + setUpMayonVolcanoContext(); + + final IntersectionAlgorithm algorithm = new DuvenhageAlgorithm(updater, 8, false); + assertEquals(AlgorithmId.DUVENHAGE, algorithm.getAlgorithmId()); + + final IntersectionAlgorithm algorithmFlatBody = new DuvenhageAlgorithm(updater, 8, true); + assertEquals(AlgorithmId.DUVENHAGE_FLAT_BODY, algorithmFlatBody.getAlgorithmId()); + } private NormalizedGeodeticPoint findExit(IntersectionAlgorithm algorithm, Tile tile, Vector3D position, Vector3D los) {