Isis 3.0 Programmer Reference
Back | Home
Mollweide.cpp
Go to the documentation of this file.
1 
23 #include "Mollweide.h"
24 
25 
26 #include <cfloat>
27 #include <cmath>
28 #include <iomanip>
29 
30 #include "Constants.h"
31 #include "IException.h"
32 #include "TProjection.h"
33 #include "Pvl.h"
34 #include "PvlGroup.h"
35 #include "PvlKeyword.h"
36 
37 using namespace std;
38 
39 
40 namespace Isis {
41 
42 
60  Mollweide::Mollweide(Pvl &label, bool allowDefaults) :
61  TProjection::TProjection(label) {
62  try {
63  // Try to read the mapping group
64  PvlGroup &mapGroup = label.findGroup("Mapping", Pvl::Traverse);
65 
66  // Compute and write the default center longitude if allowed and
67  // necessary
68  if ((allowDefaults) && (!mapGroup.hasKeyword("CenterLongitude"))) {
69  double lon = (m_minimumLongitude + m_maximumLongitude) / 2.0;
70  mapGroup += PvlKeyword("CenterLongitude", toString(lon));
71  }
72 
73  // Get the center longitude
74  m_centerLongitude = mapGroup["CenterLongitude"];
75 
76  // convert to radians, adjust for longitude direction
77  m_centerLongitude *= PI / 180.0;
79  }
80  catch(IException &e) {
81  QString message = "Invalid label group [Mapping]";
82  throw IException(e, IException::Io, message, _FILEINFO_);
83  }
84  }
85 
88  }
89 
90 
99  bool Mollweide::operator== (const Projection &proj) {
100  if (!TProjection::operator==(proj)) return false;
101  // dont do the below it is a recursive plunge
102  // if (TProjection::operator!=(proj)) return false;
103  Mollweide *moll = (Mollweide *) &proj;
104  if (moll->m_centerLongitude != m_centerLongitude) return false;
105  return true;
106  }
107 
108 
114  QString Mollweide::Name() const {
115  return "Mollweide";
116  }
117 
118 
123  QString Mollweide::Version() const {
124  return "1.0";
125  }
126 
127 
147  bool Mollweide::newton_rapheson(double phi, double &result) {
148 
149  double dtheta = 1.0;
150  int niter = 0;
151  double theta[2];
152 
153  theta[0] = asin(2*phi/PI);
154  theta[1]=0.0;
155 
156  //If this condition is too strict, a larger epsilon value than DBL_EPSILON
157  //can be used to decrease the number of iterations.
158  while (dtheta > DBL_EPSILON) {
159 
160  theta[1] = theta[0] - (2*theta[0]+sin(2*theta[0]) -(Isis::PI)*sin(phi))/(2+2*cos(theta[0]));
161  dtheta = fabs(theta[1]-theta[0]);
162  theta[0] = theta[1];
163  niter++;
164 
165  if (niter > 15000000) {
166  //cout << setprecision(10) << phi*(180/PI) << "," << niter << endl;
167  return false;
168  }
169  }
170  result = theta[1];
171 
172 
173  //cout << setprecision(10) << phi*(180/PI) << "," << niter << endl;
174  return true;
175  }
176 
177 
190  bool Mollweide::SetGround(const double lat, const double lon) {
191 
192  // Convert to radians
193  m_latitude = lat;
194  m_longitude = lon;
195  double theta;
196  double latRadians = lat * PI / 180.0;
197  double lonRadians = lon * PI / 180.0;
198  if (m_longitudeDirection == PositiveWest) lonRadians *= -1.0;
199 
200  // Compute the coordinate
201  double deltaLon = lonRadians - m_centerLongitude;
202 
203  if (newton_rapheson(latRadians,theta) ) {
204 
205  double x = (2*sqrt(2)/PI )*m_equatorialRadius*(deltaLon)*cos(theta);
206  double y = sqrt(2)*m_equatorialRadius*sin(theta);
207 
208  SetComputedXY(x, y);
209  m_good = true;
210  return m_good;
211  }
212  else {
213 
214  m_good = false;
215  return m_good;
216  }
217  }
218 
219 
233  bool Mollweide::SetCoordinate(const double x, const double y) {
234  // Save the coordinate
235 
236  SetXY(x, y);
237 
238  double theta = asin(y/(m_equatorialRadius*sqrt(2)));
239 
240  // Compute latitude and make sure it is not above 90
241  m_latitude = asin((2*theta+sin(2*theta))/(Isis::PI));
242 
243  if (fabs(m_latitude) > HALFPI) {
244  if (fabs(HALFPI - fabs(m_latitude)) > DBL_EPSILON) {
245  m_good = false;
246  return m_good;
247  }
248  else if (m_latitude < 0.0) {
249  m_latitude = -HALFPI;
250  }
251  else {
252  m_latitude = HALFPI;
253  }
254  }
255 
256  // Compute longitude
257 
258  double cosLat = cos(m_latitude);
259 
260  if (cosLat <= DBL_EPSILON) {
262  }
263 
264  else {
265  m_longitude = m_centerLongitude+(Isis::PI)*GetX()/(2*m_equatorialRadius*sqrt(2)*cos(theta));
266  }
267 
268 
269  // Convert to degrees
270  m_latitude *= 180.0 / PI;
271  m_longitude *= 180.0 / PI;
272 
273  // Cleanup the longitude
275 
276 
277  // Our double precision is not good once we pass a certain magnitude of
278  // longitude. Prevent failures down the road by failing now.
279  m_good = (fabs(m_longitude) < 1E10);
280 
281 
282  return m_good;
283  }
284 
285 
309  bool Mollweide::XYRange(double &minX, double &maxX,
310  double &minY, double &maxY) {
311  // Check the corners of the lat/lon range
316 
317  // If the latitude crosses the equator check there
318  if ((m_minimumLatitude < 0.0) && (m_maximumLatitude > 0.0)) {
321  }
322 
323  // Make sure everything is ordered
324  if (m_minimumX >= m_maximumX) return false;
325  if (m_minimumY >= m_maximumY) return false;
326 
327  // Return X/Y min/maxs
328  minX = m_minimumX;
329  maxX = m_maximumX;
330  minY = m_minimumY;
331  maxY = m_maximumY;
332  return true;
333  }
334 
335 
342  PvlGroup mapping = TProjection::Mapping();
343 
344  mapping += m_mappingGrp["CenterLongitude"];
345 
346  return mapping;
347  }
348 
349 
357 
358  return mapping;
359  }
360 
361 
369 
370  mapping += m_mappingGrp["CenterLongitude"];
371 
372  return mapping;
373  }
374 
375 } // end namespace isis
376 
377 
391  bool allowDefaults) {
392  return new Isis::Mollweide(lab, allowDefaults);
393 }
double GetX() const
Calculates the unrotated form of current x value.
Definition: Projection.cpp:804
bool operator==(const Projection &proj)
Compares two Projection objects to see if they are equal.
Definition: Mollweide.cpp:99
PvlGroupIterator findGroup(const QString &name, PvlGroupIterator beg, PvlGroupIterator end)
Find a group with the specified name, within these indexes.
Definition: PvlObject.h:141
bool newton_rapheson(double gamma, double &result)
The Newton-Rapheson method is used to find an iterative solution for:
Definition: Mollweide.cpp:147
Longitude values increase in the westerly direction.
Definition: TProjection.h:237
QString Version() const
Returns the version of the map projection.
Definition: Mollweide.cpp:123
Base class for Map TProjections.
Definition: TProjection.h:178
const double PI(3.14159265358979323846)
The mathematical constant PI.
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...
Definition: Mollweide.cpp:309
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:330
const double HALFPI(1.57079632679489661923)
The mathematical constant PI/2.
QString toString(bool boolToConvert)
Global function to convert a boolean to a string.
Definition: IString.cpp:226
A type of error that occurred when performing an actual I/O operation.
Definition: IException.h:163
PvlGroup Mapping()
This function returns the keywords that this projection uses.
Definition: Mollweide.cpp:341
PvlGroup MappingLongitudes()
This function returns the longitude keywords that this projection uses.
Definition: Mollweide.cpp:367
void SetComputedXY(double x, double y)
This protected method is a helper for derived classes.
Definition: Projection.cpp:766
double m_latitude
This contains the currently set latitude value.
Definition: TProjection.h:327
virtual PvlGroup MappingLatitudes()
This function returns the latitude keywords that this projection uses.
double m_maximumY
See minimumX description.
Definition: Projection.h:341
double m_longitude
This contains the currently set longitude value.
Definition: TProjection.h:329
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.
Definition: Mollweide.cpp:190
double m_maximumLongitude
Contains the maximum longitude for the entire ground range.
Definition: TProjection.h:371
double m_minimumLatitude
Contains the minimum latitude for the entire ground range.
Definition: TProjection.h:365
double m_maximumLatitude
Contains the maximum latitude for the entire ground range.
Definition: TProjection.h:367
Base class for Map Projections.
Definition: Projection.h:169
double m_minimumY
See minimumX description.
Definition: Projection.h:340
QString Name() const
Returns the name of the map projection, &quot;Mollweide&quot;.
Definition: Mollweide.cpp:114
double m_equatorialRadius
Polar radius of the target.
Definition: TProjection.h:346
Contains multiple PvlContainers.
Definition: PvlGroup.h:57
#define _FILEINFO_
Macro for the filename and line number.
Definition: IException.h:38
~Mollweide()
Destroys the Mollweide object.
Definition: Mollweide.cpp:87
A single keyword-value pair.
Definition: PvlKeyword.h:98
Mollweide Map Projection
Definition: Mollweide.h:66
PvlGroup MappingLatitudes()
This function returns the latitude keywords that this projection uses.
Definition: Mollweide.cpp:355
Isis::TProjection * MollweidePlugin(Isis::Pvl &lab, bool allowDefaults)
This is the function that is called in order to instantiate a Mollweide object.
Definition: Mollweide.cpp:390
Container for cube-like labels.
Definition: Pvl.h:135
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:313
LongitudeDirection m_longitudeDirection
An enumerated type indicating the LongitudeDirection read from the labels.
Definition: TProjection.h:335
bool SetCoordinate(const double x, const double y)
This method is used to set the projection x/y.
Definition: Mollweide.cpp:233
Isis exception class.
Definition: IException.h:99
virtual PvlGroup MappingLongitudes()
This function returns the longitude keywords that this projection uses.
void SetXY(double x, double y)
This protected method is a helper for derived classes.
Definition: Projection.cpp:790
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:369
double m_maximumX
See minimumX description.
Definition: Projection.h:339
bool hasKeyword(const QString &name) const
Check to see if a keyword exists.
PvlGroup m_mappingGrp
Mapping group that created this projection.
Definition: Projection.h:342
double m_centerLongitude
The center longitude for the map projection.
Definition: Mollweide.h:85

U.S. Department of the Interior | U.S. Geological Survey
ISIS | Privacy & Disclaimers | Astrogeology Research Program
To contact us, please post comments and questions on the ISIS Support Center
File Modified: 07/12/2023 23:23:51