vpgl_io_perspective_camera.hxx
Go to the documentation of this file.
1 #ifndef vpgl_io_perspective_camera_hxx_
2 #define vpgl_io_perspective_camera_hxx_
3 
5 //:
6 // \file
10 #include <vgl/io/vgl_io_point_3d.h>
11 
12 template <class T>
14 {
15  if (!os) return;
16  unsigned version = 1;
17  vsl_b_write(os, version);
18  vnl_matrix_fixed<T,3,3> K = camera.get_calibration().get_matrix();
19  vgl_rotation_3d<T> R = camera.get_rotation();
21  vgl_point_3d<T> center = camera.get_camera_center();
22  vsl_b_write(os, K);
23  vsl_b_write(os, rod);
24  vsl_b_write(os, center);
25 }
26 
27 //: Binary load camera from stream.
28 template <class T>
30 {
31  if (!is) return;
32  short ver;
33  vsl_b_read(is, ver);
34  switch (ver)
35  {
36  case 1:
37  {
40  vgl_point_3d<T> center;
41  vsl_b_read(is, K);
42  vsl_b_read(is, rod);
43  vgl_rotation_3d<T> R(rod);
44  vsl_b_read(is, center);
45  camera.set_calibration(K);
46  camera.set_camera_center(center);
47  camera.set_rotation(R);
48  break;
49  }
50  default:
51  std::cerr << "I/O ERROR: vpgl_perspective_camera::b_read(vsl_b_istream&)\n"
52  << " Unknown version number "<< ver << '\n';
53  is.is().clear(std::ios::badbit); // Set an unrecoverable IO error on stream
54  return;
55  }
56 }
57 
58 //: Print human readable summary of object to a stream
59 template <class T>
60 void vsl_print_summary(std::ostream& os,const vpgl_perspective_camera<T> & c)
61 {
62  os << c << '\n';
63 }
64 
65 
66 #define VPGL_IO_PERSPECTIVE_CAMERA_INSTANTIATE(T) \
67 template void vsl_b_write(vsl_b_ostream & os, vpgl_perspective_camera<T > const& camera); \
68 template void vsl_b_read(vsl_b_istream & is, vpgl_perspective_camera<T > &camera); \
69 template void vsl_print_summary(std::ostream& os,const vpgl_perspective_camera<T > & b)
70 
71 #endif // vpgl_io_perspective_camera_hxx_
A class for the perspective camera model.
void set_rotation(const vgl_rotation_3d< T > &R)
vnl_vector_fixed< T, 3 > as_rodrigues() const
void set_camera_center(const vgl_point_3d< T > &camera_center)
std::istream & is() const
const vpgl_calibration_matrix< T > & get_calibration() const
const vgl_rotation_3d< T > & get_rotation() const
void set_calibration(const vpgl_calibration_matrix< T > &K)
Setters and getters.
const vgl_point_3d< T > & get_camera_center() const
This class implements the perspective camera class as described in Hartley & Zisserman as a finite ca...
void vsl_b_write(vsl_b_ostream &os, vpgl_perspective_camera< T > const &camera)
Binary save camera to stream.
void vsl_b_read(vsl_b_istream &is, vpgl_perspective_camera< T > &camera)
Binary load camera from stream.
void vsl_print_summary(std::ostream &os, const vpgl_perspective_camera< T > &c)
Print human readable summary of object to a stream.