00001 // Copyright (C) 2006 EPITA Research and Development Laboratory 00002 // 00003 // This file is part of the Olena Library. This library is free 00004 // software; you can redistribute it and/or modify it under the terms 00005 // of the GNU General Public License version 2 as published by the 00006 // Free Software Foundation. 00007 // 00008 // This library is distributed in the hope that it will be useful, 00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00011 // General Public License for more details. 00012 // 00013 // You should have received a copy of the GNU General Public License 00014 // along with this library; see the file COPYING. If not, write to 00015 // the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00016 // Boston, MA 02110-1301, USA. 00017 // 00018 // As a special exception, you may use this file as part of a free 00019 // software library without restriction. Specifically, if other files 00020 // instantiate templates or use macros or inline functions from this 00021 // file, or you compile this file and link it with other files to 00022 // produce an executable, this file does not by itself cause the 00023 // resulting executable to be covered by the GNU General Public 00024 // License. This exception does not however invalidate any other 00025 // reasons why the executable file might be covered by the GNU General 00026 // Public License. 00027 00028 #ifndef OLENA_LRDE_UFMT_BASIC_MAXTREE_HH 00029 # define OLENA_LRDE_UFMT_BASIC_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 00035 00036 00037 namespace oln 00038 { 00039 00040 namespace lrde 00041 { 00042 00043 namespace ufmt 00044 { 00045 00046 00047 // FIXME: doc. 00048 00049 template <class I> 00050 struct basic_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 // aux data 00060 typename mute<I, bool>::ret isproc; 00061 std::vector<point> S; 00062 00063 00064 // ctor 00065 00066 basic_maxtree(const abstract::image<I>& f, 00067 const oln_neighborhood_type(I)& nbh) 00068 : 00069 super(f, nbh), 00070 isproc(f.size()) 00071 { 00072 } 00073 00074 void go() 00075 { 00076 init(); 00077 compute_parent(); // 1st pass 00078 extract_maxtree(); // 2nd pass 00079 } 00080 00081 void init() 00082 { 00083 S = histogram_reverse_sort_p(f); 00084 level::fill(isproc, false); 00085 } 00086 00087 void compute_parent() 00088 { 00089 for (int ip = 0; ip < int(S.size()); ++ip) 00090 { 00091 point p = S[ip]; 00092 make_set(p); 00093 00094 oln_neighb_type(Nbh) n(nbh, p); 00095 for_all(n) 00096 if (f.hold(n) and isproc[n]) 00097 do_union(n, p); 00098 isproc[p] = true; 00099 } 00100 } 00101 00102 void extract_maxtree() 00103 { 00104 // FIXME: TODO 00105 } 00106 00107 void do_union(const point& n, const point& p) 00108 { 00109 point r = find_root(n); 00110 if (r != p) 00111 par[r] = p; 00112 } 00113 00114 point find_root(point x) 00115 { 00116 while (not is_root(x)) 00117 x = find_level_root(par[x]); 00118 return x; 00119 } 00120 00121 00122 }; // end of class basic_maxtree 00123 00124 00125 00126 } // end of namespace oln::lrde::ufmt 00127 00128 } // end of namespace oln::lrde 00129 00130 } // end of namespace oln 00131 00132 00133 #endif // ! OLENA_LRDE_UFMT_BASIC_MAXTREE_HH