contrib/brl/bseg/brip/brip_roi.h
Go to the documentation of this file.
00001 // This is brl/bseg/brip/brip_roi.h
00002 #ifndef brip_roi_h_
00003 #define brip_roi_h_
00004 //-----------------------------------------------------------------------------
00005 //:
00006 // \file
00007 // \author J.L. Mundy
00008 // \brief A composite region of interest class for image processing operations
00009 //
00010 // Provides a set of rectangular regions for processing in a larger image.
00011 //
00012 // \verbatim
00013 //  Modifications
00014 //   Initial version October 6, 2003
00015 //   Actual implementation July 12, 2004
00016 //   10-sep-2004 Peter Vanroose Added copy ctor with explicit vbl_ref_count init
00017 //   07-feb-2006 Ozge Can Ozcanli fixed bug on line 41 of .cxx  was --> if (dymax >= n_image_rows_) dymax = n_image_cols_-1;
00018 //                                                              now --> if (dymax >= n_image_rows_) dymax = n_image_rows_-1;
00019 // \endverbatim
00020 //
00021 //-----------------------------------------------------------------------------
00022 #include <vsol/vsol_box_2d_sptr.h>
00023 #include <vbl/vbl_ref_count.h>
00024 #include <vcl_vector.h>
00025 #include <vcl_iosfwd.h> // for std::ostream
00026 
00027 class brip_roi : public vbl_ref_count
00028 {
00029  public:
00030   //: should initialize with image bounds on construction
00031   brip_roi(const unsigned n_image_cols = 0, const unsigned n_image_rows = 0);
00032   brip_roi(brip_roi const& r)
00033     : vbl_ref_count(), n_image_cols_(r.n_image_cols_),
00034       n_image_rows_(r.n_image_rows_), regions_(r.regions_) {}
00035 
00036   //: expand (or contract) each region of the roi by delta, creating a new roi
00037   brip_roi(brip_roi const& roi, const float delta);
00038 
00039   ~brip_roi() {}
00040   //: replace existing image bounds
00041   void set_image_bounds(const int n_image_cols,
00042                         const int n_image_rows);
00043 
00044   //: roi from origin and size
00045   void add_region(const int x0, const int y0, const int xs, const int ys);
00046   //: roi from center and radius
00047   void add_region(const int xc, const int yc, const int radius);
00048   //: roi from box
00049   void add_region(vsol_box_2d_sptr const & box);
00050 
00051   //: useful for inserting a new region, doesn't affect existing image bounds
00052   vsol_box_2d_sptr clip_to_image_bounds(vsol_box_2d_sptr box);
00053   //: clips all existing regions, doesn't affect existing image bounds
00054   void clip_to_image_bounds();
00055   bool empty() const;
00056   unsigned int n_regions() const { return regions_.size(); }
00057   int cmin(const unsigned i) const; //!< column minimum for region_i
00058   int cmax(const unsigned i) const; //!< column maximum for region_i
00059   int rmin(const unsigned i) const; //!< row minimum for region_i
00060   int rmax(const unsigned i) const; //!< row maximum for region_i
00061   unsigned csize(const unsigned i) const; //!< number of cols for region_i
00062   unsigned rsize(const unsigned i) const; //!< number of rows for region_i
00063 
00064   //: image column and row coordinates from local roi coordinates for region i
00065   unsigned ic(int local_col, unsigned i = 0) const;
00066   unsigned ir(int local_row, unsigned i = 0) const;
00067 
00068   //: local roi column and row coordinates from global image coordinates for region i
00069   unsigned lc(unsigned global_col, unsigned i = 0) const;
00070   unsigned lr(unsigned global_row, unsigned i = 0) const;
00071 
00072   vsol_box_2d_sptr region(unsigned i) const { return regions_[i]; }
00073   bool remove_region(unsigned i);
00074 
00075  protected:
00076   unsigned n_image_cols_;
00077   unsigned n_image_rows_;
00078   vcl_vector<vsol_box_2d_sptr> regions_;
00079 };
00080 
00081 vcl_ostream&  operator<<(vcl_ostream& s, brip_roi const& r);
00082 
00083 #include "brip_roi_sptr.h"
00084 
00085 #endif // brip_roi_h_