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