TabulatedProvider.java

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

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

  20. import org.hipparchus.CalculusFieldElement;
  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 BoundedAttitudeProvider {

  38.     /** Cached attitude table. */
  39.     private final transient ImmutableTimeStampedCache<? extends TimeStampedAngularCoordinates> table;

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

  42.     /** First date of the range. */
  43.     private final AbsoluteDate minDate;

  44.     /** Last date of the range. */
  45.     private final AbsoluteDate maxDate;

  46.     /** Builder for filtered attitudes. */
  47.     private final AttitudeBuilder builder;

  48.     /** Creates new instance.
  49.      * <p>
  50.      * This constructor uses the first and last point samples as the min and max dates.
  51.      * </p>
  52.      * @param referenceFrame reference frame for tabulated attitudes
  53.      * @param table tabulated attitudes
  54.      * @param n number of attitude to use for interpolation
  55.      * @param filter filter for derivatives from the sample to use in interpolation
  56.      * @see #TabulatedProvider(List, int, AngularDerivativesFilter, AbsoluteDate, AbsoluteDate, AttitudeBuilder)
  57.      */
  58.     public TabulatedProvider(final Frame referenceFrame, final List<? extends TimeStampedAngularCoordinates> table,
  59.                              final int n, final AngularDerivativesFilter filter) {
  60.         this(table, n, filter, table.get(0).getDate(), table.get(table.size() - 1).getDate(),
  61.              new FixedFrameBuilder(referenceFrame));
  62.     }

  63.     /** Creates new instance.
  64.      * @param table tabulated attitudes
  65.      * @param n number of attitude to use for interpolation
  66.      * @param filter filter for derivatives from the sample to use in interpolation
  67.      * @param minDate min date to use
  68.      * @param maxDate max date to use
  69.      * @param builder builder to use
  70.      * @since 11.0
  71.      */
  72.     public TabulatedProvider(final List<? extends TimeStampedAngularCoordinates> table,
  73.                              final int n, final AngularDerivativesFilter filter,
  74.                              final AbsoluteDate minDate, final AbsoluteDate maxDate,
  75.                              final AttitudeBuilder builder) {
  76.         this.table          = new ImmutableTimeStampedCache<TimeStampedAngularCoordinates>(n, table);
  77.         this.filter         = filter;
  78.         this.minDate        = minDate;
  79.         this.maxDate        = maxDate;
  80.         this.builder        = builder;
  81.     }

  82.     /** {@inheritDoc} */
  83.     public Attitude getAttitude(final PVCoordinatesProvider pvProv,
  84.                                 final AbsoluteDate date, final Frame frame) {

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

  87.         // interpolate
  88.         final TimeStampedAngularCoordinates interpolated =
  89.                 TimeStampedAngularCoordinates.interpolate(date, filter, sample);

  90.         // build the attitude
  91.         return builder.build(frame, pvProv, interpolated);

  92.     }

  93.     /** {@inheritDoc} */
  94.     public <T extends CalculusFieldElement<T>> FieldAttitude<T> getAttitude(final FieldPVCoordinatesProvider<T> pvProv,
  95.                                                                         final FieldAbsoluteDate<T> date,
  96.                                                                         final Frame frame) {

  97.         // get attitudes sample on which interpolation will be performed
  98.         final List<TimeStampedFieldAngularCoordinates<T>> sample =
  99.                         table.
  100.                         getNeighbors(date.toAbsoluteDate()).
  101.                         map(ac -> new TimeStampedFieldAngularCoordinates<>(date.getField(), ac)).
  102.                         collect(Collectors.toList());

  103.         // interpolate
  104.         final TimeStampedFieldAngularCoordinates<T> interpolated =
  105.                 TimeStampedFieldAngularCoordinates.interpolate(date, filter, sample);

  106.         // build the attitude
  107.         return builder.build(frame, pvProv, interpolated);

  108.     }

  109.     /** {@inheritDoc} */
  110.     public AbsoluteDate getMinDate() {
  111.         return minDate;
  112.     }

  113.     /** {@inheritDoc} */
  114.     public AbsoluteDate getMaxDate() {
  115.         return maxDate;
  116.     }

  117. }