USGS

Isis 3.0 Object Programmers' Reference

Home

Gruen.h
Go to the documentation of this file.
1 #ifndef Gruen_h
2 #define Gruen_h
3 
27 #include "AutoReg.h"
28 #include "tnt/tnt_array2d.h"
29 #include "tnt/tnt_array1d.h"
30 #include "Affine.h"
31 #include "DbProfile.h"
32 #include "GruenTypes.h"
33 #include "CollectorMap.h"
34 #include "Statistics.h"
35 #include "Pvl.h"
36 #include "PvlGroup.h"
37 
38 namespace Isis {
39  class Chip;
40 
90  class Gruen : public AutoReg {
91  public:
92 
94  Gruen();
95  Gruen(Pvl &pvl);
96 
98  virtual ~Gruen() { }
99 
101  BigInt CallCount() const { return (m_callCount); }
102 
103  void WriteSubsearchChips(const QString &pattern = "SubChip");
104 
106 
108  inline double getSpiceConstraint() const { return (m_spiceTol); }
109 
111  inline double getAffineConstraint() const { return (m_affineTol); }
112 
113  void setAffineRadio(const AffineRadio &affrad);
114  void setAffineRadio();
115 
117  const AffineRadio &getDefaultAffineRadio() const { return (m_defAffine);}
118 
120  const AffineRadio &getAffineRadio() const { return (m_affine); }
121 
136  MatchPoint getLastMatch() const { return (m_point); }
137 
138  protected:
140  virtual QString AlgorithmName() const {
141  return ("Gruen");
142  }
143 
144  int algorithm(Chip &pattern, Chip &subsearch, const Radiometric &radio,
145  BigInt &ptsUsed, double &resid, GMatrix &atai,
146  AffineRadio &affrad);
147 
148  Analysis errorAnalysis(const BigInt &npts, const double &resid,
149  const GMatrix &atai);
150 
151  // These methods are for AutoReg non-adaptive requirements
152  virtual double MatchAlgorithm(Chip &pattern, Chip &subsearch);
153  virtual bool CompareFits(double fit1, double fit2);
154 
156  virtual double IdealFit() const { return (0.0); }
157 
158  // AutoReg adaptive method
160  Chip &pChip,
161  Chip &fChip,
162  int startSamp,
163  int startLine,
164  int endSamp,
165  int endLine,
166  int bestSamp,
167  int bestLine);
168 
169  virtual Pvl AlgorithmStatistics(Pvl &pvl);
170 
171  private:
173  enum ErrorTypes { NotEnoughPoints = 1, CholeskyFailed = 2,
174  EigenSolutionFailed = 3, AffineNotInvertable = 4,
175  MaxIterationsExceeded = 5, RadShiftExceeded = 6,
176  RadGainExceeded = 7, MaxEigenExceeded = 8,
177  AffineDistExceeded = 9
178  };
179 
180 
182  struct ErrorCounter {
183  ErrorCounter() : m_gerrno(0), m_keyname("Unknown"), m_count(0) { }
184  ErrorCounter(int gerrno, const QString &keyname) : m_gerrno(gerrno),
185  m_keyname(keyname), m_count(0) { }
186 
187  inline int Errno() const { return (m_gerrno); }
188  inline BigInt Count() const { return (m_count); }
189  inline void BumpIt() { m_count++; }
190  PvlKeyword LogIt() const { return (PvlKeyword(m_keyname, toString(m_count))); }
191 
192  int m_gerrno;
193  QString m_keyname;
194  BigInt m_count;
195  };
196 
199 
200  // Iteration loop variables
201  BigInt m_callCount;
202  QString m_filePattern;
203 
204  ErrorList m_errors; // Error logger
205  BigInt m_unclassified; // Unclassified errors
206 
207  // Tolerance and count parameters
208  int m_maxIters; // Maximum iterations
209  int m_nIters; // Number iterations
210  BigInt m_totalIterations; // Running total iteration count
211 
212  DbProfile m_prof; // Parameter profile
213  double m_transTol; // Affine translation tolerance
214  double m_scaleTol; // Affine scale tolerance
215  double m_shearTol; // Affine shear tolerance
216  double m_spiceTol; // SPICE tolerance
217  double m_affineTol; // Affine Tolerance
218 
219  double m_shiftTol; // Radiometric shift tolerance
220  double m_rgainMinTol; // Radiometric Gain minimum
221  double m_rgainMaxTol; // Radiometric Gain maximum
222 
223  double m_defGain; // Default Radiometric gain
224  double m_defShift; // Default Radiometric shift
225 
226  // These are for recomputing SMTK points
227  AffineRadio m_defAffine; // Default affine/radiometric settings
228  AffineRadio m_affine; // Incoming affine setting
229  MatchPoint m_point; // Last resuting registration result
230 
231  // Statistics gathered during processing
232  Statistics m_eigenStat;
233  Statistics m_iterStat;
234  Statistics m_shiftStat;
235  Statistics m_gainStat;
236 
237 
238  // Static init of default PVL parameters
239  static Pvl &getDefaultParameters();
240 
257  QString ConfKey(const DbProfile &conf, const QString &keyname,
258  const QString &defval, int index = 0) const {
259  if(!conf.exists(keyname)) {
260  return (defval);
261  }
262  if(conf.count(keyname) < index) {
263  return (defval);
264  }
265  QString iValue(conf.value(keyname, index));
266  IString tmp(iValue);
267  QString value = tmp.ToQt(); // This makes it work with a string?
268  return (value);
269  };
270 
287  template <typename T>
288  T ConfKey(const DbProfile &conf, const QString &keyname,
289  const T &defval, int index = 0) const {
290  if(!conf.exists(keyname)) {
291  return (defval);
292  }
293  if(conf.count(keyname) < index) {
294  return (defval);
295  }
296  QString iValue(conf.value(keyname, index));
297  IString tmp(iValue);
298  T value = tmp; // This makes it work with a string?
299  return (value);
300  };
301 
315  template <typename T>
316  PvlKeyword ParameterKey(const QString &keyname,
317  const T &value,
318  const QString &unit = "") const {
319  if(m_prof.exists(keyname)) {
320  return(ValidateKey(keyname, value, unit));
321  }
322  return (PvlKeyword(keyname, "Unbounded"));
323  };
324 
325 
338  inline PvlKeyword ValidateKey(const QString keyname,
339  const double &value,
340  const QString &unit = "") const {
341  if(IsSpecial(value)) {
342  return (PvlKeyword(keyname, "NULL"));
343  }
344  else {
345  return (PvlKeyword(keyname, toString(value), unit));
346  }
347  }
348 
349  ErrorList initErrorList() const;
350  int logError(int gerrno, const QString &gerrmsg);
351  PvlGroup StatsLog() const;
352  PvlGroup ParameterLog() const;
353 
354  void init(Pvl &pvl);
355 
357  inline Radiometric getDefaultRadio() const {
358  return (Radiometric(m_defShift, m_defGain));
359  }
360 
362  inline double DegreesOfFreedom(const int npts) const {
363  return ((double) (npts - NCONSTR));
364  }
365 
366  void resetStats();
367 
368  GMatrix Identity(const int &ndiag = 3) const;
369  GMatrix Choldc(const GMatrix &a, GVector &p) const;
370  GMatrix Cholsl(const GMatrix &a, const GVector &p,
371  const GMatrix &b, const GMatrix &x) const;
372  int Jacobi(const GMatrix &a, GVector &evals, GMatrix &evecs,
373  const int &MaxIters = 50) const;
374  void EigenSort(GVector &evals, GMatrix &evecs) const;
375  BigInt MinValidPoints(BigInt totalPoints) const;
376  bool ValidPoints(BigInt totalPoints, BigInt nPoints) const;
377 
378  int CheckConstraints(MatchPoint &point);
379  Coordinate getChipUpdate(Chip &sChip, MatchPoint &point) const;
381  };
382 
383 } // namespace Isis
384 #endif