Isis 3 Developer 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 
198  typedef CollectorMap<int, ErrorCounter> ErrorList;
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;
381  AutoReg::RegisterStatus Status(const MatchPoint &result);
382  };
383 
384 } // namespace Isis
385 #endif
long long int BigInt
Big int.
Definition: Constants.h:65
void setAffineRadio()
Set affine parameters to defaults.
Definition: Gruen.cpp:143
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
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
Affine::AMatrix GMatrix
Definition: GruenTypes.h:45
Definition: GruenTypes.h:49
virtual double IdealFit() const
Returns the ideal fit for a perfect Gruen result.
Definition: Gruen.h:156
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 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
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
const AffineRadio & getAffineRadio() const
Return current state of Affine/Radio state.
Definition: Gruen.h:120
Gruen()
Default constructor.
Definition: Gruen.cpp:48
MatchPoint getLastMatch() const
Returns the register state of the last successful Gruen match.
Definition: Gruen.h:136
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
Container for cube-like labels.
Definition: Pvl.h:135
Container for Affine limits parameters.
Definition: GruenTypes.h:335
Container for affine and radiometric parameters.
Definition: GruenTypes.h:258
Auto Registration class.
Definition: AutoReg.h:183
Structure containing comprehensive registration info/results.
Definition: GruenTypes.h:449
Gruen pattern matching algorithm.
Definition: Gruen.h:90
TNT::Array1D< double > GVector
Definition: GruenTypes.h:46
RegisterStatus
Enumeration of the Register() method&#39;s return status.
Definition: AutoReg.h:195
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
double getAffineConstraint() const
Returns the Affine tolerance constraint as read from config file.
Definition: Gruen.h:111
virtual ~Gruen()
Destructor.
Definition: Gruen.h:98