Milena (Olena)
User documentation 2.0a Id
|
00001 // Copyright (C) 2008, 2009, 2011 EPITA Research and Development 00002 // 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_TRANSFORM_INFLUENCE_ZONE_GEODESIC_HH 00028 # define MLN_TRANSFORM_INFLUENCE_ZONE_GEODESIC_HH 00029 00033 00034 # include <mln/extension/adjust.hh> 00035 # include <mln/canvas/distance_geodesic.hh> 00036 # include <mln/transform/internal/influence_zone_functor.hh> 00037 00038 00039 namespace mln 00040 { 00041 00042 namespace transform 00043 { 00044 00051 // 00052 template <typename I, typename N> 00053 mln_concrete(I) 00054 influence_zone_geodesic(const Image<I>& input, const Neighborhood<N>& nbh); 00055 00056 00057 00058 # ifndef MLN_INCLUDE_ONLY 00059 00060 00061 namespace internal 00062 { 00063 00064 template <typename I, typename N> 00065 void 00066 influence_zone_geodesic_tests(const Image<I>& input, 00067 const Neighborhood<N>& nbh) 00068 { 00069 mln_precondition(exact(input).is_valid()); 00070 mln_precondition(exact(nbh).is_valid()); 00071 00072 (void) input; 00073 (void) nbh; 00074 } 00075 00076 } // end of namespace mln::transform::internal 00077 00078 00079 namespace impl 00080 { 00081 00082 namespace generic 00083 { 00084 00085 template <typename I, typename N> 00086 mln_concrete(I) 00087 influence_zone_geodesic(const Image<I>& input, 00088 const Neighborhood<N>& nbh) 00089 { 00090 (void) input; 00091 (void) nbh; 00092 00093 // FIXME: To be written... 00094 mlc_abort(I)::check(); 00095 } 00096 00097 } // end of namespace mln::transform::impl::generic 00098 00099 00100 template <typename I, typename N> 00101 mln_concrete(I) 00102 influence_zone_geodesic_fastest(const Image<I>& input_, 00103 const Neighborhood<N>& nbh_) 00104 { 00105 trace::entering("transform::impl::influence_zone_geodesic_fastest"); 00106 00107 const I& input = exact(input_); 00108 const N& nbh = exact(nbh_); 00109 00110 internal::influence_zone_geodesic_tests(input, nbh); 00111 00112 std::queue<mln_value(I)*> q; 00113 mln_concrete(I) output; 00114 00115 util::array<int> dp = offsets_wrt(input, nbh); 00116 const unsigned n_nbhs = dp.nelements(); 00117 00118 // Initialization. 00119 { 00120 extension::adjust(input, nbh); 00121 output = duplicate(input); 00122 // For the extension to be ignored: 00123 extension::fill(input, 0); // in initialization 00124 extension::fill(output, 1); // in propagation 00125 00126 const unsigned nelts = input.nelements(); 00127 const mln_value(I)* p_i = input.buffer(); 00128 mln_value(I)* p_o = output.buffer(); 00129 for (unsigned i = 0; i < nelts; ++i, ++p_i, ++p_o) 00130 { 00131 if (*p_i == 0) 00132 continue; 00133 for (unsigned j = 0; j < n_nbhs; ++j) 00134 { 00135 const mln_value(I)* n_i = p_i + dp[j]; 00136 if (*n_i == 0) 00137 { 00138 q.push(p_o); 00139 break; 00140 } 00141 } 00142 } 00143 00144 } 00145 00146 // Propagation. 00147 { 00148 mln_value(I)* ptr; 00149 00150 while (! q.empty()) 00151 { 00152 ptr = q.front(); 00153 q.pop(); 00154 mln_invariant(*ptr != 0); 00155 for (unsigned j = 0; j < n_nbhs; ++j) 00156 { 00157 mln_value(I)* ntr = ptr + dp[j]; 00158 if (*ntr == 0) 00159 { 00160 *ntr = *ptr; 00161 q.push(ntr); 00162 } 00163 } 00164 } 00165 } 00166 00167 trace::exiting("transform::impl::influence_zone_geodesic_fastest"); 00168 return output; 00169 } 00170 00171 00172 } // end of namespace mln::transform::impl 00173 00174 00175 namespace internal 00176 { 00177 00178 template <typename I, typename N> 00179 mln_concrete(I) 00180 influence_zone_geodesic_dispatch(trait::image::value_alignment::any, 00181 trait::image::value_storage::any, 00182 trait::image::value_access::any, 00183 const I& input, 00184 const N& nbh) 00185 { 00186 return impl::generic::influence_zone_geodesic(input, nbh); 00187 } 00188 00189 00190 template <typename I, typename N> 00191 mln_concrete(I) 00192 influence_zone_geodesic_dispatch(trait::image::value_alignment::with_grid, 00193 trait::image::value_storage::one_block, 00194 trait::image::value_access::direct, 00195 const I& input, 00196 const N& nbh) 00197 { 00198 return impl::influence_zone_geodesic_fastest(input, nbh); 00199 } 00200 00201 00202 template <typename I, typename N> 00203 mln_concrete(I) 00204 influence_zone_geodesic_dispatch(const Image<I>& input, 00205 const Neighborhood<N>& nbh) 00206 { 00207 return 00208 influence_zone_geodesic_dispatch(mln_trait_image_value_alignment(I)(), 00209 mln_trait_image_value_storage(I)(), 00210 mln_trait_image_value_access(I)(), 00211 exact(input), exact(nbh)); 00212 } 00213 00214 } // end of namespace mln::transform::internal 00215 00216 00217 template <typename I, typename N> 00218 mln_concrete(I) 00219 influence_zone_geodesic(const Image<I>& input, const Neighborhood<N>& nbh) 00220 { 00221 trace::entering("transform::influence_zone_geodesic"); 00222 00223 internal::influence_zone_geodesic_tests(input, nbh); 00224 00225 mln_concrete(I) 00226 output = internal::influence_zone_geodesic_dispatch(input, nbh); 00227 00228 trace::exiting("transform::influence_zone_geodesic"); 00229 return output; 00230 } 00231 00232 # endif // ! MLN_INCLUDE_ONLY 00233 00234 } // end of namespace mln::transform 00235 00236 } // end of namespace mln 00237 00238 00239 #endif // ! MLN_TRANSFORM_INFLUENCE_ZONE_GEODESIC_HH