vgl_io_box_3d.hxx
Go to the documentation of this file.
1 // This is core/vgl/io/vgl_io_box_3d.hxx
2 #ifndef vgl_io_box_3d_hxx_
3 #define vgl_io_box_3d_hxx_
4 //:
5 // \file
6 
7 #include <iostream>
8 #include "vgl_io_box_3d.h"
9 #include <vgl/vgl_box_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_box_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.min_x());
20  vsl_b_write(os, p.min_y());
21  vsl_b_write(os, p.min_z());
22  vsl_b_write(os, p.max_x());
23  vsl_b_write(os, p.max_y());
24  vsl_b_write(os, p.max_z());
25 }
26 
27 //============================================================================
28 //: Binary load self from stream.
29 template<class T>
30 void vsl_b_read(vsl_b_istream &is, vgl_box_3d<T> & p)
31 {
32  if (!is) return;
33 
34  short v;
35  T min_pos[3];
36  T max_pos[3];
37  vsl_b_read(is, v);
38  switch (v)
39  {
40  case 1:
41  vsl_b_read(is, min_pos[0]);
42  vsl_b_read(is, min_pos[1]);
43  vsl_b_read(is, min_pos[2]);
44  vsl_b_read(is, max_pos[0]);
45  vsl_b_read(is, max_pos[1]);
46  vsl_b_read(is, max_pos[2]);
47  p.set_min_position(min_pos);
48  p.set_max_position(max_pos);
49  break;
50 
51  default:
52  std::cerr << "I/O ERROR: vsl_b_read(vsl_b_istream&, vgl_box_3d<T>&)\n"
53  << " Unknown version number "<< v << '\n';
54  is.is().clear(std::ios::badbit); // Set an unrecoverable IO error on stream
55  return;
56  }
57 }
58 
59 //============================================================================
60 //: Output a human readable summary to the stream
61 template<class T>
62 void vsl_print_summary(std::ostream& os,const vgl_box_3d<T> & p)
63 {
64  if (p.is_empty())
65  os<<"Empty 3d box\n";
66  else
67  os<<"3d box with opposite corners at ("
68  <<p.min_x() << ',' << p.min_y() << ',' << p.min_z() <<") and ("
69  <<p.max_x() << ',' << p.max_y() << ',' << p.max_z() <<")\n";
70 }
71 
72 #define VGL_IO_BOX_3D_INSTANTIATE(T) \
73 template void vsl_print_summary(std::ostream &, const vgl_box_3d<T > &); \
74 template void vsl_b_read(vsl_b_istream &, vgl_box_3d<T > &); \
75 template void vsl_b_write(vsl_b_ostream &, const vgl_box_3d<T > &)
76 
77 #endif // vgl_io_box_3d_hxx_
void set_min_position(Type const m[3])
Modify min corner point. Max corner point only changed if necessary to avoid empty box.
Definition: vgl_box_3d.hxx:277
bool is_empty() const
Return true if this box is empty.
Definition: vgl_box_3d.h:158
void vsl_print_summary(std::ostream &os, const vgl_box_3d< T > &p)
Output a human readable summary to the stream.
Type min_z() const
Get min z.
Definition: vgl_box_3d.h:128
Contains class to represent a cartesian 3D bounding box.
Type max_z() const
Get max z.
Definition: vgl_box_3d.h:135
void set_max_position(Type const m[3])
Modify max corner point. Min corner point only changed if necessary to avoid empty box.
Definition: vgl_box_3d.hxx:288
Type max_y() const
Get max y.
Definition: vgl_box_3d.h:133
#define v
Definition: vgl_vector_2d.h:74
Type min_x() const
Get min x.
Definition: vgl_box_3d.h:124
void vsl_b_read(vsl_b_istream &is, vgl_box_3d< T > &p)
Binary load self from stream.
void vsl_b_write(vsl_b_ostream &os, const vgl_box_3d< T > &p)
Binary save self to stream.
Type min_y() const
Get min y.
Definition: vgl_box_3d.h:126
Represents a cartesian 3D box.
Definition: vgl_box_3d.h:65
Type max_x() const
Get max x.
Definition: vgl_box_3d.h:131