contrib/brl/bbas/bvgl/bvgl_change_obj.cxx
Go to the documentation of this file.
00001 //:
00002 // \file
00003 
00004 
00005 #include "bvgl_change_obj.h"
00006 #include <vgl/io/vgl_io_polygon.h>
00007 #include <vsol/vsol_polygon_2d.h>
00008 #include <vsol/vsol_point_2d.h>
00009 
00010 bvgl_change_obj::bvgl_change_obj(const bvgl_change_obj& other)
00011 : vbl_ref_count()
00012 {
00013   class_ = other.class_;
00014   poly_ = other.poly_;
00015 }
00016 
00017 //: Return IO version number;
00018 unsigned char
00019 bvgl_change_obj::version(  ) const
00020 {
00021   return 1;
00022 }
00023 
00024 //: return the centroid of the polygon
00025 void bvgl_change_obj::centroid(double &x_cent, double &y_cent) const
00026 {
00027   //: find the centre of this polygon
00028   x_cent = 0.0, y_cent = 0.0;
00029   int tot_size = 0;
00030   for (unsigned s = 0; s < poly_.num_sheets(); s++) {
00031     for (unsigned si = 0; si < poly_[s].size(); si++) {
00032       x_cent += poly_[s][si].x();
00033       y_cent += poly_[s][si].y();
00034     }
00035     tot_size += poly_[s].size(); 
00036   }
00037   x_cent /= tot_size;
00038   y_cent /= tot_size;
00039 }
00040 
00041 //: binary IO write
00042 void bvgl_change_obj::b_write(vsl_b_ostream& os)
00043 {
00044   // first write the version number;
00045   unsigned char ver = version();
00046   vsl_b_write(os, ver);
00047 
00048   vsl_b_write(os, class_);
00049   vsl_b_write(os, poly_);
00050 }
00051 
00052 
00053 //: binary IO read
00054 void bvgl_change_obj::b_read(vsl_b_istream& is)
00055 {
00056   // first read the version number;
00057   unsigned char ver;
00058   vsl_b_read(is, ver);
00059 
00060   switch (ver)
00061   {
00062    case 1:
00063     vsl_b_read(is, class_);
00064     vsl_b_read(is, poly_);
00065     break;
00066    default:
00067     vcl_cout << "In bvgl_change_obj::b_read() -- Unrecognized version number\n";
00068     break;
00069   }
00070 
00071   return;
00072 }
00073 
00074 #if 0
00075 void bvgl_change_obj::xml_read()
00076 {
00077 }
00078 
00079 void bvgl_change_obj::xml_write()
00080 {
00081 }
00082 #endif // 0