vpgl_io_affine_camera.hxx
Go to the documentation of this file.
1 #ifndef vpgl_io_affine_camera_hxx_
2 #define vpgl_io_affine_camera_hxx_
3 //:
4 // \file
6 //
9 
10 template <class T>
12 {
13  if (!os) return;
14  unsigned version = 1;
15  vsl_b_write(os, version);
16  vsl_b_write(os, camera.get_matrix());
17  vsl_b_write(os, camera.viewing_distance());
18 }
19 
20 //: Binary load camera from stream.
21 template <class T>
23 {
24  if (!is) return;
25  short ver;
26  vsl_b_read(is, ver);
28  switch (ver)
29  {
30  case 1:
31  vsl_b_read(is, Pnew);
32  camera.set_matrix(Pnew);
33  T view_dist;
34  vsl_b_read(is, view_dist);
35  camera.set_viewing_distance(view_dist);
36  break;
37  default:
38  std::cerr << "I/O ERROR: vpgl_affine_camera::b_read(vsl_b_istream&)\n"
39  << " Unknown version number "<< ver << '\n';
40  is.is().clear(std::ios::badbit); // Set an unrecoverable IO error on stream
41  return;
42  }
43 }
44 
45 //: Print human readable summary of object to a stream
46 template <class T>
47 void vsl_print_summary(std::ostream& os,const vpgl_affine_camera<T> & c)
48 {
49  os << c << '\n';
50 }
51 
52 
53 #define VPGL_IO_AFFINE_CAMERA_INSTANTIATE(T) \
54 template void vsl_b_write(vsl_b_ostream & os, vpgl_affine_camera<T > const& camera); \
55 template void vsl_b_read(vsl_b_istream & is, vpgl_affine_camera<T > &camera); \
56 template void vsl_print_summary(std::ostream& os,const vpgl_affine_camera<T > & b)
57 
58 #endif // vpgl_io_affine_camera_hxx_
A class for the affine camera model.
void vsl_b_read(vsl_b_istream &is, vpgl_affine_camera< T > &camera)
Binary load camera from stream.
void vsl_b_write(vsl_b_ostream &os, vpgl_affine_camera< T > const &camera)
Binary save camera to stream.
std::istream & is() const
void vsl_print_summary(std::ostream &os, const vpgl_affine_camera< T > &c)
Print human readable summary of object to a stream.
const vnl_matrix_fixed< T, 3, 4 > & get_matrix() const
Return a copy of the camera matrix.
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.