TabulatedProvider.java

  1. /* Copyright 2002-2020 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.attitudes;

  18. import java.util.List;
  19. import java.util.stream.Collectors;

  20. import org.hipparchus.RealFieldElement;
  21. import org.orekit.frames.Frame;
  22. import org.orekit.time.AbsoluteDate;
  23. import org.orekit.time.FieldAbsoluteDate;
  24. import org.orekit.utils.AngularDerivativesFilter;
  25. import org.orekit.utils.FieldPVCoordinatesProvider;
  26. import org.orekit.utils.ImmutableTimeStampedCache;
  27. import org.orekit.utils.PVCoordinatesProvider;
  28. import org.orekit.utils.TimeStampedAngularCoordinates;
  29. import org.orekit.utils.TimeStampedFieldAngularCoordinates;


  30. /**
  31.  * This class handles an attitude provider interpolating from a predefined table.
  32.  * <p>Instances of this class are guaranteed to be immutable.</p>
  33.  * @author Luc Maisonobe
  34.  * @see TabulatedLofOffset
  35.  * @since 6.1
  36.  */
  37. public class TabulatedProvider implements AttitudeProvider {

  38.     /** Reference frame for tabulated attitudes. */
  39.     private final Frame referenceFrame;

  40.     /** Cached attitude table. */
  41.     private final transient ImmutableTimeStampedCache<TimeStampedAngularCoordinates> table;

  42.     /** Filter for derivatives from the sample to use in interpolation. */
  43.     private final AngularDerivativesFilter filter;

  44.     /** Creates new instance.
  45.      * @param referenceFrame reference frame for tabulated attitudes
  46.      * @param table tabulated attitudes
  47.      * @param n number of attitude to use for interpolation
  48.      * @param filter filter for derivatives from the sample to use in interpolation
  49.      */
  50.     public TabulatedProvider(final Frame referenceFrame, final List<TimeStampedAngularCoordinates> table,
  51.                              final int n, final AngularDerivativesFilter filter) {
  52.         this.referenceFrame  = referenceFrame;
  53.         this.table           = new ImmutableTimeStampedCache<TimeStampedAngularCoordinates>(n, table);
  54.         this.filter          = filter;
  55.     }

  56.     /** {@inheritDoc} */
  57.     public Attitude getAttitude(final PVCoordinatesProvider pvProv,
  58.                                 final AbsoluteDate date, final Frame frame) {

  59.         // get attitudes sample on which interpolation will be performed
  60.         final List<TimeStampedAngularCoordinates> sample = table.getNeighbors(date).collect(Collectors.toList());

  61.         // interpolate
  62.         final TimeStampedAngularCoordinates interpolated =
  63.                 TimeStampedAngularCoordinates.interpolate(date, filter, sample);

  64.         // build the attitude
  65.         return new Attitude(referenceFrame, interpolated);

  66.     }

  67.     /** {@inheritDoc} */
  68.     public <T extends RealFieldElement<T>> FieldAttitude<T> getAttitude(final FieldPVCoordinatesProvider<T> pvProv,
  69.                                                                         final FieldAbsoluteDate<T> date,
  70.                                                                         final Frame frame) {

  71.         // get attitudes sample on which interpolation will be performed
  72.         final List<TimeStampedFieldAngularCoordinates<T>> sample =
  73.                         table.
  74.                         getNeighbors(date.toAbsoluteDate()).
  75.                         map(ac -> new TimeStampedFieldAngularCoordinates<>(date.getField(), ac)).
  76.                         collect(Collectors.toList());

  77.         // interpolate
  78.         final TimeStampedFieldAngularCoordinates<T> interpolated =
  79.                 TimeStampedFieldAngularCoordinates.interpolate(date, filter, sample);

  80.         // build the attitude
  81.         return new FieldAttitude<>(referenceFrame, interpolated);

  82.     }

  83. }