ITRFVersion.java

  1. /* Copyright 2002-2018 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.      * @exception OrekitException if no ITRF frame version is found for this year
  84.      */
  85.     public static ITRFVersion getITRFVersion(final int year)
  86.         throws OrekitException {

  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.      * @exception OrekitException if no ITRF frame version is found with this name
  100.      */
  101.     public static ITRFVersion getITRFVersion(final String name)
  102.         throws OrekitException {

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

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

  111.     }

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

  118.         TransformProvider provider = null;

  119.         // special case for no transform
  120.         if (origin == destination) {
  121.             provider = TransformProviderUtils.IDENTITY_PROVIDER;
  122.         }

  123.         if (provider == null) {
  124.             // try to find a direct provider
  125.             provider = getDirectTransformProvider(origin, destination);
  126.         }

  127.         if (provider == null) {
  128.             // no direct provider found, use ITRF 2014 as a pivot frame
  129.             provider = TransformProviderUtils.getCombinedProvider(getDirectTransformProvider(origin, ITRF_2014),
  130.                                                                   getDirectTransformProvider(ITRF_2014, destination));
  131.         }

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

  134.     }

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

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

  151.         // we don't have the required transform
  152.         return null;

  153.     }

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

  156.         /** Serializable UID. */
  157.         private static final long serialVersionUID = 20180330L;

  158.         /** Origin ITRF. */
  159.         private final ITRFVersion origin;

  160.         /** Destination ITRF. */
  161.         private final ITRFVersion destination;

  162.         /** Underlying provider. */
  163.         private final TransformProvider provider;

  164.         /** Simple constructor.
  165.          * @param origin origin ITRF
  166.          * @param destination destination ITRF
  167.          * @param provider underlying provider
  168.          */
  169.         Converter(final ITRFVersion origin, final ITRFVersion destination, final TransformProvider provider) {
  170.             this.origin      = origin;
  171.             this.destination = destination;
  172.             this.provider    = provider;
  173.         }

  174.         /** Get the origin ITRF.
  175.          * @return origin ITRF
  176.          */
  177.         public ITRFVersion getOrigin() {
  178.             return origin;
  179.         }

  180.         /** Get the destination ITRF.
  181.          * @return destination ITRF
  182.          */
  183.         public ITRFVersion getDestination() {
  184.             return destination;
  185.         }

  186.         /** {@inheritDoc} */
  187.         @Override
  188.         public Transform getTransform(final AbsoluteDate date) throws OrekitException {
  189.             return provider.getTransform(date);
  190.         }

  191.         /** {@inheritDoc} */
  192.         @Override
  193.         public <T extends RealFieldElement<T>> FieldTransform<T> getTransform(final FieldAbsoluteDate<T> date)
  194.             throws OrekitException {
  195.             return provider.getTransform(date);
  196.         }

  197.     }

  198. }