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_HPX_MAXTREE_HH
00029 # define OLENA_LRDE_UFMT_HPX_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 hpx_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 hpx_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 = histogram_reverse_sort_p(f, H);
00090 nb = split<I>(nbh, dp_pre, dp_post);
00091 nnodes = 1;
00092 }
00093
00094 void compute_parent()
00095 {
00096 int i = 0;
00097 for (int h = uint_nvalues(f) - 1; h >= 0; --h)
00098 {
00099 int i_first = i;
00100 int i_last = i_first + H[h];
00101
00102
00103
00104 for (i = i_first; i < i_last; ++i)
00105 {
00106 point p = S[i];
00107 make_x_set(p);
00108
00109 for (unsigned j = 0; j < nb; ++j)
00110 {
00111 point n = p + dp_pre[j];
00112 if (f.hold(n) and f[n] >= h)
00113 do_x_union(n, p);
00114 }
00115
00116 for (unsigned j = 0; j < nb; ++j)
00117 {
00118 point n = p + dp_post[j];
00119 if (f.hold(n) and f[n] > h)
00120 do_x_union(n, p);
00121 }
00122 }
00123
00124
00125
00126
00127
00128
00129 for (int k = i_last - 1; k >= i_first; --k)
00130 {
00131 point p = S[k];
00132
00133
00134
00135 cpar[p] = cpar[cpar[p]];
00136 }
00137
00138 }
00139 }
00140
00141
00142 void make_x_set(const point& x)
00143 {
00144 par[x] = x;
00145 cpar[x] = x;
00146 }
00147
00148 point find_x_root(point x)
00149 {
00150 if (cpar[x] == x)
00151 return x;
00152 else
00153 return cpar[x] = find_x_root(cpar[x]);
00154 }
00155
00156 void do_x_union(const point& n, const point& p)
00157 {
00158 point r = find_x_root(n);
00159 if (r != p)
00160 {
00161 par[r] = p;
00162 cpar[r] = p;
00163 if (f[p] < f[r])
00164 ++nnodes;
00165 }
00166 }
00167
00168
00169 };
00170
00171
00172
00173 }
00174
00175 }
00176
00177 }
00178
00179
00180 #endif // ! OLENA_LRDE_UFMT_HPX_MAXTREE_HH