ITRFVersion.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.frames;

  18. import org.hipparchus.RealFieldElement;
  19. import org.orekit.annotation.DefaultDataContext;
  20. import org.orekit.data.DataContext;
  21. import org.orekit.errors.OrekitException;
  22. import org.orekit.errors.OrekitMessages;
  23. import org.orekit.time.AbsoluteDate;
  24. import org.orekit.time.FieldAbsoluteDate;
  25. import org.orekit.time.TimeScale;

  26. /** Enumerate for ITRF versions.
  27.  * @see EOPEntry
  28.  * @see HelmertTransformation
  29.  * @author Luc Maisonobe
  30.  * @since 9.2
  31.  */
  32. public enum ITRFVersion {

  33.     /** Constant for ITRF 2014. */
  34.     ITRF_2014(2014),

  35.     /** Constant for ITRF 2008. */
  36.     ITRF_2008(2008),

  37.     /** Constant for ITRF 2005. */
  38.     ITRF_2005(2005),

  39.     /** Constant for ITRF 2000. */
  40.     ITRF_2000(2000),

  41.     /** Constant for ITRF 97. */
  42.     ITRF_97(1997),

  43.     /** Constant for ITRF 96. */
  44.     ITRF_96(1996),

  45.     /** Constant for ITRF 94. */
  46.     ITRF_94(1994),

  47.     /** Constant for ITRF 93. */
  48.     ITRF_93(1993),

  49.     /** Constant for ITRF 92. */
  50.     ITRF_92(1992),

  51.     /** Constant for ITRF 91. */
  52.     ITRF_91(1991),

  53.     /** Constant for ITRF 90. */
  54.     ITRF_90(1990),

  55.     /** Constant for ITRF 89. */
  56.     ITRF_89(1989),

  57.     /** Constant for ITRF 88. */
  58.     ITRF_88(1988);

  59.     /** Reference year of the frame version. */
  60.     private final int year;

  61.     /** Name. */
  62.     private final String name;

  63.     /** Simple constructor.
  64.      * @param year reference year of the frame version
  65.      */
  66.     ITRFVersion(final int year) {
  67.         this.year = year;
  68.         this.name = "ITRF-" + ((year >= 2000) ? year : (year - 1900));
  69.     }

  70.     /** Get the reference year of the frame version.
  71.      * @return reference year of the frame version
  72.      */
  73.     public int getYear() {
  74.         return year;
  75.     }

  76.     /** Get the name the frame version.
  77.      * @return name of the frame version
  78.      */
  79.     public String getName() {
  80.         return name;
  81.     }

  82.     /** Find an ITRF version from its reference year.
  83.      * @param year reference year of the frame version
  84.      * @return ITRF version for specified year
  85.      */
  86.     public static ITRFVersion getITRFVersion(final int year) {

  87.         // loop over all predefined frames versions
  88.         for (final ITRFVersion version : values()) {
  89.             if (version.getYear() == year) {
  90.                 return version;
  91.             }
  92.         }

  93.         // we don't have the required frame
  94.         throw new OrekitException(OrekitMessages.NO_SUCH_ITRF_FRAME, year);

  95.     }

  96.     /** Find an ITRF version from its name.
  97.      * @param name name of the frame version (case is ignored)
  98.      * @return ITRF version
  99.      */
  100.     public static ITRFVersion getITRFVersion(final String name) {

  101.         // loop over all predefined frames versions
  102.         for (final ITRFVersion version : values()) {
  103.             if (version.getName().equalsIgnoreCase(name)) {
  104.                 return version;
  105.             }
  106.         }

  107.         // we don't have the required frame
  108.         throw new OrekitException(OrekitMessages.NO_SUCH_ITRF_FRAME, name);

  109.     }

  110.     /** Find a converter between specified ITRF frames.
  111.      *
  112.      * <p>This method uses the {@link DataContext#getDefault() default data context}.
  113.      *
  114.      * @param origin origin ITRF
  115.      * @param destination destination ITRF
  116.      * @return transform from {@code origin} to {@code destination}
  117.      * @see #getConverter(ITRFVersion, ITRFVersion, TimeScale)
  118.      */
  119.     @DefaultDataContext
  120.     public static Converter getConverter(final ITRFVersion origin, final ITRFVersion destination) {
  121.         return getConverter(origin, destination,
  122.                 DataContext.getDefault().getTimeScales().getTT());
  123.     }

  124.     /** Find a converter between specified ITRF frames.
  125.      * @param origin origin ITRF
  126.      * @param destination destination ITRF
  127.      * @param tt TT time scale.
  128.      * @return transform from {@code origin} to {@code destination}
  129.      * @since 10.1
  130.      */
  131.     public static Converter getConverter(final ITRFVersion origin,
  132.                                          final ITRFVersion destination,
  133.                                          final TimeScale tt) {

  134.         TransformProvider provider = null;

  135.         // special case for no transform
  136.         if (origin == destination) {
  137.             provider = TransformProviderUtils.IDENTITY_PROVIDER;
  138.         }

  139.         if (provider == null) {
  140.             // try to find a direct provider
  141.             provider = getDirectTransformProvider(origin, destination, tt);
  142.         }

  143.         if (provider == null) {
  144.             // no direct provider found, use ITRF 2014 as a pivot frame
  145.             provider = TransformProviderUtils.getCombinedProvider(getDirectTransformProvider(origin, ITRF_2014, tt),
  146.                                                                   getDirectTransformProvider(ITRF_2014, destination, tt));
  147.         }

  148.         // build the converter, to keep the origin and destination information
  149.         return new Converter(origin, destination, provider);

  150.     }

  151.     /** Find a direct transform provider between specified ITRF frames.
  152.      * @param origin origin ITRF
  153.      * @param destination destination ITRF
  154.      * @param tt TT time scale.
  155.      * @return transform from {@code origin} to {@code destination}, or null if no direct transform is found
  156.      */
  157.     private static TransformProvider getDirectTransformProvider(
  158.             final ITRFVersion origin,
  159.             final ITRFVersion destination,
  160.             final TimeScale tt) {

  161.         // loop over all predefined transforms
  162.         for (final HelmertTransformation.Predefined predefined : HelmertTransformation.Predefined.values()) {
  163.             if (predefined.getOrigin() == origin && predefined.getDestination() == destination) {
  164.                 // we have an Helmert transformation in the specified direction
  165.                 return predefined.getTransformation(tt);
  166.             } else if (predefined.getOrigin() == destination && predefined.getDestination() == origin) {
  167.                 // we have an Helmert transformation in the opposite direction
  168.                 return TransformProviderUtils.getReversedProvider(predefined.getTransformation(tt));
  169.             }
  170.         }

  171.         // we don't have the required transform
  172.         return null;

  173.     }

  174.     /** Specialized transform provider between ITRF frames. */
  175.     public static class Converter implements TransformProvider {

  176.         /** Serializable UID. */
  177.         private static final long serialVersionUID = 20180330L;

  178.         /** Origin ITRF. */
  179.         private final ITRFVersion origin;

  180.         /** Destination ITRF. */
  181.         private final ITRFVersion destination;

  182.         /** Underlying provider. */
  183.         private final TransformProvider provider;

  184.         /** Simple constructor.
  185.          * @param origin origin ITRF
  186.          * @param destination destination ITRF
  187.          * @param provider underlying provider
  188.          */
  189.         Converter(final ITRFVersion origin, final ITRFVersion destination, final TransformProvider provider) {
  190.             this.origin      = origin;
  191.             this.destination = destination;
  192.             this.provider    = provider;
  193.         }

  194.         /** Get the origin ITRF.
  195.          * @return origin ITRF
  196.          */
  197.         public ITRFVersion getOrigin() {
  198.             return origin;
  199.         }

  200.         /** Get the destination ITRF.
  201.          * @return destination ITRF
  202.          */
  203.         public ITRFVersion getDestination() {
  204.             return destination;
  205.         }

  206.         /** {@inheritDoc} */
  207.         @Override
  208.         public Transform getTransform(final AbsoluteDate date) {
  209.             return provider.getTransform(date);
  210.         }

  211.         /** {@inheritDoc} */
  212.         @Override
  213.         public <T extends RealFieldElement<T>> FieldTransform<T> getTransform(final FieldAbsoluteDate<T> date) {
  214.             return provider.getTransform(date);
  215.         }

  216.     }

  217. }