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

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

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