00001
00002 #ifndef brip_rect_mask_h_
00003 #define brip_rect_mask_h_
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
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
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
00043 static void init();
00044
00045
00046 static vcl_string name(ang_id aid);
00047
00048
00049 static float angle(ang_id aid);
00050
00051
00052 static float ang_diff(ang_id aid0,ang_id aid1);
00053
00054
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
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
00067 unsigned ni() const {return current_mask_.cols();}
00068
00069
00070 unsigned nj() const {return current_mask_.rows();}
00071
00072
00073 unsigned n_angles() const {return masks_.size();}
00074
00075
00076 ang_id angle_id(unsigned angle_index) const;
00077
00078
00079 unsigned nplus() const;
00080
00081 unsigned nminus() const;
00082
00083
00084 bool set_angle_id(ang_id aid);
00085
00086
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
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_