contrib/brl/bseg/brip/brip_region_pixel.h
Go to the documentation of this file.
00001 // This is brl/bseg/brip/brip_region_pixel.h
00002 #ifndef brip_region_pixel_h_
00003 #define brip_region_pixel_h_
00004 //-----------------------------------------------------------------------------
00005 //:
00006 // \file
00007 // \author J.L. Mundy
00008 // \brief A region pixel class for the watershed algorithm.
00009 //
00010 // \verbatim
00011 //  Modifications
00012 //   Initial version July 5, 2004
00013 // \endverbatim
00014 //
00015 //-----------------------------------------------------------------------------
00016 #include <vcl_iosfwd.h>
00017 #include <vbl/vbl_ref_count.h>
00018 #include <vgl/vgl_point_2d.h>
00019 
00020 #include "brip_region_pixel_sptr.h"
00021 
00022 class brip_region_pixel : public vbl_ref_count
00023 {
00024  public:
00025   vgl_point_2d<int> location_;
00026   vgl_point_2d<int> nearest_;
00027   float cost_;
00028   int count_;
00029   unsigned int label_;
00030   int dist_;
00031 
00032   brip_region_pixel()
00033     : vbl_ref_count(), location_(0,0), nearest_(0,0), cost_(0.0f),
00034       count_(0), label_(0), dist_(0) {}
00035   brip_region_pixel(brip_region_pixel const& p)
00036     : vbl_ref_count(), location_(p.location_), nearest_(p.nearest_),
00037       cost_(p.cost_), count_(p.count_), label_(p.label_), dist_(p.dist_) {}
00038   brip_region_pixel(vgl_point_2d<int> const& location,
00039                     vgl_point_2d<int> const& nearest,
00040                     float const& cost,
00041                     int const count,
00042                     unsigned int const& label)
00043     : vbl_ref_count(), location_(location), nearest_(nearest), cost_(cost),
00044       count_(count), label_(label)
00045   {
00046     int dx = location_.x() - nearest_.x();
00047     int dy = location_.y() - nearest_.y();
00048     dist_ = dx * dx + dy * dy;
00049   }
00050 
00051   void set(vgl_point_2d<int> const& location,
00052            vgl_point_2d<int> const& nearest,
00053            float const& cost,
00054            int   const& count,
00055            int   const& label)
00056   {
00057     location_ = location;
00058     nearest_ = nearest;
00059     cost_ = cost;
00060     count_ = count;
00061     label_ = label;
00062     int dx = location_.x() - nearest_.x();
00063     int dy = location_.y() - nearest_.y();
00064     dist_ = dx * dx + dy * dy;
00065   }
00066 
00067   // must implement comparison since priority_queue looks for largest element
00068   struct compare
00069   {
00070     bool operator()(brip_region_pixel const& l,
00071                     brip_region_pixel const& r) const
00072     {
00073       if (r.cost_ == l.cost_)
00074       {
00075         if (r.dist_ == l.dist_) return r.count_ < l.count_;
00076 
00077         return r.dist_ < l.dist_;
00078       }
00079 
00080       return r.cost_ < l.cost_;
00081     }
00082 
00083 
00084     bool operator()(brip_region_pixel_sptr const& l,
00085                     brip_region_pixel_sptr const& r) const
00086     {
00087       if (r->cost_ == l->cost_)
00088       {
00089         if (r->dist_ == l->dist_) return r->count_ < l->count_;
00090 
00091         return r->dist_ < l->dist_;
00092       }
00093 
00094       return r->cost_ < l->cost_;
00095     }
00096   };
00097 };
00098 
00099 vcl_ostream& operator<<(vcl_ostream& s, brip_region_pixel const& sd);
00100 
00101 #endif // brip_region_pixel_h_