USGS

Isis 3.0 Object Programmers' Reference

Home

Gruen.h

Go to the documentation of this file.
00001 #ifndef Gruen_h
00002 #define Gruen_h
00003 
00027 #include "AutoReg.h"
00028 #include "tnt/tnt_array2d.h"
00029 #include "tnt/tnt_array1d.h"
00030 #include "Affine.h"
00031 #include "DbProfile.h"
00032 #include "GruenTypes.h"
00033 #include "CollectorMap.h"
00034 #include "Statistics.h"
00035 #include "Pvl.h"
00036 #include "PvlGroup.h"
00037 
00038 namespace Isis {
00039   class Chip;
00040 
00090   class Gruen : public AutoReg {
00091     public:
00092 
00094       Gruen();
00095       Gruen(Pvl &pvl);
00096 
00098       virtual ~Gruen() { }
00099 
00101       BigInt CallCount() const { return (m_callCount); }
00102 
00103       void WriteSubsearchChips(const QString &pattern = "SubChip");
00104 
00105       AffineTolerance getAffineTolerance() const;
00106 
00108       inline double getSpiceConstraint() const { return (m_spiceTol); }
00109 
00111       inline double getAffineConstraint() const { return (m_affineTol); }
00112 
00113       void setAffineRadio(const AffineRadio &affrad);
00114       void setAffineRadio();
00115 
00117       const AffineRadio &getDefaultAffineRadio() const { return (m_defAffine);}
00118 
00120       const AffineRadio &getAffineRadio() const { return (m_affine);  }
00121 
00136       MatchPoint getLastMatch() const { return (m_point);   }
00137 
00138     protected:
00140       virtual QString AlgorithmName() const {
00141         return ("Gruen");
00142       }
00143 
00144       int algorithm(Chip &pattern, Chip &subsearch, const Radiometric &radio, 
00145                     BigInt &ptsUsed, double &resid, GMatrix &atai, 
00146                     AffineRadio &affrad); 
00147 
00148       Analysis errorAnalysis(const BigInt &npts, const double &resid,
00149                              const GMatrix &atai);
00150 
00151       //  These methods are for AutoReg non-adaptive requirements
00152       virtual double MatchAlgorithm(Chip &pattern, Chip &subsearch);
00153       virtual bool CompareFits(double fit1, double fit2);
00154 
00156       virtual double IdealFit() const {  return (0.0); }
00157 
00158       // AutoReg adaptive method
00159       virtual AutoReg::RegisterStatus Registration(Chip &sChip,
00160           Chip &pChip,
00161           Chip &fChip,
00162           int startSamp,
00163           int startLine,
00164           int endSamp,
00165           int endLine,
00166           int bestSamp,
00167           int bestLine);
00168 
00169       virtual Pvl AlgorithmStatistics(Pvl &pvl);
00170 
00171     private:
00173       enum ErrorTypes {  NotEnoughPoints = 1, CholeskyFailed = 2,
00174                          EigenSolutionFailed = 3, AffineNotInvertable = 4,
00175                          MaxIterationsExceeded = 5, RadShiftExceeded = 6,
00176                          RadGainExceeded = 7, MaxEigenExceeded = 8,
00177                          AffineDistExceeded = 9
00178                        };
00179 
00180 
00182       struct ErrorCounter {
00183         ErrorCounter() : m_gerrno(0), m_keyname("Unknown"), m_count(0) { }
00184         ErrorCounter(int gerrno, const QString &keyname) : m_gerrno(gerrno),
00185           m_keyname(keyname), m_count(0) { }
00186     
00187         inline int  Errno() const {  return (m_gerrno); }
00188         inline BigInt Count() const { return (m_count); }
00189         inline void BumpIt() { m_count++; }
00190         PvlKeyword LogIt() const { return (PvlKeyword(m_keyname, toString(m_count))); }
00191     
00192         int         m_gerrno;
00193         QString m_keyname;
00194         BigInt      m_count;
00195       };
00196 
00198       typedef CollectorMap<int, ErrorCounter> ErrorList;
00199 
00200       // Iteration loop variables
00201       BigInt       m_callCount;
00202       QString  m_filePattern;
00203 
00204       ErrorList    m_errors;            // Error logger
00205       BigInt       m_unclassified;      // Unclassified errors
00206 
00207       // Tolerance and count parameters
00208       int          m_maxIters;          // Maximum iterations
00209       int          m_nIters;            // Number iterations
00210       BigInt       m_totalIterations;   // Running total iteration count
00211 
00212       DbProfile    m_prof;              //  Parameter profile
00213       double       m_transTol;          //  Affine translation tolerance
00214       double       m_scaleTol;          //  Affine scale tolerance
00215       double       m_shearTol;          //  Affine shear tolerance
00216       double       m_spiceTol;          // SPICE tolerance
00217       double       m_affineTol;         // Affine Tolerance
00218       
00219       double       m_shiftTol;          // Radiometric shift tolerance
00220       double       m_rgainMinTol;       // Radiometric Gain minimum
00221       double       m_rgainMaxTol;       // Radiometric Gain maximum
00222 
00223       double       m_defGain;           // Default Radiometric gain
00224       double       m_defShift;          // Default Radiometric shift
00225       
00226       // These are for recomputing SMTK points
00227       AffineRadio  m_defAffine;         // Default affine/radiometric settings
00228       AffineRadio  m_affine;            // Incoming affine setting
00229       MatchPoint   m_point;             // Last resuting registration result
00230 
00231       //  Statistics gathered during processing
00232       Statistics   m_eigenStat;
00233       Statistics   m_iterStat;
00234       Statistics   m_shiftStat;
00235       Statistics   m_gainStat;
00236 
00237 
00238       //  Static init of default PVL parameters
00239       static Pvl &getDefaultParameters();
00240 
00257       QString ConfKey(const DbProfile &conf, const QString &keyname,
00258                 const QString &defval, int index = 0) const {
00259         if(!conf.exists(keyname)) {
00260           return (defval);
00261         }
00262         if(conf.count(keyname) < index) {
00263           return (defval);
00264         }
00265         QString iValue(conf.value(keyname, index));
00266         IString tmp(iValue);
00267         QString value = tmp.ToQt();  // This makes it work with a string?
00268         return (value);
00269       };
00270 
00287       template <typename T>
00288       T ConfKey(const DbProfile &conf, const QString &keyname,
00289                 const T &defval, int index = 0) const {
00290         if(!conf.exists(keyname)) {
00291           return (defval);
00292         }
00293         if(conf.count(keyname) < index) {
00294           return (defval);
00295         }
00296         QString iValue(conf.value(keyname, index));
00297         IString tmp(iValue);
00298         T value = tmp;  // This makes it work with a string?
00299         return (value);
00300       };
00301 
00315       template <typename T>
00316       PvlKeyword ParameterKey(const QString &keyname,
00317                               const T &value,
00318                               const QString &unit = "") const {
00319         if(m_prof.exists(keyname)) {
00320           return(ValidateKey(keyname, value, unit));
00321         }
00322         return (PvlKeyword(keyname, "Unbounded"));
00323       };
00324 
00325 
00338       inline PvlKeyword ValidateKey(const QString keyname,
00339                                     const double &value,
00340                                     const QString &unit = "") const {
00341         if(IsSpecial(value)) {
00342           return (PvlKeyword(keyname, "NULL"));
00343         }
00344         else {
00345           return (PvlKeyword(keyname, toString(value), unit));
00346         }
00347       }
00348 
00349       ErrorList initErrorList() const;
00350       int logError(int gerrno, const QString &gerrmsg);
00351       PvlGroup StatsLog() const;
00352       PvlGroup ParameterLog() const;
00353 
00354       void init(Pvl &pvl);
00355 
00357       inline Radiometric getDefaultRadio() const {
00358         return (Radiometric(m_defShift, m_defGain));
00359       }
00360 
00362       inline double DegreesOfFreedom(const int npts) const {
00363         return ((double) (npts - NCONSTR));
00364       }
00365 
00366       void resetStats();
00367 
00368       GMatrix Identity(const int &ndiag = 3) const;
00369       GMatrix Choldc(const GMatrix &a, GVector &p) const;
00370       GMatrix Cholsl(const GMatrix &a, const GVector &p, 
00371                      const GMatrix &b, const GMatrix &x) const;
00372       int Jacobi(const GMatrix &a, GVector &evals, GMatrix &evecs,
00373                   const int &MaxIters = 50) const;
00374       void EigenSort(GVector &evals, GMatrix &evecs) const;
00375       BigInt MinValidPoints(BigInt totalPoints) const;
00376       bool ValidPoints(BigInt totalPoints, BigInt nPoints) const;
00377  
00378       int CheckConstraints(MatchPoint &point);
00379       Coordinate getChipUpdate(Chip &sChip, MatchPoint &point) const;
00380       AutoReg::RegisterStatus Status(const MatchPoint &result);
00381   };
00382 
00383 }  // namespace Isis
00384 #endif