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

value.hh

00001 // Copyright (C) 2007, 2008, 2009, 2010 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_VALUE_HH
00028 # define MLN_LABELING_VALUE_HH
00029 
00033 
00034 # include <mln/core/concept/image.hh>
00035 # include <mln/core/concept/neighborhood.hh>
00036 # include <mln/canvas/labeling/video.hh>
00037 # include <mln/data/fill.hh>
00038 
00039 
00040 
00041 namespace mln
00042 {
00043 
00044   namespace labeling
00045   {
00046 
00055     //
00056     template <typename I, typename N, typename L>
00057     mln_ch_value(I, L)
00058     value(const Image<I>& input, const mln_value(I)& val,
00059           const Neighborhood<N>& nbh, L& nlabels);
00060 
00061 
00062 # ifndef MLN_INCLUDE_ONLY
00063 
00064 
00065     // Tests.
00066 
00067     namespace internal
00068     {
00069 
00070       template <typename I, typename N, typename L>
00071       void
00072       value_tests(const Image<I>& input, const mln_value(I)& val, const Neighborhood<N>& nbh,
00073                   L& nlabels)
00074       {
00075         mln_precondition(exact(input).is_valid());
00076         mln_precondition(exact(nbh).is_valid());
00077 
00078         (void) input;
00079         (void) val;
00080         (void) nbh;
00081         (void) nlabels;
00082       }
00083 
00084     } // end of namespace mln::labeling::internal
00085 
00086 
00087 
00088     namespace impl
00089     {
00090 
00091       // Generic functor.
00092 
00093       template <typename I, typename L>
00094       struct value_functor
00095       {
00096         typedef mln_psite(I) P;
00097 
00098         const I& input;
00099         const mln_value(I)& val;
00100 
00101         // Requirements from mln::canvas::labeling.
00102 
00103         typedef mln_domain(I) S;
00104 
00105         // Generic implementation
00106 
00107         void init()                               {}
00108         bool handles(const P& p) const            { return input(p) == val; }
00109         bool equiv(const P& n, const P&) const    { return input(n) == val; }
00110         bool labels(const P&) const               { return true; }
00111         void do_no_union(const P&, const P&)      {}
00112         void init_attr(const P&)                  {}
00113         void merge_attr(const P&, const P&)       {}
00114         void set_new_label(const P& p, const L& l){}
00115         void set_label(const P& p, const L& l)    {}
00116         void finalize()                           {}
00117 
00118         // Fastest implementation
00119 
00120         void init_()                              {}
00121         bool handles_(unsigned p) const           { return input.element(p) == val; }
00122         bool equiv_(unsigned n, unsigned) const   { return input.element(n) == val; }
00123         bool labels_(unsigned) const              { return true; }
00124         void do_no_union_(unsigned, unsigned)     {}
00125         void init_attr_(unsigned)                 {}
00126         void merge_attr_(unsigned, unsigned)      {}
00127         void set_new_label_(unsigned, const L&)   {}
00128         void set_label_(unsigned, const L&)       {}
00129         void finalize_()                          {}
00130 
00131         // end of Requirements.
00132 
00133         value_functor(const Image<I>& input_, const mln_value(I)& val)
00134           : input(exact(input_)),
00135             val(val)
00136         {
00137         }
00138       };
00139 
00140     } // end of namespace mln::labeling::impl
00141 
00142 
00143 
00144 
00145     // Facade.
00146 
00147     template <typename I, typename N, typename L>
00148     mln_ch_value(I, L)
00149     value(const Image<I>& input, const mln_value(I)& val,
00150           const Neighborhood<N>& nbh, L& nlabels)
00151     {
00152       trace::entering("labeling::value");
00153 
00154       internal::value_tests(input, val, nbh, nlabels);
00155 
00156       mln_ch_value(I, L) output;
00157       impl::value_functor<I,L> f(input, val);
00158       output = canvas::labeling::video(input, nbh, nlabels, f);
00159 
00160       trace::exiting("labeling::value");
00161       return output;
00162     }
00163 
00164 # endif // ! MLN_INCLUDE_ONLY
00165 
00166   } // end of namespace mln::labeling
00167 
00168 } // end of namespace mln
00169 
00170 
00171 #endif // ! MLN_LABELING_VALUE_HH

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