Isis 3 Programmer Reference
LunarAzimuthalEqualArea.cpp
Go to the documentation of this file.
1 
24 
25 #include <cmath>
26 #include <cfloat>
27 
28 #include "Constants.h"
29 #include "IException.h"
30 #include "TProjection.h"
31 #include "Pvl.h"
32 #include "PvlGroup.h"
33 
34 using namespace std;
35 namespace Isis {
46  LunarAzimuthalEqualArea::LunarAzimuthalEqualArea(
47  Pvl &label) : TProjection::TProjection(label) {
48  try {
49  // Try to read the mapping group
50  PvlGroup &mapGroup = label.findGroup("Mapping", Pvl::Traverse);
51 
52  // Get the max libration
53  m_maxLibration = mapGroup["MaximumLibration"];
54  m_maxLibration *= PI / 180.0;
55  }
56  catch(IException &e) {
57  QString message = "Invalid label group [Mapping]";
58  throw IException(IException::Unknown, message, _FILEINFO_);
59  }
60  }
61 
64  }
65 
75  if (!Projection::operator==(proj))
76  return false;
77  // dont use != (it is a recusive plunge)
78  // if (Projection::operator!=(proj)) return false;
79 
81  if (LKAEA->m_maxLibration != m_maxLibration)
82  return false;
83  return true;
84  }
85 
92  return "LunarAzimuthalEqualArea";
93  }
94 
102  return "0.1";
103  }
104 
117  bool LunarAzimuthalEqualArea::SetGround(const double lat,
118  const double lon) {
119  // Convert longitude to radians
120  m_longitude = lon;
121  double lonRadians = lon * Isis::PI / 180.0;
123  lonRadians *= -1.0;
124 
125  // Now convert latitude to radians... it must be planetographic
126  m_latitude = lat;
127  double latRadians = lat;
128  if (IsPlanetocentric())
129  latRadians = ToPlanetographic(latRadians);
130  latRadians *= Isis::PI / 180.0;
131 
132  double x, y;
133  if (lonRadians == 0.0 && latRadians == 0.0) {
134  x = 0.0;
135  y = 0.0;
136  SetComputedXY(x, y);
137  m_good = true;
138  return true;
139  }
140 
141  double E = acos(cos(latRadians) * cos(lonRadians));
142  double test = (sin(lonRadians) * cos(latRadians)) / sin(E);
143 
144  if (test > 1.0) test = 1.0;
145  else if (test < -1.0) test = -1.0;
146 
147  double D = HALFPI - asin(test);
148  if (latRadians < 0.0)
149  D = -D;
150 
151  double radius = m_equatorialRadius;
152  double PFAC = (HALFPI + m_maxLibration) / HALFPI;
153  double RP = radius * sin(E / PFAC);
154 
155  x = RP * cos(D);
156  y = RP * sin(D);
157 
158  SetComputedXY(x, y);
159  m_good = true;
160  return true;
161 
162  } // of SetGround
163 
164 
179  const double y) {
180  // Save the coordinate
181  SetXY(x, y);
182 
183  double RP = sqrt((x * x) + (y * y));
184 
185  double lat, lon;
186  if (y == 0.0 && x == 0.0) {
187  lat = 0.0;
188  lon = 0.0;
189  return true;
190  }
191 
192  double radius = m_equatorialRadius;
193 
194  double D = atan2(y, x);
195  double test = RP / radius;
196  if (abs(test) > 1.0) {
197  return false;
198  }
199 
200  double EPSILON = 0.0000000001;
201  double PFAC = (HALFPI + m_maxLibration) / HALFPI;
202  double E = PFAC * asin(RP / radius);
203 
204  lat = HALFPI - (acos(sin(D) * sin(E)));
205 
206  if (abs(HALFPI - abs(lat)) <= EPSILON) {
207  lon = 0.0;
208  }
209  else {
210  test = sin(E) * cos(D) / sin(HALFPI - lat);
211  if (test > 1.0) test = 1.0;
212  else if (test < -1.0) test = -1.0;
213 
214  lon = asin(test);
215  }
216 
217  if (E >= HALFPI) {
218  if (lon <= 0.0) lon = -PI - lon;
219  else lon = PI - lon;
220  }
221 
222  // Convert to degrees
223  m_latitude = lat * 180.0 / Isis::PI;
224  m_longitude = lon * 180.0 / Isis::PI;
225 
226  // Cleanup the latitude
227  if (IsPlanetocentric())
229 
230  m_good = true;
231  return m_good;
232  }
233 
234 
258  bool LunarAzimuthalEqualArea::XYRange(double &minX, double &maxX,
259  double &minY, double &maxY) {
260  // Check the corners of the lat/lon range
265 
266  // If the latitude range contains 0
267  if ((m_minimumLatitude < 0.0) && (m_maximumLatitude > 0.0)) {
270  }
271 
272  // If the longitude range contains 0
273  if ((m_minimumLongitude < 0.0) && (m_maximumLongitude > 0.0)) {
276  }
277 
278  // Make sure everything is ordered
279  if (m_minimumX >= m_maximumX) return false;
280  if (m_minimumY >= m_maximumY) return false;
281 
282  // Return X/Y min/maxs
283  minX = m_minimumX;
284  maxX = m_maximumX;
285  minY = m_minimumY;
286  maxY = m_maximumY;
287  return true;
288  }
289 
296  PvlGroup mapping = TProjection::Mapping();
297  mapping += m_mappingGrp["MaximumLibration"];
298  return mapping;
299  }
300 
301 } // end namespace isis
302 
316  bool allowDefaults) {
317  return new Isis::LunarAzimuthalEqualArea(lab);
318 }
bool SetGround(const double lat, const double lon)
This method is used to set the latitude/longitude (assumed to be of the correct LatitudeType, LongitudeDirection, and LongitudeDomain.
double m_maxLibration
Value of the MaximumLibration keyword from the Mapping group of the labels.
PvlGroupIterator findGroup(const QString &name, PvlGroupIterator beg, PvlGroupIterator end)
Find a group with the specified name, within these indexes.
Definition: PvlObject.h:141
QString Name() const
Returns the name of the map projection, "LunarAzimuthalEqualArea".
const double PI
The mathematical constant PI.
Definition: Constants.h:56
Longitude values increase in the westerly direction.
Definition: TProjection.h:241
Base class for Map TProjections.
Definition: TProjection.h:182
Isis::TProjection * LunarAzimuthalEqualAreaPlugin(Isis::Pvl &lab, bool allowDefaults)
This is the function that is called in order to instantiate a LunarAzimuthalEqualArea object...
QString Version() const
Returns the version of the map projection.
const double HALFPI
The mathematical constant PI/2.
Definition: Constants.h:57
Namespace for the standard library.
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...
Search child objects.
Definition: PvlObject.h:170
double m_minimumX
The data elements m_minimumX, m_minimumY, m_maximumX, and m_maximumY are convience data elements when...
Definition: Projection.h:333
void SetComputedXY(double x, double y)
This protected method is a helper for derived classes.
Definition: Projection.cpp:795
double m_latitude
This contains the currently set latitude value.
Definition: TProjection.h:332
double m_maximumY
See minimumX description.
Definition: Projection.h:344
double m_longitude
This contains the currently set longitude value.
Definition: TProjection.h:334
bool IsPlanetocentric() const
This indicates if the latitude type is planetocentric (as opposed to planetographic).
double m_maximumLongitude
Contains the maximum longitude for the entire ground range.
Definition: TProjection.h:376
double m_minimumLatitude
Contains the minimum latitude for the entire ground range.
Definition: TProjection.h:370
double m_maximumLatitude
Contains the maximum latitude for the entire ground range.
Definition: TProjection.h:372
double m_minimumY
See minimumX description.
Definition: Projection.h:343
double m_equatorialRadius
Polar radius of the target.
Definition: TProjection.h:351
Contains multiple PvlContainers.
Definition: PvlGroup.h:57
#define _FILEINFO_
Macro for the filename and line number.
Definition: IException.h:40
A type of error that cannot be classified as any of the other error types.
Definition: IException.h:134
Modified Lambert Azimuthal Equal-Area Map Projection.
bool operator==(const TProjection &proj)
Compares two Projection objects to see if they are equal.
~LunarAzimuthalEqualArea()
Destroys the LunarAzimuthalEqualArea object.
Container for cube-like labels.
Definition: Pvl.h:135
double ToPlanetographic(const double lat) const
This method converts a planetocentric latitude to a planetographic latitude.
const double E
Sets some basic constants for use in ISIS programming.
Definition: Constants.h:55
virtual PvlGroup Mapping()
This function returns the keywords that this projection uses.
bool m_good
Indicates if the contents of m_x, m_y, m_latitude, and m_longitude are valid.
Definition: Projection.h:316
LongitudeDirection m_longitudeDirection
An enumerated type indicating the LongitudeDirection read from the labels.
Definition: TProjection.h:340
bool SetCoordinate(const double x, const double y)
This method is used to set the projection x/y.
PvlGroup Mapping()
This function returns the keywords that this projection uses.
Isis exception class.
Definition: IException.h:107
Namespace for ISIS/Bullet specific routines.
Definition: Apollo.h:31
double ToPlanetocentric(const double lat) const
This method converts a planetographic latitude to a planetocentric latitude.
void SetXY(double x, double y)
This protected method is a helper for derived classes.
Definition: Projection.cpp:819
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.
Definition: TProjection.h:374
double m_maximumX
See minimumX description.
Definition: Projection.h:342
PvlGroup m_mappingGrp
Mapping group that created this projection.
Definition: Projection.h:345