diff --git a/core/src/main/java/org/orekit/rugged/api/Rugged.java b/core/src/main/java/org/orekit/rugged/api/Rugged.java index fafdb26c00ad3455352ae6e010738bd0a54c6e97..7db0011bae46759720f978f417fc32a94c597cb5 100644 --- a/core/src/main/java/org/orekit/rugged/api/Rugged.java +++ b/core/src/main/java/org/orekit/rugged/api/Rugged.java @@ -26,7 +26,6 @@ import org.apache.commons.math3.geometry.euclidean.threed.FieldVector3D; 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.Pair; import org.orekit.bodies.GeodeticPoint; import org.orekit.bodies.OneAxisEllipsoid; import org.orekit.errors.OrekitException; @@ -48,6 +47,8 @@ import org.orekit.time.AbsoluteDate; import org.orekit.utils.Constants; import org.orekit.utils.IERSConventions; import org.orekit.utils.PVCoordinates; +import org.orekit.utils.TimeStampedAngularCoordinates; +import org.orekit.utils.TimeStampedPVCoordinates; /** Main class of Rugged library API. * @author Luc Maisonobe @@ -114,8 +115,8 @@ public class Rugged { final AlgorithmId algorithmID, final EllipsoidId ellipsoidID, final InertialFrameId inertialFrameID, final BodyRotatingFrameId bodyRotatingFrameID, final AbsoluteDate minDate, final AbsoluteDate maxDate, - final List<Pair<AbsoluteDate, PVCoordinates>> positionsVelocities, final int pvInterpolationOrder, - final List<Pair<AbsoluteDate, Rotation>> quaternions, final int aInterpolationOrder) + final List<TimeStampedPVCoordinates> positionsVelocities, final int pvInterpolationOrder, + final List<TimeStampedAngularCoordinates> quaternions, final int aInterpolationOrder) throws RuggedException { this(updater, maxCachedTiles, algorithmID, selectEllipsoid(ellipsoidID, selectBodyRotatingFrame(bodyRotatingFrameID)), @@ -149,8 +150,8 @@ public class Rugged { public Rugged(final TileUpdater updater, final int maxCachedTiles, final AlgorithmId algorithmID, final OneAxisEllipsoid ellipsoid, final Frame inertialFrame, final AbsoluteDate minDate, final AbsoluteDate maxDate, - final List<Pair<AbsoluteDate, PVCoordinates>> positionsVelocities, final int pvInterpolationOrder, - final List<Pair<AbsoluteDate, Rotation>> quaternions, final int aInterpolationOrder) + final List<TimeStampedPVCoordinates> positionsVelocities, final int pvInterpolationOrder, + final List<TimeStampedAngularCoordinates> quaternions, final int aInterpolationOrder) throws RuggedException { // space reference @@ -239,8 +240,10 @@ public class Rugged { this.ellipsoid = extend(ellipsoid); // extract position/attitude samples from propagator - final List<Pair<AbsoluteDate, PVCoordinates>> positionsVelocities = new ArrayList<Pair<AbsoluteDate,PVCoordinates>>(); - final List<Pair<AbsoluteDate, Rotation>> quaternions = new ArrayList<Pair<AbsoluteDate,Rotation>>(); + final List<TimeStampedPVCoordinates> positionsVelocities = + new ArrayList<TimeStampedPVCoordinates>(); + final List<TimeStampedAngularCoordinates> quaternions = + new ArrayList<TimeStampedAngularCoordinates>(); propagator.setMasterMode(interpolationStep, new OrekitFixedStepHandler() { /** {@inheritDoc} */ @@ -256,8 +259,8 @@ public class Rugged { final AbsoluteDate date = currentState.getDate(); final PVCoordinates pv = currentState.getPVCoordinates(inertialFrame); final Rotation q = currentState.getAttitude().getRotation(); - positionsVelocities.add(new Pair<AbsoluteDate, PVCoordinates>(date, pv)); - quaternions.add(new Pair<AbsoluteDate, Rotation>(date, q)); + positionsVelocities.add(new TimeStampedPVCoordinates(date, pv.getPosition(), pv.getVelocity())); + quaternions.add(new TimeStampedAngularCoordinates(date, q, Vector3D.ZERO)); } catch (OrekitException oe) { throw new PropagationException(oe); } diff --git a/core/src/main/java/org/orekit/rugged/utils/SpacecraftToObservedBody.java b/core/src/main/java/org/orekit/rugged/utils/SpacecraftToObservedBody.java index 9779983675c2c35a134a48224174e06f51b09773..0234a1049a855ea01bb5fcdedaa3a8611d49bdcd 100644 --- a/core/src/main/java/org/orekit/rugged/utils/SpacecraftToObservedBody.java +++ b/core/src/main/java/org/orekit/rugged/utils/SpacecraftToObservedBody.java @@ -16,25 +16,17 @@ */ package org.orekit.rugged.utils; -import java.util.ArrayList; import java.util.List; -import org.apache.commons.math3.geometry.euclidean.threed.Rotation; -import org.apache.commons.math3.geometry.euclidean.threed.Vector3D; -import org.apache.commons.math3.util.Pair; -import org.orekit.attitudes.Attitude; -import org.orekit.attitudes.TabulatedProvider; import org.orekit.errors.OrekitException; import org.orekit.frames.Frame; import org.orekit.frames.Transform; -import org.orekit.orbits.CartesianOrbit; -import org.orekit.orbits.Orbit; import org.orekit.rugged.api.RuggedException; import org.orekit.rugged.api.RuggedMessages; import org.orekit.time.AbsoluteDate; -import org.orekit.utils.Constants; import org.orekit.utils.ImmutableTimeStampedCache; -import org.orekit.utils.PVCoordinates; +import org.orekit.utils.TimeStampedAngularCoordinates; +import org.orekit.utils.TimeStampedPVCoordinates; /** Provider for observation transforms. * @author Luc Maisonobe @@ -48,10 +40,10 @@ public class SpacecraftToObservedBody { private final Frame bodyFrame; /** Satellite orbits. */ - private final ImmutableTimeStampedCache<Orbit> orbits; + private final ImmutableTimeStampedCache<TimeStampedPVCoordinates> positionsVelocities; /** Satellite quaternions. */ - private final TabulatedProvider attitudes; + private final ImmutableTimeStampedCache<TimeStampedAngularCoordinates> quaternions; /** Simple constructor. * @param inertialFrame inertial frame @@ -67,13 +59,13 @@ public class SpacecraftToObservedBody { */ public SpacecraftToObservedBody(final Frame inertialFrame, final Frame bodyFrame, final AbsoluteDate minDate, final AbsoluteDate maxDate, - final List<Pair<AbsoluteDate, PVCoordinates>> positionsVelocities, final int pvInterpolationOrder, - final List<Pair<AbsoluteDate, Rotation>> quaternions, final int aInterpolationOrder) + final List<TimeStampedPVCoordinates> positionsVelocities, final int pvInterpolationOrder, + final List<TimeStampedAngularCoordinates> quaternions, final int aInterpolationOrder) throws RuggedException { // safety checks - final AbsoluteDate minPVDate = positionsVelocities.get(0).getFirst(); - final AbsoluteDate maxPVDate = positionsVelocities.get(positionsVelocities.size() - 1).getFirst(); + final AbsoluteDate minPVDate = positionsVelocities.get(0).getDate(); + final AbsoluteDate maxPVDate = positionsVelocities.get(positionsVelocities.size() - 1).getDate(); if (minDate.compareTo(minPVDate) < 0) { throw new RuggedException(RuggedMessages.OUT_OF_TIME_RANGE, minDate, minPVDate, maxPVDate); } @@ -81,8 +73,8 @@ public class SpacecraftToObservedBody { throw new RuggedException(RuggedMessages.OUT_OF_TIME_RANGE, maxDate, minPVDate, maxPVDate); } - final AbsoluteDate minQDate = quaternions.get(0).getFirst(); - final AbsoluteDate maxQDate = quaternions.get(quaternions.size() - 1).getFirst(); + final AbsoluteDate minQDate = quaternions.get(0).getDate(); + final AbsoluteDate maxQDate = quaternions.get(quaternions.size() - 1).getDate(); if (minDate.compareTo(minQDate) < 0) { throw new RuggedException(RuggedMessages.OUT_OF_TIME_RANGE, minDate, minQDate, maxQDate); } @@ -93,21 +85,11 @@ public class SpacecraftToObservedBody { this.inertialFrame = inertialFrame; this.bodyFrame = bodyFrame; - // set up the orbit provider - final List<Orbit> orbits = new ArrayList<Orbit>(positionsVelocities.size()); - for (final Pair<AbsoluteDate, PVCoordinates> pv : positionsVelocities) { - final CartesianOrbit orbit = new CartesianOrbit(pv.getSecond(), inertialFrame, - pv.getFirst(), Constants.EIGEN5C_EARTH_MU); - orbits.add(orbit); - } - this.orbits = new ImmutableTimeStampedCache<Orbit>(pvInterpolationOrder, orbits); + // set up the cache for position-velocities + this.positionsVelocities = new ImmutableTimeStampedCache<TimeStampedPVCoordinates>(pvInterpolationOrder, positionsVelocities); - // set up the attitude provider - final List<Attitude> attitudes = new ArrayList<Attitude>(quaternions.size()); - for (final Pair<AbsoluteDate, Rotation> q : quaternions) { - attitudes.add(new Attitude(q.getFirst(), inertialFrame, q.getSecond(), Vector3D.ZERO)); - } - this.attitudes = new TabulatedProvider(attitudes, aInterpolationOrder, false); + // set up the cache for attitudes + this.quaternions = new ImmutableTimeStampedCache<TimeStampedAngularCoordinates>(aInterpolationOrder, quaternions); } @@ -119,17 +101,17 @@ public class SpacecraftToObservedBody { public Transform getScToInertial(final AbsoluteDate date) throws OrekitException { - //interpolate orbit and attitude - final List<Orbit> sample = orbits.getNeighbors(date); - final Orbit orbit = sample.get(0).interpolate(date, sample); - final PVCoordinates pv = orbit.getPVCoordinates(date, inertialFrame); + // interpolate position-velocity + final List<TimeStampedPVCoordinates> sample = positionsVelocities.getNeighbors(date); + final TimeStampedPVCoordinates pv = TimeStampedPVCoordinates.interpolate(date, true, sample); - //interpolate attitude - final Attitude attitude = attitudes.getAttitude(orbit, date, inertialFrame); + // interpolate attitude + final List<TimeStampedAngularCoordinates> sampleAC = quaternions.getNeighbors(date); + final TimeStampedAngularCoordinates quaternion = TimeStampedAngularCoordinates.interpolate(date, false, sampleAC); // compute transform from spacecraft frame to inertial frame return new Transform(date, - new Transform(date, attitude.getOrientation().revert()), + new Transform(date, quaternion.revert()), new Transform(date, pv)); } diff --git a/core/src/test/java/org/orekit/rugged/api/RuggedTest.java b/core/src/test/java/org/orekit/rugged/api/RuggedTest.java index 486f63c5db7b02727fdc7783018e7d890a91d12c..e5b186f37ab147304be5d4d3fa5a97361fd33715 100644 --- a/core/src/test/java/org/orekit/rugged/api/RuggedTest.java +++ b/core/src/test/java/org/orekit/rugged/api/RuggedTest.java @@ -33,7 +33,6 @@ import org.apache.commons.math3.geometry.euclidean.threed.Vector3D; import org.apache.commons.math3.ode.nonstiff.DormandPrince853Integrator; import org.apache.commons.math3.stat.descriptive.SummaryStatistics; import org.apache.commons.math3.util.FastMath; -import org.apache.commons.math3.util.Pair; import org.junit.Assert; import org.junit.Ignore; import org.junit.Rule; @@ -75,6 +74,8 @@ import org.orekit.time.TimeScalesFactory; import org.orekit.utils.Constants; import org.orekit.utils.IERSConventions; import org.orekit.utils.PVCoordinates; +import org.orekit.utils.TimeStampedAngularCoordinates; +import org.orekit.utils.TimeStampedPVCoordinates; public class RuggedTest { @@ -89,8 +90,7 @@ public class RuggedTest { DataProvidersManager.getInstance().addProvider(new DirectoryCrawler(new File(path))); AbsoluteDate t0 = new AbsoluteDate("2012-01-01T00:00:00", TimeScalesFactory.getUTC()); - @SuppressWarnings("unchecked") - List<Pair<AbsoluteDate, PVCoordinates>> pv = Arrays.asList( + List<TimeStampedPVCoordinates> pv = Arrays.asList( createPV(t0, 0.000, -1545168.478, -7001985.361, 0.000, -1095.152224, 231.344922, -7372.851944), createPV(t0, 1.000, -1546262.794, -7001750.226, -7372.851, -1093.478904, 238.925123, -7372.847995), createPV(t0, 2.000, -1547355.435, -7001507.511, -14745.693, -1091.804408, 246.505033, -7372.836044), @@ -113,8 +113,7 @@ public class RuggedTest { createPV(t0,19.000, -1565673.105, -6996221.923, -140075.049, -1063.159684, 375.311060, -7371.408591), createPV(t0,20.000, -1566735.417, -6995842.825, -147446.380, -1061.464319, 382.884328, -7371.252616)); - @SuppressWarnings("unchecked") - List<Pair<AbsoluteDate, Rotation>> q = Arrays.asList( + List<TimeStampedAngularCoordinates> q = Arrays.asList( createQ(t0, 0.000, 0.516354347549, -0.400120145429, 0.583012133139, 0.483093065155), createQ(t0, 1.000, 0.516659035405, -0.399867643627, 0.582741754688, 0.483302551263), createQ(t0, 2.000, 0.516963581177, -0.399615033309, 0.582471217473, 0.483511904409), @@ -144,7 +143,7 @@ public class RuggedTest { Rugged rugged = new Rugged(updater, 8, AlgorithmId.DUVENHAGE, EllipsoidId.WGS84, InertialFrameId.EME2000, BodyRotatingFrameId.ITRF, - pv.get(0).getFirst(), pv.get(pv.size() - 1).getFirst(), + pv.get(0).getDate(), pv.get(pv.size() - 1).getDate(), pv, 8, q, 8); Assert.assertTrue(rugged.isLightTimeCorrected()); @@ -194,8 +193,7 @@ public class RuggedTest { DataProvidersManager.getInstance().addProvider(new DirectoryCrawler(new File(path))); AbsoluteDate t0 = new AbsoluteDate("2012-01-01T00:00:00", TimeScalesFactory.getUTC()); - @SuppressWarnings("unchecked") - List<Pair<AbsoluteDate, PVCoordinates>> pv = Arrays.asList( + List<TimeStampedPVCoordinates> pv = Arrays.asList( createPV(t0, 0.000, -1545168.478, -7001985.361, 0.000, -1095.152224, 231.344922, -7372.851944), createPV(t0, 1.000, -1546262.794, -7001750.226, -7372.851, -1093.478904, 238.925123, -7372.847995), createPV(t0, 2.000, -1547355.435, -7001507.511, -14745.693, -1091.804408, 246.505033, -7372.836044), @@ -208,8 +206,7 @@ public class RuggedTest { createPV(t0, 9.000, -1554956.960, -6999596.289, -66354.697, -1080.050134, 299.555578, -7372.528320), createPV(t0,10.000, -1556036.168, -6999292.945, -73727.188, -1078.366288, 307.132868, -7372.452352)); - @SuppressWarnings("unchecked") - List<Pair<AbsoluteDate, Rotation>> q = Arrays.asList( + List<TimeStampedAngularCoordinates> q = Arrays.asList( createQ(t0, 4.000, 0.517572246112, -0.399109487434, 0.581929667081, 0.483930211565), createQ(t0, 5.000, 0.517876365096, -0.398856552030, 0.581658654071, 0.484139165451), createQ(t0, 6.000, 0.518180341637, -0.398603508416, 0.581387482627, 0.484347986126), @@ -623,8 +620,8 @@ public class RuggedTest { TimeScale gps = TimeScalesFactory.getGPS(); Frame eme2000 = FramesFactory.getEME2000(); Frame itrf = FramesFactory.getITRF(IERSConventions.IERS_2010, true); - ArrayList<Pair<AbsoluteDate, Rotation>> satelliteQList = new ArrayList<Pair<AbsoluteDate, Rotation>>(); - ArrayList<Pair<AbsoluteDate, PVCoordinates>> satellitePVList = new ArrayList<Pair<AbsoluteDate, PVCoordinates>>(); + ArrayList<TimeStampedAngularCoordinates> satelliteQList = new ArrayList<TimeStampedAngularCoordinates>(); + ArrayList<TimeStampedPVCoordinates> satellitePVList = new ArrayList<TimeStampedPVCoordinates>(); addSatelliteQ(gps, satelliteQList, "2009-12-11T16:58:42.592937", -0.340236d, 0.333952d, -0.844012d, -0.245684d); addSatelliteQ(gps, satelliteQList, "2009-12-11T16:59:06.592937", -0.354773d, 0.329336d, -0.837871d, -0.252281d); @@ -653,7 +650,7 @@ public class RuggedTest { TileUpdater updater = new RandomLandscapeUpdater(0.0, 9000.0, 0.5, 0xf0a401650191f9f6l, FastMath.toRadians(1.0), 257); Rugged rugged = new Rugged(updater, 8, AlgorithmId.DUVENHAGE, EllipsoidId.WGS84, InertialFrameId.EME2000, BodyRotatingFrameId.ITRF, - satellitePVList.get(0).getFirst(), satellitePVList.get(satellitePVList.size() - 1).getFirst(), + satellitePVList.get(0).getDate(), satellitePVList.get(satellitePVList.size() - 1).getDate(), satellitePVList, 8, satelliteQList, 8); @@ -727,7 +724,7 @@ public class RuggedTest { * @throws OrekitException */ protected void addSatellitePV(TimeScale gps, Frame eme2000, Frame itrf, - ArrayList<Pair<AbsoluteDate, PVCoordinates>> satellitePVList, + ArrayList<TimeStampedPVCoordinates> satellitePVList, String absDate, double px, double py, double pz, double vx, double vy, double vz) throws OrekitException { @@ -738,9 +735,7 @@ public class RuggedTest { Transform transform = itrf.getTransformTo(eme2000, ephemerisDate); Vector3D pEME2000 = transform.transformPosition(pvITRF.getPosition()); Vector3D vEME2000 = transform.transformVector(pvITRF.getVelocity()); - PVCoordinates pvCoords = new PVCoordinates(pEME2000, vEME2000); - Pair<AbsoluteDate, PVCoordinates> pair = new Pair<AbsoluteDate, PVCoordinates>(ephemerisDate, pvCoords); - satellitePVList.add(pair); + satellitePVList.add(new TimeStampedPVCoordinates(ephemerisDate, pEME2000, vEME2000)); } /** @@ -753,11 +748,11 @@ public class RuggedTest { * @param q2 * @param q3 */ - protected void addSatelliteQ(TimeScale gps, ArrayList<Pair<AbsoluteDate, Rotation>> satelliteQList, String absDate, double q0, double q1, double q2, + protected void addSatelliteQ(TimeScale gps, ArrayList<TimeStampedAngularCoordinates> satelliteQList, String absDate, double q0, double q1, double q2, double q3) { AbsoluteDate attitudeDate = new AbsoluteDate(absDate, gps); Rotation rotation = new Rotation(q0, q1, q2, q3, true); - Pair<AbsoluteDate, Rotation> pair = new Pair<AbsoluteDate, Rotation>(attitudeDate, rotation); + TimeStampedAngularCoordinates pair = new TimeStampedAngularCoordinates(attitudeDate, rotation, Vector3D.ZERO); satelliteQList.add(pair); } @@ -903,53 +898,57 @@ public class RuggedTest { return list; } - private Pair<AbsoluteDate, PVCoordinates> createPV(AbsoluteDate t0, double dt, - double px, double py, double pz, - double vx, double vy, double vz) { - return new Pair<AbsoluteDate, PVCoordinates>(t0.shiftedBy(dt), - new PVCoordinates(new Vector3D(px, py, pz), - new Vector3D(vx, vy, vz))); + private TimeStampedPVCoordinates createPV(AbsoluteDate t0, double dt, + double px, double py, double pz, + double vx, double vy, double vz) { + return new TimeStampedPVCoordinates(t0.shiftedBy(dt), + new Vector3D(px, py, pz), + new Vector3D(vx, vy, vz)); } - private Pair<AbsoluteDate, Rotation> createQ(AbsoluteDate t0, double dt, + private TimeStampedAngularCoordinates createQ(AbsoluteDate t0, double dt, double q0, double q1, double q2, double q3) { - return new Pair<AbsoluteDate, Rotation>(t0.shiftedBy(dt), new Rotation(q0, q1, q2, q3, true)); + return new TimeStampedAngularCoordinates(t0.shiftedBy(dt), + new Rotation(q0, q1, q2, q3, true), + Vector3D.ZERO); } - private List<Pair<AbsoluteDate, PVCoordinates>> orbitToPV(Orbit orbit, BodyShape earth, - LineDatation lineDatation, int firstLine, int lastLine, - double step) + private List<TimeStampedPVCoordinates> orbitToPV(Orbit orbit, BodyShape earth, + LineDatation lineDatation, int firstLine, int lastLine, + double step) throws PropagationException { Propagator propagator = new KeplerianPropagator(orbit); propagator.setAttitudeProvider(new YawCompensation(new NadirPointing(earth))); propagator.propagate(lineDatation.getDate(firstLine).shiftedBy(-1.0)); - final List<Pair<AbsoluteDate, PVCoordinates>> list = new ArrayList<Pair<AbsoluteDate, PVCoordinates>>(); + final List<TimeStampedPVCoordinates> list = new ArrayList<TimeStampedPVCoordinates>(); propagator.setMasterMode(step, new OrekitFixedStepHandler() { public void init(SpacecraftState s0, AbsoluteDate t) { } public void handleStep(SpacecraftState currentState, boolean isLast) { - list.add(new Pair<AbsoluteDate, PVCoordinates>(currentState.getDate(), - currentState.getPVCoordinates())); + list.add(new TimeStampedPVCoordinates(currentState.getDate(), + currentState.getPVCoordinates().getPosition(), + currentState.getPVCoordinates().getVelocity())); } }); propagator.propagate(lineDatation.getDate(lastLine).shiftedBy(+1.0)); return list; } - private List<Pair<AbsoluteDate, Rotation>> orbitToQ(Orbit orbit, BodyShape earth, - LineDatation lineDatation, int firstLine, int lastLine, - double step) + private List<TimeStampedAngularCoordinates> orbitToQ(Orbit orbit, BodyShape earth, + LineDatation lineDatation, int firstLine, int lastLine, + double step) throws PropagationException { Propagator propagator = new KeplerianPropagator(orbit); propagator.setAttitudeProvider(new YawCompensation(new NadirPointing(earth))); propagator.propagate(lineDatation.getDate(firstLine).shiftedBy(-1.0)); - final List<Pair<AbsoluteDate, Rotation>> list = new ArrayList<Pair<AbsoluteDate, Rotation>>(); + final List<TimeStampedAngularCoordinates> list = new ArrayList<TimeStampedAngularCoordinates>(); propagator.setMasterMode(step, new OrekitFixedStepHandler() { public void init(SpacecraftState s0, AbsoluteDate t) { } public void handleStep(SpacecraftState currentState, boolean isLast) { - list.add(new Pair<AbsoluteDate, Rotation>(currentState.getDate(), - currentState.getAttitude().getRotation())); + list.add(new TimeStampedAngularCoordinates(currentState.getDate(), + currentState.getAttitude().getRotation(), + Vector3D.ZERO)); } }); propagator.propagate(lineDatation.getDate(lastLine).shiftedBy(+1.0));