Isis Developer Reference
GruenTypes.h
Go to the documentation of this file.
1#ifndef GruenTypes_h
2#define GruenTypes_h
8/* SPDX-License-Identifier: CC0-1.0 */
9
10#include <cmath>
11#include <iostream>
12#include <sstream>
13#include <iomanip>
14
15#include <tnt/tnt_array1d.h>
16#include <tnt/tnt_array2d.h>
17#include <tnt/tnt_array2d_utils.h>
18
19#include "Affine.h"
20#include "Chip.h"
21#include "Constants.h"
22#include "IException.h"
23#include "PvlKeyword.h"
24#include "SpecialPixel.h"
25
26
27namespace Isis {
28
30 typedef TNT::Array1D<double> GVector;
31
32 // Constraints
33 enum { NCONSTR = 8 };
34
53 class Coordinate {
54 public:
56 Coordinate(double y, double x) : m_y(y), m_x(x) { }
57 Coordinate(const Chip &chip) : m_y(chip.CubeLine()),
58 m_x(chip.CubeSample()){ }
60
62 void setLatLon(const double &latitude, const double &longitude) {
63 m_y = latitude;
64 m_x = longitude;
65 return;
66 }
67
69 void setLineSamp(const double &line, const double &sample) {
70 m_y = line;
71 m_x = sample;
72 return;
73 }
74
77 if ( isValid() && other.isValid()) {
78 m_y += other.m_y;
79 m_x += other.m_x;
80 }
81 else {
82 m_y = m_x = Null;
83 }
84 return (*this);
85 }
86
89 if ( isValid() && other.isValid() ) {
90 m_y -= other.m_y;
91 m_x -= other.m_x;
92 }
93 else {
94 m_y = m_x = Null;
95 }
96 return (*this);
97 }
98
100 double getDistance(const Coordinate &pntA = Coordinate(0.0, 0.0)) const {
101 double yd = pntA.m_y - m_y;
102 double xd = pntA.m_x - m_x;
103 return (std::sqrt((xd * xd) + (yd * yd)));
104 }
105
107 inline bool isValid() const {
108 return ( !(IsSpecial(m_x) || IsSpecial(m_y)));
109 }
110
111 inline double getLatitude() const { return (m_y); }
112 inline double getLongitude() const { return (m_x); }
113 inline double getLine() const { return (m_y); }
114 inline double getSample() const { return (m_x); }
115
116 double m_y; // Overloaded as Latitude or line
117 double m_x; // Overloaded as Longitude or sample
118 };
119
120
130 inline Coordinate operator+(const Coordinate &A, const Coordinate &B) {
131 if ( A.isValid() && B.isValid() ) {
132 return (Coordinate(A.m_y+B.m_y, A.m_x+B.m_x));
133 }
134 else {
135 return (Coordinate());
136 }
137 }
138
148 inline Coordinate operator-(const Coordinate &A, const Coordinate &B) {
149 if ( A.isValid() && B.isValid() ) {
150 return (Coordinate(A.m_y-B.m_y, A.m_x-B.m_x));
151 }
152 else {
153 return (Coordinate());
154 }
155 }
156
171 class PointPair {
172 public:
174 PointPair(const double &line, const double &sample) : m_left(line, sample),
175 m_right() { }
177 const Coordinate &right = Coordinate()) : m_left(left),
178 m_right(right) { }
179
181 inline bool isValid() const {
182 return (m_left.isValid() && m_right.isValid());
183 }
184 inline const Coordinate &getLeft() const { return (m_left); }
185 inline const Coordinate &getRight() const { return (m_right); }
186
187 inline double getLine() const { return (getLeftLine()); }
188 inline double getSample() const { return (getLeftSample()); }
189 inline double getLeftLine() const { return (m_left.getLine()); }
190 inline double getLeftSample() const { return (m_left.getSample()); }
191 inline double getRightLine() const { return (m_right.getLine()); }
192 inline double getRightSample() const { return (m_right.getSample()); }
193
194 Coordinate m_left; // Left image line/sample
195 Coordinate m_right; // Right image line/sample
196 };
197
198
207 public:
208 Radiometric() : m_shift(0.0), m_gain(0.0) { }
209 Radiometric(const double &shift, const double &gain) :
210 m_shift(shift), m_gain(gain) { }
211
212 inline double Shift() const { return (m_shift); }
213 inline double Gain() const { return (m_gain); }
214
215
218 m_shift += B.m_shift;
219 m_gain += B.m_gain;
220 return (*this);
221 }
222
223 double m_shift; // Radiometric shift
224 double m_gain; // Radiometric gain
225 };
226
228 inline Radiometric operator+(const Radiometric &A, const Radiometric &B) {
229 return (Radiometric(A.m_shift+B.m_shift, A.m_gain+B.m_gain));
230 }
231
232
243 public:
244 AffineRadio() : m_affine(Affine::getIdentity()), m_radio() {}
245 AffineRadio(const GMatrix &A) : m_affine(A), m_radio() { }
246 AffineRadio(const GMatrix &M, const double &shift,
247 const double &gain) : m_affine(M), m_radio(shift, gain) { }
248 AffineRadio(const GVector &alpha) : m_affine(), m_radio() {
249 clone(alpha); // Clone from an alpha matrix
250 }
251 AffineRadio(const Radiometric &radio) : m_affine(Affine::getIdentity()),
252 m_radio(radio) { }
254
257 m_affine = m_affine + (other.m_affine - Affine::getIdentity());
258 m_radio += other.m_radio;
259 return (*this);
260 }
261
263 void Translate(const Coordinate &offset) {
265 trans[0][2] = offset.getSample();
266 trans[1][2] = offset.getLine();
267 m_affine = TNT::matmult(trans, m_affine);
268 return;
269 }
270
272 Coordinate getPoint(const Coordinate &location) const {
273 double x = m_affine[0][0] * location.getSample() +
274 m_affine[0][1] * location.getLine() + m_affine[0][2];
275 double y = m_affine[1][0] * location.getSample() +
276 m_affine[1][1] * location.getLine() + m_affine[1][2];
277 return (Coordinate(y, x));
278 }
279
280 GMatrix m_affine; // Affine transform
281 Radiometric m_radio; // Radiometric gain and shift
282
283 private:
285 void clone(const GVector &alpha) {
286 if ( alpha.dim1() != 8 ) {
287 QString mess = "Alpha array for AffineRadio must have 8 elements "
288 " but has " + toString(alpha.dim1());
290 }
292 m_affine[0][0] += alpha[1];
293 m_affine[0][1] += alpha[2];
294 m_affine[0][2] += alpha[0];
295
296 m_affine[1][0] += alpha[4];
297 m_affine[1][1] += alpha[5];
298 m_affine[1][2] += alpha[3];
299
300 m_radio.m_shift = alpha[6];
301 m_radio.m_gain = alpha[7];
302 }
303 };
304
305
320 public:
322 AffineTolerance(const double &transTol, const double &scaleTol,
323 const double &shearTol) : m_transTol(transTol),
324 m_scaleTol(scaleTol),
325 m_shearTol(shearTol) { }
327
328 double m_transTol; // Affine translation tolerance
329 double m_scaleTol; // Affine scale tolerance
330 double m_shearTol; // Affine shear tolerance
331 };
332
333
348 class Threshold {
349 public:
350 Threshold() : m_thresh(6, 0.0) { }
351 Threshold(const Chip &chip, const AffineTolerance &tolerance) : m_thresh(6) {
352 m_thresh[0] = tolerance.m_scaleTol / (((double)(chip.Samples() - 1)) / 2.0);
353 m_thresh[1] = tolerance.m_shearTol / (((double)(chip.Lines() - 1)) / 2.0);
354 m_thresh[2] = tolerance.m_transTol;
355
356 m_thresh[3] = tolerance.m_shearTol / (((double)(chip.Samples() - 1)) / 2.0);
357 m_thresh[4] = tolerance.m_scaleTol / (((double)(chip.Lines() - 1)) / 2.0);
358 m_thresh[5] = tolerance.m_transTol;
359 }
361
363 bool hasConverged(const AffineRadio &affine) const {
364 GMatrix Malpha = affine.m_affine - Affine::getIdentity();
365 const double *alpha = Malpha[0];
366 for ( int i = 0 ; i < m_thresh.dim1() ; i++ ) {
367 if ( std::fabs(alpha[i]) >= m_thresh[i] ) return (false);
368 }
369 return (true); // If all values are below threshold
370 }
371
373 };
374
375
383 struct Analysis {
385 m_kmat(), m_status(-1) {
386 for ( int i = 0 ; i < 2 ; i++ ) {
387 m_sevals[i] = 999.0;
388 m_kmat[i] = 999.0;
389 }
390 }
392
393 inline bool isValid() const { return (m_status == 0); }
394
396 inline double getEigen() const {
397 double eigen = std::sqrt(m_sevals[0] * m_sevals[0] +
398 m_sevals[1] * m_sevals[1]);
399 return (eigen);
400 }
401
403 inline void setZeroState() {
404 for ( int i = 0 ; i < 2 ; i++ ) {
405 m_sevals[i] = 0.0;
406 m_kmat[i] = 0.0;
407 }
408 m_status = 0;
409 return;
410 }
411
414 double m_sevals[2]; // 2 sorted eigenvalues
415 double m_kmat[2]; // Sample/Line uncertainty
416 int m_status; // Status
417 };
418
419
434 public:
436 MatchPoint(const AffineRadio &radio) : m_point(), m_affine(radio),
437 m_analysis(), m_status(-1) { }
438 MatchPoint(const PointPair &point) : m_point(point), m_affine(),
439 m_analysis(), m_status(-1) { }
441
442 inline int getStatus() const { return (m_status); }
443 const MatchPoint &setStatus(int status) {
444 m_status = status;
445 return (*this);
446 }
447
448 inline bool isValid() const { return (m_status == 0); }
449 inline double getEigen() const { return (m_analysis.getEigen()); }
450
453 const {
454 return (m_affine.getPoint(coord));
455 }
456
457 PointPair m_point; // Pattern (left) and search (right) points
458 AffineRadio m_affine; // Resulting Affine transform
459 Analysis m_analysis; // Error analysis of registration
460 int m_nIters; // Number of iterations required to match
461 int m_status; // Status - good is 0
462 };
463
464} // namespace Isis
465#endif
#define _FILEINFO_
Macro for the filename and line number.
Definition IException.h:24
Affine basis function.
Definition Affine.h:65
static AMatrix getIdentity()
Return an Affine identity matrix.
Definition Affine.cpp:61
TNT::Array2D< double > AMatrix
Affine Matrix.
Definition Affine.h:67
Container for affine and radiometric parameters.
Definition GruenTypes.h:242
Coordinate getPoint(const Coordinate &location) const
Applies the affine transfrom to a point and returns result.
Definition GruenTypes.h:272
AffineRadio & operator+=(const AffineRadio &other)
Define update procedure for accumulating Gruen iterations.
Definition GruenTypes.h:256
AffineRadio(const GMatrix &M, const double &shift, const double &gain)
Definition GruenTypes.h:246
AffineRadio(const Radiometric &radio)
Definition GruenTypes.h:251
GMatrix m_affine
Definition GruenTypes.h:280
void Translate(const Coordinate &offset)
Apply a translation to the given offset.
Definition GruenTypes.h:263
~AffineRadio()
Definition GruenTypes.h:253
AffineRadio(const GVector &alpha)
Definition GruenTypes.h:248
AffineRadio()
Definition GruenTypes.h:244
AffineRadio(const GMatrix &A)
Definition GruenTypes.h:245
Radiometric m_radio
Definition GruenTypes.h:281
A small chip of data used for pattern matching.
Definition Chip.h:86
int Samples() const
Definition Chip.h:99
int Lines() const
Definition Chip.h:106
Define a generic Y/X container.
Definition GruenTypes.h:53
double getSample() const
Definition GruenTypes.h:114
double getLine() const
Definition GruenTypes.h:113
Coordinate(const Chip &chip)
Definition GruenTypes.h:57
Coordinate()
Definition GruenTypes.h:55
double getLongitude() const
Definition GruenTypes.h:112
Coordinate & operator-=(const Coordinate &other)
Subtract a point from this point.
Definition GruenTypes.h:88
bool isValid() const
Check for goodness.
Definition GruenTypes.h:107
void setLatLon(const double &latitude, const double &longitude)
Use Latitude/Longitude interface.
Definition GruenTypes.h:62
Coordinate & operator+=(const Coordinate &other)
Add a point to this point.
Definition GruenTypes.h:76
void setLineSamp(const double &line, const double &sample)
Use the Line/Sample interface.
Definition GruenTypes.h:69
double getLatitude() const
Definition GruenTypes.h:111
~Coordinate()
Definition GruenTypes.h:59
Coordinate(double y, double x)
Definition GruenTypes.h:56
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
double m_x
Definition GruenTypes.h:117
double m_y
Definition GruenTypes.h:116
Isis exception class.
Definition IException.h:91
@ Programmer
This error is for when a programmer made an API call that was illegal.
Definition IException.h:146
Structure containing comprehensive registration info/results.
Definition GruenTypes.h:433
int m_status
Definition GruenTypes.h:461
MatchPoint(const AffineRadio &radio)
Definition GruenTypes.h:436
int getStatus() const
Definition GruenTypes.h:442
double getEigen() const
Definition GruenTypes.h:449
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
Analysis m_analysis
Definition GruenTypes.h:459
PointPair m_point
Definition GruenTypes.h:457
int m_nIters
Definition GruenTypes.h:460
bool isValid() const
Definition GruenTypes.h:448
const MatchPoint & setStatus(int status)
Definition GruenTypes.h:443
AffineRadio m_affine
Definition GruenTypes.h:458
MatchPoint(const PointPair &point)
Definition GruenTypes.h:438
MatchPoint()
Definition GruenTypes.h:435
~MatchPoint()
Definition GruenTypes.h:440
Define a point set of left, right and geometry at that location.
Definition GruenTypes.h:171
double getLeftSample() const
Definition GruenTypes.h:190
double getRightSample() const
Definition GruenTypes.h:192
bool isValid() const
Left, right and geometry coordinates must all be good data.
Definition GruenTypes.h:181
Coordinate m_left
Definition GruenTypes.h:194
double getLeftLine() const
Definition GruenTypes.h:189
double getRightLine() const
Definition GruenTypes.h:191
PointPair()
Definition GruenTypes.h:173
double getSample() const
Definition GruenTypes.h:188
PointPair(const double &line, const double &sample)
Definition GruenTypes.h:174
PointPair(const Coordinate &left, const Coordinate &right=Coordinate())
Definition GruenTypes.h:176
const Coordinate & getRight() const
Definition GruenTypes.h:185
const Coordinate & getLeft() const
Definition GruenTypes.h:184
double getLine() const
Definition GruenTypes.h:187
Coordinate m_right
Definition GruenTypes.h:195
Store for radiometric gain and shift parameters.
Definition GruenTypes.h:206
double m_gain
Definition GruenTypes.h:224
double m_shift
Definition GruenTypes.h:223
Radiometric(const double &shift, const double &gain)
Definition GruenTypes.h:209
Radiometric & operator+=(const Radiometric &B)
Add radiometric parameters from another set of parameters.
Definition GruenTypes.h:217
Radiometric()
Definition GruenTypes.h:208
double Gain() const
Definition GruenTypes.h:213
double Shift() const
Definition GruenTypes.h:212
Compute/test the Affine convergence from given parameters/chip.
Definition GruenTypes.h:348
~Threshold()
Definition GruenTypes.h:360
bool hasConverged(const AffineRadio &affine) const
Determines convergence from an affine/radiometric fit.
Definition GruenTypes.h:363
Threshold()
Definition GruenTypes.h:350
Threshold(const Chip &chip, const AffineTolerance &tolerance)
Definition GruenTypes.h:351
GVector m_thresh
Definition GruenTypes.h:372
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
const double Null
Value for an Isis Null pixel.
Definition SpecialPixel.h:95
long long int BigInt
Big int.
Definition Constants.h:49
Coordinate operator+(const Coordinate &A, const Coordinate &B)
Summation operator for Coordinate.
Definition GruenTypes.h:130
bool IsSpecial(const double d)
Returns if the input pixel is special.
Definition SpecialPixel.h:197
Coordinate operator-(const Coordinate &A, const Coordinate &B)
Subtraction operator for Coordinate.
Definition GruenTypes.h:148
Container for Affine limits parameters.
Definition GruenTypes.h:319
double m_shearTol
Definition GruenTypes.h:330
double m_transTol
Definition GruenTypes.h:328
AffineTolerance(const double &transTol, const double &scaleTol, const double &shearTol)
Definition GruenTypes.h:322
double m_scaleTol
Definition GruenTypes.h:329
~AffineTolerance()
Definition GruenTypes.h:326
AffineTolerance()
Definition GruenTypes.h:321
Error analysis of Gruen match point solution.
Definition GruenTypes.h:383
bool isValid() const
Definition GruenTypes.h:393
void setZeroState()
Resets eigenvalues to 0.
Definition GruenTypes.h:403
Analysis()
Definition GruenTypes.h:384
double getEigen() const
Returns the square of the of sum of the squares of eigenvalues.
Definition GruenTypes.h:396
double m_kmat[2]
Definition GruenTypes.h:415
int m_status
Definition GruenTypes.h:416
BigInt m_npts
Definition GruenTypes.h:412
~Analysis()
Definition GruenTypes.h:391
double m_variance
Definition GruenTypes.h:413
double m_sevals[2]
Definition GruenTypes.h:414