• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Classes
  • Files
  • File List

regional_maxima.hh

00001 // Copyright (C) 2007, 2008, 2009 EPITA Research and Development
00002 // Laboratory (LRDE)
00003 //
00004 // This file is part of Olena.
00005 //
00006 // Olena is free software: you can redistribute it and/or modify it under
00007 // the terms of the GNU General Public License as published by the Free
00008 // Software Foundation, version 2 of the License.
00009 //
00010 // Olena is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013 // General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU General Public License
00016 // along with Olena.  If not, see <http://www.gnu.org/licenses/>.
00017 //
00018 // As a special exception, you may use this file as part of a free
00019 // software project 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 produce
00022 // an executable, this file does not by itself cause the resulting
00023 // executable to be covered by the GNU General Public License.  This
00024 // exception does not however invalidate any other reasons why the
00025 // executable file might be covered by the GNU General Public License.
00026 
00027 #ifndef MLN_LABELING_REGIONAL_MAXIMA_HH
00028 # define MLN_LABELING_REGIONAL_MAXIMA_HH
00029 
00033 
00034 # include <mln/core/concept/image.hh>
00035 # include <mln/core/concept/neighborhood.hh>
00036 # include <mln/canvas/labeling/sorted.hh>
00037 # include <mln/data/fill.hh>
00038 # include <mln/data/sort_psites.hh>
00039 
00040 
00041 namespace mln
00042 {
00043 
00044   namespace labeling
00045   {
00046 
00056     template <typename I, typename N, typename L>
00057     mln_ch_value(I, L)
00058       regional_maxima(const Image<I>& input, const Neighborhood<N>& nbh,
00059                       L& nlabels);
00060 
00061 
00062 
00063 # ifndef MLN_INCLUDE_ONLY
00064 
00065     namespace impl
00066     {
00067 
00068       // Generic functor.
00069 
00070       template <typename I>
00071       struct regional_maxima_functor
00072       {
00073         typedef mln_psite(I) P;
00074 
00075         // requirements from mln::canvas::labeling:
00076 
00077         const I& input;
00078 
00079         // Generic implementation
00080 
00081         void init()                              { data::fill(attr, true); }
00082         bool handles(const P&) const             { return true; }
00083         bool labels(const P& p) const            { return attr(p); }
00084         bool equiv(const P& n, const P& p) const { return input(n) ==
00085                                                    input(p); }
00086         void do_no_union(const P& n, const P& p) { mln_invariant(input(n) >
00087                                                                  input(p));
00088                                                    attr(p) = false; (void)n; }
00089         void init_attr(const P&)                 {}
00090         void merge_attr(const P& r, const P& p)  { attr(p) = attr(p) &&
00091             attr(r); }
00092 
00093         // Fastest implementation
00094 
00095         void init_()                              { data::fill(attr, true); }
00096         bool handles_(unsigned) const           { return true; }
00097         bool labels_(unsigned p) const            { return attr.element(p); }
00098         bool equiv_(unsigned n, unsigned p) const { return input.element(n) ==
00099             input.element(p); }
00100         void do_no_union_(unsigned n, unsigned p) { // mln_invariant(input.element(n) >
00101           //      input.element(p));
00102           attr.element(p) = false;
00103           (void) n;
00104         }
00105         void init_attr_(unsigned)                 {}
00106         void merge_attr_(unsigned r, unsigned p)  { attr.element(p) = attr.element(p) &&
00107             attr.element(r); }
00108 
00109         // end of requirements
00110 
00111         mln_ch_value(I, bool) attr;
00112 
00113         regional_maxima_functor(const I& input)
00114           : input(input)
00115         {
00116           initialize(attr, input);
00117         }
00118       };
00119 
00120 
00121     } // end of namespace mln::labeling::impl
00122 
00123 
00124 
00125 
00126     // Facade.
00127 
00128     template <typename I, typename N, typename L>
00129     mln_ch_value(I, L)
00130       regional_maxima(const Image<I>& input_, const Neighborhood<N>& nbh_,
00131                       L& nlabels)
00132     {
00133       trace::entering("labeling::regional_maxima");
00134 
00135       const I& input = exact(input_);
00136       const N& nbh = exact(nbh_);
00137       mln_precondition(input.is_valid());
00138 
00139       typedef impl::regional_maxima_functor<I> F;
00140       F f(exact(input));
00141       mln_ch_value(I, L)
00142         output = canvas::labeling::sorted(input, nbh, nlabels, f, true);
00143 
00144       trace::exiting("labeling::regional_maxima");
00145       return output;
00146     }
00147 
00148 # endif // ! MLN_INCLUDE_ONLY
00149 
00150   } // end of namespace mln::labeling
00151 
00152 } // end of namespace mln
00153 
00154 
00155 #endif // ! MLN_LABELING_REGIONAL_MAXIMA_HH

Generated on Tue Oct 4 2011 15:24:21 for Milena (Olena) by  doxygen 1.7.1