attribute_closing_opening_map.hh

00001 // Copyright (C) 2004  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, 59 Temple Place - Suite 330, Boston,
00016 // MA 02111-1307, 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_MORPHO_ATTRIBUTE_CLOSING_OPENING_MAP
00029 # define OLENA_MORPHO_ATTRIBUTE_CLOSING_OPENING_MAP
00030 # include <oln/morpho/attributes.hh>
00031 # include <oln/level/fill.hh>
00032 # include <oln/basics2d.hh>
00033 # include <ntg/int.hh>
00034 # include <oln/utils/histogram.hh>
00035 # include <oln/utils/special_points.hh>
00036 # include <oln/morpho/attributes.hh>
00037 
00038 # include <iterator>
00039 # include <vector>
00040 # include <map>
00041 # include <algorithm>
00042 # include <utility>
00043 
00044 
00045 namespace oln
00046 {
00047   namespace morpho
00048   {
00052     namespace slow
00053     {
00064       template <class I, class D, class Env = morpho::env::NullEnv>
00065       struct f_tarjan_map
00066       {
00067       public:
00068         typedef abstract::non_vectorial_image<I>        input_type;
00070 
00071         typedef oln_concrete_type(I)                    img_type;
00073 
00074         typedef oln_point_type(input_type)              point_type;
00076 
00077         typedef oln_value_type(input_type)              value_type;
00079 
00080         typedef typename mute<input_type, point_type>::ret parent_type;
00082 
00083         typedef typename mute<input_type, bool>::ret    is_proc_type;
00085         typedef attr_lambda_type(D)                     lambda_type;
00087 
00088         // e.g.,
00089         // when I is image2d<int_u8> and D is area_type, we've got:
00090         // +--------------+------------------+
00091         // | input_type   | image2d<int_u8>  |
00092         // | point_type   | point2d          |
00093         // | parent_type  | image2d<point2d> |
00094         // | is_proc_type | image2d<bool>    |
00095         // | lambda_type  | int              |
00096         // +--------------+------------------+
00097 
00109         template <class N>
00110         f_tarjan_map(bool is_closing,
00111                      const input_type& input,
00112                      const abstract::neighborhood<N>& ng,
00113                      const lambda_type& lambda,
00114                      const Env & env = Env());
00118         oln_concrete_type(I)
00119           res()
00120         {
00121           return output;
00122         }
00123       protected:
00124 
00128         static const point_type
00129         inactive();
00130 
00134         static const point_type
00135         active();
00136 
00141         void
00142         make_set(const point_type& x);
00143 
00149         void
00150         link(const point_type& x, const point_type& y);
00151 
00156         point_type
00157         find_root(const point_type& x);
00158 
00162         bool
00163         equiv(const point_type& x, const point_type& y) const;
00164 
00165 
00171         void
00172         do_union(const point_type& n, const point_type& p);
00173 
00174         const bool      is_closing; 
00175         const input_type&input; 
00176         lambda_type     lambda; 
00177         parent_type     parent; 
00178         is_proc_type    is_proc;
00179         img_type        output; 
00180         std::map<point_type, D,
00181                  oln::internal::default_less<point_type> > auxdata;
00183         Env             env;    
00184       };
00185 
00186 
00193       template <class D, class I, class N>
00194       oln_concrete_type(I)
00195         tarjan_map(bool is_closing,
00196                    const abstract::non_vectorial_image<I>& input,
00197                    const abstract::neighborhood<N>& ng,
00198                    const attr_lambda_type(D)& lambda,
00199                    const attr_env_type(D)& env/* = Env()*/)
00200       {
00201         oln::morpho::slow::f_tarjan_map<I, D, attr_env_type(D) > t(is_closing,
00202                                                                    input,
00203                                                                    ng,
00204                                                                    lambda,
00205                                                                    env);
00206         return t.res();
00207       }
00208 
00209 // Some macro to declare friendly function for different attributes
00210 // opening/closing
00211 # define xxx_opening_map_decl(T)                                        \
00212 template <class I, class N>                                             \
00213 oln_concrete_type(I)                                                    \
00214 T##_opening(const abstract::non_vectorial_image<I>& input,              \
00215             const abstract::neighborhood<N>& ng,                        \
00216             const attr_lambda_type(attr::T##_type<>)& lambda)                   \
00217     {                                                                   \
00218       return tarjan_map<attr::T##_type<>, I, N>(false, input, ng, lambda,       \
00219                                           attr_env_type(attr::T##_type<>)());   \
00220     }
00221 
00222       // same but attribute take care of the image type
00223 # define xxx_opening_im_map_decl(T)                                     \
00224 template <class I, class N>                                             \
00225 oln_concrete_type(I)                                                    \
00226 T##_opening(const abstract::non_vectorial_image<I>& input,              \
00227             const abstract::neighborhood<N>& ng,                        \
00228             const attr_lambda_type(attr::T##_type<I>)& lambda)          \
00229     {                                                                   \
00230       return tarjan_map<attr::T##_type<I>, I, N>(false, input, ng, lambda,      \
00231                                   attr_env_type(attr::T##_type<I>)());  \
00232     }
00233 
00234       //return input;
00235       //      return tarjan_map<T##_type, I, N>(false, input, ng, lambda,
00236       //         attr_env_type(T##_type<>)());
00237 # define xxx_closing_map_decl(T)                                        \
00238 template <class I, class N>                                             \
00239 oln_concrete_type(I)                                                    \
00240 T##_closing(const abstract::non_vectorial_image<I>& input,              \
00241             const abstract::neighborhood<N>& ng,                        \
00242             const attr_lambda_type(attr::T##_type<>)& lambda)                   \
00243     {                                                                   \
00244       return tarjan_map<attr::T##_type<>, I, N>(true, input, ng, lambda,        \
00245                                           attr_env_type(attr::T##_type<>)()); \
00246     }
00247 
00248       // same but attribute take care of the image type
00249 # define xxx_closing_im_map_decl(T)                                     \
00250 template <class I, class N>                                             \
00251 oln_concrete_type(I)                                                    \
00252 T##_closing(const abstract::non_vectorial_image<I>& input,              \
00253             const abstract::neighborhood<N>& ng,                        \
00254             const attr_lambda_type(attr::T##_type<I>)& lambda)          \
00255     {                                                                   \
00256       return tarjan_map<attr::T##_type<I>, I, N>(true, input, ng, lambda,       \
00257                                            attr_env_type(attr::T##_type<I>)());\
00258     }
00259 
00284       xxx_closing_map_decl(card);
00285 
00310       xxx_opening_map_decl(card);
00311 
00337       xxx_closing_map_decl(integral);
00338 
00364       xxx_opening_map_decl(integral);
00365 
00390       xxx_opening_map_decl(height);
00391 
00417       xxx_closing_map_decl(height);
00418 
00419 
00445       xxx_closing_map_decl(maxvalue);
00446 
00472       xxx_opening_map_decl(maxvalue);
00473 
00499       xxx_opening_map_decl(minvalue);
00500 
00526       xxx_closing_map_decl(minvalue);
00527 
00553       xxx_opening_im_map_decl(ball);
00554 
00580       xxx_closing_im_map_decl(ball);
00581 
00607       xxx_opening_im_map_decl(dist);
00608 
00634       xxx_closing_im_map_decl(dist);
00635 
00661       xxx_closing_im_map_decl(cube);
00662 
00688       xxx_opening_im_map_decl(cube);
00689 
00716       xxx_closing_im_map_decl(box);
00717 
00744       xxx_opening_im_map_decl(box);
00745 
00746 
00747     } // end of namespace slow
00748   } // end of namespace morpho
00749 } // end of namespace oln
00750 
00751 #include "attribute_closing_opening_map.hxx"
00752 
00753 #endif

Generated on Thu Apr 15 20:13:05 2004 for Olena by doxygen 1.3.6-20040222