core/vpgl/io/vpgl_io_perspective_camera.txx
Go to the documentation of this file.
00001 #ifndef vpgl_io_perspective_camera_txx_
00002 #define vpgl_io_perspective_camera_txx_
00003 
00004 #include "vpgl_io_perspective_camera.h"
00005 //:
00006 // \file
00007 #include <vpgl/vpgl_perspective_camera.h>
00008 #include <vnl/io/vnl_io_matrix_fixed.h>
00009 #include <vnl/io/vnl_io_vector_fixed.h>
00010 #include <vgl/io/vgl_io_point_3d.h>
00011 
00012 template <class T>
00013 void vsl_b_write(vsl_b_ostream & os, vpgl_perspective_camera<T> const& camera)
00014 {
00015   if (!os) return;
00016   unsigned version = 1;
00017   vsl_b_write(os, version);
00018   vnl_matrix_fixed<T,3,3> K = camera.get_calibration().get_matrix();
00019   vgl_rotation_3d<T> R = camera.get_rotation();
00020   vnl_vector_fixed<T,3> rod = R.as_rodrigues();
00021   vgl_point_3d<T> center = camera.get_camera_center();
00022   vsl_b_write(os, K);
00023   vsl_b_write(os, rod);
00024   vsl_b_write(os, center);
00025 }
00026 
00027 //: Binary load camera from stream.
00028 template <class T>
00029 void vsl_b_read(vsl_b_istream & is, vpgl_perspective_camera<T> &camera)
00030 {
00031   if (!is) return;
00032   short ver;
00033   vsl_b_read(is, ver);
00034   switch (ver)
00035   {
00036    case 1:
00037    {
00038      vnl_matrix_fixed<T,3,3> K;
00039      vnl_vector_fixed<T,3> rod;
00040      vgl_point_3d<T> center;
00041      vsl_b_read(is, K);
00042      vsl_b_read(is, rod);
00043      vgl_rotation_3d<T> R(rod);
00044      vsl_b_read(is, center);
00045      camera.set_calibration(K);
00046      camera.set_camera_center(center);
00047      camera.set_rotation(R);
00048      break;
00049    }
00050    default:
00051     vcl_cerr << "I/O ERROR: vpgl_perspective_camera::b_read(vsl_b_istream&)\n"
00052              << "           Unknown version number "<< ver << '\n';
00053     is.is().clear(vcl_ios::badbit); // Set an unrecoverable IO error on stream
00054     return;
00055   }
00056 }
00057 
00058 //: Print human readable summary of object to a stream
00059 template <class T>
00060 void vsl_print_summary(vcl_ostream& os,const vpgl_perspective_camera<T> & c)
00061 {
00062   os << c << '\n';
00063 }
00064 
00065 
00066 #define VPGL_IO_PERSPECTIVE_CAMERA_INSTANTIATE(T) \
00067 template void vsl_b_write(vsl_b_ostream & os, vpgl_perspective_camera<T > const& camera); \
00068 template void vsl_b_read(vsl_b_istream & is, vpgl_perspective_camera<T > &camera); \
00069 template void vsl_print_summary(vcl_ostream& os,const vpgl_perspective_camera<T > & b)
00070 
00071 #endif // vpgl_io_perspective_camera_txx_