Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
TriangulationMidPoint.hh
1 #ifndef __TriangulationMidPoint_hh__
2 #define __TriangulationMidPoint_hh__
3 
4 
5 #include <Base/Debug/Debug.hh>
6 #include <Base/Geometry/HomgPoint2D.hh>
7 #include <Base/Geometry/PoseParametrization.hh>
8 #include <Base/Math/Vector3.hh>
9 #include <Geometry/ProjectionParametersBase.hh>
10 #include <vector>
11 
12 namespace BIAS
13 {
14 
15  /** @class TriangulationMidPoint
16  @ingroup g_MultiView
17 
18  @brief Class for triangulation of 3d points from multiple projection
19  rays using the mid-point method.
20 
21  Given n projection rays (parametrized by camera center points
22  C_1,...,C_n and normalized direction vectors d_1,...,d_n in
23  world coordinate system), the corresponding 3d point X is
24  computed by the mid-point method as the point with minimal
25  mean squared distance to all rays, i.e. minimize sum of
26  |C_i + l_i*d_i - X|^2 with respect to parameters X,l_1,...,l_n.
27 
28  Note that this method is neither affine nor projective
29  invariant and behaves very poorly under such transformations,
30  it should be used only with Euclidean transformations.
31 
32  See also R. I. Hartley, P. Sturm: Triangulation, in: Computer
33  Vision and Image Understanding 68 (2), p.146--157, 1997.
34 
35  @author esquivel 09/2010
36  */
37  class BIASGeometry_EXPORT TriangulationMidPoint : public BIAS::Debug
38  {
39  public:
40 
42 
44 
45  /** @brief Return point X that is closest in average to given rays
46  which have parametric description by point and direction.
47  @attention Directions MUST BE normalized!
48  @return 0 in case of no errror, <0 if errors, n>0 if intersection
49  point lies not in direction of n-th ray.
50  */
51  inline int Intersect(const std::vector< BIAS::Vector3<double> >& pos,
52  const std::vector< BIAS::Vector3<double> >& dir,
54  {
55  double dist;
56  return Intersect_(pos, dir, res, dist, false);
57  };
58 
59  /** @brief Return point X that is closest in average to given rays
60  which have parametric description by point and direction.
61  Average distance to rays is returned in parameter dist.
62  @attention Directions MUST BE normalized!
63  @return 0 in case of no errror, <0 if errors, n>0 if intersection
64  point lies not in direction of n-th ray.
65  */
66  inline int Intersect(const std::vector< BIAS::Vector3<double> >& pos,
67  const std::vector< BIAS::Vector3<double> >& dir,
68  BIAS::Vector3<double>& res, double& dist)
69  {
70  return Intersect_(pos, dir, res, dist, true);
71  };
72 
73  /** @brief Return point X that is closest in average to given rays
74  which have parametric description by point and direction.
75  @attention Directions MUST BE normalized!
76  @return 0 in case of no errror, <0 if errors, n>0 if intersection
77  point lies not in direction of n-th ray.
78  */
80  const std::vector< BIAS::Vector3<double> >& pos,
81  const std::vector< BIAS::Vector3<double> >& dir)
82  {
83  double dist;
85  if (Intersect_(pos, dir, res, dist, false) >= 0)
86  return res;
87  else
88  return BIAS::Vector3<double>(0,0,0);
89  };
90 
91  /** @brief Triangulate 3d point X from projection parameters and
92  corresponding 2d image points (in pixels).
93  @attention 2d image points MUST BE homogenized!
94  @return 0 on success, <0 on error, n>0 if point is behind n-th camera
95  */
96  inline int Triangulate(const std::vector< BIAS::ProjectionParametersBase* >& cams,
97  const std::vector< BIAS::HomgPoint2D >& points2d,
98  BIAS::Vector3<double>& point3d, double& dist)
99  {
100  return Triangulate_(cams, points2d, point3d, dist, true);
101  };
102 
103  inline int Triangulate(const std::vector< BIAS::ProjectionParametersBase* >& cams,
104  const std::vector< BIAS::HomgPoint2D >& points2d,
105  BIAS::Vector3<double>& point3d)
106  {
107  double dist;
108  return Triangulate_(cams, points2d, point3d, dist, false);
109  };
110 
111  /** @brief Triangulate 3d point X from camera poses and corresponding
112  rays in local (!) camera coordinate frames ("normalized").
113  @attention Directions of rays MUST BE normalized!
114  @return 0 on success, <0 on error, n>0 if point is behind n-th camera
115  */
116  inline int Triangulate(const std::vector< BIAS::PoseParametrization >& poses,
117  const std::vector< BIAS::HomgPoint2D >& rays,
118  BIAS::Vector3<double>& point3d, double& dist)
119  {
120  return Triangulate_(poses, rays, point3d, dist, true);
121  };
122 
123  inline int Triangulate(const std::vector< BIAS::PoseParametrization >& poses,
124  const std::vector< BIAS::HomgPoint2D >& rays,
125  BIAS::Vector3<double>& point3d)
126  {
127  double dist;
128  return Triangulate_(poses, rays, point3d, dist, false);
129  };
130 
131  protected:
132 
133  int Intersect_(const std::vector< BIAS::Vector3<double> >& pos,
134  const std::vector< BIAS::Vector3<double> >& dir,
135  BIAS::Vector3<double>& res, double& dist,
136  const bool computeDist);
137 
138  int Triangulate_(const std::vector< BIAS::ProjectionParametersBase* >& cams,
139  const std::vector< BIAS::HomgPoint2D >& points2d,
140  BIAS::Vector3<double>& point3d, double& dist,
141  const bool computeDist);
142 
143  int Triangulate_(const std::vector< BIAS::PoseParametrization >& poses,
144  const std::vector< BIAS::HomgPoint2D >& rays,
145  BIAS::Vector3<double>& point3d, double& dist,
146  const bool computeDist);
147 
148  }; // class
149 
150 } // namespace
151 
152 #endif // __TriangulationMidPoint_hh__
int Triangulate(const std::vector< BIAS::PoseParametrization > &poses, const std::vector< BIAS::HomgPoint2D > &rays, BIAS::Vector3< double > &point3d, double &dist)
Triangulate 3d point X from camera poses and corresponding rays in local (!) camera coordinate frames...
int Intersect(const std::vector< BIAS::Vector3< double > > &pos, const std::vector< BIAS::Vector3< double > > &dir, BIAS::Vector3< double > &res)
Return point X that is closest in average to given rays which have parametric description by point an...
int Triangulate(const std::vector< BIAS::ProjectionParametersBase * > &cams, const std::vector< BIAS::HomgPoint2D > &points2d, BIAS::Vector3< double > &point3d)
int Triangulate(const std::vector< BIAS::ProjectionParametersBase * > &cams, const std::vector< BIAS::HomgPoint2D > &points2d, BIAS::Vector3< double > &point3d, double &dist)
Triangulate 3d point X from projection parameters and corresponding 2d image points (in pixels)...
int Intersect(const std::vector< BIAS::Vector3< double > > &pos, const std::vector< BIAS::Vector3< double > > &dir, BIAS::Vector3< double > &res, double &dist)
Return point X that is closest in average to given rays which have parametric description by point an...
int Triangulate(const std::vector< BIAS::PoseParametrization > &poses, const std::vector< BIAS::HomgPoint2D > &rays, BIAS::Vector3< double > &point3d)
Class for triangulation of 3d points from multiple projection rays using the mid-point method...
BIAS::Vector3< double > Intersect(const std::vector< BIAS::Vector3< double > > &pos, const std::vector< BIAS::Vector3< double > > &dir)
Return point X that is closest in average to given rays which have parametric description by point an...