From 10fe582e4dc47599e0e8224bb94e4c367ba909e7 Mon Sep 17 00:00:00 2001 From: Guylaine Prat <guylaine.prat@c-s.fr> Date: Wed, 12 Dec 2018 15:44:57 +0100 Subject: [PATCH] Remove useless catch OrekitException. Fixes #373 --- .../rugged/adjustment/AdjustmentContext.java | 2 - .../org/orekit/rugged/api/RuggedBuilder.java | 172 ++++++-------- .../java/org/orekit/rugged/errors/Dump.java | 16 +- .../orekit/rugged/errors/DumpReplayer.java | 46 +--- .../intersection/BasicScanAlgorithm.java | 206 ++++++++-------- .../ConstantElevationAlgorithm.java | 32 +-- .../intersection/IntersectionAlgorithm.java | 8 +- .../duvenhage/DuvenhageAlgorithm.java | 221 ++++++++---------- .../org/orekit/rugged/los/FixedRotation.java | 24 +- .../orekit/rugged/los/FixedZHomothety.java | 24 +- .../org/orekit/rugged/los/LOSBuilder.java | 8 +- .../orekit/rugged/los/PolynomialRotation.java | 13 +- .../rugged/utils/ExtendedEllipsoid.java | 120 ++++------ .../utils/SpacecraftToObservedBody.java | 159 ++++++------- 14 files changed, 449 insertions(+), 602 deletions(-) diff --git a/src/main/java/org/orekit/rugged/adjustment/AdjustmentContext.java b/src/main/java/org/orekit/rugged/adjustment/AdjustmentContext.java index 094bd7b5..ab131736 100644 --- a/src/main/java/org/orekit/rugged/adjustment/AdjustmentContext.java +++ b/src/main/java/org/orekit/rugged/adjustment/AdjustmentContext.java @@ -162,8 +162,6 @@ public class AdjustmentContext { } catch (RuggedExceptionWrapper rew) { throw rew.getException(); - } catch (OrekitException oe) { - throw new RuggedException(oe, oe.getSpecifier(), oe.getParts()); } } } diff --git a/src/main/java/org/orekit/rugged/api/RuggedBuilder.java b/src/main/java/org/orekit/rugged/api/RuggedBuilder.java index 1113da3c..392e19a0 100644 --- a/src/main/java/org/orekit/rugged/api/RuggedBuilder.java +++ b/src/main/java/org/orekit/rugged/api/RuggedBuilder.java @@ -737,46 +737,41 @@ public class RuggedBuilder { * @exception RuggedException if data needed for some frame cannot be loaded */ private static SpacecraftToObservedBody createInterpolator(final Frame inertialFrame, final Frame bodyFrame, - final AbsoluteDate minDate, final AbsoluteDate maxDate, - final double tStep, final double overshootTolerance, - final double interpolationStep, final int interpolationNumber, - final CartesianDerivativesFilter pvFilter, - final AngularDerivativesFilter aFilter, - final Propagator propagator) - throws RuggedException { - try { + final AbsoluteDate minDate, final AbsoluteDate maxDate, + final double tStep, final double overshootTolerance, + final double interpolationStep, final int interpolationNumber, + final CartesianDerivativesFilter pvFilter, + final AngularDerivativesFilter aFilter, + final Propagator propagator) { + + // extract position/attitude samples from propagator + final List<TimeStampedPVCoordinates> positionsVelocities = + new ArrayList<TimeStampedPVCoordinates>(); + final List<TimeStampedAngularCoordinates> quaternions = + new ArrayList<TimeStampedAngularCoordinates>(); + propagator.setMasterMode(interpolationStep, new OrekitFixedStepHandler() { + + /** {@inheritDoc} */ + @Override + public void handleStep(final SpacecraftState currentState, final boolean isLast) + throws OrekitException { + final AbsoluteDate date = currentState.getDate(); + final PVCoordinates pv = currentState.getPVCoordinates(inertialFrame); + final Rotation q = currentState.getAttitude().getRotation(); + positionsVelocities.add(new TimeStampedPVCoordinates(date, pv.getPosition(), pv.getVelocity(), Vector3D.ZERO)); + quaternions.add(new TimeStampedAngularCoordinates(date, q, Vector3D.ZERO, Vector3D.ZERO)); + } - // extract position/attitude samples from propagator - final List<TimeStampedPVCoordinates> positionsVelocities = - new ArrayList<TimeStampedPVCoordinates>(); - final List<TimeStampedAngularCoordinates> quaternions = - new ArrayList<TimeStampedAngularCoordinates>(); - propagator.setMasterMode(interpolationStep, new OrekitFixedStepHandler() { + }); + propagator.propagate(minDate.shiftedBy(-interpolationStep), maxDate.shiftedBy(interpolationStep)); + + // orbit/attitude to body converter + return createInterpolator(inertialFrame, bodyFrame, + minDate, maxDate, tStep, overshootTolerance, + positionsVelocities, interpolationNumber, + pvFilter, quaternions, interpolationNumber, + aFilter); - /** {@inheritDoc} */ - @Override - public void handleStep(final SpacecraftState currentState, final boolean isLast) - throws OrekitException { - final AbsoluteDate date = currentState.getDate(); - final PVCoordinates pv = currentState.getPVCoordinates(inertialFrame); - final Rotation q = currentState.getAttitude().getRotation(); - positionsVelocities.add(new TimeStampedPVCoordinates(date, pv.getPosition(), pv.getVelocity(), Vector3D.ZERO)); - quaternions.add(new TimeStampedAngularCoordinates(date, q, Vector3D.ZERO, Vector3D.ZERO)); - } - - }); - propagator.propagate(minDate.shiftedBy(-interpolationStep), maxDate.shiftedBy(interpolationStep)); - - // orbit/attitude to body converter - return createInterpolator(inertialFrame, bodyFrame, - minDate, maxDate, tStep, overshootTolerance, - positionsVelocities, interpolationNumber, - pvFilter, quaternions, interpolationNumber, - aFilter); - - } catch (OrekitException pe) { - throw new RuggedException(pe, pe.getSpecifier(), pe.getParts()); - } } /** Set flag for light time correction. @@ -890,59 +885,45 @@ public class RuggedBuilder { /** Select inertial frame. * @param inertialFrameId inertial frame identifier * @return inertial frame - * @exception RuggedException if data needed for some frame cannot be loaded */ - private static Frame selectInertialFrame(final InertialFrameId inertialFrameId) - throws RuggedException { - - try { - // set up the inertial frame - switch (inertialFrameId) { - case GCRF : - return FramesFactory.getGCRF(); - case EME2000 : - return FramesFactory.getEME2000(); - case MOD : - return FramesFactory.getMOD(IERSConventions.IERS_1996); - case TOD : - return FramesFactory.getTOD(IERSConventions.IERS_1996, true); - case VEIS1950 : - return FramesFactory.getVeis1950(); - default : - // this should never happen - throw RuggedException.createInternalError(null); - } - } catch (OrekitException oe) { - throw new RuggedException(oe, oe.getSpecifier(), oe.getParts().clone()); + private static Frame selectInertialFrame(final InertialFrameId inertialFrameId) { + + // set up the inertial frame + switch (inertialFrameId) { + case GCRF : + return FramesFactory.getGCRF(); + case EME2000 : + return FramesFactory.getEME2000(); + case MOD : + return FramesFactory.getMOD(IERSConventions.IERS_1996); + case TOD : + return FramesFactory.getTOD(IERSConventions.IERS_1996, true); + case VEIS1950 : + return FramesFactory.getVeis1950(); + default : + // this should never happen + throw RuggedException.createInternalError(null); } - } /** Select body rotating frame. * @param bodyRotatingFrame body rotating frame identifier * @return body rotating frame - * @exception RuggedException if data needed for some frame cannot be loaded */ - private static Frame selectBodyRotatingFrame(final BodyRotatingFrameId bodyRotatingFrame) - throws RuggedException { - - try { - // set up the rotating frame - switch (bodyRotatingFrame) { - case ITRF : - return FramesFactory.getITRF(IERSConventions.IERS_2010, true); - case ITRF_EQUINOX : - return FramesFactory.getITRFEquinox(IERSConventions.IERS_1996, true); - case GTOD : - return FramesFactory.getGTOD(IERSConventions.IERS_1996, true); - default : - // this should never happen - throw RuggedException.createInternalError(null); - } - } catch (OrekitException oe) { - throw new RuggedException(oe, oe.getSpecifier(), oe.getParts().clone()); + private static Frame selectBodyRotatingFrame(final BodyRotatingFrameId bodyRotatingFrame) { + + // set up the rotating frame + switch (bodyRotatingFrame) { + case ITRF : + return FramesFactory.getITRF(IERSConventions.IERS_2010, true); + case ITRF_EQUINOX : + return FramesFactory.getITRFEquinox(IERSConventions.IERS_1996, true); + case GTOD : + return FramesFactory.getGTOD(IERSConventions.IERS_1996, true); + default : + // this should never happen + throw RuggedException.createInternalError(null); } - } /** Select ellipsoid. @@ -984,21 +965,20 @@ public class RuggedBuilder { // set up the algorithm switch (algorithmID) { - case DUVENHAGE : - return new DuvenhageAlgorithm(updater, maxCachedTiles, false); - case DUVENHAGE_FLAT_BODY : - return new DuvenhageAlgorithm(updater, maxCachedTiles, true); - case BASIC_SLOW_EXHAUSTIVE_SCAN_FOR_TESTS_ONLY : - return new BasicScanAlgorithm(updater, maxCachedTiles); - case CONSTANT_ELEVATION_OVER_ELLIPSOID : - return new ConstantElevationAlgorithm(constantElevation); - case IGNORE_DEM_USE_ELLIPSOID : - return new IgnoreDEMAlgorithm(); - default : - // this should never happen - throw RuggedException.createInternalError(null); + case DUVENHAGE : + return new DuvenhageAlgorithm(updater, maxCachedTiles, false); + case DUVENHAGE_FLAT_BODY : + return new DuvenhageAlgorithm(updater, maxCachedTiles, true); + case BASIC_SLOW_EXHAUSTIVE_SCAN_FOR_TESTS_ONLY : + return new BasicScanAlgorithm(updater, maxCachedTiles); + case CONSTANT_ELEVATION_OVER_ELLIPSOID : + return new ConstantElevationAlgorithm(constantElevation); + case IGNORE_DEM_USE_ELLIPSOID : + return new IgnoreDEMAlgorithm(); + default : + // this should never happen + throw RuggedException.createInternalError(null); } - } /** Build a {@link Rugged} instance. diff --git a/src/main/java/org/orekit/rugged/errors/Dump.java b/src/main/java/org/orekit/rugged/errors/Dump.java index a7f29c7a..9572ca90 100644 --- a/src/main/java/org/orekit/rugged/errors/Dump.java +++ b/src/main/java/org/orekit/rugged/errors/Dump.java @@ -345,18 +345,12 @@ class Dump { /** Convert a date to string with high accuracy. * @param date computation date * @return converted date - * @exception RuggedException if date cannot be converted to UTC */ - private String convertDate(final AbsoluteDate date) - throws RuggedException { - try { - final DateTimeComponents dt = date.getComponents(TimeScalesFactory.getUTC()); - return String.format(Locale.US, "%04d-%02d-%02dT%02d:%02d:%017.14fZ", - dt.getDate().getYear(), dt.getDate().getMonth(), dt.getDate().getDay(), - dt.getTime().getHour(), dt.getTime().getMinute(), dt.getTime().getSecond()); - } catch (OrekitException oe) { - throw new RuggedException(oe, oe.getSpecifier(), oe.getParts()); - } + private String convertDate(final AbsoluteDate date) { + final DateTimeComponents dt = date.getComponents(TimeScalesFactory.getUTC()); + return String.format(Locale.US, "%04d-%02d-%02dT%02d:%02d:%017.14fZ", + dt.getDate().getYear(), dt.getDate().getMonth(), dt.getDate().getDay(), + dt.getTime().getHour(), dt.getTime().getMinute(), dt.getTime().getSecond()); } /** Convert a translation to string. diff --git a/src/main/java/org/orekit/rugged/errors/DumpReplayer.java b/src/main/java/org/orekit/rugged/errors/DumpReplayer.java index cb7f6718..43dae250 100644 --- a/src/main/java/org/orekit/rugged/errors/DumpReplayer.java +++ b/src/main/java/org/orekit/rugged/errors/DumpReplayer.java @@ -524,8 +524,6 @@ public class DumpReplayer { final Frame bodyFrame; try { bodyFrame = FramesFactory.getFrame(Predefined.valueOf(fields[5])); - } catch (OrekitException oe) { - throw new RuggedException(oe, oe.getSpecifier(), oe.getParts()); } catch (IllegalArgumentException iae) { throw new RuggedException(RuggedMessages.CANNOT_PARSE_LINE, l, file, line); } @@ -539,9 +537,7 @@ public class DumpReplayer { /** {@inheritDoc} */ @Override - public void parse(final int l, final File file, final String line, final String[] fields, final DumpReplayer global) - throws RuggedException { - try { + public void parse(final int l, final File file, final String line, final String[] fields, final DumpReplayer global) { if (fields.length < 14 || !fields[0].equals(DATE) || !fields[2].equals(POSITION) || !fields[6].equals(LOS) || @@ -577,11 +573,7 @@ public class DumpReplayer { } }); - } catch (OrekitException oe) { - throw new RuggedException(oe, oe.getSpecifier(), oe.getParts()); - } } - }, /** Parser for direct location result dump lines. */ @@ -609,9 +601,7 @@ public class DumpReplayer { /** {@inheritDoc} */ @Override - public void parse(final int l, final File file, final String line, final String[] fields, final DumpReplayer global) - throws RuggedException { - try { + public void parse(final int l, final File file, final String line, final String[] fields, final DumpReplayer global) { if (fields.length < 10 || !fields[0].equals(MIN_DATE) || !fields[2].equals(MAX_DATE) || !fields[4].equals(T_STEP) || !fields[6].equals(TOLERANCE) || !fields[8].equals(INERTIAL_FRAME)) { @@ -628,11 +618,7 @@ public class DumpReplayer { } catch (IllegalArgumentException iae) { throw new RuggedException(RuggedMessages.CANNOT_PARSE_LINE, l, file, line); } - } catch (OrekitException oe) { - throw new RuggedException(oe, oe.getSpecifier(), oe.getParts()); - } } - }, /** Parser for observation transforms dump lines. */ @@ -843,9 +829,7 @@ public class DumpReplayer { /** {@inheritDoc} */ @Override - public void parse(final int l, final File file, final String line, final String[] fields, final DumpReplayer global) - throws RuggedException { - try { + public void parse(final int l, final File file, final String line, final String[] fields, final DumpReplayer global) { if (fields.length < 16 || !fields[0].equals(SENSOR_NAME) || !fields[2].equals(MIN_LINE) || !fields[4].equals(MAX_LINE) || !fields[6].equals(MAX_EVAL) || !fields[8].equals(ACCURACY) || @@ -884,12 +868,7 @@ public class DumpReplayer { base += 15; } global.getSensor(sensorName).setMeanPlane(new ParsedMeanPlane(minLine, maxLine, maxEval, accuracy, normal, cachedResults)); - - } catch (OrekitException oe) { - throw new RuggedException(oe, oe.getSpecifier(), oe.getParts()); - } } - }, /** Parser for sensor LOS dump lines. */ @@ -897,9 +876,7 @@ public class DumpReplayer { /** {@inheritDoc} */ @Override - public void parse(final int l, final File file, final String line, final String[] fields, final DumpReplayer global) - throws RuggedException { - try { + public void parse(final int l, final File file, final String line, final String[] fields, final DumpReplayer global) { if (fields.length < 10 || !fields[0].equals(SENSOR_NAME) || !fields[2].equals(DATE) || !fields[4].equals(PIXEL_NUMBER) || !fields[6].equals(LOS)) { @@ -912,12 +889,7 @@ public class DumpReplayer { Double.parseDouble(fields[8]), Double.parseDouble(fields[9])); global.getSensor(sensorName).setLOS(date, pixelNumber, los); - - } catch (OrekitException oe) { - throw new RuggedException(oe, oe.getSpecifier(), oe.getParts()); - } } - }, /** Parser for sensor datation dump lines. */ @@ -925,9 +897,7 @@ public class DumpReplayer { /** {@inheritDoc} */ @Override - public void parse(final int l, final File file, final String line, final String[] fields, final DumpReplayer global) - throws RuggedException { - try { + public void parse(final int l, final File file, final String line, final String[] fields, final DumpReplayer global) { if (fields.length < 6 || !fields[0].equals(SENSOR_NAME) || !fields[2].equals(LINE_NUMBER) || !fields[4].equals(DATE)) { throw new RuggedException(RuggedMessages.CANNOT_PARSE_LINE, l, file, line); @@ -936,13 +906,7 @@ public class DumpReplayer { final double lineNumber = Double.parseDouble(fields[3]); final AbsoluteDate date = new AbsoluteDate(fields[5], TimeScalesFactory.getUTC()); global.getSensor(sensorName).setDatation(lineNumber, date); - - } catch (OrekitException oe) { - throw new RuggedException(oe, oe.getSpecifier(), oe.getParts()); - } - } - }, /** Parser for sensor rate dump lines. */ diff --git a/src/main/java/org/orekit/rugged/intersection/BasicScanAlgorithm.java b/src/main/java/org/orekit/rugged/intersection/BasicScanAlgorithm.java index 4960edb9..b357f2a4 100644 --- a/src/main/java/org/orekit/rugged/intersection/BasicScanAlgorithm.java +++ b/src/main/java/org/orekit/rugged/intersection/BasicScanAlgorithm.java @@ -66,131 +66,119 @@ public class BasicScanAlgorithm implements IntersectionAlgorithm { /** {@inheritDoc} */ @Override public NormalizedGeodeticPoint intersection(final ExtendedEllipsoid ellipsoid, - final Vector3D position, final Vector3D los) - throws RuggedException { - try { - - DumpManager.dumpAlgorithm(AlgorithmId.BASIC_SLOW_EXHAUSTIVE_SCAN_FOR_TESTS_ONLY); - - // find the tiles between the entry and exit point in the Digital Elevation Model - NormalizedGeodeticPoint entryPoint = null; - NormalizedGeodeticPoint exitPoint = null; - double minLatitude = Double.NaN; - double maxLatitude = Double.NaN; - double minLongitude = Double.NaN; - double maxLongitude = Double.NaN; - final List<SimpleTile> scannedTiles = new ArrayList<SimpleTile>(); - double centralLongitude = Double.NaN; - for (boolean changedMinMax = true; changedMinMax; changedMinMax = checkMinMax(scannedTiles)) { - - scannedTiles.clear(); - // compute entry and exit points - entryPoint = ellipsoid.transform(ellipsoid.pointAtAltitude(position, los, Double.isInfinite(hMax) ? 0.0 : hMax), - ellipsoid.getBodyFrame(), null, - Double.isNaN(centralLongitude) ? 0.0 : centralLongitude); - final SimpleTile entryTile = cache.getTile(entryPoint.getLatitude(), entryPoint.getLongitude()); - if (Double.isNaN(centralLongitude)) { - centralLongitude = entryTile.getMinimumLongitude(); - entryPoint = new NormalizedGeodeticPoint(entryPoint.getLatitude(), entryPoint.getLongitude(), - entryPoint.getAltitude(), centralLongitude); - } - addIfNotPresent(scannedTiles, entryTile); - - exitPoint = ellipsoid.transform(ellipsoid.pointAtAltitude(position, los, Double.isInfinite(hMin) ? 0.0 : hMin), - ellipsoid.getBodyFrame(), null, centralLongitude); - final SimpleTile exitTile = cache.getTile(exitPoint.getLatitude(), exitPoint.getLongitude()); - addIfNotPresent(scannedTiles, exitTile); - - minLatitude = FastMath.min(entryPoint.getLatitude(), exitPoint.getLatitude()); - maxLatitude = FastMath.max(entryPoint.getLatitude(), exitPoint.getLatitude()); - minLongitude = FastMath.min(entryPoint.getLongitude(), exitPoint.getLongitude()); - maxLongitude = FastMath.max(entryPoint.getLongitude(), exitPoint.getLongitude()); - - if (scannedTiles.size() > 1) { - // the entry and exit tiles are different, maybe other tiles should be added on the way - // in the spirit of simple and exhaustive, we add all tiles in a rectangular area - final double latStep = 0.5 * FastMath.min(entryTile.getLatitudeStep() * entryTile.getLatitudeRows(), - exitTile.getLatitudeStep() * exitTile.getLatitudeRows()); - final double lonStep = 0.5 * FastMath.min(entryTile.getLongitudeStep() * entryTile.getLongitudeColumns(), - exitTile.getLongitudeStep() * exitTile.getLongitudeColumns()); - for (double latitude = minLatitude; latitude <= maxLatitude; latitude += latStep) { - for (double longitude = minLongitude; longitude < maxLongitude; longitude += lonStep) { - addIfNotPresent(scannedTiles, cache.getTile(latitude, longitude)); - } + final Vector3D position, final Vector3D los) { + + DumpManager.dumpAlgorithm(AlgorithmId.BASIC_SLOW_EXHAUSTIVE_SCAN_FOR_TESTS_ONLY); + + // find the tiles between the entry and exit point in the Digital Elevation Model + NormalizedGeodeticPoint entryPoint = null; + NormalizedGeodeticPoint exitPoint = null; + double minLatitude = Double.NaN; + double maxLatitude = Double.NaN; + double minLongitude = Double.NaN; + double maxLongitude = Double.NaN; + final List<SimpleTile> scannedTiles = new ArrayList<SimpleTile>(); + double centralLongitude = Double.NaN; + for (boolean changedMinMax = true; changedMinMax; changedMinMax = checkMinMax(scannedTiles)) { + + scannedTiles.clear(); + // compute entry and exit points + entryPoint = ellipsoid.transform(ellipsoid.pointAtAltitude(position, los, Double.isInfinite(hMax) ? 0.0 : hMax), + ellipsoid.getBodyFrame(), null, + Double.isNaN(centralLongitude) ? 0.0 : centralLongitude); + final SimpleTile entryTile = cache.getTile(entryPoint.getLatitude(), entryPoint.getLongitude()); + if (Double.isNaN(centralLongitude)) { + centralLongitude = entryTile.getMinimumLongitude(); + entryPoint = new NormalizedGeodeticPoint(entryPoint.getLatitude(), entryPoint.getLongitude(), + entryPoint.getAltitude(), centralLongitude); + } + addIfNotPresent(scannedTiles, entryTile); + + exitPoint = ellipsoid.transform(ellipsoid.pointAtAltitude(position, los, Double.isInfinite(hMin) ? 0.0 : hMin), + ellipsoid.getBodyFrame(), null, centralLongitude); + final SimpleTile exitTile = cache.getTile(exitPoint.getLatitude(), exitPoint.getLongitude()); + addIfNotPresent(scannedTiles, exitTile); + + minLatitude = FastMath.min(entryPoint.getLatitude(), exitPoint.getLatitude()); + maxLatitude = FastMath.max(entryPoint.getLatitude(), exitPoint.getLatitude()); + minLongitude = FastMath.min(entryPoint.getLongitude(), exitPoint.getLongitude()); + maxLongitude = FastMath.max(entryPoint.getLongitude(), exitPoint.getLongitude()); + + if (scannedTiles.size() > 1) { + // the entry and exit tiles are different, maybe other tiles should be added on the way + // in the spirit of simple and exhaustive, we add all tiles in a rectangular area + final double latStep = 0.5 * FastMath.min(entryTile.getLatitudeStep() * entryTile.getLatitudeRows(), + exitTile.getLatitudeStep() * exitTile.getLatitudeRows()); + final double lonStep = 0.5 * FastMath.min(entryTile.getLongitudeStep() * entryTile.getLongitudeColumns(), + exitTile.getLongitudeStep() * exitTile.getLongitudeColumns()); + for (double latitude = minLatitude; latitude <= maxLatitude; latitude += latStep) { + for (double longitude = minLongitude; longitude < maxLongitude; longitude += lonStep) { + addIfNotPresent(scannedTiles, cache.getTile(latitude, longitude)); } } - } - // scan the tiles - NormalizedGeodeticPoint intersectionGP = null; - double intersectionDot = Double.POSITIVE_INFINITY; - for (final SimpleTile tile : scannedTiles) { - for (int i = latitudeIndex(tile, minLatitude); i <= latitudeIndex(tile, maxLatitude); ++i) { - for (int j = longitudeIndex(tile, minLongitude); j <= longitudeIndex(tile, maxLongitude); ++j) { - final NormalizedGeodeticPoint gp = tile.cellIntersection(entryPoint, ellipsoid.convertLos(entryPoint, los), i, j); - if (gp != null) { - - // improve the point, by projecting it back on the 3D line, fixing the small body curvature at cell level - final Vector3D delta = ellipsoid.transform(gp).subtract(position); - final double s = Vector3D.dotProduct(delta, los) / los.getNormSq(); - final GeodeticPoint projected = ellipsoid.transform(new Vector3D(1, position, s, los), - ellipsoid.getBodyFrame(), null); - final NormalizedGeodeticPoint normalizedProjected = new NormalizedGeodeticPoint(projected.getLatitude(), - projected.getLongitude(), - projected.getAltitude(), - gp.getLongitude()); - final NormalizedGeodeticPoint gpImproved = tile.cellIntersection(normalizedProjected, - ellipsoid.convertLos(normalizedProjected, los), - i, j); - - if (gpImproved != null) { - final Vector3D point = ellipsoid.transform(gpImproved); - final double dot = Vector3D.dotProduct(point.subtract(position), los); - if (dot < intersectionDot) { - intersectionGP = gpImproved; - intersectionDot = dot; - } - } + } + // scan the tiles + NormalizedGeodeticPoint intersectionGP = null; + double intersectionDot = Double.POSITIVE_INFINITY; + for (final SimpleTile tile : scannedTiles) { + for (int i = latitudeIndex(tile, minLatitude); i <= latitudeIndex(tile, maxLatitude); ++i) { + for (int j = longitudeIndex(tile, minLongitude); j <= longitudeIndex(tile, maxLongitude); ++j) { + final NormalizedGeodeticPoint gp = tile.cellIntersection(entryPoint, ellipsoid.convertLos(entryPoint, los), i, j); + if (gp != null) { + + // improve the point, by projecting it back on the 3D line, fixing the small body curvature at cell level + final Vector3D delta = ellipsoid.transform(gp).subtract(position); + final double s = Vector3D.dotProduct(delta, los) / los.getNormSq(); + final GeodeticPoint projected = ellipsoid.transform(new Vector3D(1, position, s, los), + ellipsoid.getBodyFrame(), null); + final NormalizedGeodeticPoint normalizedProjected = new NormalizedGeodeticPoint(projected.getLatitude(), + projected.getLongitude(), + projected.getAltitude(), + gp.getLongitude()); + final NormalizedGeodeticPoint gpImproved = tile.cellIntersection(normalizedProjected, + ellipsoid.convertLos(normalizedProjected, los), + i, j); + + if (gpImproved != null) { + final Vector3D point = ellipsoid.transform(gpImproved); + final double dot = Vector3D.dotProduct(point.subtract(position), los); + if (dot < intersectionDot) { + intersectionGP = gpImproved; + intersectionDot = dot; + } } + } } } - - return intersectionGP; - - } catch (OrekitException oe) { - // this should never happen - throw new RuggedException(oe, oe.getSpecifier(), oe.getParts()); } + + return intersectionGP; } /** {@inheritDoc} */ @Override public NormalizedGeodeticPoint refineIntersection(final ExtendedEllipsoid ellipsoid, final Vector3D position, final Vector3D los, - final NormalizedGeodeticPoint closeGuess) - throws RuggedException { - try { - DumpManager.dumpAlgorithm(AlgorithmId.BASIC_SLOW_EXHAUSTIVE_SCAN_FOR_TESTS_ONLY); - 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), - ellipsoid.getBodyFrame(), null); - final NormalizedGeodeticPoint normalizedProjected = new NormalizedGeodeticPoint(projected.getLatitude(), - projected.getLongitude(), - projected.getAltitude(), - closeGuess.getLongitude()); - final Tile tile = cache.getTile(normalizedProjected.getLatitude(), - normalizedProjected.getLongitude()); - return tile.cellIntersection(normalizedProjected, - ellipsoid.convertLos(normalizedProjected, los), - tile.getFloorLatitudeIndex(normalizedProjected.getLatitude()), - tile.getFloorLongitudeIndex(normalizedProjected.getLongitude())); - } catch (OrekitException oe) { - throw new RuggedException(oe, oe.getSpecifier(), oe.getParts()); - } + final NormalizedGeodeticPoint closeGuess) { + DumpManager.dumpAlgorithm(AlgorithmId.BASIC_SLOW_EXHAUSTIVE_SCAN_FOR_TESTS_ONLY); + 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), + ellipsoid.getBodyFrame(), null); + final NormalizedGeodeticPoint normalizedProjected = new NormalizedGeodeticPoint(projected.getLatitude(), + projected.getLongitude(), + projected.getAltitude(), + closeGuess.getLongitude()); + final Tile tile = cache.getTile(normalizedProjected.getLatitude(), + normalizedProjected.getLongitude()); + return tile.cellIntersection(normalizedProjected, + ellipsoid.convertLos(normalizedProjected, los), + tile.getFloorLatitudeIndex(normalizedProjected.getLatitude()), + tile.getFloorLongitudeIndex(normalizedProjected.getLongitude())); } /** {@inheritDoc} */ diff --git a/src/main/java/org/orekit/rugged/intersection/ConstantElevationAlgorithm.java b/src/main/java/org/orekit/rugged/intersection/ConstantElevationAlgorithm.java index 70be321b..af339229 100644 --- a/src/main/java/org/orekit/rugged/intersection/ConstantElevationAlgorithm.java +++ b/src/main/java/org/orekit/rugged/intersection/ConstantElevationAlgorithm.java @@ -46,33 +46,23 @@ public class ConstantElevationAlgorithm implements IntersectionAlgorithm { /** {@inheritDoc} */ @Override public NormalizedGeodeticPoint intersection(final ExtendedEllipsoid ellipsoid, - final Vector3D position, final Vector3D los) - throws RuggedException { - try { - DumpManager.dumpAlgorithm(AlgorithmId.CONSTANT_ELEVATION_OVER_ELLIPSOID, 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); - } catch (OrekitException oe) { - throw new RuggedException(oe, oe.getSpecifier(), oe.getParts()); - } + final Vector3D position, final Vector3D los) { + DumpManager.dumpAlgorithm(AlgorithmId.CONSTANT_ELEVATION_OVER_ELLIPSOID, 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); } /** {@inheritDoc} */ @Override public NormalizedGeodeticPoint refineIntersection(final ExtendedEllipsoid ellipsoid, final Vector3D position, final Vector3D los, - final NormalizedGeodeticPoint closeGuess) - throws RuggedException { - try { - DumpManager.dumpAlgorithm(AlgorithmId.CONSTANT_ELEVATION_OVER_ELLIPSOID, 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(), - closeGuess.getLongitude()); - } catch (OrekitException oe) { - throw new RuggedException(oe, oe.getSpecifier(), oe.getParts()); - } + final NormalizedGeodeticPoint closeGuess) { + DumpManager.dumpAlgorithm(AlgorithmId.CONSTANT_ELEVATION_OVER_ELLIPSOID, 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(), + closeGuess.getLongitude()); } /** {@inheritDoc} diff --git a/src/main/java/org/orekit/rugged/intersection/IntersectionAlgorithm.java b/src/main/java/org/orekit/rugged/intersection/IntersectionAlgorithm.java index 17579c2f..dbc8bf1b 100644 --- a/src/main/java/org/orekit/rugged/intersection/IntersectionAlgorithm.java +++ b/src/main/java/org/orekit/rugged/intersection/IntersectionAlgorithm.java @@ -31,10 +31,8 @@ public interface IntersectionAlgorithm { * @param position pixel position in ellipsoid frame * @param los pixel line-of-sight in ellipsoid frame * @return point at which the line first enters ground - * @exception RuggedException if intersection cannot be found */ - NormalizedGeodeticPoint intersection(ExtendedEllipsoid ellipsoid, Vector3D position, Vector3D los) - throws RuggedException; + NormalizedGeodeticPoint intersection(ExtendedEllipsoid ellipsoid, Vector3D position, Vector3D los); /** Refine intersection of line with Digital Elevation Model. * <p> @@ -49,11 +47,9 @@ public interface IntersectionAlgorithm { * @param los pixel line-of-sight in ellipsoid frame * @param closeGuess guess close to the real intersection * @return point at which the line first enters ground - * @exception RuggedException if intersection cannot be found */ NormalizedGeodeticPoint refineIntersection(ExtendedEllipsoid ellipsoid, Vector3D position, Vector3D los, - NormalizedGeodeticPoint closeGuess) - throws RuggedException; + NormalizedGeodeticPoint closeGuess); /** Get elevation at a given ground point. * @param latitude ground point latitude 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 24098550..0fbd47a0 100644 --- a/src/main/java/org/orekit/rugged/intersection/duvenhage/DuvenhageAlgorithm.java +++ b/src/main/java/org/orekit/rugged/intersection/duvenhage/DuvenhageAlgorithm.java @@ -69,146 +69,131 @@ public class DuvenhageAlgorithm implements IntersectionAlgorithm { /** {@inheritDoc} */ @Override public NormalizedGeodeticPoint intersection(final ExtendedEllipsoid ellipsoid, - final Vector3D position, final Vector3D los) - throws RuggedException { - try { + final Vector3D position, final Vector3D los) { - DumpManager.dumpAlgorithm(flatBody ? AlgorithmId.DUVENHAGE_FLAT_BODY : AlgorithmId.DUVENHAGE); - - // compute intersection with ellipsoid - final NormalizedGeodeticPoint gp0 = ellipsoid.pointOnGround(position, los, 0.0); + DumpManager.dumpAlgorithm(flatBody ? AlgorithmId.DUVENHAGE_FLAT_BODY : AlgorithmId.DUVENHAGE); - // compute atmosphere deviation + // compute intersection with ellipsoid + final NormalizedGeodeticPoint gp0 = ellipsoid.pointOnGround(position, los, 0.0); - // locate the entry tile along the line-of-sight - MinMaxTreeTile tile = cache.getTile(gp0.getLatitude(), gp0.getLongitude()); + // compute atmosphere deviation - NormalizedGeodeticPoint current = null; - double hMax = tile.getMaxElevation(); - while (current == null) { + // locate the entry tile along the line-of-sight + MinMaxTreeTile tile = cache.getTile(gp0.getLatitude(), gp0.getLongitude()); - // find where line-of-sight crosses tile max altitude - final Vector3D entryP = ellipsoid.pointAtAltitude(position, los, hMax + STEP); - if (Vector3D.dotProduct(entryP.subtract(position), los) < 0) { - // the entry point is behind spacecraft! - throw new RuggedException(RuggedMessages.DEM_ENTRY_POINT_IS_BEHIND_SPACECRAFT); - } - current = ellipsoid.transform(entryP, ellipsoid.getBodyFrame(), null, tile.getMinimumLongitude()); + NormalizedGeodeticPoint current = null; + double hMax = tile.getMaxElevation(); + while (current == null) { - if (tile.getLocation(current.getLatitude(), current.getLongitude()) != Tile.Location.HAS_INTERPOLATION_NEIGHBORS) { - // the entry point is in another tile - tile = cache.getTile(current.getLatitude(), current.getLongitude()); - hMax = FastMath.max(hMax, tile.getMaxElevation()); - current = null; - } + // find where line-of-sight crosses tile max altitude + final Vector3D entryP = ellipsoid.pointAtAltitude(position, los, hMax + STEP); + if (Vector3D.dotProduct(entryP.subtract(position), los) < 0) { + // the entry point is behind spacecraft! + throw new RuggedException(RuggedMessages.DEM_ENTRY_POINT_IS_BEHIND_SPACECRAFT); + } + current = ellipsoid.transform(entryP, ellipsoid.getBodyFrame(), null, tile.getMinimumLongitude()); + if (tile.getLocation(current.getLatitude(), current.getLongitude()) != Tile.Location.HAS_INTERPOLATION_NEIGHBORS) { + // the entry point is in another tile + tile = cache.getTile(current.getLatitude(), current.getLongitude()); + hMax = FastMath.max(hMax, tile.getMaxElevation()); + current = null; } - // loop along the path - while (true) { - - // find where line-of-sight exit tile - final LimitPoint exit = findExit(tile, ellipsoid, position, los); - - // compute intersection with Digital Elevation Model - final int entryLat = FastMath.max(0, - FastMath.min(tile.getLatitudeRows() - 1, - tile.getFloorLatitudeIndex(current.getLatitude()))); - final int entryLon = FastMath.max(0, - FastMath.min(tile.getLongitudeColumns() - 1, - tile.getFloorLongitudeIndex(current.getLongitude()))); - final int exitLat = FastMath.max(0, - FastMath.min(tile.getLatitudeRows() - 1, - tile.getFloorLatitudeIndex(exit.getPoint().getLatitude()))); - final int exitLon = FastMath.max(0, - FastMath.min(tile.getLongitudeColumns() - 1, - tile.getFloorLongitudeIndex(exit.getPoint().getLongitude()))); - NormalizedGeodeticPoint intersection = recurseIntersection(0, ellipsoid, position, los, tile, - current, entryLat, entryLon, - exit.getPoint(), exitLat, exitLon); + } + // loop along the path + while (true) { + + // find where line-of-sight exit tile + final LimitPoint exit = findExit(tile, ellipsoid, position, los); + + // compute intersection with Digital Elevation Model + final int entryLat = FastMath.max(0, + FastMath.min(tile.getLatitudeRows() - 1, + tile.getFloorLatitudeIndex(current.getLatitude()))); + final int entryLon = FastMath.max(0, + FastMath.min(tile.getLongitudeColumns() - 1, + tile.getFloorLongitudeIndex(current.getLongitude()))); + final int exitLat = FastMath.max(0, + FastMath.min(tile.getLatitudeRows() - 1, + tile.getFloorLatitudeIndex(exit.getPoint().getLatitude()))); + final int exitLon = FastMath.max(0, + FastMath.min(tile.getLongitudeColumns() - 1, + tile.getFloorLongitudeIndex(exit.getPoint().getLongitude()))); + NormalizedGeodeticPoint intersection = recurseIntersection(0, ellipsoid, position, los, tile, + current, entryLat, entryLon, + exit.getPoint(), exitLat, exitLon); + + if (intersection != null) { + // we have found the intersection + return intersection; + } else if (exit.atSide()) { + // no intersection on this tile, we can proceed to next part of the line-of-sight + + // select next tile after current point + final Vector3D forward = new Vector3D(1.0, ellipsoid.transform(exit.getPoint()), STEP, los); + current = ellipsoid.transform(forward, ellipsoid.getBodyFrame(), null, tile.getMinimumLongitude()); + tile = cache.getTile(current.getLatitude(), current.getLongitude()); + + if (tile.interpolateElevation(current.getLatitude(), current.getLongitude()) >= current.getAltitude()) { + // extremely rare case! The line-of-sight traversed the Digital Elevation Model + // during the very short forward step we used to move to next tile + // we consider this point to be OK + return current; + } + + } else { + + // this should never happen + // we should have left the loop with an intersection point + // try a fallback non-recursive search + intersection = noRecurseIntersection(ellipsoid, position, los, tile, + current, entryLat, entryLon, + exitLat, exitLon); if (intersection != null) { - // we have found the intersection return intersection; - } else if (exit.atSide()) { - // no intersection on this tile, we can proceed to next part of the line-of-sight - - // select next tile after current point - final Vector3D forward = new Vector3D(1.0, ellipsoid.transform(exit.getPoint()), STEP, los); - current = ellipsoid.transform(forward, ellipsoid.getBodyFrame(), null, tile.getMinimumLongitude()); - tile = cache.getTile(current.getLatitude(), current.getLongitude()); - - if (tile.interpolateElevation(current.getLatitude(), current.getLongitude()) >= current.getAltitude()) { - // extremely rare case! The line-of-sight traversed the Digital Elevation Model - // during the very short forward step we used to move to next tile - // we consider this point to be OK - return current; - } - } else { - - // this should never happen - // we should have left the loop with an intersection point - // try a fallback non-recursive search - intersection = noRecurseIntersection(ellipsoid, position, los, tile, - current, entryLat, entryLon, - exitLat, exitLon); - if (intersection != null) { - return intersection; - } else { - throw RuggedException.createInternalError(null); - } - + throw RuggedException.createInternalError(null); } - - } - - - } catch (OrekitException oe) { - throw new RuggedException(oe, oe.getSpecifier(), oe.getParts()); } } /** {@inheritDoc} */ @Override public NormalizedGeodeticPoint refineIntersection(final ExtendedEllipsoid ellipsoid, - final Vector3D position, final Vector3D los, - final NormalizedGeodeticPoint closeGuess) - throws RuggedException { - try { + final Vector3D position, final Vector3D los, + final NormalizedGeodeticPoint closeGuess) { - DumpManager.dumpAlgorithm(flatBody ? AlgorithmId.DUVENHAGE_FLAT_BODY : AlgorithmId.DUVENHAGE); - - if (flatBody) { - // under the (bad) flat-body assumption, the reference point must remain - // at DEM entry and exit, even if we already have a much better close guess :-( - // this is in order to remain consistent with other systems - final Tile tile = cache.getTile(closeGuess.getLatitude(), closeGuess.getLongitude()); - final Vector3D exitP = ellipsoid.pointAtAltitude(position, los, tile.getMinElevation()); - final Vector3D entryP = ellipsoid.pointAtAltitude(position, los, tile.getMaxElevation()); - final NormalizedGeodeticPoint entry = ellipsoid.transform(entryP, ellipsoid.getBodyFrame(), null, - tile.getMinimumLongitude()); - return tile.cellIntersection(entry, ellipsoid.convertLos(entryP, exitP), - tile.getFloorLatitudeIndex(closeGuess.getLatitude()), - tile.getFloorLongitudeIndex(closeGuess.getLongitude())); - } else { - 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), - ellipsoid.getBodyFrame(), null); - final NormalizedGeodeticPoint normalizedProjected = new NormalizedGeodeticPoint(projected.getLatitude(), - projected.getLongitude(), - projected.getAltitude(), - closeGuess.getLongitude()); - final Tile tile = cache.getTile(normalizedProjected.getLatitude(), - normalizedProjected.getLongitude()); - return tile.cellIntersection(normalizedProjected, ellipsoid.convertLos(normalizedProjected, los), - tile.getFloorLatitudeIndex(normalizedProjected.getLatitude()), - tile.getFloorLongitudeIndex(normalizedProjected.getLongitude())); - } - } catch (OrekitException oe) { - throw new RuggedException(oe, oe.getSpecifier(), oe.getParts()); + DumpManager.dumpAlgorithm(flatBody ? AlgorithmId.DUVENHAGE_FLAT_BODY : AlgorithmId.DUVENHAGE); + + if (flatBody) { + // under the (bad) flat-body assumption, the reference point must remain + // at DEM entry and exit, even if we already have a much better close guess :-( + // this is in order to remain consistent with other systems + final Tile tile = cache.getTile(closeGuess.getLatitude(), closeGuess.getLongitude()); + final Vector3D exitP = ellipsoid.pointAtAltitude(position, los, tile.getMinElevation()); + final Vector3D entryP = ellipsoid.pointAtAltitude(position, los, tile.getMaxElevation()); + final NormalizedGeodeticPoint entry = ellipsoid.transform(entryP, ellipsoid.getBodyFrame(), null, + tile.getMinimumLongitude()); + return tile.cellIntersection(entry, ellipsoid.convertLos(entryP, exitP), + tile.getFloorLatitudeIndex(closeGuess.getLatitude()), + tile.getFloorLongitudeIndex(closeGuess.getLongitude())); + } else { + 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), + ellipsoid.getBodyFrame(), null); + final NormalizedGeodeticPoint normalizedProjected = new NormalizedGeodeticPoint(projected.getLatitude(), + projected.getLongitude(), + projected.getAltitude(), + closeGuess.getLongitude()); + final Tile tile = cache.getTile(normalizedProjected.getLatitude(), + normalizedProjected.getLongitude()); + return tile.cellIntersection(normalizedProjected, ellipsoid.convertLos(normalizedProjected, los), + tile.getFloorLatitudeIndex(normalizedProjected.getLatitude()), + tile.getFloorLongitudeIndex(normalizedProjected.getLongitude())); } } diff --git a/src/main/java/org/orekit/rugged/los/FixedRotation.java b/src/main/java/org/orekit/rugged/los/FixedRotation.java index 07399130..8f79e7ab 100644 --- a/src/main/java/org/orekit/rugged/los/FixedRotation.java +++ b/src/main/java/org/orekit/rugged/los/FixedRotation.java @@ -66,23 +66,19 @@ public class FixedRotation implements TimeIndependentLOSTransform { * @param angle rotation angle */ public FixedRotation(final String name, final Vector3D axis, final double angle) { + this.axis = axis; this.rotation = null; this.rDS = null; - try { - this.angleDriver = new ParameterDriver(name, angle, SCALE, -2 * FastMath.PI, 2 * FastMath.PI); - angleDriver.addObserver(new ParameterObserver() { - @Override - public void valueChanged(final double previousValue, final ParameterDriver driver) { - // reset rotations to null, they will be evaluated lazily if needed - rotation = null; - rDS = null; - } - }); - } catch (OrekitException oe) { - // this should never happen - throw RuggedException.createInternalError(oe); - } + this.angleDriver = new ParameterDriver(name, angle, SCALE, -2 * FastMath.PI, 2 * FastMath.PI); + angleDriver.addObserver(new ParameterObserver() { + @Override + public void valueChanged(final double previousValue, final ParameterDriver driver) { + // reset rotations to null, they will be evaluated lazily if needed + rotation = null; + rDS = null; + } + }); } /** {@inheritDoc} */ diff --git a/src/main/java/org/orekit/rugged/los/FixedZHomothety.java b/src/main/java/org/orekit/rugged/los/FixedZHomothety.java index 8b05b494..429da97c 100644 --- a/src/main/java/org/orekit/rugged/los/FixedZHomothety.java +++ b/src/main/java/org/orekit/rugged/los/FixedZHomothety.java @@ -62,22 +62,18 @@ public class FixedZHomothety implements TimeIndependentLOSTransform { * @param factorvalue homothety factor */ public FixedZHomothety(final String name, final double factorvalue) { + this.factor = factorvalue; this.factorDS = null; - try { - this.factorDriver = new ParameterDriver(name, factorvalue, SCALE, 0, 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; - factorDS = null; - } - }); - } catch (OrekitException oe) { - // this should never happen - throw RuggedException.createInternalError(oe); - } + this.factorDriver = new ParameterDriver(name, factorvalue, SCALE, 0, 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; + factorDS = null; + } + }); } /** {@inheritDoc} */ diff --git a/src/main/java/org/orekit/rugged/los/LOSBuilder.java b/src/main/java/org/orekit/rugged/los/LOSBuilder.java index 4d51d73e..57e630b2 100644 --- a/src/main/java/org/orekit/rugged/los/LOSBuilder.java +++ b/src/main/java/org/orekit/rugged/los/LOSBuilder.java @@ -234,14 +234,8 @@ public class LOSBuilder { } }; getParametersDrivers().forEach(driver -> { - try { - driver.addObserver(resettingObserver); - } catch (OrekitException oe) { - // this should never happen - throw RuggedException.createInternalError(oe); - } + driver.addObserver(resettingObserver); }); - } /** {@inheritDoc} */ diff --git a/src/main/java/org/orekit/rugged/los/PolynomialRotation.java b/src/main/java/org/orekit/rugged/los/PolynomialRotation.java index 3a978793..d7c6e965 100644 --- a/src/main/java/org/orekit/rugged/los/PolynomialRotation.java +++ b/src/main/java/org/orekit/rugged/los/PolynomialRotation.java @@ -94,15 +94,10 @@ public class PolynomialRotation implements LOSTransform { angleDS = null; } }; - try { - for (int i = 0; i < angleCoeffs.length; ++i) { - coefficientsDrivers[i] = new ParameterDriver(name + "[" + i + "]", angleCoeffs[i], SCALE, - Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY); - coefficientsDrivers[i].addObserver(resettingObserver); - } - } catch (OrekitException oe) { - // this should never happen - throw RuggedException.createInternalError(oe); + for (int i = 0; i < angleCoeffs.length; ++i) { + coefficientsDrivers[i] = new ParameterDriver(name + "[" + i + "]", angleCoeffs[i], SCALE, + Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY); + coefficientsDrivers[i].addObserver(resettingObserver); } } diff --git a/src/main/java/org/orekit/rugged/utils/ExtendedEllipsoid.java b/src/main/java/org/orekit/rugged/utils/ExtendedEllipsoid.java index 3324e0ad..81b8a8d7 100644 --- a/src/main/java/org/orekit/rugged/utils/ExtendedEllipsoid.java +++ b/src/main/java/org/orekit/rugged/utils/ExtendedEllipsoid.java @@ -191,24 +191,19 @@ public class ExtendedEllipsoid extends OneAxisEllipsoid { * @param centralLongitude reference longitude lc such that the point longitude will * be normalized between lc-Ï€ and lc+Ï€ (rad) * @return point on ground - * @exception RuggedException if no such point exists (typically line-of-sight missing body) */ public NormalizedGeodeticPoint pointOnGround(final Vector3D position, final Vector3D los, - final double centralLongitude) - throws RuggedException { - try { - DumpManager.dumpEllipsoid(this); - final GeodeticPoint gp = - getIntersectionPoint(new Line(position, new Vector3D(1, position, 1e6, los), 1.0e-12), - position, getBodyFrame(), null); - if (gp == null) { - throw new RuggedException(RuggedMessages.LINE_OF_SIGHT_DOES_NOT_REACH_GROUND); - } - return new NormalizedGeodeticPoint(gp.getLatitude(), gp.getLongitude(), gp.getAltitude(), - centralLongitude); - } catch (OrekitException oe) { - throw new RuggedException(oe, oe.getSpecifier(), oe.getParts()); + final double centralLongitude) { + + DumpManager.dumpEllipsoid(this); + final GeodeticPoint gp = + getIntersectionPoint(new Line(position, new Vector3D(1, position, 1e6, los), 1.0e-12), + position, getBodyFrame(), null); + if (gp == null) { + throw new RuggedException(RuggedMessages.LINE_OF_SIGHT_DOES_NOT_REACH_GROUND); } + return new NormalizedGeodeticPoint(gp.getLatitude(), gp.getLongitude(), gp.getAltitude(), + centralLongitude); } /** Get point at some altitude along a pixel line of sight. @@ -216,55 +211,47 @@ public class ExtendedEllipsoid extends OneAxisEllipsoid { * @param los pixel line-of-sight, not necessarily normalized (in body frame) * @param altitude altitude with respect to ellipsoid (m) * @return point at altitude (m) - * @exception RuggedException if no such point exists (typically too negative altitude) */ - public Vector3D pointAtAltitude(final Vector3D position, final Vector3D los, final double altitude) - throws RuggedException { - try { - - DumpManager.dumpEllipsoid(this); - - // point on line closest to origin - final double los2 = los.getNormSq(); - final double dot = Vector3D.dotProduct(position, los); - final double k0 = -dot / los2; - final Vector3D close0 = new Vector3D(1, position, k0, los); - - // very rough guess: if body is spherical, the desired point on line - // is at distance ae + altitude from origin - final double r = getEquatorialRadius() + altitude; - final double delta2 = r * r - close0.getNormSq(); - if (delta2 < 0) { - throw new RuggedException(RuggedMessages.LINE_OF_SIGHT_NEVER_CROSSES_ALTITUDE, altitude); - } - final double deltaK = FastMath.sqrt(delta2 / los2); - final double k1 = k0 + deltaK; - final double k2 = k0 - deltaK; - double k = (FastMath.abs(k1) <= FastMath.abs(k2)) ? k1 : k2; - - // this loop generally converges in 3 iterations - for (int i = 0; i < 100; ++i) { - - final Vector3D point = new Vector3D(1, position, k, los); - final GeodeticPoint gpK = transform(point, getBodyFrame(), null); - final double deltaH = altitude - gpK.getAltitude(); - if (FastMath.abs(deltaH) <= ALTITUDE_CONVERGENCE) { - return point; - } + public Vector3D pointAtAltitude(final Vector3D position, final Vector3D los, final double altitude) { - // improve the offset using linear ratio between - // altitude variation and displacement along line-of-sight - k += deltaH / Vector3D.dotProduct(gpK.getZenith(), los); + DumpManager.dumpEllipsoid(this); + // point on line closest to origin + final double los2 = los.getNormSq(); + final double dot = Vector3D.dotProduct(position, los); + final double k0 = -dot / los2; + final Vector3D close0 = new Vector3D(1, position, k0, los); + + // very rough guess: if body is spherical, the desired point on line + // is at distance ae + altitude from origin + final double r = getEquatorialRadius() + altitude; + final double delta2 = r * r - close0.getNormSq(); + if (delta2 < 0) { + throw new RuggedException(RuggedMessages.LINE_OF_SIGHT_NEVER_CROSSES_ALTITUDE, altitude); + } + final double deltaK = FastMath.sqrt(delta2 / los2); + final double k1 = k0 + deltaK; + final double k2 = k0 - deltaK; + double k = (FastMath.abs(k1) <= FastMath.abs(k2)) ? k1 : k2; + + // this loop generally converges in 3 iterations + for (int i = 0; i < 100; ++i) { + + final Vector3D point = new Vector3D(1, position, k, los); + final GeodeticPoint gpK = transform(point, getBodyFrame(), null); + final double deltaH = altitude - gpK.getAltitude(); + if (FastMath.abs(deltaH) <= ALTITUDE_CONVERGENCE) { + return point; } - // this should never happen - throw new RuggedException(RuggedMessages.LINE_OF_SIGHT_NEVER_CROSSES_ALTITUDE, altitude); + // improve the offset using linear ratio between + // altitude variation and displacement along line-of-sight + k += deltaH / Vector3D.dotProduct(gpK.getZenith(), los); - } catch (OrekitException oe) { - // this should never happen - throw new RuggedException(oe, oe.getSpecifier(), oe.getParts()); } + + // this should never happen + throw new RuggedException(RuggedMessages.LINE_OF_SIGHT_NEVER_CROSSES_ALTITUDE, altitude); } /** Convert a line-of-sight from Cartesian to topocentric. @@ -302,22 +289,15 @@ public class ExtendedEllipsoid extends OneAxisEllipsoid { * with respect to the primary point (in body frame and Cartesian coordinates) * @return line-of-sight in topocentric frame (East, North, Zenith) of the point, * scaled to match radians in the horizontal plane and meters along the vertical axis - * @exception RuggedException if points cannot be converted to geodetic coordinates */ - public Vector3D convertLos(final Vector3D primary, final Vector3D secondary) - throws RuggedException { - try { + public Vector3D convertLos(final Vector3D primary, final Vector3D secondary) { - // switch to geodetic coordinates using primary point as reference - final GeodeticPoint point = transform(primary, getBodyFrame(), null); - final Vector3D los = secondary.subtract(primary); + // switch to geodetic coordinates using primary point as reference + final GeodeticPoint point = transform(primary, getBodyFrame(), null); + final Vector3D los = secondary.subtract(primary); - // convert line of sight - return convertLos(point, los); - - } catch (OrekitException oe) { - throw new RuggedException(oe, oe.getSpecifier(), oe.getParts()); - } + // convert line of sight + return convertLos(point, los); } /** Transform a cartesian point to a surface-relative point. diff --git a/src/main/java/org/orekit/rugged/utils/SpacecraftToObservedBody.java b/src/main/java/org/orekit/rugged/utils/SpacecraftToObservedBody.java index 75ef6212..0ffb7479 100644 --- a/src/main/java/org/orekit/rugged/utils/SpacecraftToObservedBody.java +++ b/src/main/java/org/orekit/rugged/utils/SpacecraftToObservedBody.java @@ -86,9 +86,6 @@ public class SpacecraftToObservedBody implements Serializable { * @param quaternions satellite quaternions * @param aInterpolationNumber number of points to use for attitude interpolation * @param aFilter filter for derivatives from the sample to use in attitude interpolation - * @exception RuggedException if [{@code minDate}, {@code maxDate}] search time span overshoots - * position or attitude samples by more than {@code overshootTolerance} - * , */ public SpacecraftToObservedBody(final Frame inertialFrame, final Frame bodyFrame, final AbsoluteDate minDate, final AbsoluteDate maxDate, final double tStep, @@ -96,92 +93,86 @@ public class SpacecraftToObservedBody implements Serializable { final List<TimeStampedPVCoordinates> positionsVelocities, final int pvInterpolationNumber, final CartesianDerivativesFilter pvFilter, final List<TimeStampedAngularCoordinates> quaternions, final int aInterpolationNumber, - final AngularDerivativesFilter aFilter) - throws RuggedException { - try { - - this.inertialFrame = inertialFrame; - this.bodyFrame = bodyFrame; - this.minDate = minDate; - this.maxDate = maxDate; - this.overshootTolerance = overshootTolerance; - - // safety checks - final AbsoluteDate minPVDate = positionsVelocities.get(0).getDate(); - final AbsoluteDate maxPVDate = positionsVelocities.get(positionsVelocities.size() - 1).getDate(); - if (minPVDate.durationFrom(minDate) > overshootTolerance) { - throw new RuggedException(RuggedMessages.OUT_OF_TIME_RANGE, minDate, minPVDate, maxPVDate); - } - if (maxDate.durationFrom(maxPVDate) > overshootTolerance) { - throw new RuggedException(RuggedMessages.OUT_OF_TIME_RANGE, maxDate, minPVDate, maxPVDate); - } + final AngularDerivativesFilter aFilter) { - final AbsoluteDate minQDate = quaternions.get(0).getDate(); - final AbsoluteDate maxQDate = quaternions.get(quaternions.size() - 1).getDate(); - if (minQDate.durationFrom(minDate) > overshootTolerance) { - throw new RuggedException(RuggedMessages.OUT_OF_TIME_RANGE, minDate, minQDate, maxQDate); - } - if (maxDate.durationFrom(maxQDate) > overshootTolerance) { - throw new RuggedException(RuggedMessages.OUT_OF_TIME_RANGE, maxDate, minQDate, maxQDate); - } + this.inertialFrame = inertialFrame; + this.bodyFrame = bodyFrame; + this.minDate = minDate; + this.maxDate = maxDate; + this.overshootTolerance = overshootTolerance; + + // safety checks + final AbsoluteDate minPVDate = positionsVelocities.get(0).getDate(); + final AbsoluteDate maxPVDate = positionsVelocities.get(positionsVelocities.size() - 1).getDate(); + if (minPVDate.durationFrom(minDate) > overshootTolerance) { + throw new RuggedException(RuggedMessages.OUT_OF_TIME_RANGE, minDate, minPVDate, maxPVDate); + } + if (maxDate.durationFrom(maxPVDate) > overshootTolerance) { + throw new RuggedException(RuggedMessages.OUT_OF_TIME_RANGE, maxDate, minPVDate, maxPVDate); + } - // set up the cache for position-velocities - final TimeStampedCache<TimeStampedPVCoordinates> pvCache = - new ImmutableTimeStampedCache<TimeStampedPVCoordinates>(pvInterpolationNumber, positionsVelocities); - - // set up the cache for attitudes - final TimeStampedCache<TimeStampedAngularCoordinates> aCache = - new ImmutableTimeStampedCache<TimeStampedAngularCoordinates>(aInterpolationNumber, quaternions); - - final int n = (int) FastMath.ceil(maxDate.durationFrom(minDate) / tStep); - this.tStep = tStep; - this.bodyToInertial = new ArrayList<Transform>(n); - this.inertialToBody = new ArrayList<Transform>(n); - this.scToInertial = new ArrayList<Transform>(n); - for (AbsoluteDate date = minDate; bodyToInertial.size() < n; date = date.shiftedBy(tStep)) { - - // interpolate position-velocity, allowing slight extrapolation near the boundaries - final AbsoluteDate pvInterpolationDate; - if (date.compareTo(pvCache.getEarliest().getDate()) < 0) { - pvInterpolationDate = pvCache.getEarliest().getDate(); - } else if (date.compareTo(pvCache.getLatest().getDate()) > 0) { - pvInterpolationDate = pvCache.getLatest().getDate(); - } else { - pvInterpolationDate = date; - } - final TimeStampedPVCoordinates interpolatedPV = - TimeStampedPVCoordinates.interpolate(pvInterpolationDate, pvFilter, - pvCache.getNeighbors(pvInterpolationDate)); - final TimeStampedPVCoordinates pv = interpolatedPV.shiftedBy(date.durationFrom(pvInterpolationDate)); - - // interpolate attitude, allowing slight extrapolation near the boundaries - final AbsoluteDate aInterpolationDate; - if (date.compareTo(aCache.getEarliest().getDate()) < 0) { - aInterpolationDate = aCache.getEarliest().getDate(); - } else if (date.compareTo(aCache.getLatest().getDate()) > 0) { - aInterpolationDate = aCache.getLatest().getDate(); - } else { - aInterpolationDate = date; - } - final TimeStampedAngularCoordinates interpolatedQuaternion = - TimeStampedAngularCoordinates.interpolate(aInterpolationDate, aFilter, - aCache.getNeighbors(aInterpolationDate).collect(Collectors.toList())); - final TimeStampedAngularCoordinates quaternion = interpolatedQuaternion.shiftedBy(date.durationFrom(aInterpolationDate)); - - // store transform from spacecraft frame to inertial frame - scToInertial.add(new Transform(date, - new Transform(date, quaternion.revert()), - new Transform(date, pv))); - - // store transform from body frame to inertial frame - final Transform b2i = bodyFrame.getTransformTo(inertialFrame, date); - bodyToInertial.add(b2i); - inertialToBody.add(b2i.getInverse()); + final AbsoluteDate minQDate = quaternions.get(0).getDate(); + final AbsoluteDate maxQDate = quaternions.get(quaternions.size() - 1).getDate(); + if (minQDate.durationFrom(minDate) > overshootTolerance) { + throw new RuggedException(RuggedMessages.OUT_OF_TIME_RANGE, minDate, minQDate, maxQDate); + } + if (maxDate.durationFrom(maxQDate) > overshootTolerance) { + throw new RuggedException(RuggedMessages.OUT_OF_TIME_RANGE, maxDate, minQDate, maxQDate); + } + // set up the cache for position-velocities + final TimeStampedCache<TimeStampedPVCoordinates> pvCache = + new ImmutableTimeStampedCache<TimeStampedPVCoordinates>(pvInterpolationNumber, positionsVelocities); + + // set up the cache for attitudes + final TimeStampedCache<TimeStampedAngularCoordinates> aCache = + new ImmutableTimeStampedCache<TimeStampedAngularCoordinates>(aInterpolationNumber, quaternions); + + final int n = (int) FastMath.ceil(maxDate.durationFrom(minDate) / tStep); + this.tStep = tStep; + this.bodyToInertial = new ArrayList<Transform>(n); + this.inertialToBody = new ArrayList<Transform>(n); + this.scToInertial = new ArrayList<Transform>(n); + for (AbsoluteDate date = minDate; bodyToInertial.size() < n; date = date.shiftedBy(tStep)) { + + // interpolate position-velocity, allowing slight extrapolation near the boundaries + final AbsoluteDate pvInterpolationDate; + if (date.compareTo(pvCache.getEarliest().getDate()) < 0) { + pvInterpolationDate = pvCache.getEarliest().getDate(); + } else if (date.compareTo(pvCache.getLatest().getDate()) > 0) { + pvInterpolationDate = pvCache.getLatest().getDate(); + } else { + pvInterpolationDate = date; } + final TimeStampedPVCoordinates interpolatedPV = + TimeStampedPVCoordinates.interpolate(pvInterpolationDate, pvFilter, + pvCache.getNeighbors(pvInterpolationDate)); + final TimeStampedPVCoordinates pv = interpolatedPV.shiftedBy(date.durationFrom(pvInterpolationDate)); + + // interpolate attitude, allowing slight extrapolation near the boundaries + final AbsoluteDate aInterpolationDate; + if (date.compareTo(aCache.getEarliest().getDate()) < 0) { + aInterpolationDate = aCache.getEarliest().getDate(); + } else if (date.compareTo(aCache.getLatest().getDate()) > 0) { + aInterpolationDate = aCache.getLatest().getDate(); + } else { + aInterpolationDate = date; + } + final TimeStampedAngularCoordinates interpolatedQuaternion = + TimeStampedAngularCoordinates.interpolate(aInterpolationDate, aFilter, + aCache.getNeighbors(aInterpolationDate).collect(Collectors.toList())); + final TimeStampedAngularCoordinates quaternion = interpolatedQuaternion.shiftedBy(date.durationFrom(aInterpolationDate)); + + // store transform from spacecraft frame to inertial frame + scToInertial.add(new Transform(date, + new Transform(date, quaternion.revert()), + new Transform(date, pv))); + + // store transform from body frame to inertial frame + final Transform b2i = bodyFrame.getTransformTo(inertialFrame, date); + bodyToInertial.add(b2i); + inertialToBody.add(b2i.getInverse()); - } catch (OrekitException oe) { - throw new RuggedException(oe, oe.getSpecifier(), oe.getParts()); } } -- GitLab