00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #ifndef OLENA_LRDE_UFMT_AP_MAXTREE_HH
00029 # define OLENA_LRDE_UFMT_AP_MAXTREE_HH
00030
00031 # include <oln/lrde/ufmt/utils.hh>
00032
00033
00034 # define oln_lrde_ufmt_import_ap_maxtree_typedefs \
00035 typedef typename super::image image; \
00036 typedef typename super::point point; \
00037 typedef typename super::dpoint dpoint; \
00038 typedef typename super::value value; \
00039 typedef typename super::Nbh Nbh; \
00040 typedef typename super::niter niter
00041
00042
00043 namespace oln
00044 {
00045
00046 namespace lrde
00047 {
00048
00049 namespace ufmt
00050 {
00051
00052
00053
00054
00055 template <class I>
00056 struct ap_maxtree
00057 {
00058 typedef I image;
00059 typedef oln_point_type(I) point;
00060 typedef oln_dpoint_type(I) dpoint;
00061 typedef oln_value_type(I) value;
00062 typedef oln_neighborhood_type(I) Nbh;
00063 typedef oln_iter_type(Nbh) niter;
00064
00065
00066 typedef typename mute<I, ntg::bin>::ret bin_image_t;
00067 typedef typename mute<I, ntg::int_u8>::ret int_u8_image_t;
00068
00069
00070 const I& f;
00071 const Nbh& nbh;
00072
00073
00074 typename mute<I, point>::ret par;
00075
00076
00077
00078
00079 ap_maxtree(const abstract::image<I>& f,
00080 const oln_neighborhood_type(I)& nbh)
00081 :
00082 f(f.exact()),
00083 nbh(nbh),
00084 par(f.size())
00085 {
00086 }
00087
00088 void make_set(const point& x)
00089 {
00090 par[x] = x;
00091 }
00092
00093 bool is_root(const point& x) const
00094 {
00095 return par[x] == x;
00096 }
00097
00098 bool is_level_root(const point& x) const
00099 {
00100 return is_root(x) or f[par[x]] < f[x];
00101 }
00102
00103 point find_level_root(const point& x)
00104 {
00105 if (is_level_root(x))
00106 return x;
00107 else
00108 return par[x] = find_level_root(par[x]);
00109 }
00110
00111 point anc(point x, value h)
00112 {
00113 while (par[x] != x and h <= f[par[x]])
00114 x = find_level_root(par[x]);
00115 return x;
00116 }
00117
00118 void swap(point& x, point& y)
00119 {
00120 point memo = x;
00121 x = y;
00122 y = memo;
00123 }
00124
00125
00126
00127
00128 point parent_(const point& p) const {
00129 return par[p];
00130 }
00131 const value& f_(const point& p) const {
00132 return f[p];
00133 }
00134 const I& f_() const {
00135 return f;
00136 }
00137 bool is_root_(const point& p) const {
00138 return is_root(p);
00139 }
00140 bool is_level_root_(const point& p) const {
00141 return is_level_root(p);
00142 }
00143
00144
00145
00146
00147
00148 };
00149
00150
00151
00152 }
00153
00154 }
00155
00156 }
00157
00158
00159 #endif // ! OLENA_LRDE_UFMT_AP_MAXTREE_HH