Loading [MathJax]/jax/output/NativeMML/config.js
Isis 3 Programmer Reference
Sinusoidal.cpp
1 
6 /* SPDX-License-Identifier: CC0-1.0 */
7 #include "Sinusoidal.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 #include "PvlKeyword.h"
18 
19 using namespace std;
20 namespace Isis {
21 
38  Sinusoidal::Sinusoidal(Pvl &label, bool allowDefaults) :
39  TProjection::TProjection(label) {
40  try {
41  // Try to read the mapping group
42  PvlGroup &mapGroup = label.findGroup("Mapping", Pvl::Traverse);
43 
44  // Compute and write the default center longitude if allowed and
45  // necessary
46  if ((allowDefaults) && (!mapGroup.hasKeyword("CenterLongitude"))) {
47  double lon = (m_minimumLongitude + m_maximumLongitude) / 2.0;
48  mapGroup += PvlKeyword("CenterLongitude", toString(lon));
49  }
50 
51  // Get the center longitude
52  m_centerLongitude = mapGroup["CenterLongitude"];
53 
54  // convert to radians, adjust for longitude direction
55  m_centerLongitude *= PI / 180.0;
57  }
58  catch(IException &e) {
59  QString message = "Invalid label group [Mapping]";
60  throw IException(e, IException::Io, message, _FILEINFO_);
61  }
62  }
63 
66  }
67 
76  bool Sinusoidal::operator== (const Projection &proj) {
77  if (!TProjection::operator==(proj)) return false;
78  // dont do the below it is a recusive plunge
79  // if (TProjection::operator!=(proj)) return false;
80  Sinusoidal *sinu = (Sinusoidal *) &proj;
81  if (sinu->m_centerLongitude != m_centerLongitude) return false;
82  return true;
83  }
84 
90  QString Sinusoidal::Name() const {
91  return "Sinusoidal";
92  }
93 
100  QString Sinusoidal::Version() const {
101  return "1.0";
102  }
103 
116  bool Sinusoidal::SetGround(const double lat, const double lon) {
117  // Convert to radians
118  m_latitude = lat;
119  m_longitude = lon;
120  double latRadians = lat * PI / 180.0;
121  double lonRadians = lon * PI / 180.0;
122  if (m_longitudeDirection == PositiveWest) lonRadians *= -1.0;
123 
124  // Compute the coordinate
125  double deltaLon = (lonRadians - m_centerLongitude);
126  double x = m_equatorialRadius * deltaLon * cos(latRadians);
127  double y = m_equatorialRadius * latRadians;
128  SetComputedXY(x, y);
129  m_good = true;
130  return m_good;
131  }
132 
146  bool Sinusoidal::SetCoordinate(const double x, const double y) {
147  // Save the coordinate
148  SetXY(x, y);
149 
150  // Compute latitude and make sure it is not above 90
152  if (fabs(m_latitude) > HALFPI) {
153  if (fabs(HALFPI - fabs(m_latitude)) > DBL_EPSILON) {
154  m_good = false;
155  return m_good;
156  }
157  else if (m_latitude < 0.0) {
158  m_latitude = -HALFPI;
159  }
160  else {
161  m_latitude = HALFPI;
162  }
163  }
164 
165  // Compute longitude
166  double coslat = cos(m_latitude);
167  if (coslat <= DBL_EPSILON) {
169  }
170  else {
172  }
173 
174  // Convert to degrees
175  m_latitude *= 180.0 / PI;
176  m_longitude *= 180.0 / PI;
177 
178  // Cleanup the longitude
180  // These need to be done for circular type projections
181  // m_longitude = To360Domain (m_longitude);
182  // if (m_longitudeDomain == 180) m_longitude = To180Domain(m_longitude);
183 
184  // Our double precision is not good once we pass a certain magnitude of
185  // longitude. Prevent failures down the road by failing now.
186  m_good = (fabs(m_longitude) < 1E10);
187 
188  return m_good;
189  }
190 
214  bool Sinusoidal::XYRange(double &minX, double &maxX,
215  double &minY, double &maxY) {
216  // Check the corners of the lat/lon range
221 
222  // If the latitude crosses the equator check there
223  if ((m_minimumLatitude < 0.0) && (m_maximumLatitude > 0.0)) {
226  }
227 
228  // Make sure everything is ordered
229  if (m_minimumX >= m_maximumX) return false;
230  if (m_minimumY >= m_maximumY) return false;
231 
232  // Return X/Y min/maxs
233  minX = m_minimumX;
234  maxX = m_maximumX;
235  minY = m_minimumY;
236  maxY = m_maximumY;
237  return true;
238  }
239 
240 
247  PvlGroup mapping = TProjection::Mapping();
248 
249  mapping += m_mappingGrp["CenterLongitude"];
250 
251  return mapping;
252  }
253 
261 
262  return mapping;
263  }
264 
272 
273  mapping += m_mappingGrp["CenterLongitude"];
274 
275  return mapping;
276  }
277 
278 } // end namespace isis
279 
292 extern "C" Isis::TProjection *SinusoidalPlugin(Isis::Pvl &lab,
293  bool allowDefaults) {
294  return new Isis::Sinusoidal(lab, allowDefaults);
295 }
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::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::Sinusoidal::Mapping
PvlGroup Mapping()
This function returns the keywords that this projection uses.
Definition: Sinusoidal.cpp:246
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::Sinusoidal::m_centerLongitude
double m_centerLongitude
The center longitude for the map projection.
Definition: Sinusoidal.h:91
Isis::Projection::GetX
double GetX() const
Calculates the unrotated form of current x value.
Definition: Projection.cpp:818
Isis::Sinusoidal::XYRange
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: Sinusoidal.cpp:214
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::Sinusoidal::SetGround
bool SetGround(const double lat, const double lon)
This method is used to set the latitude/longitude (assumed to be of the correct LatitudeType,...
Definition: Sinusoidal.cpp:116
Isis::Projection::SetXY
void SetXY(double x, double y)
This protected method is a helper for derived classes.
Definition: Projection.cpp:804
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::Sinusoidal::Name
QString Name() const
Returns the name of the map projection, "Sinusoidal".
Definition: Sinusoidal.cpp:90
Isis::Projection::m_mappingGrp
PvlGroup m_mappingGrp
Mapping group that created this projection.
Definition: Projection.h:329
Isis::Projection::GetY
double GetY() const
Calculates the unrotated form of the current y value.
Definition: Projection.cpp:829
Isis::Sinusoidal::SetCoordinate
bool SetCoordinate(const double x, const double y)
This method is used to set the projection x/y.
Definition: Sinusoidal.cpp:146
Isis::Sinusoidal::~Sinusoidal
~Sinusoidal()
Destroys the Sinusoidal object.
Definition: Sinusoidal.cpp:65
Isis::PvlObject::Traverse
@ Traverse
Search child objects.
Definition: PvlObject.h:158
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::Sinusoidal::Version
QString Version() const
Returns the version of the map projection.
Definition: Sinusoidal.cpp:100
Isis::Sinusoidal::MappingLongitudes
PvlGroup MappingLongitudes()
This function returns the longitude keywords that this projection uses.
Definition: Sinusoidal.cpp:270
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::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::TProjection::m_maximumLongitude
double m_maximumLongitude
Contains the maximum longitude for the entire ground range.
Definition: TProjection.h:360
Isis::Sinusoidal::operator==
bool operator==(const Projection &proj)
Compares two Projection objects to see if they are equal.
Definition: Sinusoidal.cpp:76
Isis::Sinusoidal::MappingLatitudes
PvlGroup MappingLatitudes()
This function returns the latitude keywords that this projection uses.
Definition: Sinusoidal.cpp:259
Isis::Sinusoidal
Sinusoidal Map Projection.
Definition: Sinusoidal.h:73
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
This is free and unencumbered software released into the public domain.
Definition: Apollo.h:16

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:17:17