Isis 3 Programmer Reference
SimpleCylindrical.cpp
Go to the documentation of this file.
1 
23 #include "SimpleCylindrical.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  SimpleCylindrical::SimpleCylindrical(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 the default value if allowed and needed
61  if ((allowDefaults) && (!mapGroup.hasKeyword("CenterLongitude"))) {
62  double lon = (m_minimumLongitude + m_maximumLongitude) / 2.0;
63  mapGroup += PvlKeyword("CenterLongitude", toString(lon));
64  }
65 
66  // Get the center longitude, convert to radians, adjust for longitude
67  // direction
68  m_centerLongitude = mapGroup["CenterLongitude"];
69  m_centerLongitude *= PI / 180.0;
71  }
72  catch(IException &e) {
73  QString message = "Invalid label group [Mapping]";
74  throw IException(e, IException::Io, message, _FILEINFO_);
75  }
76  }
77 
80  }
81 
91  if (!Projection::operator==(proj)) return false;
92  // dont do the below it is a recusive plunge
93  // if (Projection::operator!=(proj)) return false;
94  SimpleCylindrical *simp = (SimpleCylindrical *) &proj;
95  if (simp->m_centerLongitude != m_centerLongitude) return false;
96  return true;
97  }
98 
104  QString SimpleCylindrical::Name() const {
105  return "SimpleCylindrical";
106  }
107 
113  QString SimpleCylindrical::Version() const {
114  return "1.0";
115  }
116 
123  return true;
124  }
125 
138  bool SimpleCylindrical::SetGround(const double lat, const double lon) {
139  // Convert to radians
140  m_latitude = lat;
141  m_longitude = lon;
142  double latRadians = lat * PI / 180.0;
143  double lonRadians = lon * PI / 180.0;
144  if (m_longitudeDirection == PositiveWest) lonRadians *= -1.0;
145 
146  // Compute the coordinate
147  double deltaLon = (lonRadians - m_centerLongitude);
148  double x = m_equatorialRadius * deltaLon;
149  double y = m_equatorialRadius * latRadians;
150  SetComputedXY(x, y);
151  m_good = true;
152  return m_good;
153  }
154 
168  bool SimpleCylindrical::SetCoordinate(const double x, const double y) {
169  // Save the coordinate
170  SetXY(x, y);
171 
172  // Compute latitude and make sure it is not above 90
174  if ((fabs(m_latitude) - HALFPI) > DBL_EPSILON) {
175  m_good = false;
176  return m_good;
177  }
178 
179  // Compute longitude
181 
182  // Convert to degrees
183  m_latitude *= 180.0 / PI;
184  m_longitude *= 180.0 / PI;
185 
186  // Cleanup the longitude
188  // Do these if the projection is circular
189  // m_longitude = To360Domain (m_longitude);
190  // if (m_longitudeDomain == 180) m_longitude = To180Domain(m_longitude);
191 
192  m_good = true;
193  return m_good;
194  }
195 
219  bool SimpleCylindrical::XYRange(double &minX, double &maxX,
220  double &minY, double &maxY) {
221  // Check the corners of the lat/lon range
226 
227  // Make sure everything is ordered
228  if (m_minimumX >= m_maximumX) return false;
229  if (m_minimumY >= m_maximumY) return false;
230 
231  // Return X/Y min/maxs
232  minX = m_minimumX;
233  maxX = m_maximumX;
234  minY = m_minimumY;
235  maxY = m_maximumY;
236  return true;
237  }
238 
239 
246  PvlGroup mapping = TProjection::Mapping();
247 
248  mapping += m_mappingGrp["CenterLongitude"];
249 
250  return mapping;
251  }
252 
260 
261  return mapping;
262  }
263 
271 
272  mapping += m_mappingGrp["CenterLongitude"];
273 
274  return mapping;
275  }
276 
277 } // end namespace isis
278 
292  bool allowDefaults) {
293  return new Isis::SimpleCylindrical(lab, allowDefaults);
294 }
bool hasKeyword(const QString &name) const
Check to see if a keyword exists.
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.
PvlGroupIterator findGroup(const QString &name, PvlGroupIterator beg, PvlGroupIterator end)
Find a group with the specified name, within these indexes.
Definition: PvlObject.h:141
bool SetCoordinate(const double x, const double y)
This method is used to set the projection x/y.
const double PI
The mathematical constant PI.
Definition: Constants.h:56
PvlGroup MappingLatitudes()
This function returns the latitude keywords that this projection uses.
Longitude values increase in the westerly direction.
Definition: TProjection.h:241
Base class for Map TProjections.
Definition: TProjection.h:182
const double HALFPI
The mathematical constant PI/2.
Definition: Constants.h:57
Namespace for the standard library.
bool operator==(const Projection &proj)
Compares two Projection objects to see if they are equal.
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 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
PvlGroup MappingLongitudes()
This function returns the longitude keywords that this projection uses.
void SetComputedXY(double x, double y)
This protected method is a helper for derived classes.
Definition: Projection.cpp:795
PvlGroup Mapping()
This function returns the keywords that this projection uses.
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
double m_maximumLongitude
Contains the maximum longitude for the entire ground range.
Definition: TProjection.h:376
QString Version() const
Returns the version of the map projection.
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
QString Name() const
Returns the name of the map projection, "SimpleCylindrical".
double m_equatorialRadius
Polar radius of the target.
Definition: TProjection.h:351
Simple Cylindrical Map Projection.
bool IsEquatorialCylindrical()
Indicates whether the projection is Equitorial Cylindrical.
Contains multiple PvlContainers.
Definition: PvlGroup.h:57
#define _FILEINFO_
Macro for the filename and line number.
Definition: IException.h:40
A single keyword-value pair.
Definition: PvlKeyword.h:98
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:316
LongitudeDirection m_longitudeDirection
An enumerated type indicating the LongitudeDirection read from the labels.
Definition: TProjection.h:340
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...
Isis exception class.
Definition: IException.h:107
double m_centerLongitude
The center longitude for the map projection.
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
~SimpleCylindrical()
Destroys the SimpleCylindrical object.
Isis::Projection * SimpleCylindricalPlugin(Isis::Pvl &lab, bool allowDefaults)
This is the function that is called in order to instantiate a SimpleCylindrical object.
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