1   /* Copyright 2022-2026 Luc Maisonobe
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  
18  package org.orekit.files.ccsds.ndm.adm.acm;
19  
20  import java.util.Collections;
21  import java.util.List;
22  import java.util.stream.Collectors;
23  
24  import org.orekit.attitudes.BoundedAttitudeProvider;
25  import org.orekit.attitudes.TabulatedProvider;
26  import org.orekit.files.ccsds.utils.Initializer;
27  import org.orekit.files.general.AttitudeEphemerisFile;
28  import org.orekit.frames.Frame;
29  import org.orekit.time.AbsoluteDate;
30  import org.orekit.utils.AngularDerivativesFilter;
31  import org.orekit.utils.TimeStampedAngularCoordinates;
32  
33  /** Attitude state history.
34   * @author Luc Maisonobe
35   * @since 12.0
36   */
37  public class AttitudeStateHistory implements AttitudeEphemerisFile.AttitudeEphemerisSegment<TimeStampedAngularCoordinates> {
38  
39      /** Metadata. */
40      private final AttitudeStateHistoryMetadata metadata;
41  
42      /** Trajectory states. */
43      private final List<AttitudeState> states;
44  
45      /** Simple constructor.
46       * @param metadata metadata
47       * @param states attitude states
48       */
49      public AttitudeStateHistory(final AttitudeStateHistoryMetadata metadata,
50                                  final List<AttitudeState> states) {
51          this.metadata = metadata;
52          this.states   = Initializer.emptyListIfNull(states);
53      }
54  
55      /** Get metadata.
56       * @return metadata
57       */
58      public AttitudeStateHistoryMetadata getMetadata() {
59          return metadata;
60      }
61  
62      /** Get the attitude states.
63       * @return attitude states
64       */
65      public List<AttitudeState> getAttitudeStates() {
66          return Collections.unmodifiableList(states);
67      }
68  
69      /** {@inheritDoc} */
70      @Override
71      public Frame getReferenceFrame() {
72          return metadata.getEndpoints().getFrameMapper()
73                  .buildCcsdsFrame(metadata.getEndpoints().getFrameA(), null);
74      }
75  
76      /** {@inheritDoc} */
77      @Override
78      public int getInterpolationSamples() {
79          return 1;
80      }
81  
82      /** {@inheritDoc} */
83      @Override
84      public String getInterpolationMethod() {
85          return "linear";
86      }
87  
88      /** {@inheritDoc} */
89      @Override
90      public AngularDerivativesFilter getAvailableDerivatives() {
91          return states.getFirst().getAvailableDerivatives();
92      }
93  
94      /** {@inheritDoc} */
95      @Override
96      public BoundedAttitudeProvider getAttitudeProvider() {
97          return new TabulatedProvider(getAngularCoordinates(), getInterpolationSamples(),
98                                       getAvailableDerivatives(), getStart(), getStop(),
99                                       getMetadata().getEndpoints());
100     }
101 
102     /** {@inheritDoc} */
103     @Override
104     public AbsoluteDate getStart() {
105         return states.getFirst().getDate();
106     }
107 
108     /** {@inheritDoc} */
109     @Override
110     public AbsoluteDate getStop() {
111         return states.getLast().getDate();
112     }
113 
114     /** {@inheritDoc} */
115     @Override
116     public List<TimeStampedAngularCoordinates> getAngularCoordinates() {
117         return states.stream().map(os -> os.toAngular(metadata.getEulerRotSeq().orElse(null))).collect(Collectors.toList());
118     }
119 
120 }