Isis 3 Programmer Reference
SimpleCylindrical.cpp
1 
6 /* SPDX-License-Identifier: CC0-1.0 */
7 #include "SimpleCylindrical.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  SimpleCylindrical::SimpleCylindrical(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 the default value if allowed and needed
45  if ((allowDefaults) && (!mapGroup.hasKeyword("CenterLongitude"))) {
46  double lon = (m_minimumLongitude + m_maximumLongitude) / 2.0;
47  mapGroup += PvlKeyword("CenterLongitude", toString(lon));
48  }
49 
50  // Get the center longitude, convert to radians, adjust for longitude
51  // direction
52  m_centerLongitude = mapGroup["CenterLongitude"];
53  m_centerLongitude *= PI / 180.0;
55  }
56  catch(IException &e) {
57  QString message = "Invalid label group [Mapping]";
58  throw IException(e, IException::Io, message, _FILEINFO_);
59  }
60  }
61 
64  }
65 
75  if (!Projection::operator==(proj)) return false;
76  // dont do the below it is a recusive plunge
77  // if (Projection::operator!=(proj)) return false;
78  SimpleCylindrical *simp = (SimpleCylindrical *) &proj;
79  if (simp->m_centerLongitude != m_centerLongitude) return false;
80  return true;
81  }
82 
88  QString SimpleCylindrical::Name() const {
89  return "SimpleCylindrical";
90  }
91 
97  QString SimpleCylindrical::Version() const {
98  return "1.0";
99  }
100 
107  return true;
108  }
109 
122  bool SimpleCylindrical::SetGround(const double lat, const double lon) {
123  // Convert to radians
124  m_latitude = lat;
125  m_longitude = lon;
126  double latRadians = lat * PI / 180.0;
127  double lonRadians = lon * PI / 180.0;
128  if (m_longitudeDirection == PositiveWest) lonRadians *= -1.0;
129 
130  // Compute the coordinate
131  double deltaLon = (lonRadians - m_centerLongitude);
132  double x = m_equatorialRadius * deltaLon;
133  double y = m_equatorialRadius * latRadians;
134  SetComputedXY(x, y);
135  m_good = true;
136  return m_good;
137  }
138 
152  bool SimpleCylindrical::SetCoordinate(const double x, const double y) {
153  // Save the coordinate
154  SetXY(x, y);
155 
156  // Compute latitude and make sure it is not above 90
158  if ((fabs(m_latitude) - HALFPI) > DBL_EPSILON) {
159  m_good = false;
160  return m_good;
161  }
162 
163  // Compute longitude
165 
166  // Convert to degrees
167  m_latitude *= 180.0 / PI;
168  m_longitude *= 180.0 / PI;
169 
170  // Cleanup the longitude
172  // Do these if the projection is circular
173  // m_longitude = To360Domain (m_longitude);
174  // if (m_longitudeDomain == 180) m_longitude = To180Domain(m_longitude);
175 
176  m_good = true;
177  return m_good;
178  }
179 
203  bool SimpleCylindrical::XYRange(double &minX, double &maxX,
204  double &minY, double &maxY) {
205  // Check the corners of the lat/lon range
210 
211  // Make sure everything is ordered
212  if (m_minimumX >= m_maximumX) return false;
213  if (m_minimumY >= m_maximumY) return false;
214 
215  // Return X/Y min/maxs
216  minX = m_minimumX;
217  maxX = m_maximumX;
218  minY = m_minimumY;
219  maxY = m_maximumY;
220  return true;
221  }
222 
223 
230  PvlGroup mapping = TProjection::Mapping();
231 
232  mapping += m_mappingGrp["CenterLongitude"];
233 
234  return mapping;
235  }
236 
244 
245  return mapping;
246  }
247 
255 
256  mapping += m_mappingGrp["CenterLongitude"];
257 
258  return mapping;
259  }
260 
261 } // end namespace isis
262 
275 extern "C" Isis::Projection *SimpleCylindricalPlugin(Isis::Pvl &lab,
276  bool allowDefaults) {
277  return new Isis::SimpleCylindrical(lab, allowDefaults);
278 }
Isis::SimpleCylindrical::Name
QString Name() const
Returns the name of the map projection, "SimpleCylindrical".
Definition: SimpleCylindrical.cpp:88
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::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::SimpleCylindrical::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: SimpleCylindrical.cpp:203
Isis::Projection::GetX
double GetX() const
Calculates the unrotated form of current x value.
Definition: Projection.cpp:818
Isis::SimpleCylindrical::m_centerLongitude
double m_centerLongitude
The center longitude for the map projection.
Definition: SimpleCylindrical.h:88
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::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::Projection::GetY
double GetY() const
Calculates the unrotated form of the current y value.
Definition: Projection.cpp:829
Isis::SimpleCylindrical::~SimpleCylindrical
~SimpleCylindrical()
Destroys the SimpleCylindrical object.
Definition: SimpleCylindrical.cpp:63
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::SimpleCylindrical::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: SimpleCylindrical.cpp:122
Isis::TProjection
Base class for Map TProjections.
Definition: TProjection.h:166
Isis::IException
Isis exception class.
Definition: IException.h:91
Isis::SimpleCylindrical::SetCoordinate
bool SetCoordinate(const double x, const double y)
This method is used to set the projection x/y.
Definition: SimpleCylindrical.cpp:152
Isis::SimpleCylindrical::MappingLatitudes
PvlGroup MappingLatitudes()
This function returns the latitude keywords that this projection uses.
Definition: SimpleCylindrical.cpp:242
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::SimpleCylindrical::operator==
bool operator==(const Projection &proj)
Compares two Projection objects to see if they are equal.
Definition: SimpleCylindrical.cpp:74
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::SimpleCylindrical::MappingLongitudes
PvlGroup MappingLongitudes()
This function returns the longitude keywords that this projection uses.
Definition: SimpleCylindrical.cpp:253
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::SimpleCylindrical::Mapping
PvlGroup Mapping()
This function returns the keywords that this projection uses.
Definition: SimpleCylindrical.cpp:229
Isis::SimpleCylindrical
Simple Cylindrical Map Projection.
Definition: SimpleCylindrical.h:69
Isis::SimpleCylindrical::IsEquatorialCylindrical
bool IsEquatorialCylindrical()
Indicates whether the projection is Equitorial Cylindrical.
Definition: SimpleCylindrical.cpp:106
Isis
This is free and unencumbered software released into the public domain.
Definition: Apollo.h:16
Isis::SimpleCylindrical::Version
QString Version() const
Returns the version of the map projection.
Definition: SimpleCylindrical.cpp:97