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_R1IC_MAXTREE_HH 00029 # define OLENA_LRDE_UFMT_R1IC_MAXTREE_HH 00030 00031 # include <oln/lrde/ufmt/utils.hh> 00032 00033 00034 00035 namespace oln 00036 { 00037 00038 namespace lrde 00039 { 00040 00041 namespace ufmt 00042 { 00043 00044 00045 // FIXME: doc. 00046 00047 template <class I> 00048 struct r1ic_maxtree 00049 { 00050 typedef I image; 00051 typedef point1d point; 00052 typedef oln_value_type(I) value; 00053 00054 // input 00055 const I& f; 00056 00057 // aux data 00058 typename mute<I, point>::ret par; 00059 00060 00061 // ctor 00062 00063 r1ic_maxtree(const abstract::image<I>& f) 00064 : 00065 f(f.exact()), 00066 // FIXME: par should NOT be initialized here! (but in "init()") 00067 par(f.size()) 00068 { 00069 } 00070 00071 void go() 00072 { 00073 init(); 00074 compute_parent(); // 1st pass 00075 extract_maxtree(); // 2nd pass 00076 } 00077 00078 void init() 00079 { 00080 } 00081 00082 void compute_parent() 00083 { 00084 oln_iter_type(I) p(f); 00085 p = mlc::begin; 00086 make_set(p); 00087 for_all_remaining(p) 00088 { 00089 make_set(p); 00090 insert(p.col() - 1, p); 00091 } 00092 } 00093 00094 void extract_maxtree() 00095 { 00096 // FIXME: TODO 00097 } 00098 00099 void make_set(const point& x) 00100 { 00101 par[x] = x; 00102 } 00103 00104 bool is_tree_root(const point& x) const 00105 { 00106 return par[x] == x; 00107 } 00108 00109 bool is_level_root(const point& x) const 00110 { 00111 return is_tree_root(x) or f[par[x]] < f[x]; 00112 } 00113 00114 point find_level_root(const point& x) 00115 { 00116 if (is_level_root(x)) 00117 return x; 00118 else 00119 return par[x] = find_level_root(par[x]); 00120 } 00121 00122 point anc(point x, ntg::int_u8 h) 00123 { 00124 while (par[x] != x and h <= f[par[x]]) 00125 x = find_level_root(par[x]); 00126 return x; 00127 } 00128 00129 void insert(const point& n, const point& p) 00130 { 00131 point r = anc(n, f[p]); 00132 00133 if (f[r] <= f[p]) 00134 par[p] = r; 00135 else 00136 { 00137 if (par[r] != r) 00138 par[p] = par[r]; 00139 par[r] = p; 00140 } 00141 } 00142 00143 00144 00145 // uniformized interface 00146 00147 const point& parent_(const point& p) const { 00148 return par[p]; 00149 } 00150 const value& f_(const point& p) const { 00151 return f[p]; 00152 } 00153 const I& f_() const { 00154 return f; 00155 } 00156 bool is_tree_root_(const point& p) const { 00157 return is_tree_root(p); 00158 } 00159 bool is_level_root_(const point& p) const { 00160 return is_level_root(p); 00161 } 00162 00163 // end of uniformized interface 00164 00165 00166 00167 }; // end of class r1ic_maxtree 00168 00169 00170 00171 } // end of namespace oln::lrde::ufmt 00172 00173 } // end of namespace oln::lrde 00174 00175 } // end of namespace oln 00176 00177 00178 #endif // ! OLENA_LRDE_UFMT_R1IC_MAXTREE_HH