Isis 3.0 Object Programmers' Reference
Home
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
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;
70
if
(
m_longitudeDirection
==
PositiveWest
)
m_centerLongitude
*= -1.0;
71
}
72
catch
(
IException
&e) {
73
QString message =
"Invalid label group [Mapping]"
;
74
throw
IException
(e,
IException::Io
, message,
_FILEINFO_
);
75
}
76
}
77
79
SimpleCylindrical::~SimpleCylindrical
() {
80
}
81
90
bool
SimpleCylindrical::operator==
(
const
Projection
&proj) {
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
122
bool
SimpleCylindrical::IsEquatorialCylindrical
() {
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
173
m_latitude
=
GetY
() /
m_equatorialRadius
;
174
if
((fabs(
m_latitude
) -
HALFPI
) > DBL_EPSILON) {
175
m_good
=
false
;
176
return
m_good
;
177
}
178
179
// Compute longitude
180
m_longitude
=
m_centerLongitude
+
GetX
() /
m_equatorialRadius
;
181
182
// Convert to degrees
183
m_latitude
*= 180.0 /
PI
;
184
m_longitude
*= 180.0 /
PI
;
185
186
// Cleanup the longitude
187
if
(
m_longitudeDirection
==
PositiveWest
)
m_longitude
*= -1.0;
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
222
XYRangeCheck
(
m_minimumLatitude
,
m_minimumLongitude
);
223
XYRangeCheck
(
m_maximumLatitude
,
m_minimumLongitude
);
224
XYRangeCheck
(
m_minimumLatitude
,
m_maximumLongitude
);
225
XYRangeCheck
(
m_maximumLatitude
,
m_maximumLongitude
);
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
245
PvlGroup
SimpleCylindrical::Mapping
() {
246
PvlGroup
mapping =
TProjection::Mapping
();
247
248
mapping +=
m_mappingGrp
[
"CenterLongitude"
];
249
250
return
mapping;
251
}
252
258
PvlGroup
SimpleCylindrical::MappingLatitudes
() {
259
PvlGroup
mapping =
TProjection::MappingLatitudes
();
260
261
return
mapping;
262
}
263
269
PvlGroup
SimpleCylindrical::MappingLongitudes
() {
270
PvlGroup
mapping =
TProjection::MappingLongitudes
();
271
272
mapping +=
m_mappingGrp
[
"CenterLongitude"
];
273
274
return
mapping;
275
}
276
277
}
// end namespace isis
278
291
extern
"C"
Isis::Projection
*
SimpleCylindricalPlugin
(
Isis::Pvl
&lab,
292
bool
allowDefaults) {
293
return
new
Isis::SimpleCylindrical
(lab, allowDefaults);
294
}