Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
HomgPoint3DCov.cpp
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 #include "HomgPoint3DCov.hh"
27 #include <Base/Geometry/HomgPoint3D.hh>
28 #include <Base/Math/Matrix3x3.hh>
29 #include <Base/Debug/Exception.hh>
30 
31 using namespace BIAS;
32 using namespace std;
33 
36  : Matrix4x4<double>()
37 {}
38 
41  : Matrix4x4<double>(i) {}
42 
45  : Matrix4x4<double>()
46 {
47  SetEuclidean(m);
48 }
49 
52  : Matrix4x4<double>(m)
53 {
54  if (!CheckSymmetry_()){
55  /*cout << setprecision(20) << (*this)[0][1] <<" == "<< (*this)[1][0] << boolalpha << Equal((*this)[0][1], (*this)[1][0])<<"\t"<<((*this)[0][1]==(*this)[1][0])<<endl;
56  cout << setprecision(20) << (*this)[0][2] <<" == "<< (*this)[2][0] << boolalpha << Equal((*this)[0][2], (*this)[2][0])<<endl;
57  cout << setprecision(20) << (*this)[1][2] <<" == "<< (*this)[2][1] << boolalpha << Equal((*this)[1][2], (*this)[2][1])<<endl; */
58  //BEXCEPTION("not a covariance matrix "<<*this);
59  // BIASERR("not a covariance matrix, forcing symmetry!! "<<*this);
61  }
62 }
63 
66  : Matrix4x4<double>(m)
67 {
68  if (!CheckSymmetry_()){
69  //BIASERR("not a covariance matrix, forcing symmetry!! "<<*this);
71  }
72 }
73 
76  : Matrix4x4<double>(m)
77 {
78  if (!CheckSymmetry_()) {
79  //BIASERR("Not a covariance matrix, forcing symmetry!! " << *this);
80  //BIASABORT;
82  }
83 }
84 
87 {}
88 
91 {
92  if (!p.IsAtInfinity()){
93  // the jacobian of the Homogenize() function
94  // 1/w 0 0 -x/w^2
95  // 0 1/w 0 -y/w^2
96  // 0 0 1/w -z/w^2
97  // 0 0 0 0
99  J[0][0] = J[1][1] = J[2][2] = 1.0/p[3];
100  J[0][3] = -p[0]/p[3]/p[3];
101  J[1][3] = -p[1]/p[3]/p[3];
102  J[2][3] = -p[2]/p[3]/p[3];
103  // the covariance transforms as J * cov * J^T
104  *this = J * *this * J.Transpose();
105  p.Homogenize();
106  } else {
107  cout << __FILE__<<":"<<__LINE__<<" p "<<p<<" at infinity, doing nothing\n";
108  }
109 }
110 
111 
113 GetEuclidean() const
114 {
115  if (!IsHomogenized()){
116  BEXCEPTION("euclidean cov matrices can only be returned when homogenized");
117  }
118  Matrix3x3<double> res;
119  res[0][0] = (*this)[0][0];
120  res[0][1] = (*this)[0][1];
121  res[0][2] = (*this)[0][2];
122  res[1][0] = (*this)[1][0];
123  res[1][1] = (*this)[1][1];
124  res[1][2] = (*this)[1][2];
125  res[2][0] = (*this)[2][0];
126  res[2][1] = (*this)[2][1];
127  res[2][2] = (*this)[2][2];
128  return res;
129 }
130 
131 
132 void HomgPoint3DCov::
134 {
135  SetZero();
136  (*this)[0][0] = m[0][0];
137  (*this)[0][1] = m[0][1];
138  (*this)[0][2] = m[0][2];
139  (*this)[1][0] = m[1][0];
140  (*this)[1][1] = m[1][1];
141  (*this)[1][2] = m[1][2];
142  (*this)[2][0] = m[2][0];
143  (*this)[2][1] = m[2][1];
144  (*this)[2][2] = m[2][2];
145  if (!CheckSymmetry_()){
146  // BIASERR("not a covariance matrix, forcing symmetry!! "<<*this);
147  MakeSymmetric_();
148  }
149 }
bool CheckSymmetry_() const
MatrixInitType
can be passed to matrix constructors to init the matrix with the most often used values ...
Definition: Matrix.hh:59
void Homogenize()
homogenize class data member elements to W==1 by divison by W
Definition: HomgPoint3D.hh:308
void SetZero()
Sets all values to zero.
Matrix4x4 Transpose() const
Definition: Matrix4x4.hh:315
Matrix3x3< double > GetEuclidean() const
bool IsAtInfinity() const
Definition: HomgPoint3D.hh:398
class HomgPoint3D describes a point with 3 degrees of freedom in projective coordinates.
Definition: HomgPoint3D.hh:61
void SetEuclidean(const Matrix3x3< double > &m)
is a &#39;fixed size&#39; quadratic matrix of dim.
Definition: Matrix4x4.hh:54
bool IsHomogenized() const
void Homogenize(HomgPoint3D &p)
homogenizes p and *this