TabulatedProvider.java

  1. /* Copyright 2002-2025 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.time.FieldTimeInterpolator;
  25. import org.orekit.time.TimeInterpolator;
  26. import org.orekit.utils.AngularDerivativesFilter;
  27. import org.orekit.utils.FieldPVCoordinatesProvider;
  28. import org.orekit.utils.ImmutableTimeStampedCache;
  29. import org.orekit.utils.PVCoordinatesProvider;
  30. import org.orekit.utils.TimeStampedAngularCoordinates;
  31. import org.orekit.utils.TimeStampedAngularCoordinatesHermiteInterpolator;
  32. import org.orekit.utils.TimeStampedFieldAngularCoordinates;
  33. import org.orekit.utils.TimeStampedFieldAngularCoordinatesHermiteInterpolator;

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

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

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

  46.     /** First date of the range. */
  47.     private final AbsoluteDate minDate;

  48.     /** Last date of the range. */
  49.     private final AbsoluteDate maxDate;

  50.     /** Builder for filtered attitudes. */
  51.     private final AttitudeBuilder builder;

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

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

  86.     /** {@inheritDoc} */
  87.     public Attitude getAttitude(final PVCoordinatesProvider pvProv,
  88.                                 final AbsoluteDate date, final Frame frame) {

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

  91.         // create interpolator
  92.         final TimeInterpolator<TimeStampedAngularCoordinates> interpolator =
  93.                 new TimeStampedAngularCoordinatesHermiteInterpolator(sample.size(), filter);

  94.         // interpolate
  95.         final TimeStampedAngularCoordinates interpolated = interpolator.interpolate(date, sample);

  96.         // build the attitude
  97.         return builder.build(frame, pvProv, interpolated);

  98.     }

  99.     /** {@inheritDoc} */
  100.     public <T extends CalculusFieldElement<T>> FieldAttitude<T> getAttitude(final FieldPVCoordinatesProvider<T> pvProv,
  101.                                                                         final FieldAbsoluteDate<T> date,
  102.                                                                         final Frame frame) {

  103.         // get attitudes sample on which interpolation will be performed
  104.         final List<TimeStampedFieldAngularCoordinates<T>> sample =
  105.                         table.
  106.                         getNeighbors(date.toAbsoluteDate()).
  107.                         map(ac -> new TimeStampedFieldAngularCoordinates<>(date.getField(), ac)).
  108.                         collect(Collectors.toList());

  109.         // create interpolator
  110.         final FieldTimeInterpolator<TimeStampedFieldAngularCoordinates<T>, T> interpolator =
  111.                 new TimeStampedFieldAngularCoordinatesHermiteInterpolator<>(sample.size(), filter);

  112.         // interpolate
  113.         final TimeStampedFieldAngularCoordinates<T> interpolated = interpolator.interpolate(date, sample);

  114.         // build the attitude
  115.         return builder.build(frame, pvProv, interpolated);

  116.     }

  117.     /** {@inheritDoc} */
  118.     public AbsoluteDate getMinDate() {
  119.         return minDate;
  120.     }

  121.     /** {@inheritDoc} */
  122.     public AbsoluteDate getMaxDate() {
  123.         return maxDate;
  124.     }

  125. }