vgl_io_h_matrix_2d.hxx
Go to the documentation of this file.
1 // This is core/vgl/io/vgl_io_h_matrix_2d.hxx
2 #ifndef vgl_io_h_matrix_2d_hxx_
3 #define vgl_io_h_matrix_2d_hxx_
4 //:
5 // \file
6 
7 #include <iostream>
8 #include "vgl_io_h_matrix_2d.h"
9 #include <vsl/vsl_binary_io.h>
10 
11 //: Binary save vgl_h_matrix_2d to stream.
12 template <class T>
13 void vsl_b_write(vsl_b_ostream &bfs, const vgl_h_matrix_2d<T>& t)
14 {
15  static const short io_version_no = 1;
16  vsl_b_write(bfs,io_version_no);
17  vnl_matrix_fixed<T,3,3> m = t.get_matrix();
18  vsl_b_write(bfs,m[0][0]); vsl_b_write(bfs,m[0][1]); vsl_b_write(bfs,m[0][2]);
19  vsl_b_write(bfs,m[1][0]); vsl_b_write(bfs,m[1][1]); vsl_b_write(bfs,m[1][2]);
20  vsl_b_write(bfs,m[2][0]); vsl_b_write(bfs,m[2][1]); vsl_b_write(bfs,m[2][2]);
21 }
22 
23 //: Binary load vgl_h_matrix_2d from stream.
24 template <class T>
25 void vsl_b_read(vsl_b_istream &bfs, vgl_h_matrix_2d<T>& v)
26 {
27  if (!bfs) return;
28 
29  short version;
30  vsl_b_read(bfs,version);
31  switch (version) {
32  case 1:
33  T xx,xy,xt,yx,yy,yt,tx,ty,tt;
34  vsl_b_read(bfs,xx); vsl_b_read(bfs,xy); vsl_b_read(bfs,xt);
35  vsl_b_read(bfs,yx); vsl_b_read(bfs,yy); vsl_b_read(bfs,yt);
36  vsl_b_read(bfs,tx); vsl_b_read(bfs,ty); vsl_b_read(bfs,tt);
37  v.set(0,0,xx); v.set(0,1,xy); v.set(0,2,xt);
38  v.set(1,0,yx); v.set(1,1,yy); v.set(1,2,yt);
39  v.set(2,0,tx); v.set(2,0,ty); v.set(2,2,tt);
40  break;
41  default:
42  std::cerr << "I/O ERROR: vgl_h_matrix_2d::b_read(vsl_b_istream&)\n"
43  << " Unknown version number "<< version << '\n';
44  bfs.is().clear(std::ios::badbit); // Set an unrecoverable IO error on stream
45  return;
46  }
47 }
48 
49 
50 #define VGL_IO_H_MATRIX_2D_INSTANTIATE(T) \
51 template void vsl_b_read(vsl_b_istream &, vgl_h_matrix_2d<T >&); \
52 template void vsl_b_write(vsl_b_ostream &, const vgl_h_matrix_2d<T >&)
53 
54 #endif // vgl_io_h_matrix_2d_hxx_
A class to hold a plane-to-plane projective transformation matrix and to perform common operations us...
Definition: vgl_algo_fwd.h:11
vnl_matrix_fixed< T, 3, 3 > const & get_matrix() const
Return the 3x3 homography matrix.
void vsl_b_write(vsl_b_ostream &bfs, const vgl_h_matrix_2d< T > &t)
Binary save vgl_h_matrix_2d to stream.
#define v
Definition: vgl_vector_2d.h:74
contains functions vsl_b_write, vsl_b_read and vsl_print_summary
void vsl_b_read(vsl_b_istream &bfs, vgl_h_matrix_2d< T > &v)
Binary load vgl_h_matrix_2d from stream.