vgl_io_vector_3d.hxx
Go to the documentation of this file.
1 // This is core/vgl/io/vgl_io_vector_3d.hxx
2 #ifndef vgl_io_vector_3d_hxx_
3 #define vgl_io_vector_3d_hxx_
4 //:
5 // \file
6 
7 #include <iostream>
8 #include "vgl_io_vector_3d.h"
9 #include <vgl/vgl_vector_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_vector_3d<T> & v)
16 {
17  constexpr short io_version_no = 1;
18  vsl_b_write(os, io_version_no);
19  vsl_b_write(os, v.x());
20  vsl_b_write(os, v.y());
21  vsl_b_write(os, v.z());
22 }
23 
24 //============================================================================
25 //: Binary load self from stream.
26 template<class T>
27 void vsl_b_read(vsl_b_istream &is, vgl_vector_3d<T> & vec)
28 {
29  if (!is) return;
30 
31  short v;
32  vsl_b_read(is, v);
33  switch (v)
34  {
35  case 1:
36  T x, y, z;
37  vsl_b_read(is, x);
38  vsl_b_read(is, y);
39  vsl_b_read(is, z);
40  vec.set(x,y,z);
41  break;
42 
43  default:
44  std::cerr << "I/O ERROR: vsl_b_read(vsl_b_istream&, vgl_vector_3d<T>&)\n"
45  << " Unknown version number "<< v << '\n';
46  is.is().clear(std::ios::badbit); // Set an unrecoverable IO error on stream
47  return;
48  }
49 }
50 
51 
52 //============================================================================
53 //: Output a human readable summary to the stream
54 template<class T>
55 void vsl_print_summary(std::ostream& os,const vgl_vector_3d<T> & v)
56 {
57  os<<'('<<v.x()<<','<<v.y()<<','<<v.z()<<')';
58 }
59 
60 #define VGL_IO_VECTOR_3D_INSTANTIATE(T) \
61 template void vsl_print_summary(std::ostream &, const vgl_vector_3d<T > &); \
62 template void vsl_b_read(vsl_b_istream &, vgl_vector_3d<T > &); \
63 template void vsl_b_write(vsl_b_ostream &, const vgl_vector_3d<T > &)
64 
65 #endif // vgl_io_vector_3d_hxx_
direction vector in Euclidean 3D space
void vsl_print_summary(std::ostream &os, const vgl_vector_3d< T > &v)
Output a human readable summary to the stream.
#define v
Definition: vgl_vector_2d.h:74
void vsl_b_write(vsl_b_ostream &os, const vgl_vector_3d< T > &v)
Binary save self to stream.
Direction vector in Euclidean 3D space, templated by type of element.
Definition: vgl_fwd.h:13
void set(T vx, T vy, T vz)
Assignment.
Definition: vgl_vector_3d.h:60
void vsl_b_read(vsl_b_istream &is, vgl_vector_3d< T > &vec)
Binary load self from stream.