|
Isis 3.0 Object Programmers' Reference |
Home |
00001 00023 #include "SimpleCylindrical.h" 00024 00025 #include <cmath> 00026 #include <cfloat> 00027 00028 #include "Constants.h" 00029 #include "IException.h" 00030 #include "Projection.h" 00031 #include "Pvl.h" 00032 #include "PvlGroup.h" 00033 #include "PvlKeyword.h" 00034 00035 using namespace std; 00036 namespace Isis { 00037 00054 SimpleCylindrical::SimpleCylindrical(Pvl &label, bool allowDefaults) : 00055 Projection::Projection(label) { 00056 try { 00057 // Try to read the mapping group 00058 PvlGroup &mapGroup = label.FindGroup("Mapping", Pvl::Traverse); 00059 00060 // Compute the default value if allowed and needed 00061 if ((allowDefaults) && (!mapGroup.HasKeyword("CenterLongitude"))) { 00062 double lon = (m_minimumLongitude + m_maximumLongitude) / 2.0; 00063 mapGroup += PvlKeyword("CenterLongitude", toString(lon)); 00064 } 00065 00066 // Get the center longitude, convert to radians, adjust for longitude 00067 // direction 00068 m_centerLongitude = mapGroup["CenterLongitude"]; 00069 m_centerLongitude *= PI / 180.0; 00070 if (m_longitudeDirection == PositiveWest) m_centerLongitude *= -1.0; 00071 } 00072 catch(IException &e) { 00073 QString message = "Invalid label group [Mapping]"; 00074 throw IException(e, IException::Io, message, _FILEINFO_); 00075 } 00076 } 00077 00079 SimpleCylindrical::~SimpleCylindrical() { 00080 } 00081 00090 bool SimpleCylindrical::operator== (const Projection &proj) { 00091 if (!Projection::operator==(proj)) return false; 00092 // dont do the below it is a recusive plunge 00093 // if (Projection::operator!=(proj)) return false; 00094 SimpleCylindrical *simp = (SimpleCylindrical *) &proj; 00095 if (simp->m_centerLongitude != m_centerLongitude) return false; 00096 return true; 00097 } 00098 00104 QString SimpleCylindrical::Name() const { 00105 return "SimpleCylindrical"; 00106 } 00107 00113 QString SimpleCylindrical::Version() const { 00114 return "1.0"; 00115 } 00116 00122 bool SimpleCylindrical::IsEquatorialCylindrical() { 00123 return true; 00124 } 00125 00138 bool SimpleCylindrical::SetGround(const double lat, const double lon) { 00139 // Convert to radians 00140 m_latitude = lat; 00141 m_longitude = lon; 00142 double latRadians = lat * PI / 180.0; 00143 double lonRadians = lon * PI / 180.0; 00144 if (m_longitudeDirection == PositiveWest) lonRadians *= -1.0; 00145 00146 // Compute the coordinate 00147 double deltaLon = (lonRadians - m_centerLongitude); 00148 double x = m_equatorialRadius * deltaLon; 00149 double y = m_equatorialRadius * latRadians; 00150 SetComputedXY(x, y); 00151 m_good = true; 00152 return m_good; 00153 } 00154 00168 bool SimpleCylindrical::SetCoordinate(const double x, const double y) { 00169 // Save the coordinate 00170 SetXY(x, y); 00171 00172 // Compute latitude and make sure it is not above 90 00173 m_latitude = GetY() / m_equatorialRadius; 00174 if ((fabs(m_latitude) - HALFPI) > DBL_EPSILON) { 00175 m_good = false; 00176 return m_good; 00177 } 00178 00179 // Compute longitude 00180 m_longitude = m_centerLongitude + GetX() / m_equatorialRadius; 00181 00182 // Convert to degrees 00183 m_latitude *= 180.0 / PI; 00184 m_longitude *= 180.0 / PI; 00185 00186 // Cleanup the longitude 00187 if (m_longitudeDirection == PositiveWest) m_longitude *= -1.0; 00188 // Do these if the projection is circular 00189 // m_longitude = To360Domain (m_longitude); 00190 // if (m_longitudeDomain == 180) m_longitude = To180Domain(m_longitude); 00191 00192 m_good = true; 00193 return m_good; 00194 } 00195 00219 bool SimpleCylindrical::XYRange(double &minX, double &maxX, 00220 double &minY, double &maxY) { 00221 // Check the corners of the lat/lon range 00222 XYRangeCheck(m_minimumLatitude, m_minimumLongitude); 00223 XYRangeCheck(m_maximumLatitude, m_minimumLongitude); 00224 XYRangeCheck(m_minimumLatitude, m_maximumLongitude); 00225 XYRangeCheck(m_maximumLatitude, m_maximumLongitude); 00226 00227 // Make sure everything is ordered 00228 if (m_minimumX >= m_maximumX) return false; 00229 if (m_minimumY >= m_maximumY) return false; 00230 00231 // Return X/Y min/maxs 00232 minX = m_minimumX; 00233 maxX = m_maximumX; 00234 minY = m_minimumY; 00235 maxY = m_maximumY; 00236 return true; 00237 } 00238 00239 00245 PvlGroup SimpleCylindrical::Mapping() { 00246 PvlGroup mapping = Projection::Mapping(); 00247 00248 mapping += m_mappingGrp["CenterLongitude"]; 00249 00250 return mapping; 00251 } 00252 00258 PvlGroup SimpleCylindrical::MappingLatitudes() { 00259 PvlGroup mapping = Projection::MappingLatitudes(); 00260 00261 return mapping; 00262 } 00263 00269 PvlGroup SimpleCylindrical::MappingLongitudes() { 00270 PvlGroup mapping = Projection::MappingLongitudes(); 00271 00272 mapping += m_mappingGrp["CenterLongitude"]; 00273 00274 return mapping; 00275 } 00276 00277 } // end namespace isis 00278 00291 extern "C" Isis::Projection *SimpleCylindricalPlugin(Isis::Pvl &lab, 00292 bool allowDefaults) { 00293 return new Isis::SimpleCylindrical(lab, allowDefaults); 00294 }