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
19using namespace std;
20namespace 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
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
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
275extern "C" Isis::Projection *SimpleCylindricalPlugin(Isis::Pvl &lab,
276 bool allowDefaults) {
277 return new Isis::SimpleCylindrical(lab, allowDefaults);
278}
Isis exception class.
Definition IException.h:91
@ Io
A type of error that occurred when performing an actual I/O operation.
Definition IException.h:155
Base class for Map Projections.
Definition Projection.h:155
double m_maximumX
See minimumX description.
Definition Projection.h:326
double GetX() const
Calculates the unrotated form of current x value.
bool m_good
Indicates if the contents of m_x, m_y, m_latitude, and m_longitude are valid.
Definition Projection.h:300
double m_minimumX
The data elements m_minimumX, m_minimumY, m_maximumX, and m_maximumY are convience data elements when...
Definition Projection.h:317
PvlGroup m_mappingGrp
Mapping group that created this projection.
Definition Projection.h:329
double m_minimumY
See minimumX description.
Definition Projection.h:327
double GetY() const
Calculates the unrotated form of the current y value.
void SetXY(double x, double y)
This protected method is a helper for derived classes.
double m_maximumY
See minimumX description.
Definition Projection.h:328
void SetComputedXY(double x, double y)
This protected method is a helper for derived classes.
Contains multiple PvlContainers.
Definition PvlGroup.h:41
Container for cube-like labels.
Definition Pvl.h:119
A single keyword-value pair.
Definition PvlKeyword.h:87
@ Traverse
Search child objects.
Definition PvlObject.h:158
PvlGroupIterator findGroup(const QString &name, PvlGroupIterator beg, PvlGroupIterator end)
Find a group with the specified name, within these indexes.
Definition PvlObject.h:129
Simple Cylindrical Map Projection.
QString Version() const
Returns the version of the map projection.
double m_centerLongitude
The center longitude for the map projection.
bool operator==(const Projection &proj)
Compares two Projection objects to see if they are equal.
bool SetGround(const double lat, const double lon)
This method is used to set the latitude/longitude (assumed to be of the correct LatitudeType,...
~SimpleCylindrical()
Destroys the SimpleCylindrical object.
bool IsEquatorialCylindrical()
Indicates whether the projection is Equitorial Cylindrical.
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...
SimpleCylindrical(Pvl &label, bool allowDefaults=false)
Constructs a SimpleCylindrical object.
PvlGroup MappingLatitudes()
This function returns the latitude keywords that this projection uses.
PvlGroup Mapping()
This function returns the keywords that this projection uses.
QString Name() const
Returns the name of the map projection, "SimpleCylindrical".
bool SetCoordinate(const double x, const double y)
This method is used to set the projection x/y.
PvlGroup MappingLongitudes()
This function returns the longitude keywords that this projection uses.
Base class for Map TProjections.
double m_longitude
This contains the currently set longitude value.
double m_minimumLatitude
Contains the minimum latitude for the entire ground range.
double m_maximumLongitude
Contains the maximum longitude for the entire ground range.
double m_equatorialRadius
Polar radius of the target.
LongitudeDirection m_longitudeDirection
An enumerated type indicating the LongitudeDirection read from the labels.
virtual PvlGroup MappingLongitudes()
This function returns the longitude keywords that this projection uses.
void XYRangeCheck(const double latitude, const double longitude)
This convience function is established to assist in the development of the XYRange virtual method.
virtual PvlGroup MappingLatitudes()
This function returns the latitude keywords that this projection uses.
double m_minimumLongitude
Contains the minimum longitude for the entire ground range.
@ PositiveWest
Longitude values increase in the westerly direction.
double m_maximumLatitude
Contains the maximum latitude for the entire ground range.
virtual PvlGroup Mapping()
This function returns the keywords that this projection uses.
double m_latitude
This contains the currently set latitude value.
This is free and unencumbered software released into the public domain.
Definition Apollo.h:16
QString toString(bool boolToConvert)
Global function to convert a boolean to a string.
Definition IString.cpp:211
const double HALFPI
The mathematical constant PI/2.
Definition Constants.h:41
const double PI
The mathematical constant PI.
Definition Constants.h:40
Namespace for the standard library.