Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
ProjectionParametersBufferedRay.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 __BIAS_ProjectionParametersBufferedRay_hh__
27 #define __BIAS_ProjectionParametersBufferedRay_hh__
28 #include "bias_config.h"
29 
30 #include <Base/Common/BIASpragmaStart.hh>
31 #include <Geometry/ProjectionParametersBase.hh>
32 #include <Geometry/ProjectionParametersPerspective.hh>
33 #include <MathAlgo/Interpolator.hh>
34 
35 namespace BIAS
36 {
37  /** @class ProjectionParametersBufferedRay
38  * @ingroup g_geometry
39  @brief This class maps image coords to rays which are buffered for fast lookup.
40  Buffering is only implemented for unProject, yet.
41 
42  The intended usage is:<br>
43  1. set up a projection that should be buffered with fixed intrinsics<br>
44  2. create an instance of PPRay class passing the projection in the constructor
45 
46  Every method that is not buffered is mapped to the genuine projection method.
47 
48  Todo:<br>
49  1. buffer Project<br>
50  2. linear interpolation between image positions (now: nearest)
51  @author djung
52  */
53  class BIASGeometry_EXPORT ProjectionParametersBufferedRay
55  {
56  public:
57 
59 
61 
63  {
64  if (ppb_) delete ppb_;
65  if (unprojectMappingIgnoreDistortion_)
66  delete[] unprojectMappingIgnoreDistortion_;
67  if (unprojectMappingDistortion_)
68  delete[] unprojectMappingDistortion_;
69  };
70 
71  virtual const bool DoIntrinsicsDiffer(const ProjectionParametersBase* p) const;
72 
73  virtual bool Distort(BIAS::HomgPoint2D& point2d) const;
74 
75  virtual bool Undistort(BIAS::HomgPoint2D& point2d) const;
76 
77  virtual HomgPoint2D ProjectLocal(const Vector3<double>& point,
78  bool IgnoreDistortion = false) const;
79 
80  virtual int ProjectLocal(const Vector3<double>& point,
81  HomgPoint2D &p2d, bool IgnoreDistortion = false) const;
82 
83  virtual HomgPoint3D UnProjectToImagePlane(const HomgPoint2D& pos,
84  const double& depth = 1.0,
85  bool IgnoreDistortion = false) const;
86 
87  virtual void UnProjectLocal(const HomgPoint2D& pos, Vector3<double>& origin,
88  Vector3<double>& direction,
89  bool IgnoreDistortion = false) const;
90 
92  {
93  return new ProjectionParametersBufferedRay(*this);
94  };
95 
96  virtual Vector3<double> UnProjectToPointLocal(const HomgPoint2D& pos,
97  const double& depth,
98  bool IgnoreDistortion = false) const;
99 
100 #ifdef BIAS_HAVE_XML2
101  /** @brief specialization of XML block name function */
102  virtual int XMLGetClassName(std::string& TopLevelTag, double& Version) const;
103 
104  /** @brief specialization of XML write function */
105  virtual int XMLOut(const xmlNodePtr Node, XMLIO& XMLObject) const;
106 
107  /** @brief specialization of XML read function */
108  virtual int XMLIn(const xmlNodePtr Node, XMLIO& XMLObject);
109 #endif
110 
111  friend std::ostream& operator<<(std::ostream &os,
113 
114  /** @brief Set mask flag and update buffered rays from wrapped
115  projection parameters. */
116  inline void SetMask(bool mask) { mask_ = mask; UpdateProjection_(); };
117 
118  /** @brief Set attributes of wrapped projection from attributes of this
119  ProjectionParametersBufferedRay instance.
120  @note Must be called explicitely when intrinsic parameters of
121  this projection have been modified! */
122  const inline bool UpdateProjection() { return UpdateProjection_(); };
123 
124  private:
125 
126  // due to const interface both options are buffered
127  Vector3<double> *unprojectMappingIgnoreDistortion_;
128  Vector3<double> *unprojectMappingDistortion_;
130  bool mask_;
131 
132  /** @brief Set attributes of wrapped projection from attributes of this
133  ProjectionParametersBufferedRay instance. */
134  const bool UpdateProjection_();
135 
136  /** @brief Set attributes of this ProjectionParametersBufferedRay
137  instance from attributes of wrapped projection (initialization). */
138  const bool UpdateFromProjection_();
139 
140  /** @brief Update buffered rays using wrapped projection parameters. */
141  const bool UpdateBuffer_();
142 
143  };
144 
145  inline std::ostream& operator<<(std::ostream &os,
147  {
148  os<<"ProjectionParametersRay:"<<std::endl;
149  return os;
150  }
151 
152 } // end namespace
153 
154 #include <Base/Common/BIASpragmaEnd.hh>
155 
156 #endif
This class maps image coords to rays which are buffered for fast lookup.
class HomgPoint2D describes a point with 2 degrees of freedom in projective coordinates.
Definition: HomgPoint2D.hh:67
const bool UpdateProjection()
Set attributes of wrapped projection from attributes of this ProjectionParametersBufferedRay instance...
void SetMask(bool mask)
Set mask flag and update buffered rays from wrapped projection parameters.
Wrapper class for reading and writing XML files based on the XML library libxml2. ...
Definition: XMLIO.hh:72
virtual ProjectionParametersBufferedRay * Clone() const
Covariant virtual copy constructor used in BIAS::Projection.
class HomgPoint3D describes a point with 3 degrees of freedom in projective coordinates.
Definition: HomgPoint3D.hh:61
std::ostream & operator<<(std::ostream &os, const Array2D< T > &arg)
Definition: Array2D.hh:260
Camera parameters which define the mapping between rays in the camera coordinate system and pixels in...