Go to the documentation of this file.00001
00002
00003
00004 #include "bvgl_changes.h"
00005 #include "bvgl_change_obj.h"
00006 #include <vil/vil_image_view.h>
00007 #include <vgl/vgl_polygon_scan_iterator.h>
00008
00009 vil_image_view_base_sptr
00010 bvgl_changes::create_mask_from_objs(unsigned ni, unsigned nj, vcl_string change_type)
00011 {
00012 vil_image_view<vxl_byte>* mask = new vil_image_view<vxl_byte>(ni, nj);
00013 mask->fill(0);
00014
00015
00016 for (unsigned i=0; i<objs_.size(); i++)
00017 {
00018 vgl_polygon<double> v_poly = objs_[i]->poly();
00019 vgl_polygon_scan_iterator<double> psi(v_poly, false);
00020 for (psi.reset(); psi.next();){
00021 int y = psi.scany();
00022 for (int x = psi.startx(); x<=psi.endx(); ++x)
00023 {
00024 unsigned u = static_cast<unsigned>(x);
00025 unsigned v = static_cast<unsigned>(y);
00026 if (u >= ni || v >= nj)
00027 continue;
00028 if (objs_[i]->type().compare(change_type)==0)
00029 (*mask)(u,v) = 255;
00030 }
00031 }
00032 }
00033
00034 return mask;
00035 }
00036
00037 vil_image_view_base_sptr
00038 bvgl_changes::create_mask_from_objs_all_types(unsigned ni, unsigned nj)
00039 {
00040 vil_image_view<vxl_byte>* mask = new vil_image_view<vxl_byte>(ni, nj);
00041 mask->fill(0);
00042
00043
00044 for (unsigned i=0; i<objs_.size(); i++)
00045 {
00046 vgl_polygon<double> v_poly = objs_[i]->poly();
00047 vgl_polygon_scan_iterator<double> psi(v_poly, false);
00048 for (psi.reset(); psi.next();){
00049 int y = psi.scany();
00050 for (int x = psi.startx(); x<=psi.endx(); ++x)
00051 {
00052 unsigned u = static_cast<unsigned>(x);
00053 unsigned v = static_cast<unsigned>(y);
00054 if (objs_[i]->type().compare("dont_care")!=0)
00055 (*mask)(u,v) = 255;
00056 else
00057 (*mask)(u,v) = 125;
00058 }
00059 }
00060 }
00061
00062 return mask;
00063 }
00064
00065 void bvgl_changes::add_obj(bvgl_change_obj_sptr obj)
00066 {
00067 objs_.push_back(obj);
00068 }
00069
00070 void bvgl_changes::remove_obj(bvgl_change_obj_sptr obj)
00071 {
00072 vcl_vector<bvgl_change_obj_sptr>::iterator iter = objs_.begin();
00073 while (iter!=objs_.end()) {
00074 if (*iter == obj) {
00075 objs_.erase(iter);
00076 vcl_cout << "DELETED!" << vcl_endl;
00077 return;
00078 }
00079 iter++;
00080 }
00081 vcl_cout << "Object is no FOUND!" << vcl_endl;
00082 }
00083
00084 #if 0
00085 void bvgl_changes::xml_read()
00086 {
00087 }
00088
00089 void bvgl_changes::xml_write()
00090 {
00091 }
00092 #endif // 0
00093
00094
00095 unsigned char
00096 bvgl_changes::version( ) const
00097 {
00098 return 1;
00099 }
00100
00101
00102 void bvgl_changes::b_write(vsl_b_ostream& os)
00103 {
00104
00105 unsigned char ver = version();
00106 vsl_b_write(os, ver);
00107
00108 vsl_b_write(os, img_name_);
00109 vsl_b_write(os, objs_.size());
00110 for (unsigned i = 0; i < objs_.size(); i++) {
00111 objs_[i]->b_write(os);
00112 }
00113 }
00114
00115
00116
00117 void bvgl_changes::b_read(vsl_b_istream& is)
00118 {
00119
00120 unsigned char ver;
00121 vsl_b_read(is, ver);
00122
00123 switch (ver)
00124 {
00125 case 1:
00126 {
00127 vsl_b_read(is, img_name_);
00128 unsigned size;
00129 vsl_b_read(is, size);
00130 for (unsigned i = 0; i < size; ++i) {
00131 bvgl_change_obj o;
00132 o.b_read(is);
00133 objs_.push_back(new bvgl_change_obj(o));
00134 }
00135 break;
00136 }
00137 default:
00138 vcl_cout << "In bvgl_changes::b_read() -- Unrecognized version number " << ver << vcl_endl;
00139 break;
00140 }
00141
00142 return;
00143 }
00144
00145 bvgl_change_obj_sptr
00146 bvgl_changes::obj(unsigned int i)
00147 {
00148 if (i<size())
00149 return objs_[i];
00150 return 0;
00151 }