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_TRANSFORM_INTERNAL_INFLUENCE_ZONE_FUNCTOR_HH 00027 # define MLN_TRANSFORM_INTERNAL_INFLUENCE_ZONE_FUNCTOR_HH 00028 00032 00033 # include <mln/core/routine/duplicate.hh> 00034 00035 00036 00037 namespace mln 00038 { 00039 00040 namespace transform 00041 { 00042 00043 namespace internal 00044 { 00045 00046 template <typename I> 00047 struct influence_zone_functor 00048 { 00049 typedef mln_value(I) V; 00050 typedef mln_psite(I) P; 00051 00052 influence_zone_functor(); 00053 influence_zone_functor(const V& background_value); 00054 00055 mln_concrete(I) output; 00056 00057 void init(const I& input); 00058 bool inqueue_p_wrt_input_p(const V& input_p); 00059 bool inqueue_p_wrt_input_n(const V& input_n); 00060 void init_p(const P&); 00061 void process(const P& p, const P& n); 00062 00063 void init_(const I& input); 00064 bool inqueue_p_wrt_input_p_(const V& input_p); 00065 bool inqueue_p_wrt_input_n_(const V& input_n); 00066 void init_p_(unsigned); 00067 void process_(unsigned p, unsigned n); 00068 00069 V background_value_; 00070 }; 00071 00072 00073 # ifndef MLN_INCLUDE_ONLY 00074 00075 00076 template <typename I> 00077 inline 00078 influence_zone_functor<I>::influence_zone_functor() 00079 { 00080 background_value_ = literal::zero; 00081 } 00082 00083 00084 template <typename I> 00085 inline 00086 influence_zone_functor<I>::influence_zone_functor(const V& background_value) 00087 { 00088 background_value_ = background_value; 00089 } 00090 00091 00092 // Generic implementation. 00093 00094 template <typename I> 00095 inline 00096 void 00097 influence_zone_functor<I>::init(const I& input) 00098 { 00099 output = duplicate(input); 00100 } 00101 00102 template <typename I> 00103 inline 00104 bool 00105 influence_zone_functor<I>::inqueue_p_wrt_input_p(const V& input_p) 00106 { 00107 return input_p != background_value_; 00108 } 00109 00110 template <typename I> 00111 inline 00112 bool 00113 influence_zone_functor<I>::inqueue_p_wrt_input_n(const V& input_n) 00114 { 00115 return input_n == background_value_; 00116 } 00117 00118 template <typename I> 00119 inline 00120 void 00121 influence_zone_functor<I>::init_p(const P&) 00122 { 00123 } 00124 00125 template <typename I> 00126 inline 00127 void influence_zone_functor<I>::process(const P& p, const P& n) 00128 { 00129 output(n) = output(p); 00130 } 00131 00132 00133 00134 // Fastest implementation. 00135 00136 template <typename I> 00137 inline 00138 void 00139 influence_zone_functor<I>::init_(const I& input) 00140 { 00141 output = duplicate(input); 00142 } 00143 00144 template <typename I> 00145 inline 00146 bool 00147 influence_zone_functor<I>::inqueue_p_wrt_input_p_(const V& input_p) 00148 { 00149 return input_p != background_value_; 00150 } 00151 00152 template <typename I> 00153 inline 00154 bool 00155 influence_zone_functor<I>::inqueue_p_wrt_input_n_(const V& input_n) 00156 { 00157 return input_n == background_value_; 00158 } 00159 00160 template <typename I> 00161 inline 00162 void 00163 influence_zone_functor<I>::init_p_(unsigned) 00164 { 00165 } 00166 00167 template <typename I> 00168 inline 00169 void influence_zone_functor<I>::process_(unsigned p, unsigned n) 00170 { 00171 output.element(n) = output.element(p); 00172 } 00173 00174 00175 # endif // ! MLN_INCLUDE_ONLY 00176 00177 } // end of namespace mln::transform::internal 00178 00179 } // end of namespace mln::transform 00180 00181 } // end of namespace mln 00182 00183 00184 #endif // ! MLN_TRANSFORM_INTERNAL_INFLUENCE_ZONE_FUNCTOR_HH