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