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.Collection;
20 import java.util.LinkedHashMap;
21 import java.util.Map;
22
23 /** Class for measurements generation.
24 * @see SensorToSensorMapping
25 * @see SensorToGroundMapping
26 * @author Lucie Labat-Allee
27 * @author Guylaine Prat
28 * @since 2.0
29 */
30 public class Observables {
31
32 /** Separator between Rugged name and sensor name. */
33 private static final String RUGGED_SENSOR_SEPARATOR = "_";
34
35 /** Separator between sensors. */
36 private static final String SENSORS_SEPARATOR = "__";
37
38 /** Sensor to ground mapping structure (example: for Ground Control Points GCP points).*/
39 private final Map<String, SensorToGroundMapping> groundMappings;
40
41 /** Sensor to sensor mappings structure (Tie points). */
42 private final Map<String, SensorToSensorMapping> interMappings;
43
44 /** Number of viewing models to map.*/
45 private final int nbModels;
46
47
48 /** Build a new instance.
49 * @param nbModels number of viewing models to map
50 */
51 public Observables(final int nbModels) {
52
53 this.groundMappings = new LinkedHashMap<String, SensorToGroundMapping>();
54 this.interMappings = new LinkedHashMap<String, SensorToSensorMapping>();
55 this.nbModels = nbModels;
56 }
57
58 /** Add a mapping between two viewing models.
59 * @param interMapping sensor to sensor mapping
60 */
61 public void addInterMapping(final SensorToSensorMapping interMapping) {
62
63 interMappings.put(this.createKey(interMapping), interMapping);
64 }
65
66 /** Add a ground mapping.
67 * <p>
68 * A ground mapping is defined by a set of GCPs.
69 * </p>
70 * @param groundMapping sensor to ground mapping
71 */
72 public void addGroundMapping(final SensorToGroundMapping groundMapping) {
73
74 groundMappings.put(this.createKey(groundMapping), groundMapping);
75 }
76
77 /** Get all the ground mapping entries.
78 * @return an unmodifiable view of all mapping entries
79 */
80 public Collection<SensorToGroundMapping> getGroundMappings() {
81 return groundMappings.values();
82 }
83
84 /**
85 * Get a ground Mapping for a sensor.
86 * @param ruggedName Rugged name
87 * @param sensorName sensor name
88 * @return selected ground mapping or null if sensor is not found
89 */
90 public SensorToGroundMapping getGroundMapping(final String ruggedName, final String sensorName) {
91
92 final SensorToGroundMapping mapping = this.groundMappings.get(ruggedName + RUGGED_SENSOR_SEPARATOR + sensorName);
93 return mapping;
94 }
95
96 /** Get the sensor to sensor values.
97 * @return the inter-mappings
98 */
99 public Collection<SensorToSensorMapping> getInterMappings() {
100 return interMappings.values();
101 }
102
103 /** Get the number of viewing models to map.
104 * @return the number of viewing models to map
105 */
106 public int getNbModels() {
107 return nbModels;
108 }
109
110 /**
111 * Get a sensor mapping for a sensor.
112 * <p>
113 * returns sensor to sensor mapping associated with specific sensors and related rugged instance.
114 * </p>
115 * @param ruggedNameA Rugged name A
116 * @param sensorNameA sensor name A
117 * @param ruggedNameB Rugged name B
118 * @param sensorNameB sensor name B
119 * @return selected ground mapping or null if a sensor is not found
120 */
121 public SensorToSensorMapping getInterMapping(final String ruggedNameA, final String sensorNameA,
122 final String ruggedNameB, final String sensorNameB) {
123
124 final String keyA = ruggedNameA + RUGGED_SENSOR_SEPARATOR + sensorNameA;
125 final String keyB = ruggedNameB + RUGGED_SENSOR_SEPARATOR + sensorNameB;
126 final SensorToSensorMapping mapping = interMappings.get(keyA + SENSORS_SEPARATOR + keyB);
127 return mapping;
128 }
129
130 /** Create key for SensorToGroundMapping map.
131 * @param groundMapping the ground mapping
132 * @return the key
133 */
134 private String createKey(final SensorToGroundMapping groundMapping)
135 {
136 final String key = groundMapping.getRuggedName() + RUGGED_SENSOR_SEPARATOR + groundMapping.getSensorName();
137 return key;
138 }
139
140 /** Create key for SensorToSensorMapping map.
141 * @param sensorMapping the inter mapping
142 * @return the key
143 */
144 private String createKey(final SensorToSensorMapping sensorMapping)
145 {
146 final String keyA = sensorMapping.getRuggedNameA() + RUGGED_SENSOR_SEPARATOR + sensorMapping.getSensorNameA();
147 final String keyB = sensorMapping.getRuggedNameB() + RUGGED_SENSOR_SEPARATOR + sensorMapping.getSensorNameB();
148 return keyA + SENSORS_SEPARATOR + keyB;
149 }
150 }