Isis Developer Reference
Gruen.h
Go to the documentation of this file.
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 
182  typedef CollectorMap<int, ErrorCounter> ErrorList;
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;
365  AutoReg::RegisterStatus Status(const MatchPoint &result);
366  };
367 
368 } // namespace Isis
369 #endif
Isis::Gruen::getAffineConstraint
double getAffineConstraint() const
Returns the Affine tolerance constraint as read from config file.
Definition: Gruen.h:95
Isis::AutoReg::SetChipSample
void SetChipSample(double sample)
Sets the search chip subpixel sample that matches the pattern tack sample.
Definition: AutoReg.h:393
Isis::MatchPoint::getEigen
double getEigen() const
Definition: GruenTypes.h:449
Isis::Analysis::m_npts
BigInt m_npts
Definition: GruenTypes.h:412
Isis::AffineRadio::m_affine
GMatrix m_affine
Definition: GruenTypes.h:280
Isis::Statistics::AddData
void AddData(const double *data, const unsigned int count)
Add an array of doubles to the accumulators and counters.
Definition: Statistics.cpp:141
Isis::Gruen::MatchAlgorithm
virtual double MatchAlgorithm(Chip &pattern, Chip &subsearch)
Minimization of data set using Gruen algorithm.
Definition: Gruen.cpp:608
Isis::DbProfile::Name
QString Name() const
Returns the name of this property.
Definition: DbProfile.h:104
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::GVector
TNT::Array1D< double > GVector
Definition: GruenTypes.h:30
Isis::Gruen::Gruen
Gruen()
Default constructor.
Definition: Gruen.cpp:32
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::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::AffineRadio::m_radio
Radiometric m_radio
Definition: GruenTypes.h:281
Isis::CollectorMap::getNth
T & getNth(int nth)
Returns the nth value in the collection.
Definition: CollectorMap.h:624
GruenTypes.h
Isis::Gruen::getAffineRadio
const AffineRadio & getAffineRadio() const
Return current state of Affine/Radio state
Definition: Gruen.h:104
Isis::Chip::SetSize
void SetSize(const int samples, const int lines)
Change the size of the Chip.
Definition: Chip.cpp:134
Isis::Coordinate::getDistance
double getDistance(const Coordinate &pntA=Coordinate(0.0, 0.0)) const
Computes the distance from this point and the point provided.
Definition: GruenTypes.h:100
Isis::AutoReg::AdaptiveAlgorithmFailed
@ AdaptiveAlgorithmFailed
Error occured in Adaptive algorithm.
Definition: AutoReg.h:189
PvlGroup.h
Isis::Analysis::isValid
bool isValid() const
Definition: GruenTypes.h:393
Isis::AutoReg::SetGoodnessOfFit
void SetGoodnessOfFit(double fit)
Sets the goodness of fit for adaptive algorithms.
Definition: AutoReg.h:413
Isis::CollectorMap::get
T & get(const K &key)
Returns the value associated with the name provided.
Definition: CollectorMap.h:567
Isis::Chip::GetValue
double GetValue(int sample, int line)
Loads a Chip with a value.
Definition: Chip.h:145
Isis::Statistics::Maximum
double Maximum() const
Returns the absolute maximum double found in all data passed through the AddData method.
Definition: Statistics.cpp:403
Isis::Gruen::getAffineTolerance
AffineTolerance getAffineTolerance() const
Return set of tolerances for affine convergence.
Definition: Gruen.cpp:1066
Isis::AffineRadio
Container for affine and radiometric parameters.
Definition: GruenTypes.h:242
Isis::Statistics::Reset
void Reset()
Reset all accumulators and counters to zero.
Definition: Statistics.cpp:113
Isis::CollectorMap::size
int size() const
Returns the size of the collection.
Definition: CollectorMap.h:512
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::Analysis::m_status
int m_status
Definition: GruenTypes.h:416
Isis::NCONSTR
@ NCONSTR
Definition: GruenTypes.h:33
Isis::Analysis::m_sevals
double m_sevals[2]
Definition: GruenTypes.h:414
Isis::MatchPoint::getStatus
int getStatus() const
Definition: GruenTypes.h:442
Isis::Chip::Extract
Chip Extract(int samples, int lines, int samp, int line)
Extract a sub-chip from a chip.
Definition: Chip.cpp:727
Isis::Coordinate::getSample
double getSample() const
Definition: GruenTypes.h:114
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::getLastMatch
MatchPoint getLastMatch() const
Returns the register state of the last successful Gruen match.
Definition: Gruen.h:120
Gruen.h
Isis::PvlObject::Traverse
@ Traverse
Search child objects.
Definition: PvlObject.h:158
Isis::MatchPoint::m_nIters
int m_nIters
Definition: GruenTypes.h:460
Isis::Chip::TackSample
int TackSample() const
This method returns a chip's fixed tack sample; the middle of the chip.
Definition: Chip.h:176
Isis::Gruen::getDefaultAffineRadio
const AffineRadio & getDefaultAffineRadio() const
Returns default settings for Affine/Radiometric parameters.
Definition: Gruen.h:101
Isis::Chip::Lines
int Lines() const
Definition: Chip.h:106
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::CollectorMap::exists
bool exists(const K &key) const
Checks the existance of a particular key in the list.
Definition: CollectorMap.h:551
Isis::Threshold
Compute/test the Affine convergence from given parameters/chip.
Definition: GruenTypes.h:348
Isis::Gruen::getSpiceConstraint
double getSpiceConstraint() const
Returns the SPICE tolerance constraint as read from config file.
Definition: Gruen.h:92
Isis::AutoReg::SuccessSubPixel
@ SuccessSubPixel
Success registering to sub-pixel accuracy.
Definition: AutoReg.h:181
Isis::Gruen::~Gruen
virtual ~Gruen()
Destructor.
Definition: Gruen.h:82
Isis::Analysis::m_kmat
double m_kmat[2]
Definition: GruenTypes.h:415
Isis::PvlGroup
Contains multiple PvlContainers.
Definition: PvlGroup.h:41
Pvl.h
_FILEINFO_
#define _FILEINFO_
Macro for the filename and line number.
Definition: IException.h:24
Isis::Chip::TackLine
int TackLine() const
This method returns a chip's fixed tack line; the middle of the chip.
Definition: Chip.h:187
Isis::IException::toString
QString toString() const
Returns a string representation of this exception.
Definition: IException.cpp:537
Isis::Chip::Write
void Write(const QString &filename)
Writes the contents of the Chip to a cube.
Definition: Chip.cpp:985
Isis::toInt
int toInt(const QString &string)
Global function to convert from a string to an integer.
Definition: IString.cpp:93
Isis::Statistics::StandardDeviation
double StandardDeviation() const
Computes and returns the standard deviation.
Definition: Statistics.cpp:312
Isis::Statistics::Minimum
double Minimum() const
Returns the absolute minimum double found in all data passed through the AddData method.
Definition: Statistics.cpp:382
Isis::Analysis
Error analysis of Gruen match point solution.
Definition: GruenTypes.h:383
Isis::Analysis::m_variance
double m_variance
Definition: GruenTypes.h:413
Isis::PointPair
Define a point set of left, right and geometry at that location.
Definition: GruenTypes.h:171
Isis::BigInt
long long int BigInt
Big int.
Definition: Constants.h:49
Isis::Coordinate::getLine
double getLine() const
Definition: GruenTypes.h:113
Isis::MatchPoint::m_analysis
Analysis m_analysis
Definition: GruenTypes.h:459
Isis::AutoReg::PatternValidPercent
double PatternValidPercent() const
Return pattern chip valid percent. The default value is.
Definition: AutoReg.h:280
Isis::IException
Isis exception class.
Definition: IException.h:91
Isis::AutoReg::RegisterStatus
RegisterStatus
Enumeration of the Register() method's return status.
Definition: AutoReg.h:179
Isis::MatchPoint::setStatus
const MatchPoint & setStatus(int status)
Definition: GruenTypes.h:443
Isis::AutoReg::Tolerance
double Tolerance() const
Return match algorithm tolerance.
Definition: AutoReg.h:290
Isis::MatchPoint
Structure containing comprehensive registration info/results.
Definition: GruenTypes.h:433
Isis::Null
const double Null
Value for an Isis Null pixel.
Definition: SpecialPixel.h:95
Affine.h
Isis::Analysis::getEigen
double getEigen() const
Returns the square of the of sum of the squares of eigenvalues.
Definition: GruenTypes.h:396
Isis::CollectorMap::add
void add(const K &key, const T &value)
Adds the element to the list.
Definition: CollectorMap.h:540
Isis::PvlObject::addGroup
void addGroup(const Isis::PvlGroup &group)
Add a group to the object.
Definition: PvlObject.h:186
Isis::Statistics::Average
double Average() const
Computes and returns the average.
Definition: Statistics.cpp:300
Isis::GMatrix
Affine::AMatrix GMatrix
Definition: GruenTypes.h:29
Isis::Gruen::AlgorithmName
virtual QString AlgorithmName() const
Returns the default name of the algorithm as Gruen.
Definition: Gruen.h:124
Statistics.h
Isis::toDouble
double toDouble(const QString &string)
Global function to convert from a string to a double.
Definition: IString.cpp:149
Isis::IException::Programmer
@ Programmer
This error is for when a programmer made an API call that was illegal.
Definition: IException.h:146
Isis::Chip::IsValid
bool IsValid(int sample, int line)
Definition: Chip.h:240
Isis::Radiometric::Gain
double Gain() const
Definition: GruenTypes.h:213
std
Namespace for the standard library.
CollectorMap.h
Isis::Gruen::setAffineRadio
void setAffineRadio()
Set affine parameters to defaults.
Definition: Gruen.cpp:127
Isis::Radiometric::Shift
double Shift() const
Definition: GruenTypes.h:212
Isis::MatchPoint::getAffinePoint
Coordinate getAffinePoint(const Coordinate &coord=Coordinate(0.0, 0.0)) const
Return registration offset of a given chip coordinate from center
Definition: GruenTypes.h:452
Isis::MatchPoint::m_affine
AffineRadio m_affine
Definition: GruenTypes.h:458
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::Chip::Samples
int Samples() const
Definition: Chip.h:99
Isis::Affine
Affine basis function.
Definition: Affine.h:65
DbProfile.h
Isis::Gruen
Gruen pattern matching algorithm.
Definition: Gruen.h:74
Isis::Chip::SetChipPosition
void SetChipPosition(const double sample, const double line)
Compute the position of the cube given a chip coordinate.
Definition: Chip.cpp:643
Isis::DbProfile::setName
void setName(const QString &name)
Set the name of this profile.
Definition: DbProfile.h:95
Isis::AutoReg::SetChipLine
void SetChipLine(double line)
Sets the search chip subpixel line that matches the pattern tack line.
Definition: AutoReg.h:404
Isis::AffineRadio::Translate
void Translate(const Coordinate &offset)
Apply a translation to the given offset.
Definition: GruenTypes.h:263
Isis::Threshold::hasConverged
bool hasConverged(const AffineRadio &affine) const
Determines convergence from an affine/radiometric fit.
Definition: GruenTypes.h:363
AutoReg.h
Isis
This is free and unencumbered software released into the public domain.
Definition: Apollo.h:16
Chip.h
Isis::MatchPoint::isValid
bool isValid() const
Definition: GruenTypes.h:448
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