Isis 3 Programmer Reference
Sinusoidal.cpp
Go to the documentation of this file.
1 
23 #include "Sinusoidal.h"
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 #include "PvlKeyword.h"
34 
35 using namespace std;
36 namespace Isis {
37 
54  Sinusoidal::Sinusoidal(Pvl &label, bool allowDefaults) :
55  TProjection::TProjection(label) {
56  try {
57  // Try to read the mapping group
58  PvlGroup &mapGroup = label.findGroup("Mapping", Pvl::Traverse);
59 
60  // Compute and write the default center longitude if allowed and
61  // necessary
62  if ((allowDefaults) && (!mapGroup.hasKeyword("CenterLongitude"))) {
63  double lon = (m_minimumLongitude + m_maximumLongitude) / 2.0;
64  mapGroup += PvlKeyword("CenterLongitude", toString(lon));
65  }
66 
67  // Get the center longitude
68  m_centerLongitude = mapGroup["CenterLongitude"];
69 
70  // convert to radians, adjust for longitude direction
71  m_centerLongitude *= PI / 180.0;
73  }
74  catch(IException &e) {
75  QString message = "Invalid label group [Mapping]";
76  throw IException(e, IException::Io, message, _FILEINFO_);
77  }
78  }
79 
82  }
83 
92  bool Sinusoidal::operator== (const Projection &proj) {
93  if (!TProjection::operator==(proj)) return false;
94  // dont do the below it is a recusive plunge
95  // if (TProjection::operator!=(proj)) return false;
96  Sinusoidal *sinu = (Sinusoidal *) &proj;
97  if (sinu->m_centerLongitude != m_centerLongitude) return false;
98  return true;
99  }
100 
106  QString Sinusoidal::Name() const {
107  return "Sinusoidal";
108  }
109 
116  QString Sinusoidal::Version() const {
117  return "1.0";
118  }
119 
132  bool Sinusoidal::SetGround(const double lat, const double lon) {
133  // Convert to radians
134  m_latitude = lat;
135  m_longitude = lon;
136  double latRadians = lat * PI / 180.0;
137  double lonRadians = lon * PI / 180.0;
138  if (m_longitudeDirection == PositiveWest) lonRadians *= -1.0;
139 
140  // Compute the coordinate
141  double deltaLon = (lonRadians - m_centerLongitude);
142  double x = m_equatorialRadius * deltaLon * cos(latRadians);
143  double y = m_equatorialRadius * latRadians;
144  SetComputedXY(x, y);
145  m_good = true;
146  return m_good;
147  }
148 
162  bool Sinusoidal::SetCoordinate(const double x, const double y) {
163  // Save the coordinate
164  SetXY(x, y);
165 
166  // Compute latitude and make sure it is not above 90
168  if (fabs(m_latitude) > HALFPI) {
169  if (fabs(HALFPI - fabs(m_latitude)) > DBL_EPSILON) {
170  m_good = false;
171  return m_good;
172  }
173  else if (m_latitude < 0.0) {
174  m_latitude = -HALFPI;
175  }
176  else {
177  m_latitude = HALFPI;
178  }
179  }
180 
181  // Compute longitude
182  double coslat = cos(m_latitude);
183  if (coslat <= DBL_EPSILON) {
185  }
186  else {
188  }
189 
190  // Convert to degrees
191  m_latitude *= 180.0 / PI;
192  m_longitude *= 180.0 / PI;
193 
194  // Cleanup the longitude
196  // These need to be done for circular type projections
197  // m_longitude = To360Domain (m_longitude);
198  // if (m_longitudeDomain == 180) m_longitude = To180Domain(m_longitude);
199 
200  // Our double precision is not good once we pass a certain magnitude of
201  // longitude. Prevent failures down the road by failing now.
202  m_good = (fabs(m_longitude) < 1E10);
203 
204  return m_good;
205  }
206 
230  bool Sinusoidal::XYRange(double &minX, double &maxX,
231  double &minY, double &maxY) {
232  // Check the corners of the lat/lon range
237 
238  // If the latitude crosses the equator check there
239  if ((m_minimumLatitude < 0.0) && (m_maximumLatitude > 0.0)) {
242  }
243 
244  // Make sure everything is ordered
245  if (m_minimumX >= m_maximumX) return false;
246  if (m_minimumY >= m_maximumY) return false;
247 
248  // Return X/Y min/maxs
249  minX = m_minimumX;
250  maxX = m_maximumX;
251  minY = m_minimumY;
252  maxY = m_maximumY;
253  return true;
254  }
255 
256 
263  PvlGroup mapping = TProjection::Mapping();
264 
265  mapping += m_mappingGrp["CenterLongitude"];
266 
267  return mapping;
268  }
269 
277 
278  return mapping;
279  }
280 
288 
289  mapping += m_mappingGrp["CenterLongitude"];
290 
291  return mapping;
292  }
293 
294 } // end namespace isis
295 
309  bool allowDefaults) {
310  return new Isis::Sinusoidal(lab, allowDefaults);
311 }
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: Sinusoidal.cpp:132
bool hasKeyword(const QString &name) const
Check to see if a keyword exists.
PvlGroup Mapping()
This function returns the keywords that this projection uses.
Definition: Sinusoidal.cpp:262
PvlGroupIterator findGroup(const QString &name, PvlGroupIterator beg, PvlGroupIterator end)
Find a group with the specified name, within these indexes.
Definition: PvlObject.h:141
const double PI
The mathematical constant PI.
Definition: Constants.h:56
Longitude values increase in the westerly direction.
Definition: TProjection.h:241
Sinusoidal Map Projection.
Definition: Sinusoidal.h:89
Base class for Map TProjections.
Definition: TProjection.h:182
double m_centerLongitude
The center longitude for the map projection.
Definition: Sinusoidal.h:107
const double HALFPI
The mathematical constant PI/2.
Definition: Constants.h:57
Namespace for the standard library.
Search child objects.
Definition: PvlObject.h:170
double GetX() const
Calculates the unrotated form of current x value.
Definition: Projection.cpp:833
double m_minimumX
The data elements m_minimumX, m_minimumY, m_maximumX, and m_maximumY are convience data elements when...
Definition: Projection.h:333
QString Version() const
Returns the version of the map projection.
Definition: Sinusoidal.cpp:116
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:171
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
virtual PvlGroup MappingLatitudes()
This function returns the latitude keywords that this projection uses.
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 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:230
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
Base class for Map Projections.
Definition: Projection.h:171
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
~Sinusoidal()
Destroys the Sinusoidal object.
Definition: Sinusoidal.cpp:81
#define _FILEINFO_
Macro for the filename and line number.
Definition: IException.h:40
A single keyword-value pair.
Definition: PvlKeyword.h:98
Isis::TProjection * SinusoidalPlugin(Isis::Pvl &lab, bool allowDefaults)
This is the function that is called in order to instantiate a Sinusoidal object.
Definition: Sinusoidal.cpp:308
QString Name() const
Returns the name of the map projection, "Sinusoidal".
Definition: Sinusoidal.cpp:106
PvlGroup MappingLongitudes()
This function returns the longitude keywords that this projection uses.
Definition: Sinusoidal.cpp:286
Container for cube-like labels.
Definition: Pvl.h:135
bool SetCoordinate(const double x, const double y)
This method is used to set the projection x/y.
Definition: Sinusoidal.cpp:162
bool operator==(const Projection &proj)
Compares two Projection objects to see if they are equal.
Definition: Sinusoidal.cpp:92
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
Isis exception class.
Definition: IException.h:107
Namespace for ISIS/Bullet specific routines.
Definition: Apollo.h:31
double GetY() const
Calculates the unrotated form of the current y value.
Definition: Projection.cpp:844
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: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 MappingLatitudes()
This function returns the latitude keywords that this projection uses.
Definition: Sinusoidal.cpp:275
PvlGroup m_mappingGrp
Mapping group that created this projection.
Definition: Projection.h:345