|
Isis 3.0 Application Source Code Reference |
Home |
00001 #if !defined(CamTools_h) 00002 #define CamTools_h 00003 /** 00004 * @file 00005 * $Revision: 1.10 $ 00006 * $Date: 2009/08/25 01:37:55 $ 00007 * 00008 * Unless noted otherwise, the portions of Isis written by the USGS are 00009 * public domain. See individual third-party library and package descriptions 00010 * for intellectual property information, user agreements, and related 00011 * information. 00012 * 00013 * Although Isis has been used by the USGS, no warranty, expressed or 00014 * implied, is made by the USGS as to the accuracy and functioning of such 00015 * software and related material nor shall the fact of distribution 00016 * constitute any such warranty, and no responsibility is assumed by the 00017 * USGS in connection therewith. 00018 * 00019 * For additional information, launch 00020 * $ISISROOT/doc//documents/Disclaimers/Disclaimers.html 00021 * in a browser or see the Privacy & Disclaimers page on the Isis website, 00022 * http://isis.astrogeology.usgs.gov, and the USGS privacy and disclaimers on 00023 * http://www.usgs.gov/privacy.html. 00024 */ 00025 00026 #include <string> 00027 #include <vector> 00028 #include <iostream> 00029 #include <iomanip> 00030 #include <sstream> 00031 00032 #include "Pvl.h" 00033 #include "PvlKeyword.h" 00034 #include "SpecialPixel.h" 00035 #include "ImagePolygon.h" 00036 #include "iException.h" 00037 00038 namespace Isis { 00039 00040 /** 00041 * @brief Checks value of key, produces appropriate value 00042 * 00043 * This function checks the value of the keyword for specialness 00044 * and will create the appropriate keyword if it is special. 00045 * 00046 * @param keyname Name of keyword to create 00047 * @param value Keyword value 00048 * @param unit Optional unit qualifer with value 00049 * 00050 * @return PvlKeyword Returns newly created keyword/value 00051 */ 00052 inline PvlKeyword ValidateKey(const std::string keyname, 00053 const double &value, 00054 const std::string &unit = "") { 00055 if (IsSpecial(value)) { 00056 return (PvlKeyword(keyname,"NULL")); 00057 } 00058 else { 00059 return (PvlKeyword(keyname,value,unit)); 00060 } 00061 } 00062 00063 /** 00064 * @brief Checks proper value of a NULLed keyword 00065 * 00066 * If the keyword is a NULL keyword, ensure it has proper value. 00067 * 00068 * @param keyname Name of keyword to create 00069 * @param key Keyword/value set 00070 * @param unit Optional unit qualifer with value 00071 * 00072 * @return PvlKeyword Returns newly created keyword/value 00073 */ 00074 00075 inline PvlKeyword ValidateKey(const std::string keyname, PvlKeyword &key, 00076 const std::string &unit = "") { 00077 if (key.IsNull()) { 00078 return (PvlKeyword(keyname,"NULL")); 00079 } 00080 else { 00081 return (ValidateKey(keyname,(double) key,unit)); 00082 } 00083 } 00084 00085 00086 /** Returns degree to radian conversion factor */ 00087 inline double DegToRad(const double ang) { return (ang * rpd_c()); } 00088 /** Returns radians to degrees conversion factor */ 00089 inline double RadToDeg(const double ang) { return (ang * dpr_c()); } 00090 00091 /** A very useful, typesafe way to delete pointers in STL container 00092 * Courtesy Scott Meyers, "Effective STL", Item 7, pg 37-40 */ 00093 struct DeleteObject { 00094 template <typename T> 00095 void operator()(const T* ptr) const { 00096 delete ptr; 00097 } 00098 }; 00099 00100 /** 00101 * @brief Collect Band geometry 00102 * 00103 * This produces the geometry and polygon information from an image cube. It 00104 * has some special processing that accounts for band independant geometrical 00105 * image cubes. It processes each band and creates unique geometry and 00106 * ploygon values consider this situation. The resulting polygon is a union 00107 * of all bands, which is a (usually) slightly better footprint of the acutal 00108 * footprint for the product. 00109 * 00110 * The other major advantage to this class is the corner latitude/longitude 00111 * points are based upon the extents of each independant band data as the 00112 * furthest point from the center of the polygon location (if requested by the 00113 * user). 00114 * 00115 * @ingroup Utility 00116 * @author 2008-09-10 Kris Becker 00117 * @history 2009-02-26 Kris Becker - Removed unconditional computation of 00118 * polygon even when the user did not request it. Reorganized some 00119 * keywords to their relevant group locations. 00120 * @history 2009-05-29 Kris Becker - Added _pixinx parameter 00121 * @history 2009-06-22 Kris Becker - Added hasLimb() method to check for the 00122 * presence of a planet limb; Added getProjGeometry() method. 00123 * @history 2009-08-04 Christopher Austin - fixed ImagePolygon::Create call for 00124 * the updated sampinc/lineinc implementation 00125 * @history 2009-08-12 Kris Becker - Modified so that images that include 00126 * poles are not converted to 180 domain when projected 00127 * @history 2009-08-24 Kris Becker - Added ability to disable use of shape 00128 * model when creating polygons that contains a limb 00129 */ 00130 class BandGeometry { 00131 00132 public: 00133 BandGeometry() : _nLines(0), _nSamps(0), _nBands(0), _pixinc(1), 00134 _radius(1.0), _isBandIndependent(true), 00135 _hasCenterGeom(false), _gBandList(), _polys(), 00136 _combined(0), _mapping() { } 00137 ~BandGeometry() { destruct(); } 00138 00139 void setPixInc(const int pixinc) { _pixinc = pixinc; } 00140 int getPixInc() const { return (_pixinc); } 00141 void setMaxIncidence(const double maxinc) { _maxIncidence = maxinc; } 00142 void setMaxEmission(const double maxema) { _maxEmission = maxema; } 00143 int size() const { return (_gBandList.size()); } 00144 bool isPointValid(const double &sample, const double &line, const Camera *camera = 0) const; 00145 bool isBandIndependent() const { return (_isBandIndependent); } 00146 bool hasCenterGeometry() const; 00147 bool hasLimb() const; 00148 void collect(Camera &camera, Cube &cube, bool doGeometry, bool doPolygon); 00149 void generateGeometryKeys(PvlObject &pband); 00150 void generatePolygonKeys(PvlObject &pband); 00151 00152 private: 00153 // Internal structure to contain geometric properties 00154 struct GProperties { 00155 GProperties() : lines(0), samples(0), bands(0), 00156 band(0), realBand(0), target(""), 00157 centerLine(0.0), centerSamp(0.0), 00158 centerLatitude(Null), centerLongitude(Null), radius(Null), 00159 rightAscension(Null), declination(Null), 00160 centroidLatitude(Null), centroidLongitude(Null), 00161 centroidLine(Null), centroidSample(Null), centroidRadius(Null), 00162 surfaceArea(Null), phase(Null), emi(Null), inc(Null), 00163 sampRes(Null), lineRes(Null), grRes(Null), 00164 solarLongitude(Null), northAzimuth(Null), offNader(Null), 00165 subSolarAzimuth(Null), subSolarGroundAzimuth(Null), 00166 subSpacecraftAzimuth(Null), subSpacecraftGroundAzimuth(Null), 00167 localSolartime (Null), targetCenterDistance(Null), slantDistance(Null), 00168 subSolarLatitude(Null), subSolarLongitude(Null), 00169 subSpacecraftLatitude(Null), subSpacecraftLongitude(Null), 00170 startTime(""), endTime(""), 00171 parallaxx(Null), parallaxy(Null), 00172 shadowx(Null), shadowy(Null), 00173 upperLeftLongitude(Null), upperLeftLatitude(Null), 00174 lowerLeftLongitude(Null), lowerLeftLatitude(Null), 00175 lowerRightLongitude(Null), lowerRightLatitude(Null), 00176 upperRightLongitude(Null),upperRightLatitude(Null), 00177 hasLongitudeBoundary(false), hasNorthPole(false), hasSouthPole(false) { } 00178 ~GProperties() { } 00179 00180 int lines, samples, bands; 00181 int band, realBand; 00182 std::string target; 00183 double centerLine, centerSamp; 00184 double centerLatitude, centerLongitude; 00185 double radius; 00186 double rightAscension, declination; 00187 double centroidLatitude, centroidLongitude; 00188 double centroidLine, centroidSample; 00189 double centroidRadius, surfaceArea; 00190 double phase, emi, inc; 00191 double sampRes, lineRes, grRes; 00192 double solarLongitude, northAzimuth, offNader; 00193 double subSolarAzimuth, subSolarGroundAzimuth; 00194 double subSpacecraftAzimuth, subSpacecraftGroundAzimuth; 00195 double localSolartime, targetCenterDistance, slantDistance; 00196 double subSolarLatitude, subSolarLongitude; 00197 double subSpacecraftLatitude, subSpacecraftLongitude; 00198 std::string startTime, endTime; 00199 double parallaxx, parallaxy, shadowx, shadowy; 00200 double upperLeftLongitude, upperLeftLatitude; 00201 double lowerLeftLongitude, lowerLeftLatitude; 00202 double lowerRightLongitude, lowerRightLatitude; 00203 double upperRightLongitude, upperRightLatitude; 00204 bool hasLongitudeBoundary, hasNorthPole, hasSouthPole; 00205 }; 00206 00207 typedef std::vector<GProperties> BandPropertiesList; 00208 typedef BandPropertiesList::iterator BandPropertiesListIter; 00209 typedef BandPropertiesList::const_iterator BandPropertiesListConstIter; 00210 00211 // Internal structure to contain geometric properties 00212 typedef std::vector<geos::geom::Geometry *> BandPolygonList; 00213 typedef BandPolygonList::iterator BandPolygonListIter; 00214 typedef BandPolygonList::const_iterator BandPolygonListConstIter; 00215 00216 00217 int _nLines; 00218 int _nSamps; 00219 int _nBands; 00220 int _pixinc; 00221 double _maxEmission; 00222 double _maxIncidence; 00223 double _radius; 00224 bool _isBandIndependent; 00225 bool _hasCenterGeom; 00226 BandPropertiesList _gBandList; 00227 BandPolygonList _polys; 00228 geos::geom::Geometry *_combined; 00229 GProperties _summary; 00230 Pvl _mapping; 00231 00232 void destruct(); 00233 GProperties getGeometrySummary() const; 00234 Pvl getProjGeometry(Camera &camera, geos::geom::MultiPolygon *footprint, 00235 GProperties &g); 00236 double getRadius() const; 00237 double getPixelResolution() const; 00238 double getPixelsPerDegree(double pixres, double radius) const; 00239 bool isDistShorter(double bestDist, double lat1, double lon1, 00240 double lat2, double lon2, double radius, 00241 double &thisDist) const; 00242 geos::geom::MultiPolygon *makeMultiPolygon(geos::geom::Geometry *g) const; 00243 00244 00245 }; 00246 00247 } // Namespace Isis 00248 00249 #endif