vgl_io_homg_point_3d.hxx
Go to the documentation of this file.
1 // This is core/vgl/io/vgl_io_homg_point_3d.hxx
2 #ifndef vgl_io_homg_point_3d_hxx_
3 #define vgl_io_homg_point_3d_hxx_
4 //:
5 // \file
6 
7 #include <iostream>
8 #include "vgl_io_homg_point_3d.h"
10 #include <vsl/vsl_binary_io.h>
11 
12 //============================================================================
13 //: Binary save self to stream.
14 template<class T>
15 void vsl_b_write(vsl_b_ostream &os, const vgl_homg_point_3d<T> & p)
16 {
17  constexpr short io_version_no = 1;
18  vsl_b_write(os, io_version_no);
19  vsl_b_write(os, p.x());
20  vsl_b_write(os, p.y());
21  vsl_b_write(os, p.z());
22  vsl_b_write(os, p.w());
23 }
24 
25 //============================================================================
26 //: Binary load self from stream.
27 template<class T>
28 void vsl_b_read(vsl_b_istream &is, vgl_homg_point_3d<T> & p)
29 {
30  if (!is) return;
31 
32  short v;
33  vsl_b_read(is, v);
34  switch (v)
35  {
36  case 1:
37  T x, y, z, w;
38  vsl_b_read(is, x);
39  vsl_b_read(is, y);
40  vsl_b_read(is, z);
41  vsl_b_read(is, w);
42  p.set(x,y,z,w);
43  break;
44 
45  default:
46  std::cerr << "I/O ERROR: vsl_b_read(vsl_b_istream&, vgl_homg_point_3d<T>&)\n"
47  << " Unknown version number "<< v << '\n';
48  is.is().clear(std::ios::badbit); // Set an unrecoverable IO error on stream
49  return;
50  }
51 }
52 
53 
54 //============================================================================
55 //: Output a human readable summary to the stream
56 template<class T>
57 void vsl_print_summary(std::ostream& os,const vgl_homg_point_3d<T> & p)
58 {
59  os<<'('<<p.x()<<','<<p.y()<<')'<<'('<<p.z()<<','<<p.w()<<')';
60 }
61 
62 #define VGL_IO_HOMG_POINT_3D_INSTANTIATE(T) \
63 template void vsl_print_summary(std::ostream &, const vgl_homg_point_3d<T > &); \
64 template void vsl_b_read(vsl_b_istream &, vgl_homg_point_3d<T > &); \
65 template void vsl_b_write(vsl_b_ostream &, const vgl_homg_point_3d<T > &)
66 
67 #endif // vgl_io_homg_point_3d_hxx_
point in projective 3D space
void vsl_b_read(vsl_b_istream &is, vgl_homg_point_3d< T > &p)
Binary load self from stream.
Represents a homogeneous 3D point.
Definition: vgl_fwd.h:9
#define v
Definition: vgl_vector_2d.h:74
void vsl_b_write(vsl_b_ostream &os, const vgl_homg_point_3d< T > &p)
Binary save self to stream.
void set(Type px, Type py, Type pz, Type pw=(Type) 1)
Set x,y,z,w.
void vsl_print_summary(std::ostream &os, const vgl_homg_point_3d< T > &p)
Output a human readable summary to the stream.