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_SPX_MAXTREE_HH
00029 # define OLENA_LRDE_UFMT_SPX_MAXTREE_HH
00030
00031 # include <oln/level/fill.hh>
00032 # include <oln/lrde/ufmt/utils.hh>
00033 # include <oln/lrde/ufmt/ap_maxtree.hh>
00034 # include <oln/lrde/ufmt/attributes.hh>
00035
00036
00037
00038 namespace oln
00039 {
00040
00041 namespace lrde
00042 {
00043
00044 namespace ufmt
00045 {
00046
00047
00048
00049 template <class I>
00050 struct spx_maxtree : public ap_maxtree<I>
00051 {
00052 typedef ap_maxtree<I> super;
00053 using super::f;
00054 using super::nbh;
00055 using super::par;
00056 oln_lrde_ufmt_import_ap_maxtree_typedefs;
00057
00058
00059 std::vector<point> S;
00060 std::vector<size_t> H;
00061 std::vector<dpoint> dp_pre, dp_post;
00062 unsigned nb;
00063 unsigned nnodes;
00064 typename mute<I, unsigned>::ret label;
00065 typename mute<I, point>::ret cpar;
00066
00067
00068
00069
00070 spx_maxtree(const abstract::image<I>& f,
00071 const oln_neighborhood_type(I)& nbh)
00072 :
00073 super(f, nbh),
00074 label(f.size()),
00075 cpar(f.size())
00076 {
00077 }
00078
00079 template <class A>
00080 void go()
00081 {
00082 init();
00083 compute_parent();
00084
00085 }
00086
00087 void init()
00088 {
00089 S.reserve(f.npoints());
00090 oln_iter_type(I) p(f);
00091 for_all(p)
00092 S.push_back(p);
00093 std::sort(S.begin(), S.end(), rev_sort<I>(f));
00094
00095 nb = split<I>(nbh, dp_pre, dp_post);
00096 nnodes = 1;
00097 }
00098
00099 void compute_parent()
00100 {
00101 for (unsigned i = 0; i < f.npoints(); ++i)
00102 {
00103 point p = S[i];
00104 make_x_set(p);
00105
00106 for (unsigned j = 0; j < nb; ++j)
00107 {
00108 point n = p + dp_pre[j];
00109 if (f.hold(n) and f[n] >= f[p])
00110 do_x_union(n, p);
00111 }
00112
00113 for (unsigned j = 0; j < nb; ++j)
00114 {
00115 point n = p + dp_post[j];
00116 if (f.hold(n) and f[n] > f[p])
00117 do_x_union(n, p);
00118 }
00119 }
00120 }
00121
00122
00123 void make_x_set(const point& x)
00124 {
00125 par[x] = x;
00126 cpar[x] = x;
00127 }
00128
00129 point find_x_root(point x)
00130 {
00131 if (cpar[x] == x)
00132 return x;
00133 else
00134 return cpar[x] = find_x_root(cpar[x]);
00135 }
00136
00137 void do_x_union(const point& n, const point& p)
00138 {
00139 point r = find_x_root(n);
00140 if (r != p)
00141 {
00142 par[r] = p;
00143 cpar[r] = p;
00144 if (f[p] < f[r])
00145 ++nnodes;
00146 }
00147 }
00148
00149
00150 };
00151
00152
00153
00154 }
00155
00156 }
00157
00158 }
00159
00160
00161 #endif // ! OLENA_LRDE_UFMT_SPX_MAXTREE_HH