Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
ProjectionParametersOrthographic.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 BIAS is free software; you can redistribute it and/or modify
10 it under the terms of the GNU Lesser General Public License as published by
11 the Free Software Foundation; either version 2.1 of the License, or
12 (at your option) any later version.
13 
14 BIAS is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU Lesser General Public License for more details.
18 
19 You should have received a copy of the GNU Lesser General Public License
20 along with BIAS; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 */
23 
24 #ifndef __BIAS_ProjectionParametersOrthographic_hh__
25 #define __BIAS_ProjectionParametersOrthographic_hh__
26 
27 #include <math.h>
28 
29 #include <bias_config.h>
30 #include <Base/Common/BIASpragmaStart.hh>
31 #include <Geometry/ProjectionParametersBase.hh>
32 
33 namespace BIAS {
34  /** @class ProjectionParametersOrthographic
35  * @ingroup g_geometry
36  * @brief Camera parameters which define the mapping between rays in the
37  * camera coordinate system and pixels in the image as well as external
38  * pose.
39  * @author Jung */
41  private:
43  public:
45  const unsigned int width=0, const unsigned int height=0,
46  const double dX=1, const double dY=1)
47  : PPB(width, height){
48  BIASASSERT(rayDir.NormL2() > 1e-7);
49  rayDir_ = rayDir.Normalize();
50  dX_ = dX;
51  dY_ = dY;
52  }
53 
54  void SetParameters(Vector3<double>&rayDir, const double dX, const double dY,
55  const unsigned int width, const unsigned int height){
56  BIASASSERT(rayDir.NormL2() > 1e-7);
57  rayDir_ = rayDir.Normalize();
58  dX_ = dX;
59  dY_ = dY;
60  width_ = width;
61  height_ = height;
62  }
63 
65  *this = P;
66  }
67 
69  PPB::operator=(P);
70  dX_ = P.dX_;
71  dY_ = P.dY_;
72  return *this;
73  }
74 
76 
77  virtual const bool DoIntrinsicsDiffer(const PPB *p) const;
78 
79  bool DoesPointProjectIntoImageLocal(const Vector3<double> &localP,
80  HomgPoint2D &p,
81  bool IgnoreDistortion = true) const;
82 
83  /** @brief map points from image onto unit diameter image plane in 3D.
84  * Chosen is the rectangular image plane with ray distance 1 from the camera center. */
85  HomgPoint3D UnProjectToImagePlane(const HomgPoint2D& pos,
86  const double& depth = 1.0, bool IgnoreDistortion = true) const;
87 
88  /** @brief calculates the projection of a point in the camera coordinate system
89  to a pixel in the image plane of the camera */
90  virtual HomgPoint2D ProjectLocal(const Vector3<double> &point,
91  bool IgnoreDistortion = true) const;
92 
93  /** @brief calculates the projection of a point in the local camera
94  coordinate system to a pixel in the image plane of the camera. */
95  virtual inline int ProjectLocal(const Vector3<double>& point, HomgPoint2D &p2d,
96  bool IgnoreDistortion = true) const{
97  p2d = ProjectLocal(point, IgnoreDistortion);
98  return 0;
99  }
100 
101  /** @brief covariant virtual copy constructor for use in Projection */
103  return new ProjectionParametersOrthographic(*this);
104  }
105 
106  /** @brief Calculates a 3D point in a local camera coordinate system
107  specified by camSystem, which belongs to the image position pos in
108  cam with distance depth to the camera center cam. */
110  const double &depth, bool IgnoreDistortion = true) const{
111  // Distortion is not implemented for orthographic projections!
112  BIASASSERT(IgnoreDistortion);
113  Vector3<double> res(rayDir_);
114  res.MultIP(depth);
115  res[0] += (pos[0]-principalX_)*dX_;
116  res[1] += (pos[1]-principalY_)*dY_;
117  return res;
118  }
119 
120  /** @brief calculates the direction of the viewing ray from the image plane,
121  shifted into the camera center (in the camera coordinate system). The origin is
122  the pixels position on the image plane, which is located in the camera center. */
123  virtual inline void UnProjectLocal(const HomgPoint2D &pos, Vector3<double>& origin,
124  Vector3<double>& direction,
125  bool ignoreDistortion = true) const{
126  // Distortion is not implemented for orthographic projections!
127  BIASASSERT(ignoreDistortion);
128  direction = rayDir_;
129  origin = Vector3<double>(pos[0], pos[1], 0.0);
130  }
131 
132  virtual bool Distort(HomgPoint2D& point2d) const;
133 
134  virtual bool Undistort(HomgPoint2D& point2d) const;
135 
136  virtual void Rescale(double ratio, const double offset = 0.0){
137  dX_ /= ratio;
138  dY_ /= ratio;
139  PPB::Rescale(ratio, offset);
140  }
141 
142  virtual void Rescale(unsigned int width, unsigned int height){
143  dX_ /= (double)width_/(double)width;
144  dY_ /= (double)height_/(double)height;
145  PPB::Rescale(width, height);
146  }
147 
148  friend std::ostream&
149  operator<<(std::ostream &os, const ProjectionParametersOrthographic& p);
150 
151 #ifdef BIAS_HAVE_XML2
152  /** @brief specialization of XML block name function */
153  virtual int XMLGetClassName(std::string &TopLevelTag, double &Version) const;
154 
155  /** @brief specialization of XML write function */
156  virtual int XMLOut(const xmlNodePtr Node, XMLIO &XMLObject) const;
157 
158  /** @brief specialization of XML read function */
159  virtual int XMLIn(const xmlNodePtr Node, XMLIO &XMLObject);
160 #endif
161 
162  protected:
163  double dX_;
164  double dY_;
166 };
167 
168 ///////// inline code ///////////////////
169 inline std::ostream& operator<<(std::ostream &os, const ProjectionParametersOrthographic& p){
170  os << "ProjectionParametersOrthographic:" << std::endl;
171  os << "- principalX_ = " << p.principalX_ << std::endl;
172  os << "- principalY_ = " << p.principalY_ << std::endl;
173  os << "- dX_ = " << p.dX_ << std::endl;
174  os << "- dY_ = " << p.dY_ << std::endl;
175  os << "- width_ = " << p.width_ << std::endl;
176  os << "- height_ = " << p.height_ << std::endl << std::endl;
177  return os;
178 }
179 } // end namespace
180 
181 #include <Base/Common/BIASpragmaEnd.hh>
182 
183 #endif
class HomgPoint2D describes a point with 2 degrees of freedom in projective coordinates.
Definition: HomgPoint2D.hh:67
virtual ProjectionParametersOrthographic * Clone() const
covariant virtual copy constructor for use in Projection
virtual void UnProjectLocal(const HomgPoint2D &pos, Vector3< double > &origin, Vector3< double > &direction, bool ignoreDistortion=true) const
calculates the direction of the viewing ray from the image plane, shifted into the camera center (in ...
ProjectionParametersOrthographic & operator=(const ProjectionParametersOrthographic &P)
virtual void Rescale(double ratio, const double offset=0.0)
Adapt internal parameters to resampled image.
Camera parameters which define the mapping between rays in the camera coordinate system and pixels in...
Wrapper class for reading and writing XML files based on the XML library libxml2. ...
Definition: XMLIO.hh:72
void SetParameters(Vector3< double > &rayDir, const double dX, const double dY, const unsigned int width, const unsigned int height)
unsigned int height_
height of image in pixels
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
virtual int ProjectLocal(const Vector3< double > &point, HomgPoint2D &p2d, bool IgnoreDistortion=true) const
calculates the projection of a point in the local camera coordinate system to a pixel in the image pl...
unsigned int width_
width of image in pixels
virtual Vector3< double > UnProjectToPointLocal(const HomgPoint2D &pos, const double &depth, bool IgnoreDistortion=true) const
Calculates a 3D point in a local camera coordinate system specified by camSystem, which belongs to th...
void MultIP(const T &scalar)
Definition: Vector3.hh:327
double principalX_
principal point in pixel coordinates (one for all zoom settings)
ProjectionParametersOrthographic(const ProjectionParametersOrthographic &P)
ProjectionParametersOrthographic(Vector3< double > &rayDir, const unsigned int width=0, const unsigned int height=0, const double dX=1, const double dY=1)
Camera parameters which define the mapping between rays in the camera coordinate system and pixels in...
Vector3< T > & Normalize()
normalize this vector to length 1
Definition: Vector3.hh:663
double NormL2() const
the L2 norm sqrt(a^2 + b^2 + c^2)
Definition: Vector3.hh:633
virtual void Rescale(unsigned int width, unsigned int height)
adapt internal parameters to new image size