|
Isis 3.0 Application Source Code Reference |
Home |
00001 #ifndef 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 QString keyname, 00053 const double &value, 00054 const QString &unit = "") { 00055 if(IsSpecial(value)) { 00056 return (PvlKeyword(keyname, "NULL")); 00057 } 00058 else { 00059 return (PvlKeyword(keyname, toString(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 QString keyname, PvlKeyword &key, 00076 const QString &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) { 00088 return (ang * rpd_c()); 00089 } 00090 /** Returns radians to degrees conversion factor */ 00091 inline double RadToDeg(const double ang) { 00092 return (ang * dpr_c()); 00093 } 00094 00095 /** A very useful, typesafe way to delete pointers in STL container 00096 * Courtesy Scott Meyers, "Effective STL", Item 7, pg 37-40 */ 00097 struct DeleteObject { 00098 template <typename T> 00099 void operator()(const T *ptr) const { 00100 delete ptr; 00101 } 00102 }; 00103 00104 /** 00105 * @brief Collect Band geometry 00106 * 00107 * This produces the geometry and polygon information from an image cube. It 00108 * has some special processing that accounts for band independant geometrical 00109 * image cubes. It processes each band and creates unique geometry and 00110 * ploygon values consider this situation. The resulting polygon is a union 00111 * of all bands, which is a (usually) slightly better footprint of the acutal 00112 * footprint for the product. 00113 * 00114 * The other major advantage to this class is the corner latitude/longitude 00115 * points are based upon the extents of each independant band data as the 00116 * furthest point from the center of the polygon location (if requested by the 00117 * user). 00118 * 00119 * @ingroup Utility 00120 * @author 2008-09-10 Kris Becker 00121 * 00122 * @internal 00123 * @history 2009-02-26 Kris Becker - Removed unconditional computation of 00124 * polygon even when the user did not request it. 00125 * Reorganized some keywords to their relevant group 00126 * locations. 00127 * @history 2009-05-29 Kris Becker - Added _pixinx parameter 00128 * @history 2009-06-22 Kris Becker - Added hasLimb() method to check for the 00129 * presence of a planet limb; Added 00130 * getProjGeometry() method. 00131 * @history 2009-08-04 Christopher Austin - fixed ImagePolygon::Create call 00132 * for the updated sampinc/lineinc implementation 00133 * @history 2009-08-12 Kris Becker - Modified so that images that include 00134 * poles are not converted to 180 domain when 00135 * projected 00136 * @history 2009-08-24 Kris Becker - Added ability to disable use of shape 00137 * model when creating polygons that contains a limb 00138 * @history 2011-02-17 Jai Rideout - Replaced pixinc with sinc and linc. 00139 * @history 2012-07-06 Debbie A. Cook, Updated Spice members to be more compliant with Isis 00140 * coding standards. References #972. 00141 * @history 2012-10-11 Debbie A. Cook, Updated to use new Target class. References Mantis 00142 * tickets #775 and #1114. 00143 * @history 2012-11-23 Kris Becker Corrected computations for parallaxx, 00144 * parallaxy, shadowx, shadowy. Fixes #1296 00145 * @history 2013-02-22 Janet Barrett, Modified the CamTools::collect method to allow a 00146 * footprint blob option. Fixes #1452. 00147 */ 00148 class BandGeometry { 00149 00150 public: 00151 BandGeometry() : _nLines(0), _nSamps(0), _nBands(0), _sampleInc(1), 00152 _lineInc(1), _radius(1.0), _isBandIndependent(true), 00153 _hasCenterGeom(false), _gBandList(), _polys(), 00154 _combined(0), _mapping() { } 00155 ~BandGeometry() { 00156 destruct(); 00157 } 00158 00159 void setSampleInc(const int sampleInc) { 00160 _sampleInc = sampleInc; 00161 } 00162 void setLineInc(const int lineInc) { 00163 _lineInc = lineInc; 00164 } 00165 int getSampleInc() const { 00166 return (_sampleInc); 00167 } 00168 int getLineInc() const { 00169 return (_lineInc); 00170 } 00171 void setMaxIncidence(const double maxinc) { 00172 _maxIncidence = maxinc; 00173 } 00174 void setMaxEmission(const double maxema) { 00175 _maxEmission = maxema; 00176 } 00177 int size() const { 00178 return (_gBandList.size()); 00179 } 00180 bool isPointValid(const double &sample, const double &line, const Camera *camera = 0) const; 00181 bool isBandIndependent() const { 00182 return (_isBandIndependent); 00183 } 00184 bool hasCenterGeometry() const; 00185 bool hasLimb() const; 00186 void collect(Camera &camera, Cube &cube, bool doGeometry, bool doPolygon, 00187 bool getFootBlob, bool increasePrecision); 00188 void generateGeometryKeys(PvlObject &pband); 00189 void generatePolygonKeys(PvlObject &pband); 00190 00191 private: 00192 // Internal structure to contain geometric properties 00193 struct GProperties { 00194 GProperties() : lines(0), samples(0), bands(0), 00195 band(0), realBand(0), target(""), 00196 centerLine(0.0), centerSamp(0.0), 00197 centerLatitude(Null), centerLongitude(Null), radius(Null), 00198 rightAscension(Null), declination(Null), 00199 centroidLatitude(Null), centroidLongitude(Null), 00200 centroidLine(Null), centroidSample(Null), centroidRadius(Null), 00201 surfaceArea(Null), phase(Null), emi(Null), inc(Null), 00202 sampRes(Null), lineRes(Null), grRes(Null), 00203 solarLongitude(Null), northAzimuth(Null), offNader(Null), 00204 subSolarAzimuth(Null), subSolarGroundAzimuth(Null), 00205 subSpacecraftAzimuth(Null), subSpacecraftGroundAzimuth(Null), 00206 localSolartime(Null), targetCenterDistance(Null), slantDistance(Null), 00207 subSolarLatitude(Null), subSolarLongitude(Null), 00208 subSpacecraftLatitude(Null), subSpacecraftLongitude(Null), 00209 startTime(""), endTime(""), 00210 parallaxx(Null), parallaxy(Null), 00211 shadowx(Null), shadowy(Null), 00212 upperLeftLongitude(Null), upperLeftLatitude(Null), 00213 lowerLeftLongitude(Null), lowerLeftLatitude(Null), 00214 lowerRightLongitude(Null), lowerRightLatitude(Null), 00215 upperRightLongitude(Null), upperRightLatitude(Null), 00216 hasLongitudeBoundary(false), hasNorthPole(false), hasSouthPole(false) { } 00217 ~GProperties() { } 00218 00219 int lines, samples, bands; 00220 int band, realBand; 00221 QString target; 00222 double centerLine, centerSamp; 00223 double centerLatitude, centerLongitude; 00224 double radius; 00225 double rightAscension, declination; 00226 double centroidLatitude, centroidLongitude; 00227 double centroidLine, centroidSample; 00228 double centroidRadius, surfaceArea; 00229 double phase, emi, inc; 00230 double sampRes, lineRes, grRes; 00231 double solarLongitude, northAzimuth, offNader; 00232 double subSolarAzimuth, subSolarGroundAzimuth; 00233 double subSpacecraftAzimuth, subSpacecraftGroundAzimuth; 00234 double localSolartime, targetCenterDistance, slantDistance; 00235 double subSolarLatitude, subSolarLongitude; 00236 double subSpacecraftLatitude, subSpacecraftLongitude; 00237 QString startTime, endTime; 00238 double parallaxx, parallaxy, shadowx, shadowy; 00239 double upperLeftLongitude, upperLeftLatitude; 00240 double lowerLeftLongitude, lowerLeftLatitude; 00241 double lowerRightLongitude, lowerRightLatitude; 00242 double upperRightLongitude, upperRightLatitude; 00243 bool hasLongitudeBoundary, hasNorthPole, hasSouthPole; 00244 }; 00245 00246 typedef std::vector<GProperties> BandPropertiesList; 00247 typedef BandPropertiesList::iterator BandPropertiesListIter; 00248 typedef BandPropertiesList::const_iterator BandPropertiesListConstIter; 00249 00250 // Internal structure to contain geometric properties 00251 typedef std::vector<geos::geom::Geometry *> BandPolygonList; 00252 typedef BandPolygonList::iterator BandPolygonListIter; 00253 typedef BandPolygonList::const_iterator BandPolygonListConstIter; 00254 00255 00256 int _nLines; 00257 int _nSamps; 00258 int _nBands; 00259 int _sampleInc; 00260 int _lineInc; 00261 double _maxEmission; 00262 double _maxIncidence; 00263 double _radius; 00264 bool _isBandIndependent; 00265 bool _hasCenterGeom; 00266 BandPropertiesList _gBandList; 00267 BandPolygonList _polys; 00268 geos::geom::Geometry *_combined; 00269 GProperties _summary; 00270 Pvl _mapping; 00271 00272 void destruct(); 00273 GProperties getGeometrySummary() const; 00274 Pvl getProjGeometry(Camera &camera, geos::geom::MultiPolygon *footprint, 00275 GProperties &g); 00276 double getRadius() const; 00277 double getPixelResolution() const; 00278 double getPixelsPerDegree(double pixres, double radius) const; 00279 bool isDistShorter(double bestDist, double lat1, double lon1, 00280 double lat2, double lon2, double radius, 00281 double &thisDist) const; 00282 geos::geom::MultiPolygon *makeMultiPolygon(geos::geom::Geometry *g) const; 00283 00284 00285 }; 00286 00287 } // Namespace Isis 00288 00289 #endif