Isis 3 Programmer Reference
Gruen.h
1 #ifndef Gruen_h
2 #define Gruen_h
3 
8 /* SPDX-License-Identifier: CC0-1.0 */
9 
10 
11 #include "AutoReg.h"
12 #include "tnt/tnt_array2d.h"
13 #include "tnt/tnt_array1d.h"
14 #include "Affine.h"
15 #include "DbProfile.h"
16 #include "GruenTypes.h"
17 #include "CollectorMap.h"
18 #include "Statistics.h"
19 #include "Pvl.h"
20 #include "PvlGroup.h"
21 
22 namespace Isis {
23  class Chip;
24 
74  class Gruen : public AutoReg {
75  public:
76 
78  Gruen();
79  Gruen(Pvl &pvl);
80 
82  virtual ~Gruen() { }
83 
85  BigInt CallCount() const { return (m_callCount); }
86 
87  void WriteSubsearchChips(const QString &pattern = "SubChip");
88 
90 
92  inline double getSpiceConstraint() const { return (m_spiceTol); }
93 
95  inline double getAffineConstraint() const { return (m_affineTol); }
96 
97  void setAffineRadio(const AffineRadio &affrad);
98  void setAffineRadio();
99 
101  const AffineRadio &getDefaultAffineRadio() const { return (m_defAffine);}
102 
104  const AffineRadio &getAffineRadio() const { return (m_affine); }
105 
120  MatchPoint getLastMatch() const { return (m_point); }
121 
122  protected:
124  virtual QString AlgorithmName() const {
125  return ("Gruen");
126  }
127 
128  int algorithm(Chip &pattern, Chip &subsearch, const Radiometric &radio,
129  BigInt &ptsUsed, double &resid, GMatrix &atai,
130  AffineRadio &affrad);
131 
132  Analysis errorAnalysis(const BigInt &npts, const double &resid,
133  const GMatrix &atai);
134 
135  // These methods are for AutoReg non-adaptive requirements
136  virtual double MatchAlgorithm(Chip &pattern, Chip &subsearch);
137  virtual bool CompareFits(double fit1, double fit2);
138 
140  virtual double IdealFit() const { return (0.0); }
141 
142  // AutoReg adaptive method
144  Chip &pChip,
145  Chip &fChip,
146  int startSamp,
147  int startLine,
148  int endSamp,
149  int endLine,
150  int bestSamp,
151  int bestLine);
152 
153  virtual Pvl AlgorithmStatistics(Pvl &pvl);
154 
155  private:
157  enum ErrorTypes { NotEnoughPoints = 1, CholeskyFailed = 2,
158  EigenSolutionFailed = 3, AffineNotInvertable = 4,
159  MaxIterationsExceeded = 5, RadShiftExceeded = 6,
160  RadGainExceeded = 7, MaxEigenExceeded = 8,
161  AffineDistExceeded = 9
162  };
163 
164 
166  struct ErrorCounter {
167  ErrorCounter() : m_gerrno(0), m_keyname("Unknown"), m_count(0) { }
168  ErrorCounter(int gerrno, const QString &keyname) : m_gerrno(gerrno),
169  m_keyname(keyname), m_count(0) { }
170 
171  inline int Errno() const { return (m_gerrno); }
172  inline BigInt Count() const { return (m_count); }
173  inline void BumpIt() { m_count++; }
174  PvlKeyword LogIt() const { return (PvlKeyword(m_keyname, toString(m_count))); }
175 
176  int m_gerrno;
177  QString m_keyname;
178  BigInt m_count;
179  };
180 
183 
184  // Iteration loop variables
185  BigInt m_callCount;
186  QString m_filePattern;
187 
188  ErrorList m_errors; // Error logger
189  BigInt m_unclassified; // Unclassified errors
190 
191  // Tolerance and count parameters
192  int m_maxIters; // Maximum iterations
193  int m_nIters; // Number iterations
194  BigInt m_totalIterations; // Running total iteration count
195 
196  DbProfile m_prof; // Parameter profile
197  double m_transTol; // Affine translation tolerance
198  double m_scaleTol; // Affine scale tolerance
199  double m_shearTol; // Affine shear tolerance
200  double m_spiceTol; // SPICE tolerance
201  double m_affineTol; // Affine Tolerance
202 
203  double m_shiftTol; // Radiometric shift tolerance
204  double m_rgainMinTol; // Radiometric Gain minimum
205  double m_rgainMaxTol; // Radiometric Gain maximum
206 
207  double m_defGain; // Default Radiometric gain
208  double m_defShift; // Default Radiometric shift
209 
210  // These are for recomputing SMTK points
211  AffineRadio m_defAffine; // Default affine/radiometric settings
212  AffineRadio m_affine; // Incoming affine setting
213  MatchPoint m_point; // Last resuting registration result
214 
215  // Statistics gathered during processing
216  Statistics m_eigenStat;
217  Statistics m_iterStat;
218  Statistics m_shiftStat;
219  Statistics m_gainStat;
220 
221 
222  // Static init of default PVL parameters
223  static Pvl &getDefaultParameters();
224 
241  QString ConfKey(const DbProfile &conf, const QString &keyname,
242  const QString &defval, int index = 0) const {
243  if(!conf.exists(keyname)) {
244  return (defval);
245  }
246  if(conf.count(keyname) < index) {
247  return (defval);
248  }
249  QString iValue(conf.value(keyname, index));
250  IString tmp(iValue);
251  QString value = tmp.ToQt(); // This makes it work with a string?
252  return (value);
253  };
254 
271  template <typename T>
272  T ConfKey(const DbProfile &conf, const QString &keyname,
273  const T &defval, int index = 0) const {
274  if(!conf.exists(keyname)) {
275  return (defval);
276  }
277  if(conf.count(keyname) < index) {
278  return (defval);
279  }
280  QString iValue(conf.value(keyname, index));
281  IString tmp(iValue);
282  T value = tmp; // This makes it work with a string?
283  return (value);
284  };
285 
286 
300  template <typename T>
301  PvlKeyword ParameterKey(const QString &keyname,
302  const T &value,
303  const QString &unit = "") const {
304  if(m_prof.exists(keyname)) {
305  return(ValidateKey(keyname, value, unit));
306  }
307  return (PvlKeyword(keyname, "Unbounded"));
308  };
309 
310 
323  inline PvlKeyword ValidateKey(const QString keyname,
324  const double &value,
325  const QString &unit = "") const {
326  if(IsSpecial(value)) {
327  return (PvlKeyword(keyname, "NULL"));
328  }
329  else {
330  return (PvlKeyword(keyname, toString(value), unit));
331  }
332  }
333 
334  ErrorList initErrorList() const;
335  int logError(int gerrno, const QString &gerrmsg);
336  PvlGroup StatsLog() const;
337  PvlGroup ParameterLog() const;
338 
339  void init(Pvl &pvl);
340 
342  inline Radiometric getDefaultRadio() const {
343  return (Radiometric(m_defShift, m_defGain));
344  }
345 
347  inline double DegreesOfFreedom(const int npts) const {
348  return ((double) (npts - NCONSTR));
349  }
350 
351  void resetStats();
352 
353  GMatrix Identity(const int &ndiag = 3) const;
354  GMatrix Choldc(const GMatrix &a, GVector &p) const;
355  GMatrix Cholsl(const GMatrix &a, const GVector &p,
356  const GMatrix &b, const GMatrix &x) const;
357  int Jacobi(const GMatrix &a, GVector &evals, GMatrix &evecs,
358  const int &MaxIters = 50) const;
359  void EigenSort(GVector &evals, GMatrix &evecs) const;
360  BigInt MinValidPoints(BigInt totalPoints) const;
361  bool ValidPoints(BigInt totalPoints, BigInt nPoints) const;
362 
363  int CheckConstraints(MatchPoint &point);
364  Coordinate getChipUpdate(Chip &sChip, MatchPoint &point) const;
366  };
367 
368 } // namespace Isis
369 #endif
Isis::Gruen::Choldc
GMatrix Choldc(const GMatrix &a, GVector &p) const
Compute Cholesky solution.
Definition: Gruen.cpp:341
Isis::Gruen::getAffineConstraint
double getAffineConstraint() const
Returns the Affine tolerance constraint as read from config file.
Definition: Gruen.h:95
Isis::Gruen::ParameterKey
PvlKeyword ParameterKey(const QString &keyname, const T &value, const QString &unit="") const
Keyword formatter for Gruen parameters.
Definition: Gruen.h:301
Isis::Statistics
This class is used to accumulate statistics on double arrays.
Definition: Statistics.h:94
Isis::Gruen::MatchAlgorithm
virtual double MatchAlgorithm(Chip &pattern, Chip &subsearch)
Minimization of data set using Gruen algorithm.
Definition: Gruen.cpp:608
Isis::Gruen::WriteSubsearchChips
void WriteSubsearchChips(const QString &pattern="SubChip")
Set up for writing subsearch for a a given registration call.
Definition: Gruen.cpp:92
Isis::Radiometric
Store for radiometric gain and shift parameters.
Definition: GruenTypes.h:206
Isis::Gruen::Gruen
Gruen()
Default constructor.
Definition: Gruen.cpp:32
Isis::DbProfile::exists
bool exists(const QString &key) const
Checks for the existance of a keyword.
Definition: DbProfile.h:115
Isis::PvlKeyword
A single keyword-value pair.
Definition: PvlKeyword.h:82
Isis::Gruen::AlgorithmStatistics
virtual Pvl AlgorithmStatistics(Pvl &pvl)
Create Gruen error and processing statistics Pvl output.
Definition: Gruen.cpp:824
Isis::Gruen::ConfKey
T ConfKey(const DbProfile &conf, const QString &keyname, const T &defval, int index=0) const
Helper method to initialize parameters.
Definition: Gruen.h:272
Isis::Gruen::CompareFits
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:636
Isis::Gruen::getAffineRadio
const AffineRadio & getAffineRadio() const
Return current state of Affine/Radio state
Definition: Gruen.h:104
Isis::Gruen::getDefaultRadio
Radiometric getDefaultRadio() const
Returns the default radiometric gain value.
Definition: Gruen.h:342
Isis::Gruen::ErrorTypes
ErrorTypes
Error enumeration values.
Definition: Gruen.h:157
Isis::Gruen::resetStats
void resetStats()
Reset Gruen statistics as needed.
Definition: Gruen.cpp:1018
Isis::Gruen::ConfKey
QString ConfKey(const DbProfile &conf, const QString &keyname, const QString &defval, int index=0) const
Helper method to initialize parameters.
Definition: Gruen.h:241
Isis::DbProfile::count
int count(const QString &key) const
Report number of values in keyword.
Definition: DbProfile.cpp:127
Isis::Gruen::getAffineTolerance
AffineTolerance getAffineTolerance() const
Return set of tolerances for affine convergence.
Definition: Gruen.cpp:1066
Isis::Gruen::ValidateKey
PvlKeyword ValidateKey(const QString keyname, const double &value, const QString &unit="") const
Checks value of key, produces appropriate value.
Definition: Gruen.h:323
Isis::Gruen::init
void init(Pvl &pvl)
Initialize the object.
Definition: Gruen.cpp:967
Isis::AffineRadio
Container for affine and radiometric parameters.
Definition: GruenTypes.h:242
Isis::Gruen::logError
int logError(int gerrno, const QString &gerrmsg)
Logs a Gruen error.
Definition: Gruen.cpp:948
Isis::Gruen::CallCount
BigInt CallCount() const
Returns the current call count.
Definition: Gruen.h:85
Isis::Pvl
Container for cube-like labels.
Definition: Pvl.h:119
Isis::Gruen::MinValidPoints
BigInt MinValidPoints(BigInt totalPoints) const
Computes the number of minimum valid points.
Definition: Gruen.cpp:1038
Isis::Gruen::ParameterLog
PvlGroup ParameterLog() const
Create a PvlGroup with the Gruen specific parameters.
Definition: Gruen.cpp:890
Isis::Coordinate
Define a generic Y/X container.
Definition: GruenTypes.h:53
Isis::Gruen::errorAnalysis
Analysis errorAnalysis(const BigInt &npts, const double &resid, const GMatrix &atai)
Compute the error analysis of convergent Gruen matrix.
Definition: Gruen.cpp:289
Isis::toString
QString toString(bool boolToConvert)
Global function to convert a boolean to a string.
Definition: IString.cpp:211
Isis::Gruen::IdealFit
virtual double IdealFit() const
Returns the ideal fit for a perfect Gruen result.
Definition: Gruen.h:140
Isis::IsSpecial
bool IsSpecial(const double d)
Returns if the input pixel is special.
Definition: SpecialPixel.h:197
Isis::AutoReg
Auto Registration class.
Definition: AutoReg.h:167
Isis::Gruen::initErrorList
ErrorList initErrorList() const
Creates an error list from know Gruen errors.
Definition: Gruen.cpp:922
Isis::Gruen::ErrorCounter
Struct that maintains error counts.
Definition: Gruen.h:166
Isis::Gruen::getLastMatch
MatchPoint getLastMatch() const
Returns the register state of the last successful Gruen match.
Definition: Gruen.h:120
Isis::Gruen::ErrorList
CollectorMap< int, ErrorCounter > ErrorList
Declaration of error count list.
Definition: Gruen.h:182
Isis::Gruen::getDefaultAffineRadio
const AffineRadio & getDefaultAffineRadio() const
Returns default settings for Affine/Radiometric parameters.
Definition: Gruen.h:101
Isis::Gruen::Registration
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:680
Isis::Gruen::getSpiceConstraint
double getSpiceConstraint() const
Returns the SPICE tolerance constraint as read from config file.
Definition: Gruen.h:92
Isis::Gruen::~Gruen
virtual ~Gruen()
Destructor.
Definition: Gruen.h:82
Isis::PvlGroup
Contains multiple PvlContainers.
Definition: PvlGroup.h:41
Isis::Gruen::Jacobi
int Jacobi(const GMatrix &a, GVector &evals, GMatrix &evecs, const int &MaxIters=50) const
Compute the Jacobian of a covariance matrix.
Definition: Gruen.cpp:427
Isis::Analysis
Error analysis of Gruen match point solution.
Definition: GruenTypes.h:383
Isis::Gruen::EigenSort
void EigenSort(GVector &evals, GMatrix &evecs) const
Sort eigenvectors from highest to lowest.
Definition: Gruen.cpp:556
Isis::BigInt
long long int BigInt
Big int.
Definition: Constants.h:49
Isis::DbProfile
A DbProfile is a container for access parameters to a database.
Definition: DbProfile.h:51
Isis::Gruen::ValidPoints
bool ValidPoints(BigInt totalPoints, BigInt nPoints) const
Determines if number of points is valid percentage of all points.
Definition: Gruen.cpp:1055
Isis::AutoReg::RegisterStatus
RegisterStatus
Enumeration of the Register() method's return status.
Definition: AutoReg.h:179
Isis::MatchPoint
Structure containing comprehensive registration info/results.
Definition: GruenTypes.h:433
Isis::Gruen::getChipUpdate
Coordinate getChipUpdate(Chip &sChip, MatchPoint &point) const
Compute the chip coordinate of the registered pixel.
Definition: Gruen.cpp:1141
Isis::Gruen::AlgorithmName
virtual QString AlgorithmName() const
Returns the default name of the algorithm as Gruen.
Definition: Gruen.h:124
Isis::Gruen::setAffineRadio
void setAffineRadio()
Set affine parameters to defaults.
Definition: Gruen.cpp:127
Isis::CollectorMap< int, ErrorCounter >
Isis::AffineTolerance
Container for Affine limits parameters.
Definition: GruenTypes.h:319
Isis::Chip
A small chip of data used for pattern matching.
Definition: Chip.h:86
Isis::Gruen::getDefaultParameters
static Pvl & getDefaultParameters()
Load default Gruen parameter file in $ISISROOT/appdata/templates.
Definition: Gruen.cpp:803
Isis::Gruen::Cholsl
GMatrix Cholsl(const GMatrix &a, const GVector &p, const GMatrix &b, const GMatrix &x) const
Compute Cholesky solution matrix from correlation.
Definition: Gruen.cpp:383
Isis::IString
Adds specific functionality to C++ strings.
Definition: IString.h:165
Isis::Gruen
Gruen pattern matching algorithm.
Definition: Gruen.h:74
Isis::DbProfile::value
QString value(const QString &key, int nth=0) const
Returns the specified value for the given keyword.
Definition: DbProfile.cpp:146
Isis::Gruen::StatsLog
PvlGroup StatsLog() const
Create a PvlGroup with the Gruen specific statistics.
Definition: Gruen.cpp:853
Isis
This is free and unencumbered software released into the public domain.
Definition: Apollo.h:16
Isis::IString::ToQt
QString ToQt() const
Retuns the object string as a QString.
Definition: IString.cpp:869
Isis::Gruen::DegreesOfFreedom
double DegreesOfFreedom(const int npts) const
Returns number of degrees of freedom of points.
Definition: Gruen.h:347
Isis::Gruen::algorithm
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:156
Isis::Gruen::Status
AutoReg::RegisterStatus Status(const MatchPoint &result)
Returns the proper status given a Gruen result container.
Definition: Gruen.cpp:1161
Isis::Gruen::CheckConstraints
int CheckConstraints(MatchPoint &point)
Test user limits/contraints after the algorithm has converged.
Definition: Gruen.cpp:1090