core/vgl/io/vgl_io_box_3d.txx
Go to the documentation of this file.
00001 // This is core/vgl/io/vgl_io_box_3d.txx
00002 #ifndef vgl_io_box_3d_txx_
00003 #define vgl_io_box_3d_txx_
00004 //:
00005 // \file
00006 
00007 #include "vgl_io_box_3d.h"
00008 #include <vgl/vgl_box_3d.h>
00009 #include <vsl/vsl_binary_io.h>
00010 
00011 //============================================================================
00012 //: Binary save self to stream.
00013 template<class T>
00014 void vsl_b_write(vsl_b_ostream &os, const vgl_box_3d<T> & p)
00015 {
00016   const short io_version_no = 1;
00017   vsl_b_write(os, io_version_no);
00018   vsl_b_write(os, p.min_x());
00019   vsl_b_write(os, p.min_y());
00020   vsl_b_write(os, p.min_z());
00021   vsl_b_write(os, p.max_x());
00022   vsl_b_write(os, p.max_y());
00023   vsl_b_write(os, p.max_z());
00024 }
00025 
00026 //============================================================================
00027 //: Binary load self from stream.
00028 template<class T>
00029 void vsl_b_read(vsl_b_istream &is, vgl_box_3d<T> & p)
00030 {
00031   if (!is) return;
00032 
00033   short v;
00034   T min_pos[3];
00035   T max_pos[3];
00036   vsl_b_read(is, v);
00037   switch (v)
00038   {
00039    case 1:
00040     vsl_b_read(is, min_pos[0]);
00041     vsl_b_read(is, min_pos[1]);
00042     vsl_b_read(is, min_pos[2]);
00043     vsl_b_read(is, max_pos[0]);
00044     vsl_b_read(is, max_pos[1]);
00045     vsl_b_read(is, max_pos[2]);
00046     p.set_min_position(min_pos);
00047     p.set_max_position(max_pos);
00048     break;
00049 
00050    default:
00051     vcl_cerr << "I/O ERROR: vsl_b_read(vsl_b_istream&, vgl_box_3d<T>&)\n"
00052              << "           Unknown version number "<< v << '\n';
00053     is.is().clear(vcl_ios::badbit); // Set an unrecoverable IO error on stream
00054     return;
00055   }
00056 }
00057 
00058 //============================================================================
00059 //: Output a human readable summary to the stream
00060 template<class T>
00061 void vsl_print_summary(vcl_ostream& os,const vgl_box_3d<T> & p)
00062 {
00063   if (p.is_empty())
00064     os<<"Empty 3d box\n";
00065   else
00066     os<<"3d box with opposite corners at ("
00067       <<p.min_x() << ',' << p.min_y() << ',' << p.min_z() <<") and ("
00068       <<p.max_x() << ',' << p.max_y() << ',' << p.max_z() <<")\n";
00069 }
00070 
00071 #define VGL_IO_BOX_3D_INSTANTIATE(T) \
00072 template void vsl_print_summary(vcl_ostream &, const vgl_box_3d<T > &); \
00073 template void vsl_b_read(vsl_b_istream &, vgl_box_3d<T > &); \
00074 template void vsl_b_write(vsl_b_ostream &, const vgl_box_3d<T > &)
00075 
00076 #endif // vgl_io_box_3d_txx_