vpgl_affine_camera.h
Go to the documentation of this file.
1 // This is core/vpgl/vpgl_affine_camera.h
2 #ifndef vpgl_affine_camera_h_
3 #define vpgl_affine_camera_h_
4 //:
5 // \file
6 // \brief A class for the affine camera model.
7 // \author Thomas Pollard
8 // \date January 28, 2005
9 // \author Joseph Mundy, Matt Leotta, Vishal Jain
10 // \verbatim
11 // Modifications
12 // March 14, 2010 J.L. Mundy brought in virtual functions of proj_camera
13 // that require special treatment for the affine case. Added a default
14 // viewing distance to allow these methods to construct finite objects when
15 // the camera center is infinity.
16 // at infinity.
17 // \endverbatim
18 
19 #include <vnl/vnl_fwd.h>
20 #include <vgl/vgl_fwd.h>
21 #include "vpgl_proj_camera.h"
22 
23 template <class T>
25 {
26  public:
27 
28  //: Default constructor creates the canonical affine camera.
30 
31  //: Construct from the first two rows.
33  const vnl_vector_fixed<T,4>& row2 );
34 
35  //: Construct from a 3x4 matrix, sets the last row to 0001.
36  // The bottom right entry had better not be 0.
37  vpgl_affine_camera( const vnl_matrix_fixed<T,3,4>& camera_matrix );
38 
39  //: Construct from a ray direction, up vector, 3-d stare point: vgl interface
40  // \a p projects to (\a u0, \a v0), \a su and \a sv are calibration scale factors
42  vgl_point_3d<T> stare_pt, T u0, T v0, T su, T sv);
43 
44  //: Construct from a ray direction, up vector, 3-d stare point: vnl interface
45  // \a p projects to (\a u0, \a v0), \a su and \a sv are calibration scale factors
47  vnl_vector_fixed<T, 3> stare_pt, T u0, T v0, T su, T sv) {
48  vgl_vector_3d<T> ry(ray[0], ray[1], ray[2]), u(up[0], up[1], up[2]);
49  vgl_point_3d<T> pt(stare_pt[0], stare_pt[1], stare_pt[2]);
50  (*this) = vpgl_affine_camera<T>(ry, u, pt, u0, v0, su, sv);
51  }
52 
53  bool set_matrix( const vnl_matrix_fixed<T,3,4>& new_camera_matrix ) override;
54  bool set_matrix( const T* new_camera_matrix ) override; // i.e., T new_camera_matrix[12]
55 
56  std::string type_name() const override { return "vpgl_affine_camera"; }
57 
58  //: Set the top two rows.
59  void set_rows( const vnl_vector_fixed<T,4>& row1,
60  const vnl_vector_fixed<T,4>& row2 );
61 
62  // === The following virtual functions require special treatment for the affine camera ===
63 
64  //: set a finite viewing distance to allow the methods below to return finite objects
65  void set_viewing_distance(T dist) {view_distance_ = dist;}
66  T viewing_distance() const {return view_distance_;}
67 
68  //: flip the ray direction so that dot product with look_dir is positive
69  void orient_ray_direction(vgl_vector_3d<T> const& look_dir);
70 
71  //: Equality test
72  inline bool operator==(vpgl_affine_camera<T> const &that) const
73  { return this == &that ||
74  (this->get_matrix()==that.get_matrix() &&
75  this->viewing_distance() == that.viewing_distance() );
76  }
77 
78 //: Find the 3d coordinates of the center of the camera. Will be an ideal point with the sense of the ray direction.
79  vgl_homg_point_3d<T> camera_center() const override;
80 
81  //: Find the 3d ray that goes through the camera center.
82  // The finite point of the ray is at the viewing distance from the origin
83  vgl_homg_line_3d_2_points<T> backproject( const vgl_homg_point_2d<T>& image_point ) const override;
84 
85  //: Find the 3d ray that goes through the camera center and the provided image point.
86  vgl_ray_3d<T> backproject_ray( const vgl_homg_point_2d<T>& image_point ) const override;
87 
88  //: Find the world plane perpendicular to the camera rays at viewing distance from the origin
89  vgl_homg_plane_3d<T> principal_plane() const override;
90 
91  //: Clone `this': creation of a new object and initialization
92  vpgl_affine_camera<T>* clone(void) const override;
93 
94  private:
95  T view_distance_; // distance from origin along rays
96  vgl_vector_3d<T> ray_dir_;//needed to assign a consistent sense to the ray
97 };
98 
99 //: Read vpgl_affine_camera from stream
100 template <class Type>
101 std::istream& operator>>(std::istream& s, vpgl_affine_camera<Type>& c);
102 
103 //: Write vpgl_affine_camera to stream
104 template <class Type>
105 std::ostream& operator<<(std::ostream& s, vpgl_affine_camera<Type> const& c);
106 
107 #endif // vpgl_affine_camera_h_
vgl_ray_3d< T > backproject_ray(const vgl_homg_point_2d< T > &image_point) const override
Find the 3d ray that goes through the camera center and the provided image point.
std::istream & operator>>(std::istream &is, vpgl_local_rational_camera< T > &p)
Read from stream.
vgl_vector_3d< T > ray_dir_
vpgl_affine_camera< T > * clone(void) const override
Clone ‘this’: creation of a new object and initialization.
vpgl_affine_camera()
Default constructor creates the canonical affine camera.
std::string type_name() const override
class identity functions for casting.
std::ostream & operator<<(std::ostream &s, const vpgl_local_rational_camera< T > &p)
Write to stream.
vgl_homg_line_3d_2_points< T > backproject(const vgl_homg_point_2d< T > &image_point) const override
Find the 3d ray that goes through the camera center.
A camera model using the standard 3x4 matrix representation.
vgl_homg_point_3d< T > camera_center() const override
Find the 3d coordinates of the center of the camera. Will be an ideal point with the sense of the ray...
void orient_ray_direction(vgl_vector_3d< T > const &look_dir)
flip the ray direction so that dot product with look_dir is positive.
const vnl_matrix_fixed< T, 3, 4 > & get_matrix() const
Return a copy of the camera matrix.
void set_rows(const vnl_vector_fixed< T, 4 > &row1, const vnl_vector_fixed< T, 4 > &row2)
Set the top two rows.
vgl_homg_plane_3d< T > principal_plane() const override
Find the world plane perpendicular to the camera rays at viewing distance from the origin.
void set_viewing_distance(T dist)
set a finite viewing distance to allow the methods below to return finite objects.
bool set_matrix(const vnl_matrix_fixed< T, 3, 4 > &new_camera_matrix) override
Setters mirror the constructors and return true if the setting was successful.
bool operator==(vpgl_affine_camera< T > const &that) const
Equality test.
vpgl_affine_camera(vnl_vector_fixed< T, 3 > ray, vnl_vector_fixed< T, 3 > up, vnl_vector_fixed< T, 3 > stare_pt, T u0, T v0, T su, T sv)
Construct from a ray direction, up vector, 3-d stare point: vnl interface.