Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
CovMatrix3x3.hh
1 /*
2 This file is part of the BIAS library (Basic ImageAlgorithmS).
3 
4 Copyright (C) 2003-2009 (see file CONTACT for details)
5  Multimediale Systeme der Informationsverarbeitung
6  Institut fuer Informatik
7  Christian-Albrechts-Universitaet Kiel
8 
9 
10 BIAS is free software; you can redistribute it and/or modify
11 it under the terms of the GNU Lesser General Public License as published by
12 the Free Software Foundation; either version 2.1 of the License, or
13 (at your option) any later version.
14 
15 BIAS is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU Lesser General Public License for more details.
19 
20 You should have received a copy of the GNU Lesser General Public License
21 along with BIAS; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 */
24 
25 
26 #ifndef __CovMatrix3x3_hh__
27 #define __CovMatrix3x3_hh__
28 
29 #include <Base/Math/Matrix3x3.hh>
30 #include <Base/Geometry/PMatrixBase.hh>
31 #include <Base/Geometry/HomgPoint3DCov.hh>
32 #include <MathAlgo/SVD.hh>
33 
34 #define COVMATRIX3X3_TYPE double
35 
36 namespace BIAS {
37  /** @class CovMatrix3x3
38  @ingroup g_math
39  @ingroup g_geometry
40  @brief class for 3x3 covariance matrices
41 
42  This class represents a 3x3 convariance matrix with the capability of
43  doing a PCA (principle component analysis).
44 
45  @attention For performance reasons, the PCA is only done once and saved,
46  subsequent calls to GetPCA() only return a copy.
47  If the covariance matrix is changed, you must call InvalidatePCA()
48  to force a recomputation at the next GetPCA()-Call ! */
49 
50  class BIASGeometry_EXPORT CovMatrix3x3 : public Matrix3x3<COVMATRIX3X3_TYPE>
51  {
52  public:
53  CovMatrix3x3();
54 
55  ~CovMatrix3x3();
56 
57  CovMatrix3x3(const CovMatrix3x3& mat);
58 
59  explicit CovMatrix3x3(const MatrixInitType& i)
60  : Matrix3x3<COVMATRIX3X3_TYPE>(i), _IsDecomposed(false) {};
61 
63  { (*this) = mat; };
64 
65 
66  int GetPCA(Vector3<COVMATRIX3X3_TYPE>& S,
68 
69  int GetS(Vector3<COVMATRIX3X3_TYPE>& S);
70 
71  CovMatrix3x3& operator=(const CovMatrix3x3& mat);
72 
75  _IsDecomposed = false; return (*this); };
76 
77  /** @brief returns matrix's trace. If this = V * S * V^T, trace means |S|^2
78  and provides a scalar measure of how uncertain a 3D point is.
79 
80  Note the difference to det() which means geometric averaging of
81  singular values rather than arithmetic. If you want to imagine an
82  ellipsoid, trace is proportional to the mean axis length, while det
83  is more like the space inside the ellipsoid.
84  @author koeser */
85  double Trace() const {
86  return ((*this)[0][0] + (*this)[1][1] + (*this)[2][2]);
87  }
88 
89 
90  /** Computes the bounding box x=[xmin,xmax] , y=[ymin,ymax] in image as
91  determined from the projected covariance matrix covmat. multiplied with
92  scale
93  @author frahm, woelk 02 2003 */
94  int GetSearchArea(PMatrixBase& P, HomgPoint3D& point3D,
95  Vector2<double>& x, Vector2<double>& y, double scale);
96 
97  /** Computes the bounding box x=[xmin,xmax] , y=[ymin,ymax] in image as
98  determined from the projected covariance matrix covmat.
99  A min Search Area can be specified with minSearchArea(which is the
100  radius of the uncertainty sphere).
101  @author Daniel Grest, Feb 2003
102  */
103  int GetSearchArea(PMatrixBase& P, HomgPoint3D& point3D,
105  double scale, double minSearchArea);
106 
107 
108  /** Call this function to indicate that the matrix fields have changed
109  The saved PCA is declared invalid and the next call to GetPCA forces
110  a recomputation
111  @author koeser 09/2003 */
112  inline void InvalidatePCA() { _IsDecomposed = false; };
113 
114  /** Type conversion for homogenous covariances
115  @author streckel 05/2006 */
117  Matrix4x4<double> dum((*this)[0][0],(*this)[0][1],(*this)[0][2],0,
118  (*this)[1][0],(*this)[1][1],(*this)[1][2],0,
119  (*this)[2][0],(*this)[2][1],(*this)[2][2],0,
120  0,0,0,0);
121  HomgPoint3DCov ch(dum);
122  return ch;
123  }
124 
125  /** Type conversion for homogenous covariances
126  @author streckel 05/2006 */
127  void SetFromHomogenized(const HomgPoint3DCov& ch, const HomgPoint3D& ph) {
128  //unconst variables
129  HomgPoint3D myph(ph);
130  HomgPoint3DCov mych(ch);
131  mych.Homogenize(myph);
132  Matrix3x3<double> mat(mych[0][0],mych[0][1],mych[0][2],
133  mych[1][0],mych[1][1],mych[1][2],
134  mych[2][0],mych[2][1],mych[2][2]);
135  CovMatrix3x3 cov(mat);
136  *this = cov;
137  }
138 
139  protected:
140  /// flag indicating whether the stored PCA is still valid
142 
143 
144 
145 #ifdef BIAS_DEBUG
146  /// saves matrix fields to make consistency checks possible later
148 #endif
149 
153 
154  int _Decompose();
155  }; // class
156 
157 
158 
159 } // namespace
160 
161 
162 #endif // __CovMatrix3x3_hh__
MatrixInitType
can be passed to matrix constructors to init the matrix with the most often used values ...
Definition: Matrix.hh:59
computes and holds the singular value decomposition of a rectangular (not necessarily quadratic) Matr...
Definition: SVD.hh:92
HomgPoint3DCov GetHomogenized() const
Type conversion for homogenous covariances.
double Trace() const
returns matrix&#39;s trace.
Definition: CovMatrix3x3.hh:85
CovMatrix3x3 & operator=(const BIAS::Matrix3x3< COVMATRIX3X3_TYPE > &mat)
Definition: CovMatrix3x3.hh:73
CovMatrix3x3(const Matrix3x3< COVMATRIX3X3_TYPE > &mat)
Definition: CovMatrix3x3.hh:62
class for 3x3 covariance matrices
Definition: CovMatrix3x3.hh:50
Matrix3x3< COVMATRIX3X3_TYPE > _VT
is a &#39;fixed size&#39; quadratic matrix of dim.
Definition: Matrix.hh:54
class HomgPoint3D describes a point with 3 degrees of freedom in projective coordinates.
Definition: HomgPoint3D.hh:61
describes a projective 3D -&gt; 2D mapping in homogenous coordinates
Definition: PMatrixBase.hh:74
Matrix3x3< COVMATRIX3X3_TYPE > ConsistencyBackup_
saves matrix fields to make consistency checks possible later
Vector3< COVMATRIX3X3_TYPE > _S
class representing the covariance matrix of a homogenous point 3D
Matrix3x3< T > & operator=(const Matrix3x3< T > &mat)
assignment operator
Definition: Matrix3x3.cpp:704
void InvalidatePCA()
Call this function to indicate that the matrix fields have changed The saved PCA is declared invalid ...
void SetFromHomogenized(const HomgPoint3DCov &ch, const HomgPoint3D &ph)
Type conversion for homogenous covariances.
bool _IsDecomposed
flag indicating whether the stored PCA is still valid
CovMatrix3x3(const MatrixInitType &i)
Definition: CovMatrix3x3.hh:59
void Homogenize(HomgPoint3D &p)
homogenizes p and *this