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_CORE_IMAGE_EDGE_IMAGE_HH
00027 # define MLN_CORE_IMAGE_EDGE_IMAGE_HH
00028
00032
00033 # include <mln/core/concept/graph.hh>
00034 # include <mln/core/site_set/p_edges.hh>
00035 # include <mln/core/image/graph_elt_window.hh>
00036 # include <mln/core/image/graph_elt_neighborhood.hh>
00037 # include <mln/pw/internal/image_base.hh>
00038 # include <mln/fun/i2v/array.hh>
00039
00040
00041
00042 namespace mln
00043 {
00044
00045 template <typename P, typename V, typename G> class edge_image;
00046 namespace util { class graph; }
00047
00048
00049
00050
00051 namespace trait
00052 {
00053
00054 template <typename P, typename V, typename G>
00055 struct image_< edge_image<P,V,G> >
00056 : pw_image_<fun::i2v::array<V>,
00057 p_edges<util::graph, fun::i2v::array<P> >,
00058 edge_image<P,V,G> >
00059 {
00060 };
00061
00062 }
00063
00064
00065
00066 namespace internal
00067 {
00068
00070 template <typename P, typename V, typename G>
00071 struct data< mln::edge_image<P,V,G> >
00072 {
00073 typedef typename edge_image<P,V,G>::site_function_t site_function_t;
00074
00075 data(const fun::i2v::array<V>& edge_values,
00076 const p_edges<G,site_function_t>& pe);
00077
00078 fun::i2v::array<V> f_;
00079 p_edges<G,site_function_t> domain_;
00080 };
00081
00082 }
00083
00084
00085
00086
00089 template <typename V, typename G, typename P>
00090 edge_image<P,V,G>
00091 operator | (const fun::i2v::array<V>& edge_values,
00092 const p_edges<G,fun::i2v::array<P> >& pe);
00093
00094
00095
00096
00097 namespace internal
00098 {
00099
00100 template <typename P, typename G>
00101 struct efsite_selector
00102 {
00103 typedef fun::i2v::array<P> site_function_t;
00104 };
00105
00106
00107
00108 template <typename G>
00109 struct efsite_selector<void,G>
00110 {
00111 typedef util::internal::id2element< G,util::edge<G> > site_function_t;
00112 };
00113
00114
00115 }
00116
00117
00121
00122 template <typename P, typename V, typename G = util::graph>
00123 class edge_image
00124 : public pw::internal::image_base<fun::i2v::array<V>,
00125 p_edges<G, typename internal::efsite_selector<P,G>::site_function_t >,
00126 edge_image<P,V,G> >
00127 {
00128 typedef pw::internal::image_base<fun::i2v::array<V>,
00129 p_edges<G, typename internal::efsite_selector<P,G>::site_function_t >,
00130 edge_image<P,V,G> > super_;
00131
00132 public:
00133 typedef typename super_::psite psite;
00134 typedef typename super_::rvalue rvalue;
00135 typedef typename super_::lvalue lvalue;
00136
00138 typedef G graph_t;
00139
00141 typedef edge_image< tag::psite_<P>,
00142 tag::value_<V>,
00143 tag::graph_<G> > skeleton;
00144
00146 typedef typename internal::efsite_selector<P,G>::site_function_t
00147 site_function_t;
00148 typedef mln_result(site_function_t) function_result_t;
00149
00151 typedef graph_elt_window<G,p_edges<G,site_function_t> > edge_win_t;
00153 typedef graph_elt_neighborhood<G,p_edges<G,site_function_t> > edge_nbh_t;
00154
00156 typedef edge_win_t win_t;
00157
00159 typedef edge_nbh_t nbh_t;
00160
00161
00164 edge_image();
00165 edge_image(const p_edges<G, site_function_t>& pe);
00166 edge_image(const Graph<G>& g,
00167 const Function_v2v< site_function_t >& edge_sites,
00168 const Function_v2v< fun::i2v::array<V> >& edge_values);
00169
00170 edge_image(const p_edges<G, site_function_t >& pe,
00171 const Function_v2v< fun::i2v::array<V> >& edge_values);
00172
00173 template <typename FP, typename FV>
00174 edge_image(const Graph<G>& g,
00175 const Function_v2v<FP>& edge_sites,
00176 const Function_v2v<FV>& edge_values);
00177
00178 template <typename FV>
00179 edge_image(const p_edges<G,site_function_t>& pe,
00180 const Function_v2v<FV>& edge_values);
00182
00185 rvalue operator()(unsigned e_id) const;
00186 lvalue operator()(unsigned e_id);
00188
00189
00190 rvalue operator()(const psite& p) const;
00191 lvalue operator()(const psite& p);
00192
00193
00194 };
00195
00196 template <typename P, typename V, typename G, typename J>
00197 void init_(tag::image_t, edge_image<P,V,G>& target, const Image<J>& model);
00198
00199
00200 # ifndef MLN_INCLUDE_ONLY
00201
00202 template <typename P, typename V, typename G, typename J>
00203 void init_(tag::image_t, edge_image<P,V,G>& target, const Image<J>& model)
00204 {
00205 fun::i2v::array<V> f;
00206 init_(tag::function, f, exact(model));
00207 p_edges<G, typename edge_image<P,V,G>::site_function_t> s;
00208 init_(tag::domain, s, exact(model));
00209 target.init_(f, s);
00210 }
00211
00212
00213
00214 template <typename V, typename G, typename P>
00215 inline
00216 edge_image<P,V,G>
00217 operator | (const fun::i2v::array<V>& edge_values,
00218 const p_edges<G,fun::i2v::array<P> >& pe)
00219 {
00220 edge_image<P,V,G> tmp(edge_values, pe);
00221 return tmp;
00222 }
00223
00224
00225
00226
00227
00228 namespace internal
00229 {
00230
00231 template <typename P, typename V, typename G>
00232 inline
00233 data< mln::edge_image<P,V,G> >::data(const fun::i2v::array<V>& f,
00234 const p_edges<G,site_function_t>& ps)
00235 : f_(exact(f)),
00236 domain_(ps)
00237 {
00238 }
00239
00240 }
00241
00242
00243
00244
00245
00246 template <typename P, typename V, typename G>
00247 inline
00248 edge_image<P,V,G>::edge_image()
00249 {
00250 }
00251
00252 template <typename P, typename V, typename G>
00253 inline
00254 edge_image<P,V,G>::edge_image(const p_edges<G,site_function_t>& pe)
00255 : super_(fun::i2v::array<V>(pe.nsites()), pe)
00256 {
00257 }
00258
00259 template <typename P, typename V, typename G>
00260 inline
00261 edge_image<P,V,G>::edge_image(const Graph<G>& g,
00262 const Function_v2v< site_function_t >& edge_sites,
00263 const Function_v2v< fun::i2v::array<V> >& edge_values)
00264 : super_(exact(edge_values),
00265 p_edges<G,site_function_t>(g, exact(edge_sites)))
00266 {
00267 }
00268
00269 template <typename P, typename V, typename G>
00270 inline
00271 edge_image<P,V,G>::edge_image(const p_edges<G,site_function_t>& pe,
00272 const Function_v2v< fun::i2v::array<V> >& edge_values)
00273 : super_(exact(edge_values), pe)
00274 {
00275 }
00276
00277 template <typename P, typename V, typename G>
00278 template <typename FP, typename FV>
00279 inline
00280 edge_image<P,V,G>::edge_image(const Graph<G>& g,
00281 const Function_v2v<FP>& edge_sites,
00282 const Function_v2v<FV>& edge_values)
00283 : super_(convert::to<fun::i2v::array<V> >(exact(edge_values)),
00284 p_edges<G,site_function_t>(g, exact(edge_sites)))
00285 {
00286 mlc_equal(mln_result(FP),P)::check();
00287 mlc_equal(mln_result(FV),V)::check();
00288 }
00289
00290 template <typename P, typename V, typename G>
00291 template <typename FV>
00292 inline
00293 edge_image<P,V,G>::edge_image(const p_edges<G,site_function_t>& pe,
00294 const Function_v2v<FV>& edge_values)
00295 : super_(convert::to<fun::i2v::array<V> >(exact(edge_values)), pe)
00296 {
00297 mlc_equal(mln_result(FV),V)::check();
00298 }
00299
00300 template <typename P, typename V, typename G>
00301 typename edge_image<P,V,G>::rvalue
00302 edge_image<P,V,G>::operator()(unsigned e_id) const
00303 {
00304 return this->data_->f_(e_id);
00305 }
00306
00307 template <typename P, typename V, typename G>
00308 typename edge_image<P,V,G>::lvalue
00309 edge_image<P,V,G>::operator()(unsigned e_id)
00310 {
00311 return this->data_->f_(e_id);
00312 }
00313
00314 template <typename P, typename V, typename G>
00315 typename edge_image<P,V,G>::rvalue
00316 edge_image<P,V,G>::operator()(const typename edge_image<P,V,G>::psite& p) const
00317 {
00318 return this->super_::operator()(p);
00319 }
00320
00321 template <typename P, typename V, typename G>
00322 typename edge_image<P,V,G>::lvalue
00323 edge_image<P,V,G>::operator()(const typename edge_image<P,V,G>::psite& p)
00324 {
00325 return this->super_::operator()(p);
00326 }
00327
00328 # endif // ! MLN_INCLUDE_ONLY
00329
00330 }
00331
00332
00333 #endif // ! MLN_CORE_IMAGE_EDGE_IMAGE_HH