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