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

regional_minima.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_MINIMA_HH
00027 # define MLN_LABELING_REGIONAL_MINIMA_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_minima(const Image<I>& input, const Neighborhood<N>& nbh,
00058                     L& nlabels);
00059 
00060 
00061 # ifndef MLN_INCLUDE_ONLY
00062 
00063     namespace impl
00064     {
00065 
00066       // Generic functor.
00067 
00068       template <typename I>
00069       struct regional_minima_functor
00070       {
00071         typedef mln_psite(I) P;
00072 
00073         // requirements from mln::canvas::labeling:
00074 
00075         const I& input;
00076 
00077         // Generic implementation
00078 
00079         void init()                              { data::fill(attr, true); }
00080         bool handles(const P&) const             { return true; }
00081         bool labels(const P& p) const            { return attr(p); }
00082         bool equiv(const P& n, const P& p) const { return input(n) ==
00083                                                           input(p); }
00084         void do_no_union(const P& n, const P& p)
00085         {
00086           // Avoid a warning about an undefined variable when NDEBUG
00087           // is not defined.
00088           (void)n;
00089 
00090           mln_invariant(input(n) < input(p));
00091           attr(p) = false;
00092         }
00093 
00094         void init_attr(const P&)                 {}
00095         void merge_attr(const P& r, const P& p)  { attr(p) = attr(p) &&
00096                                                    attr(r); }
00097 
00098         // Fastest implementation
00099 
00100         void init_()                              { data::fill(attr, true); }
00101         bool handles_(unsigned) const             { return true; }
00102         bool labels_(unsigned p) const            { return attr.element(p); }
00103         bool equiv_(unsigned n, unsigned p) const { return input.element(n) ==
00104                                                            input.element(p); }
00105         void do_no_union_(unsigned n, unsigned p)
00106         {
00107           // Avoid a warning about an undefined variable when NDEBUG
00108           // is not defined.
00109           (void)n;
00110 
00111           mln_invariant(input.element(n) < input.element(p));
00112           attr.element(p) = false;
00113         }
00114 
00115         void init_attr_(unsigned)                 {}
00116         void merge_attr_(unsigned r, unsigned p)  { attr.element(p) = attr.element(p) &&
00117                                                    attr.element(r); }
00118 
00119         // end of requirements
00120 
00121         mln_ch_value(I, bool) attr;
00122 
00123         regional_minima_functor(const I& input)
00124           : input(input)
00125         {
00126           initialize(attr, input);
00127         }
00128       };
00129 
00130 
00131     } // end of namespace mln::labeling::impl
00132 
00133 
00134 
00135     // Facade.
00136 
00137     template <typename I, typename N, typename L>
00138     mln_ch_value(I, L)
00139       regional_minima(const Image<I>& input_, const Neighborhood<N>& nbh_,
00140                       L& nlabels)
00141     {
00142       trace::entering("labeling::regional_minima");
00143 
00144       const I& input = exact(input_);
00145       const N& nbh = exact(nbh_);
00146       mln_precondition(input.is_valid());
00147 
00148       // FIXME: abort if L is not wide enough to encode the set of
00149       // minima.
00150 
00151       typedef impl::regional_minima_functor<I> F;
00152       F f(exact(input));
00153       mln_ch_value(I, L) output = canvas::labeling_sorted(input, nbh, nlabels,
00154                                                           f, false);
00155 
00156       trace::exiting("labeling::regional_minima");
00157       return output;
00158     }
00159 
00160 # endif // ! MLN_INCLUDE_ONLY
00161 
00162   } // end of namespace mln::labeling
00163 
00164 } // end of namespace mln
00165 
00166 
00167 #endif // ! MLN_LABELING_REGIONAL_MINIMA_HH

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