File failed to load: https://isis.astrogeology.usgs.gov/6.0.0/Object/assets/jax/output/NativeMML/config.js
Isis 3 Programmer Reference
Mollweide.cpp
1 
6 /* SPDX-License-Identifier: CC0-1.0 */
7 #include "Mollweide.h"
8 
9 
10 #include <cfloat>
11 #include <cmath>
12 #include <iomanip>
13 
14 #include "Constants.h"
15 #include "IException.h"
16 #include "TProjection.h"
17 #include "Pvl.h"
18 #include "PvlGroup.h"
19 #include "PvlKeyword.h"
20 
21 using namespace std;
22 
23 
24 namespace Isis {
25 
26 
44  Mollweide::Mollweide(Pvl &label, bool allowDefaults) :
45  TProjection::TProjection(label) {
46  try {
47  // Try to read the mapping group
48  PvlGroup &mapGroup = label.findGroup("Mapping", Pvl::Traverse);
49 
50  // Compute and write the default center longitude if allowed and
51  // necessary
52  if ((allowDefaults) && (!mapGroup.hasKeyword("CenterLongitude"))) {
53  double lon = (m_minimumLongitude + m_maximumLongitude) / 2.0;
54  mapGroup += PvlKeyword("CenterLongitude", toString(lon));
55  }
56 
57  // Get the center longitude
58  m_centerLongitude = mapGroup["CenterLongitude"];
59 
60  // convert to radians, adjust for longitude direction
61  m_centerLongitude *= PI / 180.0;
63  }
64  catch(IException &e) {
65  QString message = "Invalid label group [Mapping]";
66  throw IException(e, IException::Io, message, _FILEINFO_);
67  }
68  }
69 
72  }
73 
74 
83  bool Mollweide::operator== (const Projection &proj) {
84  if (!TProjection::operator==(proj)) return false;
85  // dont do the below it is a recursive plunge
86  // if (TProjection::operator!=(proj)) return false;
87  Mollweide *moll = (Mollweide *) &proj;
88  if (moll->m_centerLongitude != m_centerLongitude) return false;
89  return true;
90  }
91 
92 
98  QString Mollweide::Name() const {
99  return "Mollweide";
100  }
101 
102 
107  QString Mollweide::Version() const {
108  return "1.0";
109  }
110 
111 
131  bool Mollweide::newton_rapheson(double phi, double &result) {
132 
133  double dtheta = 1.0;
134  int niter = 0;
135  double theta[2];
136 
137  theta[0] = asin(2*phi/PI);
138  theta[1]=0.0;
139 
140  //If this condition is too strict, a larger epsilon value than DBL_EPSILON
141  //can be used to decrease the number of iterations.
142  while (dtheta > DBL_EPSILON) {
143 
144  theta[1] = theta[0] - (2*theta[0]+sin(2*theta[0]) -(Isis::PI)*sin(phi))/(2+2*cos(theta[0]));
145  dtheta = fabs(theta[1]-theta[0]);
146  theta[0] = theta[1];
147  niter++;
148 
149  if (niter > 15000000) {
150  //cout << setprecision(10) << phi*(180/PI) << "," << niter << endl;
151  return false;
152  }
153  }
154  result = theta[1];
155 
156 
157  //cout << setprecision(10) << phi*(180/PI) << "," << niter << endl;
158  return true;
159  }
160 
161 
176  bool Mollweide::SetGround(const double lat, const double lon) {
177 
178  // Convert to radians
179  m_latitude = lat;
180  m_longitude = lon;
181  double theta;
182  double latRadians = lat * PI / 180.0;
183  double lonRadians = lon * PI / 180.0;
184  if (m_longitudeDirection == PositiveWest) lonRadians *= -1.0;
185 
186  // Compute the coordinate
187  double deltaLon = lonRadians - m_centerLongitude;
188 
189  if (newton_rapheson(latRadians,theta) ) {
190 
191  double x = (2*sqrt(2)/PI )*m_equatorialRadius*(deltaLon)*cos(theta);
192  double y = sqrt(2)*m_equatorialRadius*sin(theta);
193 
194  SetComputedXY(x, y);
195  m_good = true;
196  return m_good;
197  }
198  else {
199 
200  m_good = false;
201  return m_good;
202  }
203  }
204 
205 
219  bool Mollweide::SetCoordinate(const double x, const double y) {
220  // Save the coordinate
221 
222  SetXY(x, y);
223 
224  double theta = asin(y/(m_equatorialRadius*sqrt(2)));
225 
226  // Compute latitude and make sure it is not above 90
227  m_latitude = asin((2*theta+sin(2*theta))/(Isis::PI));
228 
229  if (fabs(m_latitude) > HALFPI) {
230  if (fabs(HALFPI - fabs(m_latitude)) > DBL_EPSILON) {
231  m_good = false;
232  return m_good;
233  }
234  else if (m_latitude < 0.0) {
235  m_latitude = -HALFPI;
236  }
237  else {
238  m_latitude = HALFPI;
239  }
240  }
241 
242  // Compute longitude
243 
244  double cosLat = cos(m_latitude);
245 
246  if (cosLat <= DBL_EPSILON) {
248  }
249 
250  else {
251  m_longitude = m_centerLongitude+(Isis::PI)*GetX()/(2*m_equatorialRadius*sqrt(2)*cos(theta));
252  }
253 
254 
255  // Convert to degrees
256  m_latitude *= 180.0 / PI;
257  m_longitude *= 180.0 / PI;
258 
259  // Cleanup the longitude
261 
262 
263  // Our double precision is not good once we pass a certain magnitude of
264  // longitude. Prevent failures down the road by failing now.
265  m_good = (fabs(m_longitude) < 1E10);
266 
267 
268  return m_good;
269  }
270 
271 
297  bool Mollweide::XYRange(double &minX, double &maxX,
298  double &minY, double &maxY) {
299  // Check the corners of the lat/lon range
304 
305  // If the latitude crosses the equator check there
306  if ((m_minimumLatitude < 0.0) && (m_maximumLatitude > 0.0)) {
309  }
310 
311  // Make sure everything is ordered
312  if (m_minimumX >= m_maximumX) return false;
313  if (m_minimumY >= m_maximumY) return false;
314 
315  // Return X/Y min/maxs
316  minX = m_minimumX;
317  maxX = m_maximumX;
318  minY = m_minimumY;
319  maxY = m_maximumY;
320  return true;
321  }
322 
323 
330  PvlGroup mapping = TProjection::Mapping();
331 
332  mapping += m_mappingGrp["CenterLongitude"];
333 
334  return mapping;
335  }
336 
337 
345 
346  return mapping;
347  }
348 
349 
357 
358  mapping += m_mappingGrp["CenterLongitude"];
359 
360  return mapping;
361  }
362 
363 } // end namespace isis
364 
365 
378 extern "C" Isis::TProjection *MollweidePlugin(Isis::Pvl &lab,
379  bool allowDefaults) {
380  return new Isis::Mollweide(lab, allowDefaults);
381 }
Isis::TProjection::m_maximumLatitude
double m_maximumLatitude
Contains the maximum latitude for the entire ground range.
Definition: TProjection.h:356
Isis::HALFPI
const double HALFPI
The mathematical constant PI/2.
Definition: Constants.h:41
Isis::Mollweide::XYRange
bool XYRange(double &minX, double &maxX, double &minY, double &maxY)
Find x/y range from lat/lon range.
Definition: Mollweide.cpp:297
Isis::TProjection::m_longitude
double m_longitude
This contains the currently set longitude value.
Definition: TProjection.h:318
Isis::PvlObject::findGroup
PvlGroupIterator findGroup(const QString &name, PvlGroupIterator beg, PvlGroupIterator end)
Find a group with the specified name, within these indexes.
Definition: PvlObject.h:129
Isis::IException::Io
@ Io
A type of error that occurred when performing an actual I/O operation.
Definition: IException.h:155
Isis::TProjection::m_minimumLongitude
double m_minimumLongitude
Contains the minimum longitude for the entire ground range.
Definition: TProjection.h:358
Isis::TProjection::m_latitude
double m_latitude
This contains the currently set latitude value.
Definition: TProjection.h:316
Isis::Mollweide::operator==
bool operator==(const Projection &proj)
Compares two Projection objects to see if they are equal.
Definition: Mollweide.cpp:83
Isis::Mollweide::SetCoordinate
bool SetCoordinate(const double x, const double y)
This method is used to set the projection x/y.
Definition: Mollweide.cpp:219
Isis::Mollweide::Mapping
PvlGroup Mapping()
This function returns the keywords that this projection uses.
Definition: Mollweide.cpp:329
Isis::PI
const double PI
The mathematical constant PI.
Definition: Constants.h:40
Isis::PvlKeyword
A single keyword-value pair.
Definition: PvlKeyword.h:82
Isis::TProjection::m_longitudeDirection
LongitudeDirection m_longitudeDirection
An enumerated type indicating the LongitudeDirection read from the labels.
Definition: TProjection.h:324
Isis::TProjection::m_minimumLatitude
double m_minimumLatitude
Contains the minimum latitude for the entire ground range.
Definition: TProjection.h:354
Isis::TProjection::PositiveWest
@ PositiveWest
Longitude values increase in the westerly direction.
Definition: TProjection.h:225
Isis::Projection::m_minimumY
double m_minimumY
See minimumX description.
Definition: Projection.h:327
Isis::Projection::GetX
double GetX() const
Calculates the unrotated form of current x value.
Definition: Projection.cpp:818
Isis::Mollweide::MappingLatitudes
PvlGroup MappingLatitudes()
This function returns the latitude keywords that this projection uses.
Definition: Mollweide.cpp:343
Isis::PvlContainer::hasKeyword
bool hasKeyword(const QString &name) const
Check to see if a keyword exists.
Definition: PvlContainer.cpp:159
Isis::Pvl
Container for cube-like labels.
Definition: Pvl.h:119
Isis::Projection::SetXY
void SetXY(double x, double y)
This protected method is a helper for derived classes.
Definition: Projection.cpp:804
Isis::Mollweide::newton_rapheson
bool newton_rapheson(double gamma, double &result)
The Newton-Rapheson method is used to find an iterative solution for:
Definition: Mollweide.cpp:131
Isis::TProjection::XYRangeCheck
void XYRangeCheck(const double latitude, const double longitude)
This convience function is established to assist in the development of the XYRange virtual method.
Definition: TProjection.cpp:1062
Isis::toString
QString toString(bool boolToConvert)
Global function to convert a boolean to a string.
Definition: IString.cpp:211
Isis::Projection::m_mappingGrp
PvlGroup m_mappingGrp
Mapping group that created this projection.
Definition: Projection.h:329
Isis::PvlObject::Traverse
@ Traverse
Search child objects.
Definition: PvlObject.h:158
Isis::Mollweide::Version
QString Version() const
Returns the version of the map projection.
Definition: Mollweide.cpp:107
Isis::Projection::m_minimumX
double m_minimumX
The data elements m_minimumX, m_minimumY, m_maximumX, and m_maximumY are convience data elements when...
Definition: Projection.h:317
Isis::PvlGroup
Contains multiple PvlContainers.
Definition: PvlGroup.h:41
Isis::Projection::m_good
bool m_good
Indicates if the contents of m_x, m_y, m_latitude, and m_longitude are valid.
Definition: Projection.h:300
Isis::TProjection
Base class for Map TProjections.
Definition: TProjection.h:166
Isis::Mollweide::Name
QString Name() const
Returns the name of the map projection, "Mollweide".
Definition: Mollweide.cpp:98
Isis::Mollweide::MappingLongitudes
PvlGroup MappingLongitudes()
This function returns the longitude keywords that this projection uses.
Definition: Mollweide.cpp:355
Isis::IException
Isis exception class.
Definition: IException.h:91
Isis::TProjection::MappingLongitudes
virtual PvlGroup MappingLongitudes()
This function returns the longitude keywords that this projection uses.
Definition: TProjection.cpp:1739
Isis::Mollweide::SetGround
bool SetGround(const double lat, const double lon)
Set lat/lon and attempt to calculate x/y values.
Definition: Mollweide.cpp:176
Isis::Projection::SetComputedXY
void SetComputedXY(double x, double y)
This protected method is a helper for derived classes.
Definition: Projection.cpp:780
std
Namespace for the standard library.
Isis::Mollweide::~Mollweide
~Mollweide()
Destroys the Mollweide object.
Definition: Mollweide.cpp:71
Isis::TProjection::m_maximumLongitude
double m_maximumLongitude
Contains the maximum longitude for the entire ground range.
Definition: TProjection.h:360
Isis::TProjection::MappingLatitudes
virtual PvlGroup MappingLatitudes()
This function returns the latitude keywords that this projection uses.
Definition: TProjection.cpp:1723
Isis::TProjection::Mapping
virtual PvlGroup Mapping()
This function returns the keywords that this projection uses.
Definition: TProjection.cpp:1698
Isis::TProjection::m_equatorialRadius
double m_equatorialRadius
Polar radius of the target.
Definition: TProjection.h:335
Isis::Projection::m_maximumY
double m_maximumY
See minimumX description.
Definition: Projection.h:328
Isis::Projection
Base class for Map Projections.
Definition: Projection.h:155
Isis::Projection::m_maximumX
double m_maximumX
See minimumX description.
Definition: Projection.h:326
Isis::Mollweide::m_centerLongitude
double m_centerLongitude
The center longitude for the map projection.
Definition: Mollweide.h:69
Isis
This is free and unencumbered software released into the public domain.
Definition: Apollo.h:16
Isis::Mollweide
Mollweide Map Projection.
Definition: Mollweide.h:50

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 USGS Astrogeology Discussion Board
To report a bug, or suggest a feature go to: ISIS Github
File Modified: 07/13/2023 15:16:53