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

regional_maxima.hh

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

Generated on Thu Sep 8 2011 18:32:23 for Milena (Olena) by  doxygen 1.7.1