1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.orekit.attitudes;
18
19 import java.io.NotSerializableException;
20 import java.io.Serializable;
21 import java.util.List;
22 import java.util.stream.Collectors;
23
24 import org.hipparchus.RealFieldElement;
25 import org.orekit.errors.OrekitException;
26 import org.orekit.errors.OrekitInternalError;
27 import org.orekit.errors.OrekitMessages;
28 import org.orekit.frames.FieldTransform;
29 import org.orekit.frames.Frame;
30 import org.orekit.frames.LOFType;
31 import org.orekit.frames.Transform;
32 import org.orekit.time.AbsoluteDate;
33 import org.orekit.time.FieldAbsoluteDate;
34 import org.orekit.utils.AngularDerivativesFilter;
35 import org.orekit.utils.FieldPVCoordinates;
36 import org.orekit.utils.FieldPVCoordinatesProvider;
37 import org.orekit.utils.ImmutableTimeStampedCache;
38 import org.orekit.utils.PVCoordinates;
39 import org.orekit.utils.PVCoordinatesProvider;
40 import org.orekit.utils.TimeStampedAngularCoordinates;
41 import org.orekit.utils.TimeStampedFieldAngularCoordinates;
42
43
44
45
46
47
48
49
50
51
52 public class TabulatedLofOffset implements AttitudeProvider {
53
54
55
56 private static final long serialVersionUID = 20151211L;
57
58
59 private final Frame inertialFrame;
60
61
62 private LOFType type;
63
64
65 private final transient ImmutableTimeStampedCache<TimeStampedAngularCoordinates> table;
66
67
68 private final AngularDerivativesFilter filter;
69
70
71
72
73
74
75
76
77
78 public TabulatedLofOffset(final Frame inertialFrame, final LOFType type,
79 final List<TimeStampedAngularCoordinates> table,
80 final int n, final AngularDerivativesFilter filter)
81 throws OrekitException {
82 if (!inertialFrame.isPseudoInertial()) {
83 throw new OrekitException(OrekitMessages.NON_PSEUDO_INERTIAL_FRAME,
84 inertialFrame.getName());
85 }
86 this.inertialFrame = inertialFrame;
87 this.type = type;
88 this.table = new ImmutableTimeStampedCache<TimeStampedAngularCoordinates>(n, table);
89 this.filter = filter;
90 }
91
92
93
94
95 public List<TimeStampedAngularCoordinates> getTable() {
96 return table.getAll();
97 }
98
99
100 public Attitude getAttitude(final PVCoordinatesProvider pvProv,
101 final AbsoluteDate date, final Frame frame)
102 throws OrekitException {
103
104
105 final List<TimeStampedAngularCoordinates> sample = table.getNeighbors(date).collect(Collectors.toList());
106
107
108 final TimeStampedAngularCoordinates interpolated =
109 TimeStampedAngularCoordinates.interpolate(date, filter, sample);
110
111
112 final PVCoordinates pv = pvProv.getPVCoordinates(date, inertialFrame);
113 final Transform inertialToLof = type.transformFromInertial(date, pv);
114
115
116 final Transform frameToInertial = frame.getTransformTo(inertialFrame, date);
117 final Transform frameToLof = new Transform(date, frameToInertial, inertialToLof);
118
119
120 return new Attitude(date, frame,
121 interpolated.addOffset(frameToLof.getAngular()));
122 }
123
124
125 public <T extends RealFieldElement<T>> FieldAttitude<T> getAttitude(final FieldPVCoordinatesProvider<T> pvProv,
126 final FieldAbsoluteDate<T> date,
127 final Frame frame)
128 throws OrekitException {
129
130
131 final List<TimeStampedFieldAngularCoordinates<T>> sample =
132 table.
133 getNeighbors(date.toAbsoluteDate()).
134 map(ac -> new TimeStampedFieldAngularCoordinates<>(date.getField(), ac)).
135 collect(Collectors.toList());
136
137
138 final TimeStampedFieldAngularCoordinates<T> interpolated =
139 TimeStampedFieldAngularCoordinates.interpolate(date, filter, sample);
140
141
142 final FieldPVCoordinates<T> pv = pvProv.getPVCoordinates(date, inertialFrame);
143 final FieldTransform<T> inertialToLof = type.transformFromInertial(date, pv);
144
145
146 final FieldTransform<T> frameToInertial = frame.getTransformTo(inertialFrame, date);
147 final FieldTransform<T> frameToLof = new FieldTransform<>(date, frameToInertial, inertialToLof);
148
149
150 return new FieldAttitude<>(date, frame,
151 interpolated.addOffset(frameToLof.getAngular()));
152 }
153
154
155
156
157
158 private Object writeReplace() throws NotSerializableException {
159 return new DataTransferObject(inertialFrame, type, table.getAll(), table.getNeighborsSize(), filter);
160 }
161
162
163 private static class DataTransferObject implements Serializable {
164
165
166 private static final long serialVersionUID = 20151211L;
167
168
169 private final Frame inertialFrame;
170
171
172 private LOFType type;
173
174
175 private final List<TimeStampedAngularCoordinates> list;
176
177
178 private final int n;
179
180
181 private final AngularDerivativesFilter filter;
182
183
184
185
186
187
188
189
190 DataTransferObject(final Frame inertialFrame, final LOFType type,
191 final List<TimeStampedAngularCoordinates> list,
192 final int n, final AngularDerivativesFilter filter) {
193 this.inertialFrame = inertialFrame;
194 this.type = type;
195 this.list = list;
196 this.n = n;
197 this.filter = filter;
198 }
199
200
201
202
203 private Object readResolve() {
204 try {
205 return new TabulatedLofOffset(inertialFrame, type, list, n, filter);
206 } catch (OrekitException oe) {
207
208 throw new OrekitInternalError(oe);
209 }
210 }
211
212 }
213
214 }