Go to the documentation of this file.00001 #ifndef vpgl_io_camera_txx_
00002 #define vpgl_io_camera_txx_
00003
00004
00005 #include "vpgl_io_camera.h"
00006 #include "vpgl_io_rational_camera.h"
00007 #include "vpgl_io_proj_camera.h"
00008 #include "../vpgl_camera.h"
00009 #include "../vpgl_proj_camera.h"
00010 #include "../vpgl_rational_camera.h"
00011 #include "../vpgl_local_rational_camera.h"
00012
00013 #include <vsl/vsl_binary_io.h>
00014 #include <vcl_string.h>
00015 #include <vcl_iostream.h>
00016
00017
00018
00019 template <class T>
00020 void vsl_b_write(vsl_b_ostream & os, vpgl_camera<T>* const& camera)
00021 {
00022 if ( vpgl_proj_camera<T> *procam = dynamic_cast<vpgl_proj_camera<T>*>(camera) ){
00023
00024 vcl_string cam_type("vpgl_proj_camera");
00025 vsl_b_write(os,cam_type);
00026 vsl_b_write(os,*procam);
00027
00028 }else if ( vpgl_rational_camera<T> *ratcam = dynamic_cast<vpgl_rational_camera<T>*>(camera) ) {
00029
00030 vcl_string cam_type("vpgl_rational_camera");
00031 vsl_b_write(os,cam_type);
00032 vsl_b_write(os,*ratcam);
00033 }else if ( vpgl_local_rational_camera<T> *lratcam = dynamic_cast<vpgl_local_rational_camera<T>*>(camera) ) {
00034
00035 vcl_string cam_type("vpgl_local_rational_camera");
00036 vsl_b_write(os,cam_type);
00037 vsl_b_write(os,*lratcam);
00038 }else {
00039 vcl_cerr << "tried to write unknown camera type!\n";
00040 vcl_string cam_type("unknown");
00041 vsl_b_write(os,cam_type);
00042 }
00043 return;
00044 }
00045
00046
00047
00048 template <class T>
00049 void vsl_b_read(vsl_b_istream & is, vpgl_camera<T>* &camera)
00050 {
00051 vcl_string cam_type;
00052 vsl_b_read(is,cam_type);
00053
00054 if (cam_type == "vpgl_proj_camera") {
00055
00056 vpgl_proj_camera<T>* procam = new vpgl_proj_camera<T>();
00057 vsl_b_read(is,*procam);
00058 camera = procam;
00059 } else if (cam_type == "vpgl_rational_camera") {
00060
00061 vpgl_rational_camera<T>* ratcam = new vpgl_rational_camera<T>();
00062 vsl_b_read(is,*ratcam);
00063 camera = ratcam;
00064 } else if (cam_type == "vpgl_local_rational_camera") {
00065
00066 vpgl_local_rational_camera<T>* lratcam=new vpgl_local_rational_camera<T>();
00067 vsl_b_read(is,*lratcam);
00068 camera = lratcam;
00069 }else if (cam_type == "unknown") {
00070 vcl_cerr << "cannot read camera of unknown type!\n";
00071 }
00072 else {
00073 vcl_cerr << "error reading vpgl_camera!\n";
00074 }
00075 return;
00076 }
00077
00078 #define VPGL_IO_CAMERA_INSTANTIATE(T) \
00079 template void vsl_b_read(vsl_b_istream &, vpgl_camera<T >* &); \
00080 template void vsl_b_write(vsl_b_ostream &, vpgl_camera<T >* const&)
00081
00082 #endif // vpgl_io_camera_txx_