Isis 3 Programmer Reference
LunarAzimuthalEqualArea.cpp
1
6/* SPDX-License-Identifier: CC0-1.0 */
7#include "LunarAzimuthalEqualArea.h"
8
9#include <cmath>
10#include <cfloat>
11
12#include "Constants.h"
13#include "IException.h"
14#include "TProjection.h"
15#include "Pvl.h"
16#include "PvlGroup.h"
17
18using namespace std;
19namespace Isis {
31 Pvl &label) : TProjection::TProjection(label) {
32 try {
33 // Try to read the mapping group
34 PvlGroup &mapGroup = label.findGroup("Mapping", Pvl::Traverse);
35
36 // Get the max libration
37 m_maxLibration = mapGroup["MaximumLibration"];
38 m_maxLibration *= PI / 180.0;
39 }
40 catch(IException &e) {
41 QString message = "Invalid label group [Mapping]";
42 throw IException(IException::Unknown, message, _FILEINFO_);
43 }
44 }
45
49
59 if (!Projection::operator==(proj))
60 return false;
61 // dont use != (it is a recusive plunge)
62 // if (Projection::operator!=(proj)) return false;
63
65 if (LKAEA->m_maxLibration != m_maxLibration)
66 return false;
67 return true;
68 }
69
76 return "LunarAzimuthalEqualArea";
77 }
78
86 return "0.1";
87 }
88
102 const double lon) {
103 // Convert longitude to radians
104 m_longitude = lon;
105 double lonRadians = lon * Isis::PI / 180.0;
107 lonRadians *= -1.0;
108
109 // Now convert latitude to radians... it must be planetographic
110 m_latitude = lat;
111 double latRadians = lat;
112 if (IsPlanetocentric())
113 latRadians = ToPlanetographic(latRadians);
114 latRadians *= Isis::PI / 180.0;
115
116 double x, y;
117 if (lonRadians == 0.0 && latRadians == 0.0) {
118 x = 0.0;
119 y = 0.0;
120 SetComputedXY(x, y);
121 m_good = true;
122 return true;
123 }
124
125 double E = acos(cos(latRadians) * cos(lonRadians));
126 double test = (sin(lonRadians) * cos(latRadians)) / sin(E);
127
128 if (test > 1.0) test = 1.0;
129 else if (test < -1.0) test = -1.0;
130
131 double D = HALFPI - asin(test);
132 if (latRadians < 0.0)
133 D = -D;
134
135 double radius = m_equatorialRadius;
136 double PFAC = (HALFPI + m_maxLibration) / HALFPI;
137 double RP = radius * sin(E / PFAC);
138
139 x = RP * cos(D);
140 y = RP * sin(D);
141
142 SetComputedXY(x, y);
143 m_good = true;
144 return true;
145
146 } // of SetGround
147
148
163 const double y) {
164 // Save the coordinate
165 SetXY(x, y);
166
167 double RP = sqrt((x * x) + (y * y));
168
169 double lat, lon;
170 if (y == 0.0 && x == 0.0) {
171 lat = 0.0;
172 lon = 0.0;
173 return true;
174 }
175
176 double radius = m_equatorialRadius;
177
178 double D = atan2(y, x);
179 double test = RP / radius;
180 if (abs(test) > 1.0) {
181 return false;
182 }
183
184 double EPSILON = 0.0000000001;
185 double PFAC = (HALFPI + m_maxLibration) / HALFPI;
186 double E = PFAC * asin(RP / radius);
187
188 lat = HALFPI - (acos(sin(D) * sin(E)));
189
190 if (abs(HALFPI - abs(lat)) <= EPSILON) {
191 lon = 0.0;
192 }
193 else {
194 test = sin(E) * cos(D) / sin(HALFPI - lat);
195 if (test > 1.0) test = 1.0;
196 else if (test < -1.0) test = -1.0;
197
198 lon = asin(test);
199 }
200
201 if (E >= HALFPI) {
202 if (lon <= 0.0) lon = -PI - lon;
203 else lon = PI - lon;
204 }
205
206 // Convert to degrees
207 m_latitude = lat * 180.0 / Isis::PI;
208 m_longitude = lon * 180.0 / Isis::PI;
209
210 // Cleanup the latitude
211 if (IsPlanetocentric())
213
214 m_good = true;
215 return m_good;
216 }
217
218
242 bool LunarAzimuthalEqualArea::XYRange(double &minX, double &maxX,
243 double &minY, double &maxY) {
244 // Check the corners of the lat/lon range
249
250 // If the latitude range contains 0
251 if ((m_minimumLatitude < 0.0) && (m_maximumLatitude > 0.0)) {
254 }
255
256 // If the longitude range contains 0
257 if ((m_minimumLongitude < 0.0) && (m_maximumLongitude > 0.0)) {
260 }
261
262 // Make sure everything is ordered
263 if (m_minimumX >= m_maximumX) return false;
264 if (m_minimumY >= m_maximumY) return false;
265
266 // Return X/Y min/maxs
267 minX = m_minimumX;
268 maxX = m_maximumX;
269 minY = m_minimumY;
270 maxY = m_maximumY;
271 return true;
272 }
273
280 PvlGroup mapping = TProjection::Mapping();
281 mapping += m_mappingGrp["MaximumLibration"];
282 return mapping;
283 }
284
285} // end namespace isis
286
299extern "C" Isis::TProjection *LunarAzimuthalEqualAreaPlugin(Isis::Pvl &lab,
300 bool allowDefaults) {
301 return new Isis::LunarAzimuthalEqualArea(lab);
302}
Isis exception class.
Definition IException.h:91
@ Unknown
A type of error that cannot be classified as any of the other error types.
Definition IException.h:118
Modified Lambert Azimuthal Equal-Area Map Projection.
bool SetCoordinate(const double x, const double y)
This method is used to set the projection x/y.
bool operator==(const TProjection &proj)
Compares two Projection objects to see if they are equal.
QString Name() const
Returns the name of the map projection, "LunarAzimuthalEqualArea".
QString Version() const
Returns the version of the map projection.
double m_maxLibration
Value of the MaximumLibration keyword from the Mapping group of the labels.
PvlGroup Mapping()
This function returns the keywords that this projection uses.
~LunarAzimuthalEqualArea()
Destroys the LunarAzimuthalEqualArea object.
bool XYRange(double &minX, double &maxX, double &minY, double &maxY)
This method is used to determine the x/y range which completely covers the area of interest specified...
LunarAzimuthalEqualArea(Pvl &label)
Constructs a LunarAzimuthalEqualArea object.
bool SetGround(const double lat, const double lon)
This method is used to set the latitude/longitude (assumed to be of the correct LatitudeType,...
double m_maximumX
See minimumX description.
Definition Projection.h:326
bool m_good
Indicates if the contents of m_x, m_y, m_latitude, and m_longitude are valid.
Definition Projection.h:300
double m_minimumX
The data elements m_minimumX, m_minimumY, m_maximumX, and m_maximumY are convience data elements when...
Definition Projection.h:317
PvlGroup m_mappingGrp
Mapping group that created this projection.
Definition Projection.h:329
double m_minimumY
See minimumX description.
Definition Projection.h:327
void SetXY(double x, double y)
This protected method is a helper for derived classes.
double m_maximumY
See minimumX description.
Definition Projection.h:328
void SetComputedXY(double x, double y)
This protected method is a helper for derived classes.
Contains multiple PvlContainers.
Definition PvlGroup.h:41
Container for cube-like labels.
Definition Pvl.h:119
@ Traverse
Search child objects.
Definition PvlObject.h:158
PvlGroupIterator findGroup(const QString &name, PvlGroupIterator beg, PvlGroupIterator end)
Find a group with the specified name, within these indexes.
Definition PvlObject.h:129
Base class for Map TProjections.
double m_longitude
This contains the currently set longitude value.
bool IsPlanetocentric() const
This indicates if the latitude type is planetocentric (as opposed to planetographic).
double m_minimumLatitude
Contains the minimum latitude for the entire ground range.
double m_maximumLongitude
Contains the maximum longitude for the entire ground range.
double m_equatorialRadius
Polar radius of the target.
LongitudeDirection m_longitudeDirection
An enumerated type indicating the LongitudeDirection read from the labels.
double ToPlanetocentric(const double lat) const
This method converts a planetographic latitude to a planetocentric latitude.
void XYRangeCheck(const double latitude, const double longitude)
This convience function is established to assist in the development of the XYRange virtual method.
double m_minimumLongitude
Contains the minimum longitude for the entire ground range.
@ PositiveWest
Longitude values increase in the westerly direction.
double m_maximumLatitude
Contains the maximum latitude for the entire ground range.
virtual PvlGroup Mapping()
This function returns the keywords that this projection uses.
double ToPlanetographic(const double lat) const
This method converts a planetocentric latitude to a planetographic latitude.
double m_latitude
This contains the currently set latitude value.
const double E
Sets some basic constants for use in ISIS programming.
Definition Constants.h:39
This is free and unencumbered software released into the public domain.
Definition Apollo.h:16
const double HALFPI
The mathematical constant PI/2.
Definition Constants.h:41
const double PI
The mathematical constant PI.
Definition Constants.h:40
Namespace for the standard library.