1 /* Copyright 2013-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.rugged.refraction;
18
19 import org.orekit.rugged.errors.RuggedException;
20 import org.orekit.rugged.errors.RuggedMessages;
21 import org.orekit.rugged.linesensor.LineSensor;
22 import org.orekit.rugged.utils.GridCreation;
23
24 /**
25 * Atmospheric refraction computation parameters.
26 * Defines for inverse location a set of parameters in order to be able to perform the computation.
27 * @author Guylaine Prat
28 * @since 2.1
29 */
30 public class AtmosphericComputationParameters {
31
32 /** Margin for definition of the interpolation grid.
33 * To be inside the min line and max line range to avoid problem with inverse location grid computation. */
34 private static final int MARGIN_LINE = 10;
35
36 /** Default value for pixel step. */
37 private static final int DEFAULT_STEP_PIXEL = 100;
38 /** Default value for line step. */
39 private static final int DEFAULT_STEP_LINE = 100;
40
41 /** Actual values for pixel step in case default are overwritten. */
42 private int pixelStep;
43 /** Actual values for line step in case default are overwritten. */
44 private int lineStep;
45
46 // Definition of grids for sensor (u = along pixel; v = along line)
47 /** Linear grid in pixel. */
48 private double[] uGrid;
49 /** Linear grid in line. */
50 private double[] vGrid;
51 /** Size of uGrid = nbPixelGrid. */
52 private int nbPixelGrid;
53 /** Size of vGrid = nbLineGrid. */
54 private int nbLineGrid;
55
56 // Definition of the associated sensor
57 /** Current min line. */
58 private double minLineSensor = Double.NaN;
59 /** Current max line. */
60 private double maxLineSensor = Double.NaN;
61 /** Current sensor name. */
62 private String sensorName = null;
63
64 /**
65 * Default constructor.
66 */
67 public AtmosphericComputationParameters() {
68 this.pixelStep = DEFAULT_STEP_PIXEL;
69 this.lineStep = DEFAULT_STEP_LINE;
70 }
71
72 /** Configuration of the interpolation grid. This grid is associated to the given sensor,
73 * with the given min and max lines.
74 * @param sensor line sensor
75 * @param minLine min line defined for the inverse location
76 * @param maxLine max line defined for the inverse location
77 */
78 public void configureCorrectionGrid(final LineSensor sensor, final int minLine, final int maxLine) {
79
80 // Keep information about the sensor and the required search lines.
81 // Needed to test if the grid is initialized with this context.
82 this.minLineSensor = minLine;
83 this.maxLineSensor = maxLine;
84 this.sensorName = sensor.getName();
85
86 // Compute the number of pixels and lines for the grid (round value is sufficient)
87 final int sensorNbPxs = sensor.getNbPixels();
88 this.nbPixelGrid = sensorNbPxs / this.pixelStep;
89
90 // check the validity of the min and max lines
91 if ((maxLine - minLine + 1 - 2 * MARGIN_LINE) < 2 * this.lineStep) {
92 final String info = ": (maxLine - minLine + 1 - 2*" + MARGIN_LINE + ") < 2*" + this.lineStep;
93 throw new RuggedException(RuggedMessages.INVALID_RANGE_FOR_LINES, minLine, maxLine, info);
94 }
95 this.nbLineGrid = (maxLine - minLine + 1 - 2 * MARGIN_LINE) / this.lineStep;
96
97 // CHECKSTYLE: stop UnnecessaryParentheses check
98
99 // Compute the linear grids in pixel (u index) and line (v index)
100 this.uGrid = GridCreation.createLinearGrid(0, (sensorNbPxs - 1), this.nbPixelGrid);
101 this.vGrid = GridCreation.createLinearGrid((minLine + MARGIN_LINE), (maxLine - MARGIN_LINE), this.nbLineGrid);
102
103 // CHECKSTYLE: resume UnnecessaryParentheses check
104
105 }
106
107 /**
108 * Set the grid steps in pixel and line (used to compute inverse location).
109 * Overwrite the default values, for time optimization if necessary.
110 * @param gridPixelStep grid pixel step for the inverse location computation
111 * @param gridLineStep grid line step for the inverse location computation
112 */
113 public void setGridSteps(final int gridPixelStep, final int gridLineStep) {
114
115 if (gridPixelStep <= 0) {
116 final String reason = " pixelStep <= 0";
117 throw new RuggedException(RuggedMessages.INVALID_STEP, gridPixelStep, reason);
118 }
119 if (gridLineStep <= 0) {
120 final String reason = " lineStep <= 0";
121 throw new RuggedException(RuggedMessages.INVALID_STEP, gridLineStep, reason);
122 }
123 this.pixelStep = gridPixelStep;
124 this.lineStep = gridLineStep;
125 }
126
127 /**
128 * @return the size of pixel grid
129 */
130 public int getNbPixelGrid() {
131 return nbPixelGrid;
132 }
133
134 /**
135 * @return the size of line grid
136 */
137 public int getNbLineGrid() {
138 return nbLineGrid;
139 }
140
141 /**
142 * @return the pixel grid
143 */
144 public double[] getUgrid() {
145 return uGrid.clone();
146 }
147
148 /**
149 * @return the line grid
150 */
151 public double[] getVgrid() {
152 return vGrid.clone();
153 }
154
155 /**
156 * @return the min line used to compute the current grids
157 */
158 public double getMinLineSensor() {
159 return minLineSensor;
160 }
161
162 /**
163 * @return the max line used to compute the current grids
164 */
165 public double getMaxLineSensor() {
166 return maxLineSensor;
167 }
168
169 /**
170 * @return the sensor name used to compute the current grids
171 */
172 public String getSensorName() {
173 return sensorName;
174 }
175 }