Isis Developer Reference
Gruen.h
Go to the documentation of this file.
1#ifndef Gruen_h
2#define Gruen_h
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
22namespace 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
Container for affine and radiometric parameters.
Definition GruenTypes.h:242
Auto Registration class.
Definition AutoReg.h:167
RegisterStatus
Enumeration of the Register() method's return status.
Definition AutoReg.h:179
A small chip of data used for pattern matching.
Definition Chip.h:86
Gruen pattern matching algorithm.
Definition Gruen.h:74
double getAffineConstraint() const
Returns the Affine tolerance constraint as read from config file.
Definition Gruen.h:95
void WriteSubsearchChips(const QString &pattern="SubChip")
Set up for writing subsearch for a a given registration call.
Definition Gruen.cpp:92
Gruen()
Default constructor.
Definition Gruen.cpp:32
const AffineRadio & getDefaultAffineRadio() const
Returns default settings for Affine/Radiometric parameters.
Definition Gruen.h:101
virtual double MatchAlgorithm(Chip &pattern, Chip &subsearch)
Minimization of data set using Gruen algorithm.
Definition Gruen.cpp:608
virtual QString AlgorithmName() const
Returns the default name of the algorithm as Gruen.
Definition Gruen.h:124
Analysis errorAnalysis(const BigInt &npts, const double &resid, const GMatrix &atai)
Compute the error analysis of convergent Gruen matrix.
Definition Gruen.cpp:289
virtual double IdealFit() const
Returns the ideal fit for a perfect Gruen result.
Definition Gruen.h:140
void setAffineRadio()
Set affine parameters to defaults.
Definition Gruen.cpp:127
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
double getSpiceConstraint() const
Returns the SPICE tolerance constraint as read from config file.
Definition Gruen.h:92
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
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
BigInt CallCount() const
Returns the current call count.
Definition Gruen.h:85
virtual Pvl AlgorithmStatistics(Pvl &pvl)
Create Gruen error and processing statistics Pvl output.
Definition Gruen.cpp:824
virtual ~Gruen()
Destructor.
Definition Gruen.h:82
const AffineRadio & getAffineRadio() const
Return current state of Affine/Radio state
Definition Gruen.h:104
AffineTolerance getAffineTolerance() const
Return set of tolerances for affine convergence.
Definition Gruen.cpp:1066
MatchPoint getLastMatch() const
Returns the register state of the last successful Gruen match.
Definition Gruen.h:120
Structure containing comprehensive registration info/results.
Definition GruenTypes.h:433
Container for cube-like labels.
Definition Pvl.h:119
Store for radiometric gain and shift parameters.
Definition GruenTypes.h:206
This is free and unencumbered software released into the public domain.
Definition Apollo.h:16
QString toString(bool boolToConvert)
Global function to convert a boolean to a string.
Definition IString.cpp:211
Affine::AMatrix GMatrix
Definition GruenTypes.h:29
@ NCONSTR
Definition GruenTypes.h:33
TNT::Array1D< double > GVector
Definition GruenTypes.h:30
long long int BigInt
Big int.
Definition Constants.h:49
bool IsSpecial(const double d)
Returns if the input pixel is special.
Definition SpecialPixel.h:197
Container for Affine limits parameters.
Definition GruenTypes.h:319
Error analysis of Gruen match point solution.
Definition GruenTypes.h:383