Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
ProjectionParametersGreatCircles.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_ProjectionParametersGreatCircles_hh__
27 #define __BIAS_ProjectionParametersGreatCircles_hh__
28 #include "bias_config.h"
29 
30 #include <Base/Common/BIASpragmaStart.hh>
31 #include <Geometry/ProjectionParametersBase.hh>
32 #include <Base/Geometry/KMatrix.hh>
33 #include <Geometry/PMatrix.hh>
34 #include <Base/Common/CompareFloatingPoint.hh>
35 #include <iostream>
36 
37 namespace BIAS {
38 
39  /** \class ProjectionParametersGreatCircles
40  * \ingroup g_geometry
41  * \brief spherical camera that samples along big circles containig the H
42  * vector. Sampling is done along spherical coordinates e.g.
43  * along phi and theta.
44  * Theta is mapped to the x-component and phi is mapped to the
45  * y-component of the corresponding image.
46  *
47  * Projection was originaly desigened for the purpose of
48  * image rectification.
49  *
50  * \author bartczak
51  */
52  class BIASGeometry_EXPORT ProjectionParametersGreatCircles
53  : public ProjectionParametersBase {
54  public:
55 
56  ProjectionParametersGreatCircles(const unsigned int width = 0,
57  const unsigned int height = 0)
58  : ProjectionParametersBase(width, height), focallengthTheta_(1.0)
59  {
60  // set default internals
61  SetInternals(-M_PI, M_PI, 0, M_PI, width, height);
62  }
63 
65  {
66  *this = P;
67  };
68 
70  operator=(const ProjectionParametersGreatCircles& P);
71 
73 
74  virtual const bool DoIntrinsicsDiffer(const ProjectionParametersBase* p)
75  const;
76 
77 
78  bool DoesPointProjectIntoImageLocal(const Vector3<double>& localX,
79  HomgPoint2D& x,
80  bool IgnoreDistortion = false) const;
81 
82 
83 
84  /** Determines angle intervalls for the camera from viewing cone.
85  * The viewing cone is defined through the optical ray passing through the
86  * given worlPoint functioning as cone axis. The halfAngleRange defines
87  * the opening angle of the cone. The calculated parameters are chosen
88  * so that the whole viewing cone projects into the image. Yet no minimal
89  * solution is sought!! The resulting ranges lie within
90  * [thetaMin, thetaMax] in [0, M_PI] and
91  * [phiMin, phiMax] in [-M_PI, M_PI]!
92  *
93  * \author bartczak 08/2007
94  **/
95  bool GetAngleInterval(const HomgPoint3D& worldPoint,
96  const double halfAngleRange,
97  double& thetaMin, double& thetaMax,
98  double& phiMin, double& phiMax) const;
99 
100 
101  virtual bool Distort(BIAS::HomgPoint2D& point2d) const;
102 
103  virtual bool Undistort(BIAS::HomgPoint2D& point2d) const;
104 
105 
106  /** Sets viewing volume of camera using GetAngleInterval().
107  * width_ and height_ are kept!
108  */
109  bool SetAngleInterval(const HomgPoint3D& worldPoint,
110  const double& halfAngleRange);
111 
112  /** @brief calculates the projection of a point
113  in the camera coordinate system
114  to a pixel in the image plane of the camera
115  with lens distortion
116  In the simplest case perspective pinhole projection x = K * y
117  where y is the projection of X using y = (R^T | -R^T C) X
118  */
119  virtual HomgPoint2D ProjectLocal(const Vector3<double>& point,
120  bool IgnoreDistortion = false) const;
121 
122  /** @brief calculates the projection of a point in the local camera
123  coordinate system to a pixel in the image plane of the camera. The
124  only case when this function may not compute the 2d point is when the
125  camera center and the 3d point coincide. This case must be indicated
126  by a negative return value. In all other cases, a 2d point must be
127  computed, *particularily* when the 3d point is behind the camera
128  or when the resulting 2d point is at infinity.
129 
130  In the simplest case perspective pinhole projection x = K * point
131  where point is transformed of X using point = (R^T | -R^T C) X
132  @author woelk 08/2008 (c) www.vision-n.de */
133  virtual int ProjectLocal(const Vector3<double>& point, HomgPoint2D &p2d,
134  bool IgnoreDistortion = false) const;
135 
136  /** @brief map points from image onto unit diameter image plane in 3D.
137  * Chosen is the image plane with distance of one from the image center.
138  */
139  HomgPoint3D UnProjectToImagePlane(const HomgPoint2D& pos,
140  const double& depth = 1.0,
141  bool IgnoreDistortion = false) const;
142 
143 
144  /** @brief calculates the viewing ray from the camera center (in the
145  camera coordinate system) which belongs to the image position pos
146  with lens distortion
147  e.g. (0,0,1) means optical axis
148  */
149  virtual void UnProjectLocal(const HomgPoint2D& pos, Vector3<double>& pointOnRay,
150  Vector3<double>& direction, bool ignoreDistortion = false)const;
151 
152 
153  /** @brief covariant virtual copy constructor for use in Projection */
155  return new ProjectionParametersGreatCircles(*this);
156  }
157 
158  /** \attention off set is being ignored - just for interface purposes
159  *
160  */
161  virtual void Rescale(double ratio, const double offset = 0.0);
162 
163  virtual void Rescale(unsigned int width, unsigned int height);
164 
165 #ifdef BIAS_HAVE_XML2
166  /** @brief specialization of XML block name function */
167  virtual int XMLGetClassName(std::string& TopLevelTag,
168  double& Version) const;
169 
170  /** @brief specialization of XML write function */
171  virtual int XMLOut(const xmlNodePtr Node, XMLIO& XMLObject) const;
172 
173  /** @brief specialization of XML read function */
174  virtual int XMLIn(const xmlNodePtr Node, XMLIO& XMLObject);
175 #endif
176 
177  /** Calculate spherical angles from local 3D point.
178  * \param euc coordinates in the local camera coordinate frame.
179  * \returns phi angle around the H axis, zero lies at direction of A
180  * and value range is [-pi, pi].
181  * \returns theta angle within plane containing H relative to \b -H,
182  * value range is [0,pi]
183  *
184  * \returns true if a direction could be calculated, else false.
185  * \author bartczak 08/2007
186  **/
187  static bool LocalEuclideanCamCoordinates2SphericalAngles(
188  const BIAS::Vector3<double>& euc, double& phi, double& theta);
189 
190  /// deprecated version
192  const BIAS::Vector3<double>& euc, double& phi, double& theta) {
193  return LocalEuclideanCamCoordinates2SphericalAngles(euc, phi, theta);
194  };
195 
196 
197  /** Calculate euclidean ray direction in local camera frame from
198  * angles
199  * \returns ray ray direction in the local camera coordinate frame.
200  * \param phi angle around the H axis, zero lies at direction of A
201  * and value range is [-pi, pi].
202  * \params theta angle within plane containing H relative to \b -H,
203  * value range is [0,pi]
204  *
205  * \returns true if given angles allow for unique ray reconstruction.
206  * \author bartczak 08/2007
207  **/
208  static bool SphericalAngles2LocalEuclideanRay(
209  const double phi, const double theta, BIAS::Vector3<double>& ray);
210 
211  /// deprecated version
213  const double phi, const double theta, BIAS::Vector3<double>& ray) {
214  return SphericalAngles2LocalEuclideanRay(phi, theta, ray);
215  };
216 
217  /** Calculates image coordinates from local angle vectors.
218  * See LocalEuclideanCamCoordinates2SphericalAngles().
219  * \author bartczak 08/2007
220  **/
221  void Angle2Image(double phi, double theta,
222  BIAS::HomgPoint2D& imgPoint) const;
223 
224  /** Calculates local angle vectors from image coordinate.
225  * See LocalEuclideanCamCoordinates2SphericalAngles().
226  * \author bartczak 08/2007
227  **/
228  void Image2Angle(const BIAS::HomgPoint2D& imgPoint,
229  double& phi, double& theta) const;
230 
231  /** Calculates and sets internal camera parameters.
232  *
233  * Valid ranges for the parameters are
234  * [minPhi, maxPhi] in [-M_PI, M_PI] and
235  * [minTheta, maxTheta] in [0,M_PI].
236  *
237  * The behaviour of the camera outside this ranges is undefined.
238  *
239  * Of course all modulo M_PI ranges are valid but it is a nasty thing
240  * to work with. Learn how this camera works, before assuming that it is
241  * easy to handle arbitrary ranges for this parameters.
242  *
243  * \author bartczak 08/2007
244  **/
245  void SetInternals(const double minPhi, const double maxPhi,
246  const double minTheta, const double maxTheta,
247  const unsigned int imgWidth, const unsigned int imgHeight);
248 
249  double GetFocallengthTheta();
250 
251  friend std::ostream&
252  operator<<(std::ostream &os, const ProjectionParametersGreatCircles& p);
253 
254 
255  protected:
256  /** scale from angles to image*/
258 
259 
260  };
261 
262  inline std::ostream& operator<<(std::ostream &os,
264  {
265  os << "ProjectionParametersGreatCircles:" << std::endl;
266  os<<"pixel2AngleScale: theta = "<<p.focallengthTheta_;
267  os <<", phi = "<<p.aspectratio_*p.focallengthTheta_<<std::endl;
268  return os;
269  }
270 
271 
272 
273 } // end namespace
274 
275 
276 #include <Base/Common/BIASpragmaEnd.hh>
277 
278 #endif
279 
class HomgPoint2D describes a point with 2 degrees of freedom in projective coordinates.
Definition: HomgPoint2D.hh:67
ProjectionParametersGreatCircles(const unsigned int width=0, const unsigned int height=0)
virtual ProjectionParametersGreatCircles * Clone() const
covariant virtual copy constructor for use in Projection
Down-, Upsampling routines and Resize.
Definition: Rescale.hh:71
spherical camera that samples along big circles containig the H vector.
static bool LocalEuclidianCamCoordinates2SphericalAngles(const BIAS::Vector3< double > &euc, double &phi, double &theta)
deprecated version
Wrapper class for reading and writing XML files based on the XML library libxml2. ...
Definition: XMLIO.hh:72
static bool SphericalAngles2LocalEuclidianRay(const double phi, const double theta, BIAS::Vector3< double > &ray)
deprecated version
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
ProjectionParametersGreatCircles(const ProjectionParametersGreatCircles &P)
double aspectratio_
aspect ratio of the camera CCD
Camera parameters which define the mapping between rays in the camera coordinate system and pixels in...