Go to the documentation of this file.00001 #include "sdet_region.h"
00002
00003
00004 #include <vgl/vgl_point_2d.h>
00005 #include <vgl/vgl_polygon.h>
00006 #include <vgl/algo/vgl_convex_hull_2d.h>
00007 #include <vdgl/vdgl_digital_region.h>
00008 #include <vsol/vsol_polygon_2d.h>
00009 #include <bsol/bsol_algs.h>
00010
00011 sdet_region::sdet_region()
00012 {
00013 boundary_valid_ = false;
00014 region_label_ = 0;
00015 }
00016
00017 sdet_region::sdet_region(int npts, const float* xp, const float* yp,
00018 const unsigned short *pix)
00019 : vdgl_digital_region(npts, xp, yp, pix)
00020 {
00021 boundary_valid_ = false;
00022 region_label_ = 0;
00023 }
00024
00025 sdet_region::sdet_region(vdgl_digital_region const& reg)
00026 :vdgl_digital_region(reg.Npix(), reg.Xj(), reg.Yj(), reg.Ij())
00027 {
00028 boundary_valid_ = false;
00029 region_label_ = 0;
00030 }
00031
00032 bool sdet_region::compute_boundary()
00033 {
00034 if (boundary_valid_)
00035 return true;
00036
00037 if (this->Npix()<3)
00038 return false;
00039 vcl_vector<vgl_point_2d<double> > region_points;
00040 for (this->reset(); this->next();)
00041 region_points.push_back(vgl_point_2d<double>(this->X(), this->Y()));
00042 vgl_convex_hull_2d<double> ch(region_points);
00043 vgl_polygon<double> h = ch.hull();
00044 vsol_polygon_2d_sptr poly = bsol_algs::poly_from_vgl(h);
00045 if (!poly)
00046 return false;
00047 boundary_ = poly;
00048 boundary_valid_ = true;
00049 return true;
00050 }
00051
00052 vsol_polygon_2d_sptr sdet_region::boundary()
00053 {
00054 vsol_polygon_2d_sptr temp;
00055 if (!boundary_valid_)
00056 if (!this->compute_boundary())
00057 return temp;
00058 return boundary_;
00059 }