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 #ifndef MLN_TRANSFORM_INTERNAL_CLOSEST_POINT_FUNCTOR_HH
00027 # define MLN_TRANSFORM_INTERNAL_CLOSEST_POINT_FUNCTOR_HH
00028
00032
00033 # include <mln/core/site_set/p_array.hh>
00034 # include <mln/core/macros.hh>
00035 # include <mln/data/fill.hh>
00036 # include <mln/trait/ch_value.hh>
00037
00038 namespace mln
00039 {
00040
00041 namespace transform
00042 {
00043
00044 namespace internal
00045 {
00046
00047
00052 template <typename I>
00053 struct closest_point_functor_with_indexes
00054 {
00055 typedef mln_value(I) V;
00056 typedef mln_psite(I) P;
00057
00058 closest_point_functor_with_indexes(const p_array<P>& pset);
00059
00060 mln_ch_value(I,unsigned) cp_ima;
00061 const p_array<P>& pset_;
00062
00064 void init(const I&);
00065 bool inqueue_p_wrt_input_p(const V& input_p);
00066 void init_p(const P&);
00067 bool inqueue_p_wrt_input_n(const V& input_n);
00068 void process(const P&, const P&);
00069
00071 void init_(const I& input);
00072 bool inqueue_p_wrt_input_p_(const V& input_p);
00073 void init_p_(unsigned);
00074 bool inqueue_p_wrt_input_n_(const V& input_n);
00075 void process_(unsigned p, unsigned n);
00076 };
00077
00082 template <typename I>
00083 struct closest_point_functor_with_sites
00084 {
00085 typedef mln_value(I) V;
00086 typedef mln_psite(I) P;
00087
00088 closest_point_functor_with_sites();
00089
00090 mln_ch_value(I,P) cp_ima;
00091
00093 void init(const I&);
00094 bool inqueue_p_wrt_input_p(const V& input_p);
00095 void init_p(const P&);
00096 bool inqueue_p_wrt_input_n(const V& input_n);
00097 void process(const P&, const P&);
00098
00100 void init_(const I& input);
00101 bool inqueue_p_wrt_input_p_(const V& input_p);
00102 void init_p_(unsigned p);
00103 bool inqueue_p_wrt_input_n_(const V& input_n);
00104 void process_(unsigned p, unsigned n);
00105 };
00106
00107
00108 # ifndef MLN_INCLUDE_ONLY
00109
00110 template <typename I>
00111 inline
00112 closest_point_functor_with_indexes<I>::closest_point_functor_with_indexes(
00113 const p_array<mln_psite(I)>& pset)
00114 : pset_(pset)
00115 {
00116 }
00117
00118 template <typename I>
00119 inline
00120 void
00121 closest_point_functor_with_indexes<I>::init(const I& input)
00122 {
00123 initialize(cp_ima, input);
00124 data::fill(cp_ima, pset_.nsites());
00125
00126 mln_piter(p_array<mln_psite(I)>) p(pset_);
00127 for_all(p)
00128 cp_ima(p) = p.index();
00129 }
00130
00131 template <typename I>
00132 inline
00133 bool
00134 closest_point_functor_with_indexes<I>::inqueue_p_wrt_input_p(const V& input_p)
00135 {
00136 return input_p == true;
00137 }
00138
00139 template <typename I>
00140 inline
00141 void
00142 closest_point_functor_with_indexes<I>::init_p(const P&)
00143 {
00144 }
00145
00146 template <typename I>
00147 inline
00148 bool
00149 closest_point_functor_with_indexes<I>::inqueue_p_wrt_input_n(const V& input_n)
00150 {
00151 return input_n == false;
00152 }
00153
00154 template <typename I>
00155 inline
00156 void closest_point_functor_with_indexes<I>::process(const P& p, const P& n)
00157 {
00158 cp_ima(n) = cp_ima(p);
00159 }
00160
00161
00162
00163 template <typename I>
00164 inline
00165 void
00166 closest_point_functor_with_indexes<I>::init_(const I& input)
00167 {
00168 init(input);
00169 }
00170
00171 template <typename I>
00172 inline
00173 bool
00174 closest_point_functor_with_indexes<I>::inqueue_p_wrt_input_p_(const V& input_p)
00175 {
00176 return input_p == true;
00177 }
00178
00179 template <typename I>
00180 inline
00181 void closest_point_functor_with_indexes<I>::init_p_(unsigned)
00182 {
00183 }
00184
00185 template <typename I>
00186 inline
00187 bool
00188 closest_point_functor_with_indexes<I>::inqueue_p_wrt_input_n_(const V& input_n)
00189 {
00190 return input_n == false;
00191 }
00192
00193 template <typename I>
00194 inline
00195 void
00196 closest_point_functor_with_indexes<I>::process_(unsigned p, unsigned n)
00197 {
00198 cp_ima.element(n) = cp_ima.element(p);
00199 }
00200
00201
00205
00206
00207 template <typename I>
00208 inline
00209 closest_point_functor_with_sites<I>::closest_point_functor_with_sites()
00210 {
00211 }
00212
00213 template <typename I>
00214 inline
00215 void
00216 closest_point_functor_with_sites<I>::init(const I& input)
00217 {
00218 initialize(cp_ima, input);
00219 data::fill(cp_ima, literal::origin);
00220 }
00221
00222 template <typename I>
00223 inline
00224 bool
00225 closest_point_functor_with_sites<I>::inqueue_p_wrt_input_p(const V& input_p)
00226 {
00227 return input_p == true;
00228 }
00229
00230 template <typename I>
00231 inline
00232 void
00233 closest_point_functor_with_sites<I>::init_p(const P& p)
00234 {
00235 cp_ima(p) = p;
00236 }
00237
00238 template <typename I>
00239 inline
00240 bool
00241 closest_point_functor_with_sites<I>::inqueue_p_wrt_input_n(const V& input_n)
00242 {
00243 return input_n == false;
00244 }
00245
00246 template <typename I>
00247 inline
00248 void
00249 closest_point_functor_with_sites<I>::process(const P& p, const P& n)
00250 {
00251 cp_ima(n) = cp_ima(p);
00252 }
00253
00254
00255
00256 template <typename I>
00257 inline
00258 void
00259 closest_point_functor_with_sites<I>::init_(const I& input)
00260 {
00261 init(input);
00262 }
00263
00264 template <typename I>
00265 inline
00266 bool
00267 closest_point_functor_with_sites<I>::inqueue_p_wrt_input_p_(const V& input_p)
00268 {
00269 return input_p == true;
00270 }
00271
00272 template <typename I>
00273 inline
00274 void closest_point_functor_with_sites<I>::init_p_(unsigned p)
00275 {
00276 cp_ima.element(p) = cp_ima.point_at_index(p);
00277 }
00278
00279 template <typename I>
00280 inline
00281 bool
00282 closest_point_functor_with_sites<I>::inqueue_p_wrt_input_n_(const V& input_n)
00283 {
00284 return input_n == false;
00285 }
00286
00287 template <typename I>
00288 inline
00289 void
00290 closest_point_functor_with_sites<I>::process_(unsigned p, unsigned n)
00291 {
00292 cp_ima.element(n) = cp_ima.element(p);
00293 }
00294
00295 # endif // ! MLN_INCLUDE_ONLY
00296
00297 }
00298
00299 }
00300
00301 }
00302
00303
00304 #endif // ! MLN_TRANSFORM_INTERNAL_CLOSEST_POINT_FUNCTOR_HH