core/vgl/io/vgl_io_homg_point_3d.txx
Go to the documentation of this file.
00001 // This is core/vgl/io/vgl_io_homg_point_3d.txx
00002 #ifndef vgl_io_homg_point_3d_txx_
00003 #define vgl_io_homg_point_3d_txx_
00004 //:
00005 // \file
00006 
00007 #include "vgl_io_homg_point_3d.h"
00008 #include <vgl/vgl_homg_point_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_homg_point_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.x());
00019   vsl_b_write(os, p.y());
00020   vsl_b_write(os, p.z());
00021   vsl_b_write(os, p.w());
00022 }
00023 
00024 //============================================================================
00025 //: Binary load self from stream.
00026 template<class T>
00027 void vsl_b_read(vsl_b_istream &is, vgl_homg_point_3d<T> & p)
00028 {
00029   if (!is) return;
00030 
00031   short v;
00032   vsl_b_read(is, v);
00033   switch (v)
00034   {
00035    case 1:
00036     T x, y, z, w;
00037     vsl_b_read(is, x);
00038     vsl_b_read(is, y);
00039     vsl_b_read(is, z);
00040     vsl_b_read(is, w);
00041     p.set(x,y,z,w);
00042     break;
00043 
00044    default:
00045     vcl_cerr << "I/O ERROR: vsl_b_read(vsl_b_istream&, vgl_homg_point_3d<T>&)\n"
00046              << "           Unknown version number "<< v << '\n';
00047     is.is().clear(vcl_ios::badbit); // Set an unrecoverable IO error on stream
00048     return;
00049   }
00050 }
00051 
00052 
00053 //============================================================================
00054 //: Output a human readable summary to the stream
00055 template<class T>
00056 void vsl_print_summary(vcl_ostream& os,const vgl_homg_point_3d<T> & p)
00057 {
00058     os<<'('<<p.x()<<','<<p.y()<<')'<<'('<<p.z()<<','<<p.w()<<')';
00059 }
00060 
00061 #define VGL_IO_HOMG_POINT_3D_INSTANTIATE(T) \
00062 template void vsl_print_summary(vcl_ostream &, const vgl_homg_point_3d<T > &); \
00063 template void vsl_b_read(vsl_b_istream &, vgl_homg_point_3d<T > &); \
00064 template void vsl_b_write(vsl_b_ostream &, const vgl_homg_point_3d<T > &)
00065 
00066 #endif // vgl_io_homg_point_3d_txx_