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.hipparchus.util.FastMath;
25 import org.orekit.errors.OrekitException;
26 import org.orekit.errors.OrekitExceptionWrapper;
27 import org.orekit.time.AbsoluteDate;
28 import org.orekit.utils.AngularDerivativesFilter;
29 import org.orekit.utils.CartesianDerivativesFilter;
30 import org.orekit.utils.GenericTimeStampedCache;
31 import org.orekit.utils.TimeStampedGenerator;
32
33
34
35
36
37
38
39
40
41
42 public class ShiftingTransformProvider implements TransformProvider {
43
44
45 private static final long serialVersionUID = 20150601L;
46
47
48 private final InterpolatingTransformProvider interpolatingProvider;
49
50
51 private final transient GenericTimeStampedCache<Transform> cache;
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68 public ShiftingTransformProvider(final TransformProvider rawProvider,
69 final CartesianDerivativesFilter cFilter,
70 final AngularDerivativesFilter aFilter,
71 final AbsoluteDate earliest, final AbsoluteDate latest,
72 final int gridPoints, final double step,
73 final int maxSlots, final double maxSpan, final double newSlotInterval) {
74 this(new InterpolatingTransformProvider(rawProvider, cFilter, aFilter,
75 earliest, latest, gridPoints, step,
76 maxSlots, maxSpan, newSlotInterval),
77 maxSlots, maxSpan, newSlotInterval);
78 }
79
80
81
82
83
84
85
86
87
88
89 private ShiftingTransformProvider(final InterpolatingTransformProvider interpolatingProvider,
90 final int maxSlots, final double maxSpan, final double newSlotInterval) {
91 this.interpolatingProvider = interpolatingProvider;
92 this.cache = new GenericTimeStampedCache<Transform>(2, maxSlots, maxSpan, newSlotInterval,
93 new Generator(), Transform.class);
94 }
95
96
97
98
99 public TransformProvider getRawProvider() {
100 return interpolatingProvider.getRawProvider();
101 }
102
103
104
105
106 public int getGridPoints() {
107 return interpolatingProvider.getGridPoints();
108 }
109
110
111
112
113 public double getStep() {
114 return interpolatingProvider.getStep();
115 }
116
117
118 public Transform getTransform(final AbsoluteDate date) throws OrekitException {
119 try {
120
121
122 final List<Transform> sample = cache.getNeighbors(date);
123 final double dt0 = date.durationFrom(sample.get(0).getDate());
124 final double dt1 = date.durationFrom(sample.get(1).getDate());
125 if (FastMath.abs(dt0) < FastMath.abs(dt1)) {
126 return sample.get(0).shiftedBy(dt0);
127 } else {
128 return sample.get(1).shiftedBy(dt1);
129 }
130
131 } catch (OrekitExceptionWrapper oew) {
132
133
134 throw oew.getException();
135 }
136 }
137
138
139
140
141
142
143
144
145
146 private Object writeReplace() {
147 return new DTO(interpolatingProvider,
148 cache.getMaxSlots(), cache.getMaxSpan(), cache.getNewSlotQuantumGap());
149 }
150
151
152 private static class DTO implements Serializable {
153
154
155 private static final long serialVersionUID = 20150601L;
156
157
158 private final InterpolatingTransformProvider interpolatingProvider;
159
160
161 private final int maxSlots;
162
163
164 private final double maxSpan;
165
166
167 private final double newSlotInterval;
168
169
170
171
172
173
174
175
176
177
178 private DTO(final InterpolatingTransformProvider interpolatingProvider,
179 final int maxSlots, final double maxSpan, final double newSlotInterval) {
180 this.interpolatingProvider = interpolatingProvider;
181 this.maxSlots = maxSlots;
182 this.maxSpan = maxSpan;
183 this.newSlotInterval = newSlotInterval;
184 }
185
186
187
188
189 private Object readResolve() {
190
191 return new ShiftingTransformProvider(interpolatingProvider,
192 maxSlots, maxSpan, newSlotInterval);
193 }
194
195 }
196
197
198 private class Generator implements TimeStampedGenerator<Transform> {
199
200
201 public List<Transform> generate(final Transform existing, final AbsoluteDate date) {
202
203 try {
204 final List<Transform> generated = new ArrayList<Transform>();
205
206 if (existing == null) {
207
208
209 for (int i = 0; i < cache.getNeighborsSize(); ++i) {
210 generated.add(interpolatingProvider.getTransform(date.shiftedBy(i * interpolatingProvider.getStep())));
211 }
212
213 } else {
214
215
216
217
218 AbsoluteDate t = existing.getDate();
219 if (date.compareTo(t) > 0) {
220
221 do {
222 t = t.shiftedBy(interpolatingProvider.getStep());
223 generated.add(generated.size(), interpolatingProvider.getTransform(t));
224 } while (t.compareTo(date) <= 0);
225 } else {
226
227 do {
228 t = t.shiftedBy(-interpolatingProvider.getStep());
229 generated.add(0, interpolatingProvider.getTransform(t));
230 } while (t.compareTo(date) >= 0);
231 }
232 }
233
234
235 return generated;
236 } catch (OrekitException oe) {
237 throw new OrekitExceptionWrapper(oe);
238 }
239
240 }
241
242 }
243
244 }