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_GENERAL_HH 00027 # define MLN_MORPHO_GENERAL_HH 00028 00035 00036 # include <mln/core/concept/image.hh> 00037 # include <mln/core/concept/window.hh> 00038 # include <mln/core/concept/neighborhood.hh> 00039 00040 # include <mln/extension/adjust_fill.hh> 00041 # include <mln/accu/transform.hh> 00042 00043 // Specializations are in: 00044 # include <mln/morpho/general.spe.hh> 00045 00046 00047 # define mln_morpho_select_accu(I, S, F) \ 00048 typename mln::metal::if_< mln::metal::is< mln_trait_image_kind(I), \ 00049 trait::image::kind::binary >, \ 00050 mln::accu::meta::S, \ 00051 mln::accu::meta::F >::ret 00052 00053 00054 namespace mln 00055 { 00056 00057 namespace morpho 00058 { 00059 00061 template <typename Op, typename I, typename W> 00062 mln_concrete(I) 00063 general(const Op& op, const Image<I>& input, const Window<W>& win); 00064 00065 00066 # ifndef MLN_INCLUDE_ONLY 00067 00068 00069 namespace internal 00070 { 00071 00072 template <typename Op, typename I, typename W> 00073 inline 00074 void 00075 general_tests(const Op& op, const Image<I>& input_, const Window<W>& win_) 00076 { 00077 const I& input = exact(input_); 00078 const W& win = exact(win_); 00079 00080 mln_precondition(input.is_valid()); 00081 mln_precondition(! win.is_empty()); 00082 mln_precondition(win.is_valid()); 00083 00084 (void) op; 00085 (void) input; 00086 (void) win; 00087 } 00088 00089 00090 // Temporary code; see 'todo' above. 00091 template <typename I, bool is_binary> // true 00092 struct neutral_impl 00093 { 00094 static mln_value(I) infimum() { return false; } 00095 static mln_value(I) supremum() { return true; } 00096 }; 00097 template <typename I> 00098 struct neutral_impl< I, false > 00099 { 00100 static mln_value(I) infimum() { return mln_min(mln_value(I)); } 00101 static mln_value(I) supremum() { return mln_max(mln_value(I)); } 00102 }; 00103 template <typename I> 00104 struct neutral : neutral_impl< I, mlc_is(mln_trait_image_kind(I), 00105 trait::image::kind::binary)::value > 00106 { 00107 }; 00108 00109 } // end of mln::morpho::internal 00110 00111 00112 namespace impl 00113 { 00114 00115 namespace generic 00116 { 00117 00118 00119 // On function. 00120 00121 template <typename Op, typename I, typename W> 00122 inline 00123 mln_concrete(I) 00124 general_on_function(const Op& op, const Image<I>& input, const Window<W>& win) 00125 { 00126 trace::entering("morpho::impl::generic::general_on_function"); 00127 00128 internal::general_tests(op, input, win); 00129 00130 extension::adjust_fill(input, win, op.neutral(input)); 00131 mln_concrete(I) output; 00132 output = accu::transform(input, op.accu(input), win); 00133 00134 trace::exiting("morpho::impl::generic::general_on_function"); 00135 return output; 00136 } 00137 00138 // On set. 00139 00140 template <typename Op, typename I, typename W> 00141 inline 00142 mln_concrete(I) 00143 general_on_set(const Op& op, const Image<I>& input, const Window<W>& win) 00144 { 00145 trace::entering("morpho::impl::generic::general_on_set"); 00146 00147 internal::general_tests(op, input, win); 00148 00149 extension::adjust_fill(input, win, op.neutral(input)); 00150 mln_concrete(I) output; 00151 output = accu::transform_stop(input, op.accu(input), win); 00152 00153 trace::exiting("morpho::impl::generic::general_on_set"); 00154 return output; 00155 } 00156 00157 } // end of namespace mln::morpho::impl::generic 00158 00159 } // end of namespace mln::morpho::impl 00160 00161 00162 00163 // Facades. 00164 00165 template <typename Op, typename I, typename W> 00166 inline 00167 mln_concrete(I) 00168 general(const Op& op, const Image<I>& input, const Window<W>& win) 00169 { 00170 trace::entering("morpho::general"); 00171 mln_precondition(exact(input).is_valid()); 00172 mln_precondition(! exact(win).is_empty()); 00173 00174 internal::general_tests(op, input, win); 00175 mln_concrete(I) output = internal::general_dispatch(op, input, win); 00176 00177 trace::exiting("morpho::general"); 00178 return output; 00179 } 00180 00181 # endif // ! MLN_INCLUDE_ONLY 00182 00183 } // end of namespace mln::morpho 00184 00185 } // end of namespace mln 00186 00187 00188 #endif // ! MLN_MORPHO_GENERAL_HH