26 #ifndef __BIAS_PMatrix_hh__
27 #define __BIAS_PMatrix_hh__
28 #include "bias_config.h"
30 #include <Base/Common/BIASpragmaStart.hh>
33 #include <Base/Debug/Debug.hh>
35 # include <Base/Common/XMLBase.hh>
37 #include <Base/Geometry/PMatrixBase.hh>
39 #include <Base/Geometry/HomgLine2D.hh>
40 #include <Base/Geometry/HomgPlane3D.hh>
41 #include <Base/Geometry/HomgPoint3D.hh>
42 #include <MathAlgo/SVD.hh>
43 #include <Base/Geometry/KMatrix.hh>
96 { Svd_ = NULL; InvalidateDecomposition(); };
99 :
PMatrixBase(i) { Svd_ = NULL; InvalidateDecomposition(); };
104 explicit PMatrix(
const std::string & s);
108 { Svd_=NULL; operator=(A); }
114 { Svd_ = NULL; InvalidateDecomposition(); };
128 Svd_ = NULL; Compose(K, R, C); }
139 PMatrix& newsize(
int rows,
int cols);
162 {
if (!IsDecomposed_ )
if (Decompose_() != 0)
163 BIASERR(
"error decomposing");
return R_; };
169 {
if (!IsDecomposed_ )
if (Decompose_() != 0)
170 BIASERR(
"error decomposing");
return K_; };
199 return ((X-GetC()).ScalarProduct(GetA())>0.0);
239 inline void InvalidateDecomposition();
254 enum E_ParametrizationType param_type);
276 void BackprojectWorldCoo(
const HomgPoint2D& point,
double depth,
282 void BackprojectByZDepth(
const double& x,
284 const double& z_depth,
303 int WriteCAHV_10(
int cols,
int rows, std::ostream &os=std::cout);
322 float GetFieldOfView(
const unsigned int dimX,
323 const unsigned int dimY,
324 const bool optmin=
true);
332 float GetFieldOfViewY(
const unsigned int dimX,
const unsigned int dimY,
333 const bool & compY=
true);
337 {
return GetFieldOfViewY(dimX, dimY,
false);}
348 bool Load(
const std::string & filename){
350 InvalidateDecomposition();
355 bool Save(
const std::string & filename);
371 inline void Normalize();
380 int LoadBBC(
const std::string &filename,
381 const double& AddCenterPointShiftX = 0.0,
382 const double& AddCenterPointShiftY = 0.0);
388 int BBCIn(std::ifstream &ifs,
389 const double& AddCenterPointShiftX = 0.0,
390 const double& AddCenterPointShiftY = 0.0);
392 #ifdef BIAS_HAVE_XML2
394 virtual int XMLGetClassName(std::string& TopLevelTag,
395 double& Version)
const;
398 virtual int XMLOut(
const xmlNodePtr Node,
XMLIO& XMLObject)
const;
401 virtual int XMLIn(
const xmlNodePtr Node,
XMLIO& XMLObject);
406 Covariance_ = cov;
return 0;}
409 cov = Covariance_ ;
return 0;}
412 double GetProjectionError(
const std::vector<BIAS::HomgPoint2D>& points2D,
const std::vector<BIAS::HomgPoint3D>& points3D);
439 inline int MakeSVD_();
442 inline void CheckSVD_();
445 inline void CheckDecomposition_();
517 for(
unsigned int i=0; i < 3; i++){
518 for(
unsigned int j=0; j < 3; j++){
519 M[i][j] = (*this)[i][j];
522 bool changedSign =
false;
529 const PMATRIX_TYPE* pLastRow =
row_[2];
530 (*this) /= sqrt(pLastRow[0]*pLastRow[0] +
531 pLastRow[1]*pLastRow[1] + pLastRow[2]*pLastRow[2]);
568 (
void*)
GetData(),12*
sizeof(double))) {
569 BIASERR(
"Tried to access cached decomp.(outdated) for changed PMatrix! "
570 <<
"You have to invalidate after changing PMatrix! Aborting.");
580 (
void*)
GetData(),12*
sizeof(double))) {
581 BIASERR(
"Tried to access cached(outdated) svd for changed PMatrix ! "
582 <<
"You have to invalidate after changing PMatrix! Aborting.");
592 #include <Base/Common/BIASpragmaEnd.hh>
Matrix3x4< double > PConsistencyBackup_
backup of P at time of last decomposition to check whether decomposition is still valid ...
bool IsDecomposed_
tells us whether we have a chached decomposition with C,A,...
KMatrix K_
camera calibration matrix (intrinsic parameter)
MatrixInitType
can be passed to matrix constructors to init the matrix with the most often used values ...
class HomgPoint2D describes a point with 2 degrees of freedom in projective coordinates.
computes and holds the singular value decomposition of a rectangular (not necessarily quadratic) Matr...
PMatrix(const MatrixInitType &i)
bool Load(const std::string &filename)
overload Load because it has to invalidate decomposition! JW 09/2003
void Fill(const T &scalar)
Takes the elements of a Vector and put them as diagonal elements into a matrix.
void CheckSVD_()
check if SVD is still valid
float GetFieldOfViewX(const unsigned int dimX, const unsigned int dimY)
Vector3< double > V0_
unit vector in wcs assigning the direction of the vertical axis of the image plane ...
Matrix3x3< double > R_
rotation matrix (intrinsic parameter)
Matrix< double > Covariance_
BIAS::Vector3< T > GetNormalized() const
return a normalized vector of this
PMatrix(const PMatrixBase &Amat_)
SVD * Svd_
(for decomposition, docu: JW 11/2002)
Matrix3x3< double > GetR()
Wrapper class for reading and writing XML files based on the XML library libxml2. ...
bool Load(const std::string &filename)
method to load directly from a given filename.
void InvalidateDecomposition()
to re-Decompose_() after filling with data use this.
a line l = (a b c)^T is a form of the implicit straight line equation 0 = a*x + b*y + c if homogenize...
BIAS::Vector3< double > GetUp_gl()
T * GetData()
get the pointer to the data array of the matrix (for faster direct memeory access) ...
class BIASGeometry_EXPORT PMatrix
is a 'fixed size' quadratic matrix of dim.
Base class with interface for xml output.
class HomgPoint3D describes a point with 3 degrees of freedom in projective coordinates.
describes a projective 3D -> 2D mapping in homogenous coordinates
int GetIntersectionOfImagePlanes(PMatrix &P, HomgLine2D &intersection)
return line resulting of intersection of the two image planes in pixel coordinates of this camera ret...
class Vector3 contains a Vector of fixed dim.
void MultiplyIP(const PMATRIX_TYPE &scalar)
in place multiplication function
K describes the mapping from world coordinates (wcs) to pixel coordinates (pcs).
T GetDeterminant() const
returns the Determinant |A| of this
Vector3< double > C_
camera center in wcs (extrinsic parameter)
bool IsInFrontOfCamera(const Vector3< double > &X)
checks whether X is in optical A-dir from C (only for metric cameras)
Matrix3x4< double > PConsistencyBackupSVD_
Vector3< double > A_
unit vector in wcs assigning the direction of the optical axis
bool IsMetric_
tells us whether we have an arbitrary 3x4 matrix or a P which is exactly a composition of P = K * R [...
int SetCovariance(const BIAS::Matrix< double > &cov)
describes a projective 3D -> 2D mapping in homogenous coordinates
PMatrix(const Matrix3x3< PMATRIX_TYPE > &K, const Matrix3x3< PMATRIX_TYPE > &R, const Vector3< PMATRIX_TYPE > &C)
Take R, K, C and compose PMatrix.
int GetCovariance(BIAS::Matrix< double > &cov)
void CheckDecomposition_()
check if Decomposition is still valid
PMatrix(const PMatrix &A)
Vector3< double > H0_
unit vector in wcs assigning the direction of the horizontal axis of the image plane ...
int compute(const Matrix< double > &M, double ZeroThreshold=DEFAULT_DOUBLE_ZERO_THRESHOLD)
use our naming convention
void Normalize()
scale P such that optical axis (first three entries of last row) has unit length
Matrix3x3< double > Hinf_
Hinfinity.
A homogeneous plane (in P^3) All points X on the plane p fulfill p ' * X = 0.