Observables.java

  1. /* Copyright 2013-2022 CS GROUP
  2.  * Licensed to CS GROUP (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. import java.util.Collection;
  19. import java.util.LinkedHashMap;
  20. import java.util.Map;

  21. /** Class for measurements generation.
  22.  * @see SensorToSensorMapping
  23.  * @see SensorToGroundMapping
  24.  * @author Lucie Labat-Allee
  25.  * @author Guylaine Prat
  26.  * @since 2.0
  27.  */
  28. public class Observables {

  29.     /** Separator between Rugged name and sensor name. */
  30.     private static final String RUGGED_SENSOR_SEPARATOR = "_";

  31.     /** Separator between sensors. */
  32.     private static final String SENSORS_SEPARATOR = "__";

  33.     /** Sensor to ground mapping structure (example: for Ground Control Points GCP points).*/
  34.     private final Map<String, SensorToGroundMapping> groundMappings;

  35.     /** Sensor to sensor mappings structure (Tie points). */
  36.     private final Map<String, SensorToSensorMapping> interMappings;

  37.     /** Number of viewing models to map.*/
  38.     private final int nbModels;


  39.     /** Build a new instance.
  40.      * @param nbModels number of viewing models to map
  41.      */
  42.     public Observables(final int nbModels) {

  43.         this.groundMappings = new LinkedHashMap<String, SensorToGroundMapping>();
  44.         this.interMappings = new LinkedHashMap<String, SensorToSensorMapping>();
  45.         this.nbModels = nbModels;
  46.     }

  47.     /** Add a mapping between two viewing models.
  48.      * @param interMapping sensor to sensor mapping
  49.      */
  50.     public void addInterMapping(final SensorToSensorMapping interMapping) {

  51.         interMappings.put(this.createKey(interMapping), interMapping);
  52.     }

  53.     /** Add a ground mapping.
  54.      * <p>
  55.      * A ground mapping is defined by a set of GCPs.
  56.      * </p>
  57.      * @param groundMapping sensor to ground mapping
  58.      */
  59.     public void addGroundMapping(final SensorToGroundMapping groundMapping) {

  60.         groundMappings.put(this.createKey(groundMapping), groundMapping);
  61.     }

  62.     /** Get all the ground mapping entries.
  63.      * @return an unmodifiable view of all mapping entries
  64.      */
  65.     public Collection<SensorToGroundMapping> getGroundMappings() {
  66.         return  groundMappings.values();
  67.     }

  68.     /**
  69.      * Get a ground Mapping for a sensor.
  70.      * @param ruggedName Rugged name
  71.      * @param sensorName sensor name
  72.      * @return selected ground mapping or null if sensor is not found
  73.      */
  74.     public SensorToGroundMapping getGroundMapping(final String ruggedName, final String sensorName) {

  75.         final SensorToGroundMapping mapping = this.groundMappings.get(ruggedName + RUGGED_SENSOR_SEPARATOR + sensorName);
  76.         return mapping;
  77.     }

  78.     /** Get the sensor to sensor values.
  79.      * @return the inter-mappings
  80.      */
  81.     public Collection<SensorToSensorMapping> getInterMappings() {
  82.         return interMappings.values();
  83.     }

  84.     /** Get the number of viewing models to map.
  85.      * @return the number of viewing models to map
  86.      */
  87.     public int getNbModels() {
  88.         return nbModels;
  89.     }

  90.     /**
  91.      * Get a sensor mapping for a sensor.
  92.      * <p>
  93.      * returns sensor to sensor mapping associated with specific sensors and related rugged instance.
  94.      * </p>
  95.      * @param ruggedNameA Rugged name A
  96.      * @param sensorNameA sensor name A
  97.      * @param ruggedNameB Rugged name B
  98.      * @param sensorNameB sensor name B
  99.      * @return selected ground mapping or null if a sensor is not found
  100.      */
  101.     public SensorToSensorMapping getInterMapping(final String ruggedNameA, final String sensorNameA,
  102.                                                  final String ruggedNameB, final String sensorNameB) {

  103.         final String keyA = ruggedNameA + RUGGED_SENSOR_SEPARATOR + sensorNameA;
  104.         final String keyB = ruggedNameB + RUGGED_SENSOR_SEPARATOR + sensorNameB;
  105.         final SensorToSensorMapping mapping = interMappings.get(keyA + SENSORS_SEPARATOR + keyB);
  106.         return mapping;
  107.     }

  108.     /** Create key for SensorToGroundMapping map.
  109.      * @param groundMapping the ground mapping
  110.      * @return the key
  111.      */
  112.     private String createKey(final SensorToGroundMapping groundMapping)
  113.     {
  114.         final String key = groundMapping.getRuggedName() + RUGGED_SENSOR_SEPARATOR + groundMapping.getSensorName();
  115.         return key;
  116.     }

  117.     /** Create key for SensorToSensorMapping map.
  118.      * @param sensorMapping the inter mapping
  119.      * @return the key
  120.      */
  121.     private String createKey(final SensorToSensorMapping sensorMapping)
  122.     {
  123.         final String keyA = sensorMapping.getRuggedNameA() + RUGGED_SENSOR_SEPARATOR + sensorMapping.getSensorNameA();
  124.         final String keyB = sensorMapping.getRuggedNameB() + RUGGED_SENSOR_SEPARATOR + sensorMapping.getSensorNameB();
  125.         return keyA + SENSORS_SEPARATOR + keyB;
  126.     }
  127. }