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
19using namespace std;
20namespace 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
67
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) {
159 }
160 else {
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
292extern "C" Isis::TProjection *SinusoidalPlugin(Isis::Pvl &lab,
293 bool allowDefaults) {
294 return new Isis::Sinusoidal(lab, allowDefaults);
295}
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
Sinusoidal Map Projection.
Definition Sinusoidal.h:73
PvlGroup MappingLongitudes()
This function returns the longitude keywords that this projection uses.
bool SetCoordinate(const double x, const double y)
This method is used to set the projection x/y.
Sinusoidal(Pvl &label, bool allowDefaults=false)
Constructs a Sinusoidal object.
double m_centerLongitude
The center longitude for the map projection.
Definition Sinusoidal.h:91
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...
PvlGroup MappingLatitudes()
This function returns the latitude keywords that this projection uses.
PvlGroup Mapping()
This function returns the keywords that this projection uses.
bool SetGround(const double lat, const double lon)
This method is used to set the latitude/longitude (assumed to be of the correct LatitudeType,...
bool operator==(const Projection &proj)
Compares two Projection objects to see if they are equal.
~Sinusoidal()
Destroys the Sinusoidal object.
QString Version() const
Returns the version of the map projection.
QString Name() const
Returns the name of the map projection, "Sinusoidal".
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.