core/vgl/io/vgl_io_cylinder.txx
Go to the documentation of this file.
00001 #ifndef vgl_io_cylinder_txx_
00002 #define vgl_io_cylinder_txx_
00003 //:
00004 // \file
00005 #include "vgl_io_cylinder.h"
00006 #include <vgl/io/vgl_io_point_3d.h>
00007 #include <vgl/io/vgl_io_vector_3d.h>
00008 #include <vgl/vgl_cylinder.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_cylinder<T> & cyl)
00015 {
00016   const short io_version_no = 1;
00017   vsl_b_write(os, io_version_no);
00018   vsl_b_write(os, cyl.center());
00019   vsl_b_write(os, cyl.radius());
00020   vsl_b_write(os, cyl.length());
00021   vsl_b_write(os, cyl.orientation());
00022 }
00023 
00024 //: Binary load self from stream
00025 template<class T>
00026 void vsl_b_read(vsl_b_istream &is, vgl_cylinder<T> & cyl)
00027 {
00028   vgl_point_3d<double> center;
00029   vgl_vector_3d<double> orient;
00030   double radius, length;
00031 
00032   if (!is)
00033     return;
00034   short ver;
00035   vsl_b_read(is, ver);
00036   switch (ver)
00037   {
00038    case 1:
00039    // read center
00040     vsl_b_read(is, center);
00041     cyl.set_center(center);
00042 
00043     // read radius
00044     vsl_b_read(is, radius);
00045     cyl.set_radius(radius);
00046 
00047     // read length
00048     vsl_b_read(is, length);
00049     cyl.set_length(length);
00050 
00051     // read orientation
00052     vsl_b_read(is, orient);
00053     cyl.set_orientation(orient);
00054     break;
00055    default:
00056     vcl_cerr << "vsol_cylinder: unknown I/O version " << ver << '\n';
00057   }
00058 }
00059 
00060 //: Print an ascii summary to the stream
00061 template<class T>
00062 void vsl_print_summary(vcl_ostream& os, const vgl_cylinder<T> & cyl)
00063 {
00064   //os << *this;
00065   os << "Cylinder with center=" << cyl.center() << " radius=" << cyl.radius() << " length=" << cyl.length() << vcl_endl;
00066 }
00067 
00068 #undef VGL_IO_CYLINDER_INSTANTIATE
00069 #define VGL_IO_CYLINDER_INSTANTIATE(T) \
00070 template void vsl_print_summary(vcl_ostream &, const vgl_cylinder<T > &); \
00071 template void vsl_b_read(vsl_b_istream &, vgl_cylinder<T > &); \
00072 template void vsl_b_write(vsl_b_ostream &, const vgl_cylinder<T > &)
00073 
00074 #endif