vgl_io_plane_3d.hxx
Go to the documentation of this file.
1 // This is core/vgl/io/vgl_io_plane_3d.hxx
2 #ifndef vgl_io_plane_3d_hxx_
3 #define vgl_io_plane_3d_hxx_
4 //:
5 // \file
6 
7 #include <iostream>
8 #include "vgl_io_plane_3d.h"
9 #include <vgl/vgl_plane_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_plane_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.a());
20  vsl_b_write(os, p.b());
21  vsl_b_write(os, p.c());
22  vsl_b_write(os, p.d());
23 }
24 
25 //============================================================================
26 //: Binary load self from stream.
27 template<class T>
28 void vsl_b_read(vsl_b_istream &is, vgl_plane_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 a, b, c, d;
38  vsl_b_read(is, a);
39  vsl_b_read(is, b);
40  vsl_b_read(is, c);
41  vsl_b_read(is, d);
42  p.set(a,b,c,d);
43  break;
44 
45  default:
46  std::cerr << "I/O ERROR: vsl_b_read(vsl_b_istream&, vgl_plane_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_plane_3d<T> & p)
58 {
59  os<<'('<<p.a()<<','<<p.b()<<','<<p.c()<<','<<p.d()<<')';
60 }
61 
62 #define VGL_IO_PLANE_3D_INSTANTIATE(T) \
63 template void vsl_print_summary(std::ostream &, const vgl_plane_3d<T > &); \
64 template void vsl_b_read(vsl_b_istream &, vgl_plane_3d<T > &); \
65 template void vsl_b_write(vsl_b_ostream &, const vgl_plane_3d<T > &)
66 
67 #endif // vgl_io_plane_3d_hxx_
T a() const
Return x coefficient.
Definition: vgl_plane_3d.h:89
void vsl_print_summary(std::ostream &os, const vgl_plane_3d< T > &p)
Output a human readable summary to the stream.
void vsl_b_write(vsl_b_ostream &os, const vgl_plane_3d< T > &p)
Binary save self to stream.
void vsl_b_read(vsl_b_istream &is, vgl_plane_3d< T > &p)
Binary load self from stream.
#define v
Definition: vgl_vector_2d.h:74
T b() const
Return y coefficient.
Definition: vgl_plane_3d.h:92
Represents a Euclidean 3D plane.
Definition: vgl_fwd.h:23
T d() const
Return constant coefficient.
Definition: vgl_plane_3d.h:98
void set(T ta, T tb, T tc, T td)
Set this vgl_plane_3d to have the equation $ax+by+cz+d=0$.
Definition: vgl_plane_3d.h:101
a plane in 3D nonhomogeneous space
T c() const
Return z coefficient.
Definition: vgl_plane_3d.h:95