Milena (Olena)
User documentation 2.0a Id
|
00001 // Copyright (C) 2007, 2008, 2009, 2010, 2011 EPITA Research and 00002 // Development 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_FLAT_ZONES_HH 00028 # define MLN_LABELING_FLAT_ZONES_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 00038 00039 namespace mln 00040 { 00041 00042 namespace labeling 00043 { 00044 00052 template <typename I, typename N, typename L> 00053 mln_ch_value(I, L) 00054 flat_zones(const Image<I>& input, const Neighborhood<N>& nbh, 00055 L& nlabels); 00056 00057 00058 00059 # ifndef MLN_INCLUDE_ONLY 00060 00061 namespace impl 00062 { 00063 00064 // Flat zone functor for the labeling canvas. 00065 00066 template <typename I, typename L> 00067 struct flat_zones_functor 00068 { 00069 const I& input; 00070 00071 // Generic implementation. 00072 00073 typedef mln_psite(I) P; 00074 00075 void init() {} 00076 bool handles(const P&) const { return true; } 00077 00078 bool equiv(const P& n, const P& p) const 00079 { return input(n) == input(p); } 00080 00081 bool labels(const P&) const { return true; } 00082 void do_no_union(const P&, const P&) {} 00083 void init_attr(const P&) {} 00084 void merge_attr(const P&, const P&) {} 00085 void set_new_label(const P&, const L&){} 00086 void set_label(const P&, const L&) {} 00087 void finalize() {} 00088 00089 00090 // Fastest implementation. 00091 00092 void init_() {} 00093 00094 bool handles_(unsigned) const 00095 { return true; } 00096 00097 bool equiv_(unsigned n, unsigned p) const 00098 { return input.element(n) == input.element(p); } 00099 00100 bool labels_(unsigned) const { return true; } 00101 void do_no_union_(unsigned, unsigned) {} 00102 void init_attr_(unsigned) {} 00103 void merge_attr_(unsigned, unsigned) {} 00104 void set_new_label_(unsigned, const L&) {} 00105 void set_label_(unsigned, const L&) {} 00106 void finalize_() {} 00107 00108 // end of requirements. 00109 00110 flat_zones_functor(const I& input) 00111 : input(input) 00112 {} 00113 }; 00114 00115 00116 } // end of namespace mln::labeling::impl 00117 00118 00119 00120 // Facade. 00121 00122 template <typename I, typename N, typename L> 00123 mln_ch_value(I, L) 00124 flat_zones(const Image<I>& input_, const Neighborhood<N>& nbh_, 00125 L& nlabels) 00126 { 00127 trace::entering("labeling::flat_zones"); 00128 00129 const I& input = exact(input_); 00130 const N& nbh = exact(nbh_); 00131 mln_precondition(input.is_valid()); 00132 00133 // Call the labeling canvas. 00134 typedef impl::flat_zones_functor<I,L> F; 00135 F f(input); 00136 mln_ch_value(I, L) 00137 output = canvas::labeling::video(input, nbh, nlabels, f); 00138 00139 trace::exiting("labeling::flat_zones"); 00140 return output; 00141 } 00142 00143 # endif // ! MLN_INCLUDE_ONLY 00144 00145 } // end of namespace mln::labeling 00146 00147 } // end of namespace mln 00148 00149 00150 #endif // ! MLN_LABELING_FLAT_ZONES_HH