TrajectoryStateHistory.java

  1. /* Copyright 2002-2022 CS GROUP
  2.  * Licensed to CS GROUP (CS) under one or more
  3.  * contributor license agreements.  See the NOTICE file distributed with
  4.  * this work for additional information regarding copyright ownership.
  5.  * CS licenses this file to You under the Apache License, Version 2.0
  6.  * (the "License"); you may not use this file except in compliance with
  7.  * the License.  You may obtain a copy of the License at
  8.  *
  9.  *   http://www.apache.org/licenses/LICENSE-2.0
  10.  *
  11.  * Unless required by applicable law or agreed to in writing, software
  12.  * distributed under the License is distributed on an "AS IS" BASIS,
  13.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14.  * See the License for the specific language governing permissions and
  15.  * limitations under the License.
  16.  */

  17. package org.orekit.files.ccsds.ndm.odm.ocm;

  18. import java.util.Collections;
  19. import java.util.List;
  20. import java.util.stream.Collectors;

  21. import org.orekit.errors.OrekitException;
  22. import org.orekit.errors.OrekitMessages;
  23. import org.orekit.files.general.EphemerisFile;
  24. import org.orekit.frames.Frame;
  25. import org.orekit.time.AbsoluteDate;
  26. import org.orekit.utils.CartesianDerivativesFilter;
  27. import org.orekit.utils.TimeStampedPVCoordinates;

  28. /** Trajectory state history.
  29.  * @author Luc Maisonobe
  30.  * @since 11.0
  31.  */
  32. public class TrajectoryStateHistory implements EphemerisFile.EphemerisSegment<TimeStampedPVCoordinates> {

  33.     /** Metadata. */
  34.     private final TrajectoryStateHistoryMetadata metadata;

  35.     /** Trajectory states. */
  36.     private final List<TrajectoryState> states;

  37.     /** Gravitational parameter in m³/s². */
  38.     private final double mu;

  39.     /** Simple constructor.
  40.      * @param metadata metadata
  41.      * @param states orbital states
  42.      * @param mu gravitational parameter in m³/s²
  43.      */
  44.     TrajectoryStateHistory(final TrajectoryStateHistoryMetadata metadata,
  45.                       final List<TrajectoryState> states,
  46.                       final double mu) {
  47.         this.metadata = metadata;
  48.         this.states   = states;
  49.         this.mu       = mu;
  50.     }

  51.     /** Get metadata.
  52.      * @return metadata
  53.      */
  54.     public TrajectoryStateHistoryMetadata getMetadata() {
  55.         return metadata;
  56.     }

  57.     /** Get the trajectory states.
  58.      * @return trajectory states
  59.      */
  60.     public List<TrajectoryState> getTrajectoryStates() {
  61.         return Collections.unmodifiableList(states);
  62.     }

  63.     /** {@inheritDoc} */
  64.     @Override
  65.     public double getMu() {
  66.         return mu;
  67.     }

  68.     /** {@inheritDoc} */
  69.     @Override
  70.     public Frame getFrame() {
  71.         final Frame frame = metadata.getTrajReferenceFrame().asFrame();
  72.         if (frame == null) {
  73.             throw new OrekitException(OrekitMessages.CCSDS_INVALID_FRAME,
  74.                                       metadata.getTrajReferenceFrame().getName());
  75.         }
  76.         return frame;
  77.     }

  78.     /** {@inheritDoc} */
  79.     @Override
  80.     public int getInterpolationSamples() {
  81.         return metadata.getInterpolationDegree() + 1;
  82.     }

  83.     /** {@inheritDoc} */
  84.     @Override
  85.     public CartesianDerivativesFilter getAvailableDerivatives() {
  86.         return states.get(0).getAvailableDerivatives();
  87.     }

  88.     /** {@inheritDoc} */
  89.     @Override
  90.     public AbsoluteDate getStart() {
  91.         return states.get(0).getDate();
  92.     }

  93.     /** {@inheritDoc} */
  94.     @Override
  95.     public AbsoluteDate getStop() {
  96.         return states.get(states.size() - 1).getDate();
  97.     }

  98.     /** {@inheritDoc} */
  99.     @Override
  100.     public List<TimeStampedPVCoordinates> getCoordinates() {
  101.         return states.stream().map(os -> os.toCartesian(mu)).collect(Collectors.toList());
  102.     }

  103. }