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.ArrayList;
22 import java.util.List;
23
24 import org.apache.commons.math3.util.Pair;
25 import org.orekit.errors.OrekitException;
26 import org.orekit.frames.Frame;
27 import org.orekit.time.AbsoluteDate;
28 import org.orekit.utils.AngularCoordinates;
29 import org.orekit.utils.ImmutableTimeStampedCache;
30 import org.orekit.utils.PVCoordinatesProvider;
31
32
33
34
35
36
37
38
39 public class TabulatedProvider implements AttitudeProvider {
40
41
42
43 private static final long serialVersionUID = 20131128L;
44
45
46 private final transient ImmutableTimeStampedCache<Attitude> table;
47
48
49 private final boolean useRotationRate;
50
51
52
53
54
55
56
57
58 public TabulatedProvider(final List<Attitude> table, final int n, final boolean useRotationRate) {
59 this.table = new ImmutableTimeStampedCache<Attitude>(n, table);
60 this.useRotationRate = useRotationRate;
61 }
62
63
64 public Attitude getAttitude(final PVCoordinatesProvider pvProv,
65 final AbsoluteDate date, final Frame frame)
66 throws OrekitException {
67
68
69 final List<Attitude> sample = table.getNeighbors(date);
70
71
72 final List<Pair<AbsoluteDate, AngularCoordinates>> datedAC =
73 new ArrayList<Pair<AbsoluteDate, AngularCoordinates>>(sample.size());
74 for (final Attitude attitude : sample) {
75 datedAC.add(new Pair<AbsoluteDate, AngularCoordinates>(attitude.getDate(), attitude.getOrientation()));
76 }
77 final AngularCoordinates interpolated = AngularCoordinates.interpolate(date, useRotationRate, datedAC);
78
79
80 return new Attitude(date, sample.get(0).getReferenceFrame(), interpolated);
81
82 }
83
84
85
86
87
88 private Object writeReplace() throws NotSerializableException {
89 return new DataTransferObject(table.getAll(), table.getNeighborsSize(), useRotationRate);
90 }
91
92
93 private static class DataTransferObject implements Serializable {
94
95
96 private static final long serialVersionUID = 20131205L;
97
98
99 private final List<Attitude> list;
100
101
102 private final int n;
103
104
105 private final boolean useRotationRate;
106
107
108
109
110
111
112 public DataTransferObject(final List<Attitude> list, final int n, final boolean useRotationRate) {
113 this.list = list;
114 this.n = n;
115 this.useRotationRate = useRotationRate;
116 }
117
118
119
120
121 private Object readResolve() {
122 return new TabulatedProvider(list, n, useRotationRate);
123 }
124
125 }
126
127 }