LineSensor.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.linesensor;

  18. import java.util.stream.Stream;

  19. import org.hipparchus.analysis.differentiation.Derivative;
  20. import org.hipparchus.geometry.euclidean.threed.FieldVector3D;
  21. import org.hipparchus.geometry.euclidean.threed.Vector3D;
  22. import org.hipparchus.util.FastMath;
  23. import org.orekit.rugged.errors.DumpManager;
  24. import org.orekit.rugged.los.TimeDependentLOS;
  25. import org.orekit.rugged.utils.DerivativeGenerator;
  26. import org.orekit.time.AbsoluteDate;
  27. import org.orekit.utils.ParameterDriver;

  28. /** Line sensor model.
  29.  * @author Luc Maisonobe
  30.  * @author Guylaine Prat
  31.  */
  32. public class LineSensor {

  33.     /** Name of the sensor. */
  34.     private final String name;

  35.     /** Datation model. */
  36.     private final LineDatation datationModel;

  37.     /** Sensor position. */
  38.     private final Vector3D position;

  39.     /** Pixels lines-of-sight. */
  40.     private final TimeDependentLOS los;

  41.     /** Simple constructor.
  42.      * @param name name of the sensor
  43.      * @param datationModel datation model
  44.      * @param position sensor position in spacecraft frame
  45.      * @param los pixels lines-of-sight in spacecraft frame
  46.      * @see org.orekit.rugged.los.LOSBuilder
  47.      */
  48.     public LineSensor(final String name, final LineDatation datationModel,
  49.                       final Vector3D position, final TimeDependentLOS los) {

  50.         this.name          = name;
  51.         this.datationModel = datationModel;
  52.         this.position      = position;
  53.         this.los           = los;

  54.     }

  55.     /** Get the name of the sensor.
  56.      * @return name of the sensor
  57.      */
  58.     public String getName() {
  59.         return name;
  60.     }

  61.     /** Get the number of pixels.
  62.      * @return number of pixels
  63.      */
  64.     public int getNbPixels() {
  65.         return los.getNbPixels();
  66.     }

  67.     /** Get the drivers for LOS parameters.
  68.      * @return drivers for LOS parameters
  69.      * @since 2.0
  70.      */
  71.     public Stream<ParameterDriver> getParametersDrivers() {
  72.         return los.getParametersDrivers();
  73.     }

  74.     /** Get the pixel normalized line-of-sight at some date.
  75.      * @param date current date
  76.      * @param i pixel index (must be between 0 and {@link #getNbPixels()} - 1
  77.      * @return pixel normalized line-of-sight
  78.      */
  79.     public Vector3D getLOS(final AbsoluteDate date, final int i) {
  80.         final Vector3D l = los.getLOS(i, date);
  81.         DumpManager.dumpSensorLOS(this, date, i, l);
  82.         return l;
  83.     }

  84.     /** Get the pixel normalized interpolated line-of-sight at some date.
  85.      * @param date current date
  86.      * @param i pixel index (must be between 0 and {@link #getNbPixels()} - 1
  87.      * @return pixel normalized line-of-sight
  88.      * @since 2.0
  89.      */
  90.     public Vector3D getLOS(final AbsoluteDate date, final double i) {

  91.         final int iInf = FastMath.max(0, FastMath.min(getNbPixels() - 2, (int) FastMath.floor(i)));
  92.         final int iSup = iInf + 1;
  93.         final Vector3D interpolatedLos     = new Vector3D(iSup - i, los.getLOS(iInf, date),
  94.                                                   i - iInf, los.getLOS(iSup, date));
  95.         return interpolatedLos;
  96.     }

  97.     /** Get the pixel normalized line-of-sight at some date,
  98.      * and their derivatives with respect to estimated parameters.
  99.      * @param <T> derivative type
  100.      * @param date current date
  101.      * @param i pixel index (must be between 0 and {@link #getNbPixels()} - 1
  102.      * @param generator generator to use for building {@link Derivative} instances
  103.      * @return pixel normalized line-of-sight
  104.      */
  105.     public <T extends Derivative<T>> FieldVector3D<T> getLOSDerivatives(final AbsoluteDate date, final int i,
  106.                                                                         final DerivativeGenerator<T> generator) {
  107.         return los.getLOSDerivatives(i, date, generator);
  108.     }

  109.     /** Get the pixel normalized line-of-sight at some date,
  110.      * and their derivatives with respect to estimated parameters.
  111.      * @param <T> derivative type
  112.      * @param date current date
  113.      * @param i pixel index (must be between 0 and {@link #getNbPixels()} - 1
  114.      * @param generator generator to use for building {@link Derivative} instances
  115.      * @return pixel normalized line-of-sight
  116.      * @since 2.0
  117.      */
  118.     public <T extends Derivative<T>> FieldVector3D<T> getLOSDerivatives(final AbsoluteDate date, final double i,
  119.                                                                         final DerivativeGenerator<T> generator) {

  120.         // find surrounding pixels of pixelB (in order to interpolate LOS from pixelB (that is not an integer)
  121.         final int iInf = FastMath.max(0, FastMath.min(getNbPixels() - 2, (int) FastMath.floor(i)));
  122.         final int iSup = iInf + 1;

  123.         final FieldVector3D<T> interpolatedLos =
  124.                         new FieldVector3D<> (iSup - i, los.getLOSDerivatives(iInf, date, generator),
  125.                                              i - iInf, los.getLOSDerivatives(iSup, date, generator)).normalize();
  126.         return interpolatedLos;
  127.     }

  128.     /** Get the date.
  129.      * @param lineNumber line number
  130.      * @return date corresponding to line number
  131.      */
  132.     public AbsoluteDate getDate(final double lineNumber) {
  133.         final AbsoluteDate date = datationModel.getDate(lineNumber);
  134.         DumpManager.dumpSensorDatation(this, lineNumber, date);
  135.         return date;
  136.     }

  137.     /** Get the line number.
  138.      * @param date date
  139.      * @return line number corresponding to date
  140.      */
  141.     public double getLine(final AbsoluteDate date) {
  142.         final double lineNumber = datationModel.getLine(date);
  143.         DumpManager.dumpSensorDatation(this, lineNumber, date);
  144.         return lineNumber;
  145.     }

  146.     /** Get the rate of lines scanning.
  147.      * @param lineNumber line number
  148.      * @return rate of lines scanning (lines / seconds)
  149.      */
  150.     public double getRate(final double lineNumber) {
  151.         final double rate = datationModel.getRate(lineNumber);
  152.         DumpManager.dumpSensorRate(this, lineNumber, rate);
  153.         return rate;
  154.     }

  155.     /** Get the sensor position.
  156.      * @return position
  157.      */
  158.     public Vector3D getPosition() {
  159.         return position;
  160.     }

  161.     /** Dump the rate for the current line number.
  162.      * @param lineNumber line number
  163.      */
  164.     public void dumpRate(final double lineNumber) {
  165.         final double rate = datationModel.getRate(lineNumber);
  166.         DumpManager.dumpSensorRate(this, lineNumber, rate);
  167.     }
  168. }