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
19 import org.hipparchus.CalculusFieldElement;
20 import org.orekit.bodies.CelestialBody;
21 import org.orekit.frames.FieldTransform;
22 import org.orekit.frames.Frame;
23 import org.orekit.frames.Transform;
24 import org.orekit.frames.TransformProvider;
25 import org.orekit.time.AbsoluteDate;
26 import org.orekit.time.FieldAbsoluteDate;
27
28 /**
29 * A reference frame created from the {@code REF_FRAME} and {@code CENTER_NAME} is a CCSDS
30 * OPM, OMM, or OEM file.
31 *
32 * @author Evan Ward
33 */
34 public class ModifiedFrame extends Frame {
35
36 /** Serializable UID. */
37 private static final long serialVersionUID = 20170619L;
38
39 /** Reference frame used to create this frame. */
40 private final CelestialBodyFrame refFrame;
41
42 /** Value of the CENTER_NAME keyword in the ODM file used to create this frame. */
43 private final String centerName;
44
45 /**
46 * Create a CCSDS reference frame by changing the origin of an existing frame.
47 *
48 * @param frame the existing frame that specifies the orientation.
49 * @param refFrame the reference frame used to create this frame.
50 * @param body the new origin.
51 * @param centerName the value of the {@code CENTER_NAME} key word used to create
52 * {@code body}.
53 */
54 public ModifiedFrame(final Frame frame,
55 final CelestialBodyFrame refFrame,
56 final CelestialBody body,
57 final String centerName) {
58 super(frame, new OriginTransformProvider(body, frame),
59 body.getName() + "/" + frame.getName(), frame.isPseudoInertial());
60 this.refFrame = refFrame;
61 this.centerName = centerName;
62 }
63
64 /**
65 * Get the CCSDS reference frame.
66 *
67 * @return the reference frame used to create this frame.
68 */
69 public CelestialBodyFrame getRefFrame() {
70 return refFrame;
71 }
72
73 /**
74 * Get the CCSDS center name.
75 *
76 * @return the value of the {@code CENTER_NAME} key word used to specify the origin of
77 * this frame.
78 */
79 public String getCenterName() {
80 return centerName;
81 }
82
83 /** Transform provider for {@link ModifiedFrame}. */
84 private static class OriginTransformProvider implements TransformProvider {
85
86 /** Serializable UID. */
87 private static final long serialVersionUID = 20170619L;
88
89 /** The new origin. */
90 private final CelestialBody body;
91
92 /** The original frame, specifying the orientation. */
93 private final Frame frame;
94
95 /**
96 * Create a transform provider to change the origin of an existing frame.
97 *
98 * @param frame the existing frame that specifies the orientation.
99 * @param body the new origin.
100 */
101 OriginTransformProvider(final CelestialBody body, final Frame frame) {
102 this.body = body;
103 this.frame = frame;
104 }
105
106 @Override
107 public Transform getTransform(final AbsoluteDate date) {
108 return new Transform(date, body.getPVCoordinates(date, frame).negate());
109 }
110
111 @Override
112 public <T extends CalculusFieldElement<T>> FieldTransform<T> getTransform(
113 final FieldAbsoluteDate<T> date) {
114 return new FieldTransform<>(
115 date,
116 body.getPVCoordinates(date, frame).negate());
117 }
118
119 }
120
121 }