Milena (Olena)
User documentation 2.0a Id
|
00001 // Copyright (C) 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_MORPHO_ELEMENTARY_LIKE_ERO_SET_HH 00027 # define MLN_MORPHO_ELEMENTARY_LIKE_ERO_SET_HH 00028 00032 00033 # include <mln/morpho/includes.hh> 00034 00035 00036 namespace mln 00037 { 00038 00039 namespace morpho 00040 { 00041 00042 namespace elementary 00043 { 00044 00045 template <typename I, typename N> 00046 mln_concrete(I) 00047 like_ero_set(bool val[5], 00048 const Image<I>& input, const Neighborhood<N>& nbh); 00049 00050 00051 # ifndef MLN_INCLUDE_ONLY 00052 00053 namespace impl 00054 { 00055 00056 namespace generic 00057 { 00058 00059 template <typename I, typename N> 00060 mln_concrete(I) 00061 like_ero_set(bool val[5], 00062 const Image<I>& input_, const Neighborhood<N>& nbh_) 00063 { 00064 trace::entering("morpho::elementary::impl::generic::like_ero_set"); 00065 00066 bool 00067 ext_value = val[0], 00068 do_duplicate = val[1], 00069 on_input_p = val[2], 00070 on_input_n = val[3], 00071 output_p = val[4]; 00072 00073 const I& input = exact(input_); 00074 const N& nbh = exact(nbh_); 00075 00076 extension::adjust_fill(input, nbh, ext_value); 00077 00078 mln_concrete(I) output; 00079 if (do_duplicate) 00080 output = duplicate(input); 00081 else 00082 { 00083 initialize(output, input); 00084 data::fill(output, false); 00085 } 00086 00087 mln_piter(I) p(input.domain()); 00088 mln_niter(N) n(nbh, p); 00089 for_all(p) 00090 if (input(p) == on_input_p) 00091 for_all(n) 00092 if (input.has(n) && input(n) == on_input_n) 00093 output(p) = output_p; 00094 00095 trace::exiting("morpho::elementary::impl::generic::like_ero_set"); 00096 return output; 00097 } 00098 00099 } // end of namespace mln::morpho::elementary::impl::generic 00100 00101 00102 template <typename I, typename N> 00103 mln_concrete(I) 00104 like_ero_set_fastest(bool val[5], 00105 const Image<I>& input_, const Neighborhood<N>& nbh_) 00106 { 00107 trace::entering("morpho::elementary::impl::like_ero_set_fastest"); 00108 00109 bool 00110 ext_value = val[0], 00111 do_duplicate = val[1], 00112 on_input_p = val[2], 00113 on_input_n = val[3], 00114 output_p = val[4]; 00115 00116 const I& input = exact(input_); 00117 const N& nbh = exact(nbh_); 00118 00119 extension::adjust_fill(input, nbh, ext_value); 00120 00121 mln_concrete(I) output; 00122 if (do_duplicate) 00123 output = duplicate(input); 00124 else 00125 { 00126 initialize(output, input); 00127 data::fill(output, false); 00128 } 00129 00130 mln_pixter(const I) p_in(input); 00131 mln_pixter(I) p_out(output); 00132 mln_nixter(const I, N) n(p_in, nbh); 00133 for_all_2(p_in, p_out) 00134 if (p_in.val() == on_input_p) 00135 for_all(n) 00136 if (n.val() == on_input_n) 00137 p_out.val() = output_p; 00138 00139 trace::exiting("morpho::elementary::impl::like_ero_set_fastest"); 00140 return output; 00141 } 00142 00143 } // end of namespace mln::morpho::elementary::impl 00144 00145 00146 namespace internal 00147 { 00148 00149 template <typename I, typename N> 00150 mln_concrete(I) 00151 like_ero_set_dispatch(metal::false_, 00152 bool val[5], 00153 const I& input, const N& nbh) 00154 { 00155 return impl::generic::like_ero_set(val, input, nbh); 00156 } 00157 00158 template <typename I, typename N> 00159 mln_concrete(I) 00160 like_ero_set_dispatch(metal::true_, 00161 bool val[5], 00162 const I& input, const N& nbh) 00163 { 00164 return impl::like_ero_set_fastest(val, input, nbh); 00165 } 00166 00167 template <typename I, typename N> 00168 mln_concrete(I) 00169 like_ero_set_dispatch(bool val[5], 00170 const I& input, const N& nbh) 00171 { 00172 typedef mlc_equal(mln_trait_image_speed(I), 00173 trait::image::speed::fastest) I_fastest; 00174 typedef mln_window(N) W; 00175 typedef mln_is_simple_window(W) N_simple; 00176 00177 return like_ero_set_dispatch(mlc_and(I_fastest, N_simple)(), 00178 val, input, nbh); 00179 } 00180 00181 } // end of namespace mln::morpho::elementary::internal 00182 00183 00184 // Facade. 00185 00186 template <typename I, typename N> 00187 mln_concrete(I) 00188 like_ero_set(bool val[5], 00189 const Image<I>& input, const Neighborhood<N>& nbh) 00190 { 00191 return internal::like_ero_set_dispatch(val, exact(input), exact(nbh)); 00192 } 00193 00194 # endif // ! MLN_INCLUDE_ONLY 00195 00196 } // end of namespace mln::morpho::elementary 00197 00198 } // end of namespace mln::morpho 00199 00200 } // end of namespace mln 00201 00202 00203 #endif // ! MLN_MORPHO_ELEMENTARY_LIKE_ERO_SET_HH