ITRFVersion.java

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

  18. import org.hipparchus.RealFieldElement;
  19. import org.orekit.errors.OrekitException;
  20. import org.orekit.errors.OrekitMessages;
  21. import org.orekit.frames.HelmertTransformation;
  22. import org.orekit.time.AbsoluteDate;
  23. import org.orekit.time.FieldAbsoluteDate;

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

  31.     /** Constant for ITRF 2014. */
  32.     ITRF_2014(2014),

  33.     /** Constant for ITRF 2008. */
  34.     ITRF_2008(2008),

  35.     /** Constant for ITRF 2005. */
  36.     ITRF_2005(2005),

  37.     /** Constant for ITRF 2000. */
  38.     ITRF_2000(2000),

  39.     /** Constant for ITRF 97. */
  40.     ITRF_97(1997),

  41.     /** Constant for ITRF 96. */
  42.     ITRF_96(1996),

  43.     /** Constant for ITRF 94. */
  44.     ITRF_94(1994),

  45.     /** Constant for ITRF 93. */
  46.     ITRF_93(1993),

  47.     /** Constant for ITRF 92. */
  48.     ITRF_92(1992),

  49.     /** Constant for ITRF 91. */
  50.     ITRF_91(1991),

  51.     /** Constant for ITRF 90. */
  52.     ITRF_90(1990),

  53.     /** Constant for ITRF 89. */
  54.     ITRF_89(1989),

  55.     /** Constant for ITRF 88. */
  56.     ITRF_88(1988);

  57.     /** Reference year of the frame version. */
  58.     private final int year;

  59.     /** Name. */
  60.     private final String name;

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

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

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

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

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

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

  93.     }

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

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

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

  107.     }

  108.     /** Find a converter between specified ITRF frames.
  109.      * @param origin origin ITRF
  110.      * @param destination destination ITRF
  111.      * @return transform from {@code origin} to {@code destination}
  112.      */
  113.     public static Converter getConverter(final ITRFVersion origin, final ITRFVersion destination) {

  114.         TransformProvider provider = null;

  115.         // special case for no transform
  116.         if (origin == destination) {
  117.             provider = TransformProviderUtils.IDENTITY_PROVIDER;
  118.         }

  119.         if (provider == null) {
  120.             // try to find a direct provider
  121.             provider = getDirectTransformProvider(origin, destination);
  122.         }

  123.         if (provider == null) {
  124.             // no direct provider found, use ITRF 2014 as a pivot frame
  125.             provider = TransformProviderUtils.getCombinedProvider(getDirectTransformProvider(origin, ITRF_2014),
  126.                                                                   getDirectTransformProvider(ITRF_2014, destination));
  127.         }

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

  130.     }

  131.     /** Find a direct transform provider between specified ITRF frames.
  132.      * @param origin origin ITRF
  133.      * @param destination destination ITRF
  134.      * @return transform from {@code origin} to {@code destination}, or null if no direct transform is found
  135.      */
  136.     private static TransformProvider getDirectTransformProvider(final ITRFVersion origin, final ITRFVersion destination) {

  137.         // loop over all predefined transforms
  138.         for (final HelmertTransformation.Predefined predefined : HelmertTransformation.Predefined.values()) {
  139.             if (predefined.getOrigin() == origin && predefined.getDestination() == destination) {
  140.                 // we have an Helmert transformation in the specified direction
  141.                 return predefined.getTransformation();
  142.             } else if (predefined.getOrigin() == destination && predefined.getDestination() == origin) {
  143.                 // we have an Helmert transformation in the opposite direction
  144.                 return TransformProviderUtils.getReversedProvider(predefined.getTransformation());
  145.             }
  146.         }

  147.         // we don't have the required transform
  148.         return null;

  149.     }

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

  152.         /** Serializable UID. */
  153.         private static final long serialVersionUID = 20180330L;

  154.         /** Origin ITRF. */
  155.         private final ITRFVersion origin;

  156.         /** Destination ITRF. */
  157.         private final ITRFVersion destination;

  158.         /** Underlying provider. */
  159.         private final TransformProvider provider;

  160.         /** Simple constructor.
  161.          * @param origin origin ITRF
  162.          * @param destination destination ITRF
  163.          * @param provider underlying provider
  164.          */
  165.         Converter(final ITRFVersion origin, final ITRFVersion destination, final TransformProvider provider) {
  166.             this.origin      = origin;
  167.             this.destination = destination;
  168.             this.provider    = provider;
  169.         }

  170.         /** Get the origin ITRF.
  171.          * @return origin ITRF
  172.          */
  173.         public ITRFVersion getOrigin() {
  174.             return origin;
  175.         }

  176.         /** Get the destination ITRF.
  177.          * @return destination ITRF
  178.          */
  179.         public ITRFVersion getDestination() {
  180.             return destination;
  181.         }

  182.         /** {@inheritDoc} */
  183.         @Override
  184.         public Transform getTransform(final AbsoluteDate date) {
  185.             return provider.getTransform(date);
  186.         }

  187.         /** {@inheritDoc} */
  188.         @Override
  189.         public <T extends RealFieldElement<T>> FieldTransform<T> getTransform(final FieldAbsoluteDate<T> date) {
  190.             return provider.getTransform(date);
  191.         }

  192.     }

  193. }