1 /* Copyright 2013-2017 CS Systèmes d'Information
2 * Licensed to CS Systèmes d'Information (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 package org.orekit.rugged.linesensor;
18
19 import java.util.stream.Stream;
20
21 import org.hipparchus.analysis.differentiation.DerivativeStructure;
22 import org.hipparchus.geometry.euclidean.threed.FieldVector3D;
23 import org.hipparchus.geometry.euclidean.threed.Vector3D;
24 import org.hipparchus.util.FastMath;
25 import org.orekit.rugged.errors.DumpManager;
26 import org.orekit.rugged.errors.RuggedException;
27 import org.orekit.rugged.los.TimeDependentLOS;
28 import org.orekit.rugged.utils.DSGenerator;
29 import org.orekit.time.AbsoluteDate;
30 import org.orekit.utils.ParameterDriver;
31
32 /** Line sensor model.
33 * @author Luc Maisonobe
34 * @author Guylaine Prat
35 */
36 public class LineSensor {
37
38 /** Name of the sensor. */
39 private final String name;
40
41 /** Datation model. */
42 private final LineDatation datationModel;
43
44 /** Sensor position. */
45 private final Vector3D position;
46
47 /** Pixels lines-of-sight. */
48 private final TimeDependentLOS los;
49
50 /** Simple constructor.
51 * @param name name of the sensor
52 * @param datationModel datation model
53 * @param position sensor position in spacecraft frame
54 * @param los pixels lines-of-sight in spacecraft frame
55 * @see org.orekit.rugged.los.LOSBuilder
56 */
57 public LineSensor(final String name, final LineDatation datationModel,
58 final Vector3D position, final TimeDependentLOS los) {
59
60 this.name = name;
61 this.datationModel = datationModel;
62 this.position = position;
63 this.los = los;
64
65 }
66
67 /** Get the name of the sensor.
68 * @return name of the sensor
69 */
70 public String getName() {
71 return name;
72 }
73
74 /** Get the number of pixels.
75 * @return number of pixels
76 */
77 public int getNbPixels() {
78 return los.getNbPixels();
79 }
80
81 /** Get the drivers for LOS parameters.
82 * @return drivers for LOS parameters
83 * @since 2.0
84 */
85 public Stream<ParameterDriver> getParametersDrivers() {
86 return los.getParametersDrivers();
87 }
88
89 /** Get the pixel normalized line-of-sight at some date.
90 * @param date current date
91 * @param i pixel index (must be between 0 and {@link #getNbPixels()} - 1
92 * @return pixel normalized line-of-sight
93 * @exception RuggedException if date cannot be handled
94 */
95 public Vector3D getLOS(final AbsoluteDate date, final int i)
96 throws RuggedException {
97 final Vector3D l = los.getLOS(i, date);
98 DumpManager.dumpSensorLOS(this, date, i, l);
99 return l;
100 }
101
102 /** Get the pixel normalized interpolated line-of-sight at some date.
103 * @param date current date
104 * @param i pixel index (must be between 0 and {@link #getNbPixels()} - 1
105 * @return pixel normalized line-of-sight
106 * @exception RuggedException if date cannot be handled
107 * @since 2.0
108 */
109 public Vector3D getLOS(final AbsoluteDate date, final double i)
110 throws RuggedException {
111
112 final int iInf = FastMath.max(0, FastMath.min(getNbPixels() - 2, (int) FastMath.floor(i)));
113 final int iSup = iInf + 1;
114 final Vector3D interpolatedLos = new Vector3D(iSup - i, los.getLOS(iInf, date),
115 i - iInf, los.getLOS(iSup, date));
116 return interpolatedLos;
117 }
118
119 /** Get the pixel normalized line-of-sight at some date,
120 * and their derivatives with respect to estimated parameters.
121 * @param date current date
122 * @param i pixel index (must be between 0 and {@link #getNbPixels()} - 1
123 * @param generator generator to use for building {@link DerivativeStructure} instances
124 * @return pixel normalized line-of-sight
125 * @since 2.0
126 */
127 public FieldVector3D<DerivativeStructure> getLOSDerivatives(final AbsoluteDate date, final int i,
128 final DSGenerator generator) {
129 return los.getLOSDerivatives(i, date, generator);
130 }
131
132 /** Get the pixel normalized line-of-sight at some date,
133 * and their derivatives with respect to estimated parameters.
134 * @param date current date
135 * @param i pixel index (must be between 0 and {@link #getNbPixels()} - 1
136 * @param generator generator to use for building {@link DerivativeStructure} instances
137 * @return pixel normalized line-of-sight
138 * @since 2.0
139 */
140 public FieldVector3D<DerivativeStructure> getLOSDerivatives(final AbsoluteDate date, final double i,
141 final DSGenerator generator) {
142
143 // find surrounding pixels of pixelB (in order to interpolate LOS from pixelB (that is not an integer)
144 final int iInf = FastMath.max(0, FastMath.min(getNbPixels() - 2, (int) FastMath.floor(i)));
145 final int iSup = iInf + 1;
146
147 final FieldVector3D<DerivativeStructure> interpolatedLos = new FieldVector3D<DerivativeStructure> (
148 iSup - i,
149 los.getLOSDerivatives(iInf, date, generator),
150 i - iInf,
151 los.getLOSDerivatives(iSup, date, generator)).normalize();
152 return interpolatedLos;
153 }
154
155 /** Get the date.
156 * @param lineNumber line number
157 * @return date corresponding to line number
158 * @exception RuggedException if date cannot be handled
159 */
160 public AbsoluteDate getDate(final double lineNumber)
161 throws RuggedException {
162 final AbsoluteDate date = datationModel.getDate(lineNumber);
163 DumpManager.dumpSensorDatation(this, lineNumber, date);
164 return date;
165 }
166
167 /** Get the line number.
168 * @param date date
169 * @return line number corresponding to date
170 * @exception RuggedException if date cannot be handled
171 */
172 public double getLine(final AbsoluteDate date)
173 throws RuggedException {
174 final double lineNumber = datationModel.getLine(date);
175 DumpManager.dumpSensorDatation(this, lineNumber, date);
176 return lineNumber;
177 }
178
179 /** Get the rate of lines scanning.
180 * @param lineNumber line number
181 * @return rate of lines scanning (lines / seconds)
182 */
183 public double getRate(final double lineNumber) {
184 final double rate = datationModel.getRate(lineNumber);
185 DumpManager.dumpSensorRate(this, lineNumber, rate);
186 return rate;
187 }
188
189 /** Get the sensor position.
190 * @return position
191 */
192 public Vector3D getPosition() {
193 return position;
194 }
195
196 }