Milena (Olena)
User documentation 2.0a Id
|
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_MORPHO_DILATION_HH 00027 # define MLN_MORPHO_DILATION_HH 00028 00034 00035 # include <mln/morpho/includes.hh> 00036 # include <mln/morpho/general.hh> 00037 # include <mln/accu/logic/lor.hh> 00038 # include <mln/accu/logic/lor_basic.hh> 00039 # include <mln/accu/stat/max.hh> 00040 # include <mln/accu/stat/max_h.hh> 00041 00042 00043 namespace mln 00044 { 00045 00046 namespace morpho 00047 { 00048 00050 template <typename I, typename W> 00051 mln_concrete(I) 00052 dilation(const Image<I>& input, const Window<W>& win); 00053 00054 00055 # ifndef MLN_INCLUDE_ONLY 00056 00057 00058 struct dilation_op 00059 { 00060 00061 template <typename I> 00062 mln_morpho_select_accu(I, logic::lor_basic, stat::max) 00063 accu(const Image<I>&) const 00064 { 00065 mln_morpho_select_accu(I, logic::lor_basic, stat::max) tmp; 00066 return tmp; 00067 } 00068 00069 template <typename I> 00070 mln_morpho_select_accu(I, logic::lor, stat::max_h) 00071 accu_incr(const Image<I>&) const 00072 { 00073 mln_morpho_select_accu(I, logic::lor, stat::max_h) tmp; 00074 return tmp; 00075 } 00076 00077 template <typename I> 00078 mln_value(I) neutral(const Image<I>&) const 00079 { 00080 return internal::neutral<I>::infimum(); 00081 } 00082 00083 }; 00084 00085 00086 namespace impl 00087 { 00088 00089 00090 // On set with centered window (overloads). 00091 00092 template <typename I, typename W> 00093 mln_concrete(I) 00094 general_on_set_centered(const dilation_op&, 00095 const Image<I>& input_, const Window<W>& win_) 00096 { 00097 trace::entering("morpho::impl::general_on_set_centered__dilation"); 00098 00099 typedef mln_concrete(I) O; 00100 const I& input = exact(input_); 00101 const W& win = exact(win_); 00102 00103 extension::adjust_fill(input, win, false); 00104 00105 O output; 00106 output = duplicate(input); 00107 00108 mln_piter(I) p(input.domain()); 00109 mln_qiter(W) q(win, p); 00110 for_all(p) 00111 if (input(p) == false) 00112 for_all(q) if (input.has(q)) 00113 if (input(q) == true) 00114 { 00115 output(p) = true; 00116 break; 00117 } 00118 00119 trace::exiting("morpho::impl::general_on_set_centered__dilation"); 00120 return output; 00121 } 00122 00123 00124 template <typename I, typename W> 00125 mln_concrete(I) 00126 general_on_set_centered_fastest(const dilation_op&, 00127 const Image<I>& input_, const Window<W>& win_) 00128 { 00129 trace::entering("morpho::impl::general_on_set_centered_fastest__dilation"); 00130 00131 typedef mln_concrete(I) O; 00132 const I& input = exact(input_); 00133 const W& win = exact(win_); 00134 00135 extension::adjust_fill(input, win, false); 00136 00137 O output; 00138 output = duplicate(input); 00139 00140 mln_pixter(const I) p(input); 00141 mln_qixter(const I, W) q(p, win); 00142 mln_pixter(O) p_out(output); 00143 for_all_2(p, p_out) 00144 if (p.val() == false) 00145 for_all(q) 00146 if (q.val() == true) 00147 { 00148 p_out.val() = true; 00149 break; 00150 } 00151 00152 trace::exiting("morpho::impl::general_on_set_centered_fastest__dilation"); 00153 return output; 00154 } 00155 00156 } // end of namespace morpho::impl 00157 00158 00159 template <typename I, typename W> 00160 inline 00161 mln_concrete(I) 00162 dilation(const Image<I>& input, const Window<W>& win) 00163 { 00164 trace::entering("morpho::dilation"); 00165 mln_precondition(exact(input).is_valid()); 00166 mln_precondition(! exact(win).is_empty()); 00167 00168 mln_concrete(I) output = general(dilation_op(), input, win); 00169 00170 if (exact(win).is_centered()) 00171 mln_postcondition(output >= input); 00172 00173 trace::exiting("morpho::dilation"); 00174 return output; 00175 } 00176 00177 # endif // ! MLN_INCLUDE_ONLY 00178 00179 } // end of namespace mln::morpho 00180 00181 } // end of namespace mln 00182 00183 00184 #endif // ! MLN_MORPHO_DILATION_HH