00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
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 }
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
00091 mlc_abort(I)::check();
00092 }
00093
00094 }
00095
00096
00097 template <typename I, typename N>
00098 mln_concrete(I)
00099 influence_zone_geodesic_fastest(const Image<I>& input_,
00100 const Neighborhood<N>& nbh_)
00101 {
00102 trace::entering("transform::impl::influence_zone_geodesic_fastest");
00103
00104 const I& input = exact(input_);
00105 const N& nbh = exact(nbh_);
00106
00107 internal::influence_zone_geodesic_tests(input, nbh);
00108
00109 std::queue<mln_value(I)*> q;
00110 mln_concrete(I) output;
00111
00112 util::array<int> dp = offsets_wrt(input, nbh);
00113 const unsigned n_nbhs = dp.nelements();
00114
00115
00116 {
00117 extension::adjust(input, nbh);
00118 output = duplicate(input);
00119
00120 extension::fill(input, 0);
00121 extension::fill(output, 1);
00122
00123 const unsigned nelts = input.nelements();
00124 const mln_value(I)* p_i = input.buffer();
00125 mln_value(I)* p_o = output.buffer();
00126 for (unsigned i = 0; i < nelts; ++i, ++p_i, ++p_o)
00127 {
00128 if (*p_i == 0)
00129 continue;
00130 for (unsigned j = 0; j < n_nbhs; ++j)
00131 {
00132 const mln_value(I)* n_i = p_i + dp[j];
00133 if (*n_i == 0)
00134 {
00135 q.push(p_o);
00136 break;
00137 }
00138 }
00139 }
00140
00141 }
00142
00143
00144 {
00145 mln_value(I)* ptr;
00146
00147 while (! q.empty())
00148 {
00149 ptr = q.front();
00150 q.pop();
00151 mln_invariant(*ptr != 0);
00152 for (unsigned j = 0; j < n_nbhs; ++j)
00153 {
00154 mln_value(I)* ntr = ptr + dp[j];
00155 if (*ntr == 0)
00156 {
00157 *ntr = *ptr;
00158 q.push(ntr);
00159 }
00160 }
00161 }
00162 }
00163
00164 trace::exiting("transform::impl::influence_zone_geodesic_fastest");
00165 return output;
00166 }
00167
00168
00169 }
00170
00171
00172 namespace internal
00173 {
00174
00175 template <typename I, typename N>
00176 mln_concrete(I)
00177 influence_zone_geodesic_dispatch(trait::image::value_alignment::any,
00178 trait::image::value_storage::any,
00179 trait::image::value_access::any,
00180 const I& input,
00181 const N& nbh)
00182 {
00183 return impl::generic::influence_zone_geodesic(input, nbh);
00184 }
00185
00186
00187 template <typename I, typename N>
00188 mln_concrete(I)
00189 influence_zone_geodesic_dispatch(trait::image::value_alignment::with_grid,
00190 trait::image::value_storage::one_block,
00191 trait::image::value_access::direct,
00192 const I& input,
00193 const N& nbh)
00194 {
00195 return impl::influence_zone_geodesic_fastest(input, nbh);
00196 }
00197
00198
00199 template <typename I, typename N>
00200 mln_concrete(I)
00201 influence_zone_geodesic_dispatch(const Image<I>& input,
00202 const Neighborhood<N>& nbh)
00203 {
00204 return
00205 influence_zone_geodesic_dispatch(mln_trait_image_value_alignment(I)(),
00206 mln_trait_image_value_storage(I)(),
00207 mln_trait_image_value_access(I)(),
00208 exact(input), exact(nbh));
00209 }
00210
00211 }
00212
00213
00214 template <typename I, typename N>
00215 mln_concrete(I)
00216 influence_zone_geodesic(const Image<I>& input, const Neighborhood<N>& nbh)
00217 {
00218 trace::entering("transform::influence_zone_geodesic");
00219
00220 internal::influence_zone_geodesic_tests(input, nbh);
00221
00222 mln_concrete(I)
00223 output = internal::influence_zone_geodesic_dispatch(input, nbh);
00224
00225 trace::exiting("transform::influence_zone_geodesic");
00226 return output;
00227 }
00228
00229 # endif // ! MLN_INCLUDE_ONLY
00230
00231 }
00232
00233 }
00234
00235
00236 #endif // ! MLN_TRANSFORM_INFLUENCE_ZONE_GEODESIC_HH