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