core/vpgl/io/vpgl_io_lvcs.cxx
Go to the documentation of this file.
00001 #include "vpgl_io_lvcs.h"
00002 //:
00003 // \file
00004 #include <vpgl/vpgl_lvcs.h>
00005 #include <vnl/io/vnl_io_matrix_fixed.h>
00006 
00007 void vsl_b_write(vsl_b_ostream & os, vpgl_lvcs const& lvcs)
00008 {
00009   if (!os) return;
00010   unsigned version = 1;
00011   vsl_b_write(os, version);
00012   unsigned csn = static_cast<unsigned>(lvcs.get_cs_name());
00013   vsl_b_write(os, csn);
00014   double lat, lon, elev;
00015   lvcs.get_origin(lat, lon, elev);
00016   vsl_b_write(os, lat);
00017   vsl_b_write(os, lon);
00018   vsl_b_write(os, elev);
00019   double lat_scale, lon_scale;
00020   lvcs.get_scale(lat_scale, lon_scale);
00021   vsl_b_write(os, lat_scale);
00022   vsl_b_write(os, lon_scale);
00023   unsigned gaunit = static_cast<unsigned>(lvcs.geo_angle_unit());
00024   vsl_b_write(os, gaunit);
00025   unsigned xyzunit = static_cast<unsigned>(lvcs.local_length_unit());
00026   vsl_b_write(os, xyzunit);
00027   double lox, loy, theta;
00028   lvcs.get_transform(lox, loy, theta);
00029   vsl_b_write(os, lox);
00030   vsl_b_write(os, loy);
00031   vsl_b_write(os, theta);
00032 }
00033 
00034 //: Binary load lvcs from stream.
00035 void vsl_b_read(vsl_b_istream & is, vpgl_lvcs &lvcs)
00036 {
00037   if (!is) return;
00038   short ver;
00039   vsl_b_read(is, ver);
00040   switch (ver)
00041   {
00042     case 1:
00043     {
00044       unsigned cs_name;
00045       vsl_b_read(is, cs_name);
00046       vpgl_lvcs::cs_names name = static_cast<vpgl_lvcs::cs_names>(cs_name);
00047       double lat, lon, elev, lat_scale, lon_scale;
00048       vsl_b_read(is, lat);
00049       vsl_b_read(is, lon);
00050       vsl_b_read(is, elev);
00051       vsl_b_read(is, lat_scale);
00052       vsl_b_read(is, lon_scale);
00053       unsigned gaunit;
00054       vsl_b_read(is, gaunit);
00055       vpgl_lvcs::AngUnits geo_angle_unit = static_cast<vpgl_lvcs::AngUnits>(gaunit);
00056       unsigned lunit;
00057       vsl_b_read(is, lunit);
00058       vpgl_lvcs::LenUnits localXYZUnit = static_cast<vpgl_lvcs::LenUnits>(lunit);
00059       double lox, loy, theta;
00060       vsl_b_read(is, lox);
00061       vsl_b_read(is, loy);
00062       vsl_b_read(is, theta);
00063       vpgl_lvcs temp(lat, lon, elev, name, lat_scale, lon_scale,
00064                      geo_angle_unit, localXYZUnit, lox, loy, theta);
00065       lvcs = temp;
00066       break;
00067     }
00068     default:
00069       vcl_cerr << "I/O ERROR: vpgl_lvcs::b_read(vsl_b_istream&)\n"
00070                << "           Unknown version number "<< ver << '\n';
00071       is.is().clear(vcl_ios::badbit); // Set an unrecoverable IO error on stream
00072       return;
00073   }
00074 }
00075 
00076 //: Print human readable summary of object to a stream
00077 void vsl_print_summary(vcl_ostream& os,const vpgl_lvcs & c)
00078 {
00079   os << c << '\n';
00080 }
00081 
00082 //: Binary save lvcs sptr to stream
00083 void vsl_b_write(vsl_b_ostream & os, vpgl_lvcs_sptr const& lvcs_sptr)
00084 {
00085   if (!lvcs_sptr) return;
00086   vpgl_lvcs* lvcs = lvcs_sptr.ptr();
00087   vsl_b_write(os, *lvcs);
00088 }
00089 
00090 //: Binary load lvcs sptr from stream.
00091 void vsl_b_read(vsl_b_istream & is, vpgl_lvcs_sptr &lvcs_sptr)
00092 {
00093   vpgl_lvcs* lvcs = 0;
00094   vsl_b_read(is, *lvcs);
00095   lvcs_sptr = lvcs;
00096 }