vpgl_io_rational_camera.hxx
Go to the documentation of this file.
1 #ifndef vpgl_io_rational_camera_hxx_
2 #define vpgl_io_rational_camera_hxx_
3 
5 //:
6 // \file
9 
10 template <class T>
12 {
13  if (!os) return;
14  unsigned version = 1;
15  vsl_b_write(os, version);
16  // write rational coefficients
17  vsl_b_write(os, camera.coefficient_matrix());
18  // write scale offsets
19  std::vector<vpgl_scale_offset<T> > scale_off = camera.scale_offsets();
20  vsl_b_write(os,scale_off.size());
21  for (unsigned i=0; i<scale_off.size(); ++i) {
22  vsl_b_write(os,scale_off[i].scale());
23  vsl_b_write(os,scale_off[i].offset());
24  }
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  {
38  // read rational coefficients
39  vnl_matrix_fixed<T, 4, 20> coefficient_matrix;
40  vsl_b_read(is,coefficient_matrix);
41  // read scale+offsets
42  unsigned n_scale_offsets;
43  vsl_b_read(is,n_scale_offsets);
44  std::vector<vpgl_scale_offset<T> > scale_off(n_scale_offsets);
45  for (unsigned i=0; i<n_scale_offsets; ++i) {
46  T scale, off;
47  vsl_b_read(is,scale);
48  vsl_b_read(is,off);
49  scale_off[i] = vpgl_scale_offset<T>(scale,off);
50  }
51  camera.set_coefficients(coefficient_matrix);
52  camera.set_scale_offsets(scale_off);
53  break;
54  }
55  default:
56  std::cerr << "I/O ERROR: vpgl_rational_camera::b_read(vsl_b_istream&)\n"
57  << " Unknown version number "<< ver << '\n';
58  is.is().clear(std::ios::badbit); // Set an unrecoverable IO error on stream
59  return;
60  }
61 }
62 
63 //: Print human readable summary of object to a stream
64 template <class T>
65 void vsl_print_summary(std::ostream& os,const vpgl_rational_camera<T> & c)
66 {
67  os << c << '\n';
68 }
69 
70 
71 #define VPGL_IO_RATIONAL_CAMERA_INSTANTIATE(T) \
72 template void vsl_b_write(vsl_b_ostream & os, vpgl_rational_camera<T > const& camera); \
73 template void vsl_b_read(vsl_b_istream & is, vpgl_rational_camera<T > &camera); \
74 template void vsl_print_summary(std::ostream& os,const vpgl_rational_camera<T > & b)
75 
76 #endif // vpgl_io_rational_camera_hxx_
vnl_matrix_fixed< T, 4, 20 > coefficient_matrix() const
get the rational polynomial coefficients in a vnl matrix.
A camera model based on ratios of cubic polynomials.
std::istream & is() const
void vsl_print_summary(std::ostream &os, const vpgl_rational_camera< T > &c)
Print human readable summary of object to a stream.
std::vector< vpgl_scale_offset< T > > scale_offsets() const
get the scale and offsets in a vector.
void set_scale_offsets(std::vector< vpgl_scale_offset< T > > const &scale_offsets)
set coordinate scale and offsets.
void vsl_b_read(vsl_b_istream &is, vpgl_rational_camera< T > &camera)
Binary load camera from stream.
void set_coefficients(std::vector< std::vector< T > > const &rational_coeffs)
set rational polynomial coefficients.
void vsl_b_write(vsl_b_ostream &os, vpgl_rational_camera< T > const &camera)
Binary save camera to stream.