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.adjustment.measurements;
18  
19  import java.util.ArrayList;
20  import java.util.List;
21  import java.util.Map;
22  import java.util.Set;
23  
24  import org.orekit.rugged.linesensor.SensorPixel;
25  
26  /** Container for mapping sensors pixels of two viewing models.
27   * Store the distance between both lines of sight computed with
28   * {@link org.orekit.rugged.api.Rugged#distanceBetweenLOS(org.orekit.rugged.linesensor.LineSensor, org.orekit.time.AbsoluteDate, double, org.orekit.rugged.utils.SpacecraftToObservedBody, org.orekit.rugged.linesensor.LineSensor, org.orekit.time.AbsoluteDate, double)}
29   * <p> Constraints in relation to central body distance can be added.
30   * @see SensorMapping
31   * @author Lucie LabatAllee
32   * @author Guylaine Prat
33   * @since 2.0
34   */
35  public class SensorToSensorMapping {
36  
37      /** Default name for Rugged. */
38      private static final String RUGGED = "Rugged";
39  
40      /** Name of the sensor B to which mapping applies. */
41      private final String sensorNameB;
42  
43      /** Name of the Rugged B to which mapping applies. */
44      private final String ruggedNameB;
45  
46      /** Mapping from sensor A to sensor B. */
47      private final SensorMapping<SensorPixel> interMapping;
48  
49      /** Distances between two LOS. */
50      private final List<Double> losDistances;
51  
52      /** Central body distances associated with pixel A. */
53      private final List<Double> bodyDistances;
54  
55      /** Body constraint weight. */
56      private double bodyConstraintWeight;
57  
58  
59      /** Build a new instance without central body constraint (with default Rugged names).
60       * @param sensorNameA name of the sensor A to which mapping applies
61       * @param sensorNameB name of the sensor B to which mapping applies
62       */
63      public SensorToSensorMapping(final String sensorNameA, final String sensorNameB) {
64  
65          this(sensorNameA, RUGGED, sensorNameB, RUGGED, 0.0);
66      }
67  
68      /** Build a new instance with central body constraint.
69       * @param sensorNameA name of the sensor A to which mapping applies
70       * @param ruggedNameA name of the Rugged A to which mapping applies
71       * @param sensorNameB name of the sensor B to which mapping applies
72       * @param ruggedNameB name of the Rugged B to which mapping applies
73       * @param bodyConstraintWeight weight given to the central body distance constraint
74       * with respect to the LOS distance (between 0 and 1).
75       * <br>Weighting will be applied as follow :
76       * <ul>
77       *    <li>(1 - bodyConstraintWeight) for LOS distance weighting</li>
78       *    <li>bodyConstraintWeight for central body distance weighting</li>
79       * </ul>
80       */
81      public SensorToSensorMapping(final String sensorNameA, final String ruggedNameA,
82                                   final String sensorNameB, final String ruggedNameB,
83                                   final double bodyConstraintWeight) {
84  
85          this.interMapping = new SensorMapping<SensorPixel>(sensorNameA, ruggedNameA);
86          this.sensorNameB = sensorNameB;
87          this.ruggedNameB = ruggedNameB;
88          this.losDistances = new ArrayList<Double>();
89          this.bodyDistances = new ArrayList<Double>();
90          this.bodyConstraintWeight = bodyConstraintWeight;
91      }
92  
93      /** Build a new instance without central body constraints.
94       * @param sensorNameA name of the sensor A to which mapping applies
95       * @param ruggedNameA name of the Rugged A to which mapping applies
96       * @param sensorNameB name of the sensor B to which mapping applies
97       * @param ruggedNameB name of the Rugged B to which mapping applies
98       */
99      public SensorToSensorMapping(final String sensorNameA, final String ruggedNameA,
100                                  final String sensorNameB, final String ruggedNameB) {
101 
102         this(sensorNameA, ruggedNameA, sensorNameB, ruggedNameB, 0.0);
103     }
104 
105     /** Build a new instance with central body constraints  (with default Rugged names):
106      * we want to minimize the distance between pixel A and central body.
107      * @param sensorNameA name of the sensor A to which mapping applies
108      * @param sensorNameB name of the sensor B to which mapping applies
109      * @param bodyConstraintWeight weight given to the central body distance constraint
110      * with respect to the LOS distance (between 0 and 1).
111      * <br>Weighting will be applied as follow :
112      * <ul>
113      *    <li>(1 - bodyConstraintWeight) for LOS distance weighting</li>
114      *    <li>bodyConstraintWeight for central body distance weighting</li>
115      * </ul>
116      */
117     public SensorToSensorMapping(final String sensorNameA, final String sensorNameB,
118                                  final double bodyConstraintWeight) {
119 
120         this(sensorNameA, RUGGED, sensorNameB, RUGGED, bodyConstraintWeight);
121     }
122 
123     /** Get the name of the sensor B to which mapping applies.
124      * @return name of the sensor B to which mapping applies
125      */
126     public String getSensorNameB() {
127         return sensorNameB;
128     }
129 
130     /** Get the name of the sensor A to which mapping applies.
131      * @return name of the sensor A to which mapping applies
132      */
133     public String getSensorNameA() {
134         return interMapping.getSensorName();
135     }
136 
137     /** Get the name of the Rugged B to which mapping applies.
138      * @return name of the Rugged B to which mapping applies
139      */
140     public String getRuggedNameB() {
141         return ruggedNameB;
142     }
143 
144     /** Get the name of the Rugged A to which mapping applies.
145      * @return name of the Rugged A to which mapping applies
146      */
147     public String getRuggedNameA() {
148         return interMapping.getRuggedName();
149     }
150 
151     /** Get all the inter-mapping entries.
152      * @return an unmodifiable view of all mapping entries
153      */
154     public Set<Map.Entry<SensorPixel, SensorPixel>> getMapping() {
155         return interMapping.getMapping();
156     }
157 
158     /** Get distances between lines of sight (from both view).
159      * @return the LOS distances
160      */
161     public  List<Double> getLosDistances() {
162         return losDistances;
163     }
164 
165     /** Get distances between central body and pixel A (mapping with constraints).
166      * @return the central body distances
167      */
168     public List<Double> getBodyDistances() {
169         return bodyDistances;
170     }
171 
172     /** Get the weight given to the central body distance constraint with respect to the LOS distance.
173      * @return the central body constraint weight
174      */
175     public double getBodyConstraintWeight() {
176         return bodyConstraintWeight;
177     }
178 
179     /** Get distance between central body and pixel A, corresponding to the inter-mapping index.
180      * @param idx inter-mapping index
181      * @return the central body distances at index idx
182      */
183     public Double getBodyDistance(final int idx) {
184         return getBodyDistances().get(idx);
185     }
186 
187     /** Get distance between LOS, corresponding to the inter-mapping index.
188      * @param idx inter-mapping index
189      * @return the LOS distance at index idx
190      */
191     public Double getLosDistance(final int idx) {
192         return getLosDistances().get(idx);
193     }
194 
195     /** Add a mapping between two sensor pixels (A and B) and corresponding distance between the LOS.
196      * @param pixelA sensor pixel A
197      * @param pixelB sensor pixel B corresponding to the sensor pixel A (by direct then inverse location)
198      * @param losDistance distance between the two lines of sight
199      */
200     public void addMapping(final SensorPixelnsorPixel.html#SensorPixel">SensorPixel pixelA, final SensorPixel pixelB, final Double losDistance) {
201 
202         interMapping.addMapping(pixelA, pixelB);
203         losDistances.add(losDistance);
204     }
205 
206     /** Add a mapping between two sensor pixels (A and B) and corresponding distance between the LOS
207      *  and the central body distance constraint associated with pixel A.
208      * @param pixelA sensor pixel A
209      * @param pixelB sensor pixel B corresponding to the sensor pixel A (by direct then inverse location)
210      * @param losDistance distance between the two lines of sight
211      * @param bodyDistance elevation to central body
212      */
213     public void addMapping(final SensorPixelnsorPixel.html#SensorPixel">SensorPixel pixelA, final SensorPixel pixelB,
214                            final Double losDistance, final Double bodyDistance) {
215 
216         interMapping.addMapping(pixelA, pixelB);
217         losDistances.add(losDistance);
218         bodyDistances.add(bodyDistance);
219     }
220 
221     /** Set the central body constraint weight.
222      * @param bodyConstraintWeight the central body constraint weight to set
223      */
224     public void setBodyConstraintWeight(final double bodyConstraintWeight) {
225         this.bodyConstraintWeight = bodyConstraintWeight;
226     }
227 }