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, 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_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       // same but attribute take care of the image type
00235 # define xxx_opening_im_env_map_decl(T)                                 \
00236 template <class I, class N>                                             \
00237 oln_concrete_type(I)                                                    \
00238 T##_opening(const abstract::non_vectorial_image<I>& input,              \
00239             const abstract::neighborhood<N>& ng,                        \
00240             const attr_lambda_type(attr::T##_type<I>)& lambda,          \
00241             const attr_env_type(attr::T##_type<I>) &env)                \
00242     {                                                                   \
00243       return tarjan_map<attr::T##_type<I>, I, N>(false, input, ng, lambda,      \
00244                                   env); \
00245     }
00246 
00247       //return input;
00248       //      return tarjan_map<T##_type, I, N>(false, input, ng, lambda,
00249       //         attr_env_type(T##_type<>)());
00250 # define xxx_closing_map_decl(T)                                        \
00251 template <class I, class N>                                             \
00252 oln_concrete_type(I)                                                    \
00253 T##_closing(const abstract::non_vectorial_image<I>& input,              \
00254             const abstract::neighborhood<N>& ng,                        \
00255             const attr_lambda_type(attr::T##_type<>)& lambda)                   \
00256     {                                                                   \
00257       return tarjan_map<attr::T##_type<>, I, N>(true, input, ng, lambda,        \
00258                                           attr_env_type(attr::T##_type<>)()); \
00259     }
00260 
00261       // same but attribute take care of the image type
00262 # define xxx_closing_im_map_decl(T)                                     \
00263 template <class I, class N>                                             \
00264 oln_concrete_type(I)                                                    \
00265 T##_closing(const abstract::non_vectorial_image<I>& input,              \
00266             const abstract::neighborhood<N>& ng,                        \
00267             const attr_lambda_type(attr::T##_type<I>)& lambda)          \
00268     {                                                                   \
00269       return tarjan_map<attr::T##_type<I>, I, N>(true, input, ng, lambda,       \
00270                                            attr_env_type(attr::T##_type<I>)());\
00271     }
00272 
00273 # define xxx_closing_im_env_map_decl(T)                                 \
00274 template <class I, class N>                                             \
00275 oln_concrete_type(I)                                                    \
00276 T##_closing(const abstract::non_vectorial_image<I>& input,              \
00277             const abstract::neighborhood<N>& ng,                        \
00278             const attr_lambda_type(attr::T##_type<I>)& lambda,          \
00279             const attr_env_type(attr::T##_type<I>) &env)                \
00280     {                                                                   \
00281       return tarjan_map<attr::T##_type<I>, I, N>(true, input, ng, lambda,       \
00282                                   env); \
00283     }
00284 
00309       xxx_closing_map_decl(card)
00310 
00311       
00335       xxx_opening_map_decl(card)
00336 
00362       xxx_closing_map_decl(integral)
00363 
00389       xxx_opening_map_decl(integral)
00390 
00417       xxx_closing_im_env_map_decl(volume)
00418 
00445       xxx_opening_im_env_map_decl(volume)
00446 
00471       xxx_opening_map_decl(height)
00472 
00498       xxx_closing_map_decl(height)
00499 
00500 
00526       xxx_closing_map_decl(maxvalue)
00527 
00553       xxx_opening_map_decl(maxvalue)
00554 
00580       xxx_opening_map_decl(minvalue)
00581 
00607       xxx_closing_map_decl(minvalue)
00608 
00634       xxx_opening_im_map_decl(ball)
00635 
00661       xxx_closing_im_map_decl(ball)
00662 
00688       xxx_opening_im_map_decl(dist)
00689 
00715       xxx_closing_im_map_decl(dist)
00716 
00742       xxx_closing_im_map_decl(cube)
00743 
00769       xxx_opening_im_map_decl(cube)
00770 
00797       xxx_closing_im_map_decl(box)
00798 
00825       xxx_opening_im_map_decl(box)
00826 
00827 
00828     } // end of namespace slow
00829   } // end of namespace morpho
00830 } // end of namespace oln
00831 
00832 #include "attribute_closing_opening_map.hxx"
00833 
00834 #endif

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