1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.orekit.frames;
19
20 import java.io.Serializable;
21 import java.util.ArrayList;
22 import java.util.List;
23
24 import org.orekit.errors.OrekitException;
25 import org.orekit.errors.OrekitExceptionWrapper;
26 import org.orekit.time.AbsoluteDate;
27 import org.orekit.utils.AngularDerivativesFilter;
28 import org.orekit.utils.CartesianDerivativesFilter;
29 import org.orekit.utils.GenericTimeStampedCache;
30 import org.orekit.utils.TimeStampedGenerator;
31
32
33
34
35
36
37
38
39
40
41
42
43
44 public class InterpolatingTransformProvider implements TransformProvider {
45
46
47 private static final long serialVersionUID = 20140723L;
48
49
50 private final TransformProvider rawProvider;
51
52
53 private final CartesianDerivativesFilter cFilter;
54
55
56 private final AngularDerivativesFilter aFilter;
57
58
59 private final AbsoluteDate earliest;
60
61
62 private final AbsoluteDate latest;
63
64
65 private final double step;
66
67
68 private final transient GenericTimeStampedCache<Transform> cache;
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85 public InterpolatingTransformProvider(final TransformProvider rawProvider,
86 final CartesianDerivativesFilter cFilter,
87 final AngularDerivativesFilter aFilter,
88 final AbsoluteDate earliest, final AbsoluteDate latest,
89 final int gridPoints, final double step,
90 final int maxSlots, final double maxSpan, final double newSlotInterval) {
91 this.rawProvider = rawProvider;
92 this.cFilter = cFilter;
93 this.aFilter = aFilter;
94 this.earliest = earliest;
95 this.latest = latest;
96 this.step = step;
97 this.cache = new GenericTimeStampedCache<Transform>(gridPoints, maxSlots, maxSpan, newSlotInterval,
98 new Generator(), Transform.class);
99 }
100
101
102
103
104 public TransformProvider getRawProvider() {
105 return rawProvider;
106 }
107
108
109
110
111 public int getGridPoints() {
112 return cache.getNeighborsSize();
113 }
114
115
116
117
118 public double getStep() {
119 return step;
120 }
121
122
123 public Transform getTransform(final AbsoluteDate date) throws OrekitException {
124 try {
125
126
127 final List<Transform> sample = cache.getNeighbors(date);
128
129
130 return Transform.interpolate(date, cFilter, aFilter, sample);
131
132 } catch (OrekitExceptionWrapper oew) {
133
134
135 throw oew.getException();
136 }
137 }
138
139
140
141
142
143
144
145
146
147 private Object writeReplace() {
148 return new DTO(rawProvider, cFilter.getMaxOrder(), aFilter.getMaxOrder(),
149 earliest, latest, cache.getNeighborsSize(), step,
150 cache.getMaxSlots(), cache.getMaxSpan(), cache.getNewSlotQuantumGap());
151 }
152
153
154 private static class DTO implements Serializable {
155
156
157 private static final long serialVersionUID = 20140723L;
158
159
160 private final TransformProvider rawProvider;
161
162
163 private final int cDerivatives;
164
165
166 private final int aDerivatives;
167
168
169 private final AbsoluteDate earliest;
170
171
172 private final AbsoluteDate latest;
173
174
175 private final int gridPoints;
176
177
178 private final double step;
179
180
181 private final int maxSlots;
182
183
184 private final double maxSpan;
185
186
187 private final double newSlotInterval;
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204 private DTO(final TransformProvider rawProvider, final int cDerivatives, final int aDerivatives,
205 final AbsoluteDate earliest, final AbsoluteDate latest,
206 final int gridPoints, final double step,
207 final int maxSlots, final double maxSpan, final double newSlotInterval) {
208 this.rawProvider = rawProvider;
209 this.cDerivatives = cDerivatives;
210 this.aDerivatives = aDerivatives;
211 this.earliest = earliest;
212 this.latest = latest;
213 this.gridPoints = gridPoints;
214 this.step = step;
215 this.maxSlots = maxSlots;
216 this.maxSpan = maxSpan;
217 this.newSlotInterval = newSlotInterval;
218 }
219
220
221
222
223 private Object readResolve() {
224
225 return new InterpolatingTransformProvider(rawProvider,
226 CartesianDerivativesFilter.getFilter(cDerivatives),
227 AngularDerivativesFilter.getFilter(aDerivatives),
228 earliest, latest, gridPoints, step,
229 maxSlots, maxSpan, newSlotInterval);
230 }
231
232 }
233
234
235 private class Generator implements TimeStampedGenerator<Transform> {
236
237
238 public List<Transform> generate(final Transform existing, final AbsoluteDate date) {
239
240 try {
241 final List<Transform> generated = new ArrayList<Transform>();
242
243 if (existing == null) {
244
245
246 for (int i = 0; i < cache.getNeighborsSize(); ++i) {
247 generated.add(rawProvider.getTransform(date.shiftedBy(i * step)));
248 }
249
250 } else {
251
252
253
254
255 AbsoluteDate t = existing.getDate();
256 if (date.compareTo(t) > 0) {
257
258 do {
259 t = t.shiftedBy(step);
260 generated.add(generated.size(), rawProvider.getTransform(t));
261 } while (t.compareTo(date) <= 0);
262 } else {
263
264 do {
265 t = t.shiftedBy(-step);
266 generated.add(0, rawProvider.getTransform(t));
267 } while (t.compareTo(date) >= 0);
268 }
269 }
270
271
272 return generated;
273 } catch (OrekitException oe) {
274 throw new OrekitExceptionWrapper(oe);
275 }
276
277 }
278
279 }
280
281 }