Isis 3 Programmer Reference
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 
302 
316  template <typename T>
317  PvlKeyword ParameterKey(const QString &keyname,
318  const T &value,
319  const QString &unit = "") const {
320  if(m_prof.exists(keyname)) {
321  return(ValidateKey(keyname, value, unit));
322  }
323  return (PvlKeyword(keyname, "Unbounded"));
324  };
325 
326 
339  inline PvlKeyword ValidateKey(const QString keyname,
340  const double &value,
341  const QString &unit = "") const {
342  if(IsSpecial(value)) {
343  return (PvlKeyword(keyname, "NULL"));
344  }
345  else {
346  return (PvlKeyword(keyname, toString(value), unit));
347  }
348  }
349 
350  ErrorList initErrorList() const;
351  int logError(int gerrno, const QString &gerrmsg);
352  PvlGroup StatsLog() const;
353  PvlGroup ParameterLog() const;
354 
355  void init(Pvl &pvl);
356 
358  inline Radiometric getDefaultRadio() const {
359  return (Radiometric(m_defShift, m_defGain));
360  }
361 
363  inline double DegreesOfFreedom(const int npts) const {
364  return ((double) (npts - NCONSTR));
365  }
366 
367  void resetStats();
368 
369  GMatrix Identity(const int &ndiag = 3) const;
370  GMatrix Choldc(const GMatrix &a, GVector &p) const;
371  GMatrix Cholsl(const GMatrix &a, const GVector &p,
372  const GMatrix &b, const GMatrix &x) const;
373  int Jacobi(const GMatrix &a, GVector &evals, GMatrix &evecs,
374  const int &MaxIters = 50) const;
375  void EigenSort(GVector &evals, GMatrix &evecs) const;
376  BigInt MinValidPoints(BigInt totalPoints) const;
377  bool ValidPoints(BigInt totalPoints, BigInt nPoints) const;
378 
379  int CheckConstraints(MatchPoint &point);
380  Coordinate getChipUpdate(Chip &sChip, MatchPoint &point) const;
382  };
383 
384 } // namespace Isis
385 #endif
bool ValidPoints(BigInt totalPoints, BigInt nPoints) const
Determines if number of points is valid percentage of all points.
Definition: Gruen.cpp:1071
long long int BigInt
Big int.
Definition: Constants.h:65
int Jacobi(const GMatrix &a, GVector &evals, GMatrix &evecs, const int &MaxIters=50) const
Compute the Jacobian of a covariance matrix.
Definition: Gruen.cpp:443
void setAffineRadio()
Set affine parameters to defaults.
Definition: Gruen.cpp:143
AutoReg::RegisterStatus Status(const MatchPoint &result)
Returns the proper status given a Gruen result container.
Definition: Gruen.cpp:1177
CollectorMap< int, ErrorCounter > ErrorList
Declaration of error count list.
Definition: Gruen.h:198
virtual AutoReg::RegisterStatus Registration(Chip &sChip, Chip &pChip, Chip &fChip, int startSamp, int startLine, int endSamp, int endLine, int bestSamp, int bestLine)
Applies the adaptive Gruen algorithm to pattern and search chips.
Definition: Gruen.cpp:696
Define a generic Y/X container.
Definition: GruenTypes.h:69
int count(const QString &key) const
Report number of values in keyword.
Definition: DbProfile.cpp:141
Store for radiometric gain and shift parameters.
Definition: GruenTypes.h:222
A small chip of data used for pattern matching.
Definition: Chip.h:102
virtual bool CompareFits(double fit1, double fit2)
This virtual method must return if the 1st fit is equal to or better than the second fit...
Definition: Gruen.cpp:652
BigInt CallCount() const
Returns the current call count.
Definition: Gruen.h:101
GMatrix Cholsl(const GMatrix &a, const GVector &p, const GMatrix &b, const GMatrix &x) const
Compute Cholesky solution matrix from correlation.
Definition: Gruen.cpp:399
ErrorTypes
Error enumeration values.
Definition: Gruen.h:173
PvlGroup StatsLog() const
Create a PvlGroup with the Gruen specific statistics.
Definition: Gruen.cpp:869
virtual double IdealFit() const
Returns the ideal fit for a perfect Gruen result.
Definition: Gruen.h:156
bool exists(const QString &key) const
Checks for the existance of a keyword.
Definition: DbProfile.h:129
virtual QString AlgorithmName() const
Returns the default name of the algorithm as Gruen.
Definition: Gruen.h:140
Analysis errorAnalysis(const BigInt &npts, const double &resid, const GMatrix &atai)
Compute the error analysis of convergent Gruen matrix.
Definition: Gruen.cpp:305
QString toString(bool boolToConvert)
Global function to convert a boolean to a string.
Definition: IString.cpp:226
int logError(int gerrno, const QString &gerrmsg)
Logs a Gruen error.
Definition: Gruen.cpp:964
int algorithm(Chip &pattern, Chip &subsearch, const Radiometric &radio, BigInt &ptsUsed, double &resid, GMatrix &atai, AffineRadio &affrad)
Real workhorse of the computational Gruen algorithm.
Definition: Gruen.cpp:172
A DbProfile is a container for access parameters to a database.
Definition: DbProfile.h:65
virtual Pvl AlgorithmStatistics(Pvl &pvl)
Create Gruen error and processing statistics Pvl output.
Definition: Gruen.cpp:840
double getSpiceConstraint() const
Returns the SPICE tolerance constraint as read from config file.
Definition: Gruen.h:108
Coordinate getChipUpdate(Chip &sChip, MatchPoint &point) const
Compute the chip coordinate of the registered pixel.
Definition: Gruen.cpp:1157
const AffineRadio & getAffineRadio() const
Return current state of Affine/Radio state.
Definition: Gruen.h:120
double DegreesOfFreedom(const int npts) const
Returns number of degrees of freedom of points.
Definition: Gruen.h:363
This class is used to accumulate statistics on double arrays.
Definition: Statistics.h:107
BigInt MinValidPoints(BigInt totalPoints) const
Computes the number of minimum valid points.
Definition: Gruen.cpp:1054
Gruen()
Default constructor.
Definition: Gruen.cpp:48
ErrorList initErrorList() const
Creates an error list from know Gruen errors.
Definition: Gruen.cpp:938
MatchPoint getLastMatch() const
Returns the register state of the last successful Gruen match.
Definition: Gruen.h:136
QString ConfKey(const DbProfile &conf, const QString &keyname, const QString &defval, int index=0) const
Helper method to initialize parameters.
Definition: Gruen.h:257
void EigenSort(GVector &evals, GMatrix &evecs) const
Sort eigenvectors from highest to lowest.
Definition: Gruen.cpp:572
PvlKeyword ParameterKey(const QString &keyname, const T &value, const QString &unit="") const
Keyword formatter for Gruen parameters.
Definition: Gruen.h:317
Contains multiple PvlContainers.
Definition: PvlGroup.h:57
QString value(const QString &key, int nth=0) const
Returns the specified value for the given keyword.
Definition: DbProfile.cpp:160
A single keyword-value pair.
Definition: PvlKeyword.h:98
void WriteSubsearchChips(const QString &pattern="SubChip")
Set up for writing subsearch for a a given registration call.
Definition: Gruen.cpp:108
bool IsSpecial(const double d)
Returns if the input pixel is special.
Definition: SpecialPixel.h:212
AffineTolerance getAffineTolerance() const
Return set of tolerances for affine convergence.
Definition: Gruen.cpp:1082
virtual double MatchAlgorithm(Chip &pattern, Chip &subsearch)
Minimization of data set using Gruen algorithm.
Definition: Gruen.cpp:624
PvlGroup ParameterLog() const
Create a PvlGroup with the Gruen specific parameters.
Definition: Gruen.cpp:906
Container for cube-like labels.
Definition: Pvl.h:135
Container for Affine limits parameters.
Definition: GruenTypes.h:335
Radiometric getDefaultRadio() const
Returns the default radiometric gain value.
Definition: Gruen.h:358
Container for affine and radiometric parameters.
Definition: GruenTypes.h:258
Auto Registration class.
Definition: AutoReg.h:183
int CheckConstraints(MatchPoint &point)
Test user limits/contraints after the algorithm has converged.
Definition: Gruen.cpp:1106
void init(Pvl &pvl)
Initialize the object.
Definition: Gruen.cpp:983
Structure containing comprehensive registration info/results.
Definition: GruenTypes.h:449
Gruen pattern matching algorithm.
Definition: Gruen.h:90
PvlKeyword ValidateKey(const QString keyname, const double &value, const QString &unit="") const
Checks value of key, produces appropriate value.
Definition: Gruen.h:339
void resetStats()
Reset Gruen statistics as needed.
Definition: Gruen.cpp:1034
RegisterStatus
Enumeration of the Register() method&#39;s return status.
Definition: AutoReg.h:195
T ConfKey(const DbProfile &conf, const QString &keyname, const T &defval, int index=0) const
Helper method to initialize parameters.
Definition: Gruen.h:288
Adds specific functionality to C++ strings.
Definition: IString.h:181
const AffineRadio & getDefaultAffineRadio() const
Returns default settings for Affine/Radiometric parameters.
Definition: Gruen.h:117
Namespace for ISIS/Bullet specific routines.
Definition: Apollo.h:31
Error analysis of Gruen match point solution.
Definition: GruenTypes.h:399
static Pvl & getDefaultParameters()
Load default Gruen parameter file in $ISIS3DATA/base/templates.
Definition: Gruen.cpp:819
GMatrix Choldc(const GMatrix &a, GVector &p) const
Compute Cholesky solution.
Definition: Gruen.cpp:357
double getAffineConstraint() const
Returns the Affine tolerance constraint as read from config file.
Definition: Gruen.h:111
Struct that maintains error counts.
Definition: Gruen.h:182
virtual ~Gruen()
Destructor.
Definition: Gruen.h:98