Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
TrifocalTensorBase.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 "TrifocalTensorBase.hh"
27 
28 using namespace BIAS;
29 using namespace std;
30 
32  : Tensor3D3x3x3<double>()
33 {}
34 
36  : Tensor3D3x3x3<double>(t)
37 {}
38 
40 {}
41 
42 
44 {
46  GetMatrices(T1,T2,T3);
47  cout << "TRIFOCAL TENSOR [T1,T2,T3]: " << endl;
48  cout << " T1 = " << T1 << endl;
49  cout << " T2 = " << T2 << endl;
50  cout << " T3 = " << T3 << endl;
51 }
52 
53 
55  RMatrixBase& R3,
57  Vector3<double>& C3)
58 {
59  RMatrixBase R2n, R3n, R1i;
60  Vector3<double> C2n, C3n;
61  R1i=R1.Transpose();
62  R1i.Mult(R2, R2n); // R2n = R1i * R2
63  R1i.Mult(R3, R3n); // R3n = R1i * R3
64  R1i.Mult((C2 - C1), C2n); // C2n = R1i * (C2 - C1)
65  R1i.Mult((C3 - C1), C3n); // C3n = R1i * (C3 - C1)
66  Compose(R2n, R3n, C2n, C3n);
67 }
68 
69 void
71  HomgPoint3D& C1, HomgPoint3D& C2, HomgPoint3D& C3)
72 {
73  Vector3<double> c1, c2, c3;
74  C1.GetEuclidean(c1);
75  C2.GetEuclidean(c2);
76  C3.GetEuclidean(c3);
77  Compose(R1, R2, R3, c1, c2, c3);
78 }
79 
82 {
83  // see Hartley Zissermann, second edition p 367, (eq 15.1)
84 
85  //cerr << "composition from : "<<R2<<"\n"<<R3<<"\n"<<C2<<"\n"<<C3<<endl;
86  Matrix3x3<double> T1, T2, T3, M;
87  Vector3<double> a1, a2, a3, b1, b2, b3, RC2, RC3;
88  R2.GetRow(0, a1); // a1=R2.GetRow(0);
89  R2.GetRow(1, a2); // a2=R2.GetRow(1);
90  R2.GetRow(2, a3); // a3=R2.GetRow(2);
91  R3.GetRow(0, b1); // b1=R3.GetRow(0);
92  R3.GetRow(1, b2); // b2=R3.GetRow(1);
93  R3.GetRow(2, b3); // b3=R3.GetRow(2);
94 
95  R2.Transpose().Mult(C2, RC2); //RC2=R2.Transpose()*C2;
96  R3.Transpose().Mult(C3, RC3); //RC3=R3.Transpose()*C3;
97  //T1=a1.OuterProduct(RC3) - RC2.OuterProduct(b1);
98  a1.OuterProduct(RC3, T1);
99  RC2.OuterProduct(b1, M);
100  T1-=M;
101  //T2=a2.OuterProduct(RC3) - RC2.OuterProduct(b2);
102  a2.OuterProduct(RC3, T2);
103  RC2.OuterProduct(b2, M);
104  T2-=M;
105  //T3=a3.OuterProduct(RC3) - RC2.OuterProduct(b3);
106  a3.OuterProduct(RC3, T3);
107  RC2.OuterProduct(b3, M);
108  T3-=M;
109 
110  SetFromMatrices(T1, T2, T3);
111 }
112 
113 void
115  HomgPoint3D& C2, HomgPoint3D& C3)
116 {
117  Vector3<double> c2, c3;
118  C2.GetEuclidean(c2);
119  C3.GetEuclidean(c3);
120  Compose(R2, R3, c2, c3);
121 }
122 
123 
125  HomgPoint2D& p3,
126  Matrix3x3<double>& res)
127 {
128  // aequivalent to:
129  // Matrix3x3<double> p2x, p3x, T1, T2, T3;
130  // GetMatrices(T1, T2, T3);
131  // p2x.SetAsCrossProductMatrix(p2);
132  // p3x.SetAsCrossProductMatrix(p3);
133  // res = p2x * ((p1[0] * T1)+(p1[1] * T2)+(p1[2] * T3)) * p3x;
134  HomgPoint2D x1 = p1;
135  HomgPoint2D x2 = p2;
136  HomgPoint2D x3 = p3;
137 
138  x1.Normalize();
139  x2.Normalize();
140  x3.Normalize();
141 
142  Matrix3x3<double> p2x, p3x, cont, tmp;
143  p2x.SetAsCrossProductMatrix(x2);
144  p3x.SetAsCrossProductMatrix(x3);
146  p2x.Mult(cont, tmp);
147  tmp.Mult(p3x, res);
148 }
149 
151 {
153  return *this;
154 }
155 
void GetRow(const unsigned int row, Vector3< T > &r) const
extract one row (&#39;Zeile&#39;) from ths matrix (for convenience)
Definition: Matrix3x3.cpp:287
void GetEuclidean(Vector3< HOMGPOINT3D_TYPE > &dest) const
calculate affine coordinates of this and write them to dest affine coordinates are projective coordin...
Definition: HomgPoint3D.hh:336
class HomgPoint2D describes a point with 2 degrees of freedom in projective coordinates.
Definition: HomgPoint2D.hh:67
TrifocalTensorBase & operator=(const TrifocalTensorBase &t)
void OuterProduct(const Vector3< T > &v, Matrix3x3< T > &res) const
outer product, constructs a matrix.
Definition: Vector3.cpp:151
Tensor3D3x3x3< T > & operator=(const Tensor3D3x3x3< T > &t)
void LeftContravariantContraction1(Vector3< TRIFOCALTENSOR_TYPE > &v, Matrix3x3< TRIFOCALTENSOR_TYPE > &res)
computes the contraction of index 1 from left with contravariant vector , i.e.
void Mult(const Vector3< T > &argvec, Vector3< T > &destvec) const
matrix - vector multiplicate this matrix with Vector3, storing the result in destvec calculates: dest...
Definition: Matrix3x3.hh:302
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
Matrix3x3< T > Transpose() const
returns transposed matrix tested 12.06.2002
Definition: Matrix3x3.cpp:167
void GetMatrices(Matrix3x3< TRIFOCALTENSOR_TYPE > &T1, Matrix3x3< TRIFOCALTENSOR_TYPE > &T2, Matrix3x3< TRIFOCALTENSOR_TYPE > &T3) const
Implements a 3D rotation matrix.
Definition: RMatrixBase.hh:44
void SetFromMatrices(const Matrix3x3< TRIFOCALTENSOR_TYPE > &T1, const Matrix3x3< TRIFOCALTENSOR_TYPE > &T2, const Matrix3x3< TRIFOCALTENSOR_TYPE > &T3)
void SetAsCrossProductMatrix(const Vector3< T > &vec)
Sets matrix from vector as cross product matrix of this vector.
Definition: Matrix3x3.cpp:275
void CheckPointCorr(HomgPoint2D &p1, HomgPoint2D &p2, HomgPoint2D &p3, Matrix3x3< double > &res)
Vector3< T > & Normalize()
normalize this vector to length 1
Definition: Vector3.hh:663
void Compose(RMatrixBase &R1, RMatrixBase &R2, RMatrixBase &R3, Vector3< double > &C1, Vector3< double > &C2, Vector3< double > &C3)
composition for &quot;normalized&quot; (with K^-1) image points