contrib/brl/bseg/brip/brip_rect_mask.h
Go to the documentation of this file.
00001 // This is brl/bseg/brip/brip_rect_mask.h
00002 #ifndef brip_rect_mask_h_
00003 #define brip_rect_mask_h_
00004 //-----------------------------------------------------------------------------
00005 //:
00006 // \file
00007 // \author J.L. Mundy
00008 // \brief A rectangular pixel mask with positive interior negative surround
00009 //
00010 // \verbatim
00011 //  Modifications
00012 //   Initial version April 17, 2008
00013 // \endverbatim
00014 //
00015 //-----------------------------------------------------------------------------
00016 //  An example mask
00017 //
00018 //
00019 //       0 0 0 0 - - 0
00020 //       0 0 0 - + - 0
00021 //       0 0 - + - 0 0
00022 //       0 - + - 0 0 0
00023 //       0 - - 0 0 0 0
00024 //
00025 #include <vcl_string.h>
00026 #include <vcl_iosfwd.h>
00027 #include <vnl/vnl_matrix.h>
00028 #include <vcl_map.h>
00029 
00030 class brip_rect_mask
00031 {
00032  public:
00033   //: construct from radius, aspect ratio and orientation (degrees)
00034   enum mask_id { cr1 = 0, s1, b0, b1, b0s, b1s, r10, r30, r31, r32, r51, r52,
00035                  c4_90_0, c4_45_0, c4_45_45, e2, e3, e5, e11, m1, m4, m4s,m7,
00036                  f3, b3, f5, b5, b7, ntypes};
00037   enum ang_id {a0 = 0, a22, a45, a67, a90, a112, a135, a157, a180,a202, a225,
00038                a247, a270, a292, a315, a337, nangles};
00039   brip_rect_mask(mask_id mid);
00040   ~brip_rect_mask() {}
00041 
00042   //: initialize static quantities
00043   static void init();
00044 
00045   //: string name of angle id
00046   static vcl_string name(ang_id aid);
00047 
00048   //: floating point angle from id
00049   static float angle(ang_id aid);
00050 
00051   //: angle difference angle(aid1)-angle(aid0)
00052   static float ang_diff(ang_id aid0,ang_id aid1);
00053 
00054   //: Intersect '+' symbols of two masks of the same type
00055   static bool intersect(mask_id mid, 
00056                         ang_id aid0, 
00057                         unsigned short i0, unsigned short j0,
00058                         ang_id aid1,
00059                         unsigned short i1, unsigned short j1);
00060   //: Intersect full domain of two masks of the same type (0, ni, 0-nj)
00061   static bool intersect_domain(mask_id mid, 
00062                                ang_id aid0, 
00063                                unsigned short i0, unsigned short j0,
00064                                ang_id aid1,
00065                                unsigned short i1, unsigned short j1);
00066   //: the number of columns needed to span the mask
00067   unsigned ni() const {return current_mask_.cols();}
00068 
00069   //: the number of rows needed to span the mask
00070   unsigned nj() const {return current_mask_.rows();}
00071 
00072   //: the number of orientations
00073   unsigned n_angles() const {return masks_.size();}
00074 
00075   //: the orientation code
00076   ang_id angle_id(unsigned angle_index) const;
00077 
00078   //: the number of plus symbols for the current mask
00079   unsigned nplus() const;
00080   //: the number of minus symbols for the current mask
00081   unsigned nminus() const;
00082 
00083   //: set current angle id
00084   bool set_angle_id(ang_id aid);
00085 
00086   //: du and dv are measured from the center of the mask, returns +1, -1, 0;
00087   int operator () (int du, int dv) const
00088   {
00089     if (du>ru_||du<-ru_) return 0;
00090     if (dv>rv_||dv<-rv_) return 0;
00091     return current_mask_[dv+rv_][du+ru_];
00092   }
00093   //: print the mask with angle id, aid
00094   void print(ang_id aid);
00095  protected:
00096   bool find_ait(ang_id aid,
00097                 vcl_map<ang_id, vnl_matrix<int> >::const_iterator& ait) const;
00098   brip_rect_mask();
00099   vnl_matrix<int> current_mask_;
00100   int ru_, rv_;
00101   vcl_map<ang_id, vnl_matrix<int> > masks_;
00102   static vcl_map<ang_id, vcl_string > names_;
00103   static vcl_map<ang_id, float > angles_;
00104   static bool is_init_;
00105 };
00106 
00107 vcl_ostream& operator<<(vcl_ostream& s, brip_rect_mask const& m);
00108 
00109 #endif // brip_rect_mask_h_