ModifiedFrame.java

  1. /* Contributed in the public domain.
  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.files.ccsds.definitions;

  18. import org.hipparchus.CalculusFieldElement;
  19. import org.orekit.bodies.CelestialBody;
  20. import org.orekit.frames.FieldTransform;
  21. import org.orekit.frames.Frame;
  22. import org.orekit.frames.Transform;
  23. import org.orekit.frames.TransformProvider;
  24. import org.orekit.time.AbsoluteDate;
  25. import org.orekit.time.FieldAbsoluteDate;

  26. /**
  27.  * A reference frame created from the {@code REF_FRAME} and {@code CENTER_NAME} is a CCSDS
  28.  * OPM, OMM, or OEM file.
  29.  *
  30.  * @author Evan Ward
  31.  */
  32. public class ModifiedFrame extends Frame {

  33.     /** Serializable UID. */
  34.     private static final long serialVersionUID = 20170619L;

  35.     /** Reference frame used to create this frame. */
  36.     private final CelestialBodyFrame refFrame;

  37.     /** Value of the CENTER_NAME keyword in the ODM file used to create this frame. */
  38.     private final String centerName;

  39.     /**
  40.      * Create a CCSDS reference frame by changing the origin of an existing frame.
  41.      *
  42.      * @param frame      the existing frame that specifies the orientation.
  43.      * @param refFrame   the reference frame used to create this frame.
  44.      * @param body       the new origin.
  45.      * @param centerName the value of the {@code CENTER_NAME} key word used to create
  46.      *                   {@code body}.
  47.      */
  48.     public ModifiedFrame(final Frame frame,
  49.                          final CelestialBodyFrame refFrame,
  50.                          final CelestialBody body,
  51.                          final String centerName) {
  52.         super(frame, new OriginTransformProvider(body, frame),
  53.               body.getName() + "/" + frame.getName(), frame.isPseudoInertial());
  54.         this.refFrame   = refFrame;
  55.         this.centerName = centerName;
  56.     }

  57.     /**
  58.      * Get the CCSDS reference frame.
  59.      *
  60.      * @return the reference frame used to create this frame.
  61.      */
  62.     public CelestialBodyFrame getRefFrame() {
  63.         return refFrame;
  64.     }

  65.     /**
  66.      * Get the CCSDS center name.
  67.      *
  68.      * @return the value of the {@code CENTER_NAME} key word used to specify the origin of
  69.      * this frame.
  70.      */
  71.     public String getCenterName() {
  72.         return centerName;
  73.     }

  74.     /** Transform provider for {@link ModifiedFrame}. */
  75.     private static class OriginTransformProvider implements TransformProvider {

  76.         /** Serializable UID. */
  77.         private static final long serialVersionUID = 20170619L;

  78.         /** The new origin. */
  79.         private final CelestialBody body;

  80.         /** The original frame, specifying the orientation. */
  81.         private final Frame frame;

  82.         /**
  83.          * Create a transform provider to change the origin of an existing frame.
  84.          *
  85.          * @param frame the existing frame that specifies the orientation.
  86.          * @param body  the new origin.
  87.          */
  88.         OriginTransformProvider(final CelestialBody body, final Frame frame) {
  89.             this.body = body;
  90.             this.frame = frame;
  91.         }

  92.         @Override
  93.         public Transform getTransform(final AbsoluteDate date) {
  94.             return new Transform(date, body.getPVCoordinates(date, frame).negate());
  95.         }

  96.         @Override
  97.         public <T extends CalculusFieldElement<T>> FieldTransform<T> getTransform(
  98.                 final FieldAbsoluteDate<T> date) {
  99.             return new FieldTransform<>(
  100.                     date,
  101.                     body.getPVCoordinates(date, frame).negate());
  102.         }

  103.     }

  104. }