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

flat_zones.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_FLAT_ZONES_HH
00027 # define MLN_LABELING_FLAT_ZONES_HH
00028 
00032 
00033 # include <mln/core/concept/image.hh>
00034 # include <mln/core/concept/neighborhood.hh>
00035 # include <mln/canvas/labeling.hh>
00036 
00037 
00038 namespace mln
00039 {
00040 
00041   namespace labeling
00042   {
00043 
00051     template <typename I, typename N, typename L>
00052     mln_ch_value(I, L)
00053     flat_zones(const Image<I>& input, const Neighborhood<N>& nbh, L& nlabels);
00054 
00055 
00056 
00057 # ifndef MLN_INCLUDE_ONLY
00058 
00059     namespace impl
00060     {
00061 
00062       // Flat zone functor for the labeling canvas.
00063 
00064       template <typename I>
00065       struct flat_zones_functor
00066       {
00067         const I& input;
00068 
00069         // Generic implementation.
00070 
00071         typedef mln_psite(I) P;
00072 
00073         void init()                          {}
00074         bool handles(const P&) const             { return true; }
00075         bool equiv(const P& n, const P& p) const { return input(n) ==
00076                                                           input(p); }
00077         bool labels(const P&) const          { return true;  }
00078         void do_no_union(const P&, const P&) {}
00079         void init_attr(const P&)             {}
00080         void merge_attr(const P&, const P&)  {}
00081 
00082         // Fastest implementation.
00083 
00084         void init_()                          {}
00085         bool handles_(unsigned) const             { return true; }
00086         bool equiv_(unsigned n, unsigned p) const { return input.element(n) ==
00087                                                            input.element(p); }
00088         bool labels_(unsigned) const          { return true;  }
00089         void do_no_union_(unsigned, unsigned) {}
00090         void init_attr_(unsigned)             {}
00091         void merge_attr_(unsigned, unsigned)  {}
00092 
00093         // end of requirements.
00094 
00095         flat_zones_functor(const I& input)
00096           : input(input)
00097         {}
00098       };
00099 
00100 
00101     } // end of namespace mln::labeling::impl
00102 
00103 
00104 
00105     // Facade.
00106 
00107     template <typename I, typename N, typename L>
00108     mln_ch_value(I, L)
00109     flat_zones(const Image<I>& input_, const Neighborhood<N>& nbh_,
00110                L& nlabels)
00111     {
00112       trace::entering("labeling::flat_zones");
00113 
00114       const I& input = exact(input_);
00115       const N& nbh = exact(nbh_);
00116       mln_precondition(input.is_valid());
00117 
00118       // Call the labeling canvas.
00119       typedef impl::flat_zones_functor<I> F;
00120       F f(input);
00121       mln_ch_value(I, L) output = canvas::labeling_video(input, nbh, nlabels, f);
00122 
00123       trace::exiting("labeling::flat_zones");
00124       return output;
00125     }
00126 
00127 # endif // ! MLN_INCLUDE_ONLY
00128 
00129   } // end of namespace mln::labeling
00130 
00131 } // end of namespace mln
00132 
00133 
00134 #endif // ! MLN_LABELING_FLAT_ZONES_HH

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