ap_maxtree.hh

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_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       // FIXME: doc.
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         // aux typedefs
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         // input
00070         const I& f;
00071         const Nbh& nbh;
00072 
00073         // aux data
00074         typename mute<I, point>::ret par;
00075 
00076 
00077         // ctor
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         // uniformized interface
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         // end of uniformized interface
00145 
00146 
00147 
00148       }; // end of class ap_maxtree
00149 
00150 
00151 
00152     } // end of namespace oln::lrde::ufmt
00153 
00154   } // end of namespace oln::lrde
00155 
00156 } // end of namespace oln
00157 
00158 
00159 #endif // ! OLENA_LRDE_UFMT_AP_MAXTREE_HH

Generated on Tue Feb 20 20:17:47 2007 for Olena by  doxygen 1.5.1