Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
MatchDataBase.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 __MatchDataBase_hh__
27 #define __MatchDataBase_hh__
28 
29 #include <bias_config.h>
30 #include <Base/Debug/Debug.hh>
31 #include <Base/Geometry/HomgPoint2D.hh>
32 #include <Base/Geometry/HomgPoint3D.hh>
33 #include <Base/Geometry/KMatrix.hh>
34 #include <Base/Geometry/RMatrixBase.hh>
35 #include <Base/Geometry/PMatrixBase.hh>
36 #include <Utils/Param.hh>
37 
38 #define D_MD_IO 0x00000001
39 
40 namespace BIAS {
41 
42  /** @class MatchDataBase
43  @ingroup g_utils
44  @brief class for representing matches, used in GenSynthMatches and biasshowsm
45  @author woelk 2004 */
46  class BIASUtils_EXPORT MatchDataBase : public Debug
47  {
48  public:
49  MatchDataBase(Param &para);
50  virtual ~MatchDataBase();
51 
52  void Reset();
53 
54  void GetK(KMatrix& K) const;
55 
56  void GetR(int imNo, RMatrixBase& R) const;
57  void GetR(std::vector<RMatrixBase>& R) const;
58 
59  void GetC(int imNo, HomgPoint3D& C) const;
60  void GetC(std::vector<HomgPoint3D>& C) const;
61 
62  void GetP(int imNo, PMatrixBase& P) const;
63  void GetP(std::vector<PMatrixBase>& P) const;
64 
65  void GetPoints(int imNo, std::vector<HomgPoint2D>& p) const;
66  /// p[i][k] is point number k in image i
67  void GetPoints(std::vector<std::vector<HomgPoint2D> >& p) const;
68  /// same as GetPOints with inverted indices :
69  /// p[i][k] is point number i in image k
70  void GetCorrespondences(std::vector<std::vector<HomgPoint2D> >& p) const;
71 
72  void GetNormalizedPoints(int imNo, std::vector<HomgPoint2D>& p) const;
73  /// p[i][k] is point number k in image i
74  void GetNormalizedPoints(std::vector<std::vector<HomgPoint2D> >& p) const;
75  /// same as GetNormalizedPoints with inverted indices :
76  /// p[i][k] is point number i in image k
77  void GetNormalizedCorrespondences(std::vector<std::vector<HomgPoint2D> >& p) const;
78 
79 
80  void SetData(KMatrix& K, std::vector<RMatrixBase>& R,
81  std::vector<HomgPoint3D>& C,
82  std::vector<std::vector<HomgPoint2D> >& m);
83 
84  void SetNormalizedData(KMatrix& K, std::vector<RMatrixBase>& R,
85  std::vector<HomgPoint3D>& C,
86  std::vector<std::vector<HomgPoint2D> >& m);
87 
88  inline int GetNumImages() const
89  { return *_NumImages; }
90 
91  /// binary read
92  int Read(const std::string& fname);
93  /// binary read
94  virtual int Read(std::istream& is);
95 
96  /// binary write
97  int Write(const std::string& fname) const;
98  /// binary write
99  virtual int Write(std::ostream& os) const;
100 
101  friend BIASUtils_EXPORT std::ostream& operator<<(std::ostream& os, const MatchDataBase& m);
102 
103  friend BIASUtils_EXPORT std::istream& operator>>(std::istream& is, MatchDataBase& m);
104 
105  bool operator==(MatchDataBase& l);
106 
107  protected:
108  int *_NumImages, *_NumPoints;
109 
110  // internal calibration matrix
111  KMatrix _K, _Ki; // _Ki is inverse of _K
112  // vector of rotation matrizes of cameras
113  std::vector<RMatrixBase> _R;
114  // vector of camera centers
115  std::vector<HomgPoint3D> _C;
116  // vector of projection matrizes, composed from _K, _R[i] and _C[i]
117  std::vector<PMatrixBase> _P;
118 
119  // the generated match data
120  // _Points[k][i] is point number i in image k
121  std::vector<std::vector<HomgPoint2D> > _Points;
122  std::vector<std::vector<HomgPoint2D> > _NormalizedPoints;
123 
124  void _SetCamData(KMatrix& K, std::vector<RMatrixBase>& R,
125  std::vector<HomgPoint3D>& C);
126 
127  // fills all protected pointer values
128  virtual void _AddParameter(Param &para);
129 
130  inline void _Transpose(const std::vector<std::vector<HomgPoint2D> >& src,
131  std::vector<std::vector<HomgPoint2D> >& dst) const
132  {
133  const int numimg=(int)src.size();
134  if (numimg>0){
135  const int numpoints=(int)src[0].size();
136  dst.resize(numpoints);
137  for (int i=0; i<numpoints; i++){
138  dst[i].resize(numimg);
139  for (int k=0; k<numimg; k++){
140  dst[i][k]=src[k][i];
141  }
142  }
143  }
144  }
145 
146  }; // class
147 
148  BIASUtils_EXPORT std::ostream& operator<<(std::ostream& os, const MatchDataBase& m);
149 
150  BIASUtils_EXPORT std::istream& operator>>(std::istream& is, MatchDataBase& m);
151 
152 
153 
154 } // namespace
155 
156 
157 #endif // __MatchDataBase_hh__
std::vector< std::vector< HomgPoint2D > > _NormalizedPoints
std::vector< PMatrixBase > _P
void _Transpose(const std::vector< std::vector< HomgPoint2D > > &src, std::vector< std::vector< HomgPoint2D > > &dst) const
std::vector< RMatrixBase > _R
class for representing matches, used in GenSynthMatches and biasshowsm
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
std::ostream & operator<<(std::ostream &os, const Array2D< T > &arg)
Definition: Array2D.hh:260
This class Param provides generic support for parameters.
Definition: Param.hh:231
std::vector< HomgPoint3D > _C
std::vector< std::vector< HomgPoint2D > > _Points
K describes the mapping from world coordinates (wcs) to pixel coordinates (pcs).
Definition: KMatrix.hh:48
Implements a 3D rotation matrix.
Definition: RMatrixBase.hh:44
int GetNumImages() const
BIASCommon_EXPORT std::istream & operator>>(std::istream &is, BIAS::TimeStamp &ts)
Standard input operator for TimeStamps.
Definition: TimeStamp.cpp:157