FieldOfViewDetector.java

  1. /* Copyright 2002-2016 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.propagation.events;

  18. import org.hipparchus.geometry.euclidean.threed.Vector3D;
  19. import org.orekit.errors.OrekitException;
  20. import org.orekit.propagation.SpacecraftState;
  21. import org.orekit.propagation.events.handlers.EventHandler;
  22. import org.orekit.propagation.events.handlers.StopOnIncreasing;
  23. import org.orekit.utils.PVCoordinatesProvider;

  24. /** Finder for target entry/exit events with respect to a satellite sensor
  25.  * {@link FieldOfView Field Of View}.
  26.  * <p>The default implementation behavior is to {@link
  27.  * org.orekit.propagation.events.handlers.EventHandler.Action#CONTINUE continue}
  28.  * propagation at FOV entry and to {@link
  29.  * org.orekit.propagation.events.handlers.EventHandler.Action#STOP stop} propagation
  30.  * at FOV exit. This can be changed by calling
  31.  * {@link #withHandler(EventHandler)} after construction.</p>
  32.  * @see org.orekit.propagation.Propagator#addEventDetector(EventDetector)
  33.  * @see CircularFieldOfViewDetector
  34.  * @see FootprintOverlapDetector
  35.  * @author Luc Maisonobe
  36.  * @since 7.1
  37.  */
  38. public class FieldOfViewDetector extends AbstractDetector<FieldOfViewDetector> {

  39.     /** Serializable UID. */
  40.     private static final long serialVersionUID = 20160114L;

  41.     /** Position/velocity provider of the considered target. */
  42.     private final PVCoordinatesProvider targetPVProvider;

  43.     /** Field of view. */
  44.     private final FieldOfView fov;

  45.     /** Build a new instance.
  46.      * <p>The maximal interval between distance to FOV boundary checks should
  47.      * be smaller than the half duration of the minimal pass to handle,
  48.      * otherwise some short passes could be missed.</p>
  49.      * @param pvTarget Position/velocity provider of the considered target
  50.      * @param fov Field Of View
  51.      */
  52.     public FieldOfViewDetector(final PVCoordinatesProvider pvTarget, final FieldOfView fov) {
  53.         this(DEFAULT_MAXCHECK, DEFAULT_THRESHOLD, DEFAULT_MAX_ITER,
  54.              new StopOnIncreasing<FieldOfViewDetector>(),
  55.              pvTarget, fov);
  56.     }

  57.     /** Private constructor with full parameters.
  58.      * <p>
  59.      * This constructor is private as users are expected to use the builder
  60.      * API with the various {@code withXxx()} methods to set up the instance
  61.      * in a readable manner without using a huge amount of parameters.
  62.      * </p>
  63.      * @param maxCheck maximum checking interval (s)
  64.      * @param threshold convergence threshold (s)
  65.      * @param maxIter maximum number of iterations in the event time search
  66.      * @param handler event handler to call at event occurrences
  67.      * @param pvTarget Position/velocity provider of the considered target
  68.      * @param fov Field Of View
  69.      */
  70.     private FieldOfViewDetector(final double maxCheck, final double threshold, final int maxIter,
  71.                                 final EventHandler<? super FieldOfViewDetector> handler,
  72.                                 final PVCoordinatesProvider pvTarget, final FieldOfView fov) {
  73.         super(maxCheck, threshold, maxIter, handler);
  74.         this.targetPVProvider = pvTarget;
  75.         this.fov              = fov;
  76.     }

  77.     /** {@inheritDoc} */
  78.     @Override
  79.     protected FieldOfViewDetector create(final double newMaxCheck, final double newThreshold,
  80.                                          final int newMaxIter,
  81.                                          final EventHandler<? super FieldOfViewDetector> newHandler) {
  82.         return new FieldOfViewDetector(newMaxCheck, newThreshold, newMaxIter, newHandler,
  83.                                        targetPVProvider, fov);
  84.     }

  85.     /** Get the position/velocity provider of the target .
  86.      * @return the position/velocity provider of the target
  87.      */
  88.     public PVCoordinatesProvider getPVTarget() {
  89.         return targetPVProvider;
  90.     }

  91.     /** Get the Field Of View.
  92.      * @return Field Of View
  93.      */
  94.     public FieldOfView getFieldOfView() {
  95.         return fov;
  96.     }

  97.     /** {@inheritDoc}
  98.      * <p>
  99.      * The g function value is the angular offset between the
  100.      * target and the {@link FieldOfView#offsetFromBoundary(Vector3D)
  101.      * Field Of View boundary}. It is negative if the target is
  102.      * visible within the Field Of View and positive if it is outside of the
  103.      * Field Of View, including the margin.
  104.      * </p>
  105.      * <p>
  106.      * As per the previous definition, when the target enters the Field Of
  107.      * View, a decreasing event is generated, and when the target leaves
  108.      * the Field Of View, an increasing event is generated.
  109.      * </p>
  110.      */
  111.     public double g(final SpacecraftState s) throws OrekitException {

  112.         // get line of sight in spacecraft frame
  113.         final Vector3D targetPosInert =
  114.                 targetPVProvider.getPVCoordinates(s.getDate(), s.getFrame()).getPosition();
  115.         final Vector3D lineOfSightSC = s.toTransform().transformPosition(targetPosInert);

  116.         return fov.offsetFromBoundary(lineOfSightSC);

  117.     }

  118. }