• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Classes
  • Files
  • File List

vertex_image.hh

00001 // Copyright (C) 2009 EPITA Research and Development Laboratory (LRDE)
00002 //
00003 // This file is part of Olena.
00004 //
00005 // Olena is free software: you can redistribute it and/or modify it under
00006 // the terms of the GNU General Public License as published by the Free
00007 // Software Foundation, version 2 of the License.
00008 //
00009 // Olena is distributed in the hope that it will be useful,
00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012 // General Public License for more details.
00013 //
00014 // You should have received a copy of the GNU General Public License
00015 // along with Olena.  If not, see <http://www.gnu.org/licenses/>.
00016 //
00017 // As a special exception, you may use this file as part of a free
00018 // software project without restriction.  Specifically, if other files
00019 // instantiate templates or use macros or inline functions from this
00020 // file, or you compile this file and link it with other files to produce
00021 // an executable, this file does not by itself cause the resulting
00022 // executable to be covered by the GNU General Public License.  This
00023 // exception does not however invalidate any other reasons why the
00024 // executable file might be covered by the GNU General Public License.
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/site_set/p_vertices.hh>
00037 # include <mln/pw/internal/image_base.hh>
00038 # include <mln/fun/i2v/array.hh>
00039 
00040 # include <mln/util/internal/id2element.hh>
00041 
00042 
00043 namespace mln
00044 {
00045 
00046   // Forward declaration.
00047   template <typename P, typename V, typename G> class vertex_image;
00048   namespace util { class graph; }
00049 
00050 
00051   // Properties
00052 
00053   namespace trait
00054   {
00055 
00056     template <typename P, typename V, typename G>
00057     struct image_< vertex_image<P,V,G> >
00058       : pw_image_<fun::i2v::array<V>,
00059                   p_vertices<util::graph, fun::i2v::array<P> >,
00060                   vertex_image<P,V,G> >
00061     {
00062     };
00063 
00064   } // end of namespace mln::traits.
00065 
00066 
00067 
00068   namespace internal
00069   {
00070 
00072     template <typename P, typename V, typename G>
00073     struct data< mln::vertex_image<P,V,G> >
00074     {
00075       typedef typename vertex_image<P,V,G>::site_function_t site_function_t;
00076 
00077       template <typename F>
00078       data(const fun::i2v::array<V>& vertex_values,
00079            const p_vertices<G,F>& pv);
00080 
00081       fun::i2v::array<V> f_;
00082       p_vertices<G,site_function_t> domain_;
00083     };
00084 
00085   } // end of namespace mln::internal
00086 
00087 
00088 
00091   template <typename V, typename G, typename P>
00092   vertex_image<P,V,G>
00093   operator | (const fun::i2v::array<V>& vertex_values,
00094               const p_vertices<G,fun::i2v::array<P> >& pv);
00095 
00096 
00097   // Vertex_image_fsite_selector
00098 
00099   namespace internal
00100   {
00101 
00102     template <typename P, typename G>
00103     struct vfsite_selector
00104     {
00105       typedef fun::i2v::array<P> site_function_t;
00106     };
00107 
00108 
00109 
00110     template <typename G>
00111     struct vfsite_selector<void,G>
00112     {
00113       typedef util::internal::id2element< G,util::vertex<G> > site_function_t;
00114     };
00115 
00116 
00117   } // end of namespace mln::internal
00118 
00119 
00123   //
00124   template <typename P, typename V, typename G = util::graph>
00125   class vertex_image
00126     : public pw::internal::image_base<fun::i2v::array<V>,
00127                                       p_vertices<G, typename internal::vfsite_selector<P,G>::site_function_t >,
00128                                       vertex_image<P,V,G> >
00129   {
00130     typedef pw::internal::image_base<fun::i2v::array<V>,
00131                                      p_vertices<G, typename internal::vfsite_selector<P,G>::site_function_t >,
00132                                      vertex_image<P,V,G> > super_;
00133 
00134   public:
00135     typedef typename super_::psite  psite;
00136     typedef typename super_::rvalue rvalue;
00137     typedef typename super_::lvalue lvalue;
00138 
00140     typedef G graph_t;
00141 
00143     typedef typename internal::vfsite_selector<P,G>::site_function_t
00144             site_function_t;
00145     typedef mln_result(site_function_t) function_result_t;
00146 
00147 
00149     typedef vertex_image< tag::psite_<P>,
00150                           tag::value_<V>,
00151                           tag::graph_<G> > skeleton;
00152 
00154     typedef graph_elt_window<G,p_vertices<G,site_function_t> > win_t;
00156     typedef graph_elt_neighborhood<G,p_vertices<G,site_function_t> > nbh_t;
00157 
00160     vertex_image();
00161     vertex_image(const p_vertices<G, site_function_t>& pv);
00162     vertex_image(const p_vertices<G, site_function_t>& pv,
00163                  const Function_v2v< fun::i2v::array<V> >& vertex_values);
00164     template <typename FV>
00165     vertex_image(const p_vertices<G, site_function_t>& pv,
00166                  const Function_v2v<FV>& vertex_values);
00168 
00171     rvalue operator()(unsigned v_id) const;
00172     lvalue operator()(unsigned v_id);
00174 
00175 
00176     // Just to help g++-2.95...
00177     rvalue operator()(const psite& p) const;
00178     lvalue operator()(const psite& p);
00179     // ...because "using super_::operator()" does not properly work.
00180 
00181   };
00182 
00183   template <typename P, typename V, typename G, typename J>
00184   void init_(tag::image_t, vertex_image<P,V,G>& target, const Image<J>& model);
00185 
00186 
00187 # ifndef MLN_INCLUDE_ONLY
00188 
00189   template <typename P, typename V, typename G, typename J>
00190   void init_(tag::image_t, vertex_image<P,V,G>& target, const Image<J>& model)
00191   {
00192     fun::i2v::array<V> f;
00193     init_(tag::function, f, exact(model));
00194     p_vertices<G,typename vertex_image<P,V,G>::site_function_t> s;
00195     init_(tag::domain, s, exact(model));
00196     target.init_(f, s);
00197   }
00198 
00199   // Operator.
00200 
00201   template <typename V, typename G, typename P>
00202   inline
00203   vertex_image<P,V,G>
00204   operator | (const fun::i2v::array<V>& vertex_values,
00205               const p_vertices<G, fun::i2v::array<P> >& pv)
00206   {
00207     vertex_image<P,V,G> tmp(vertex_values, pv);
00208     return tmp;
00209   }
00210 
00211 
00212 
00213   // data< pw::image >
00214 
00215   namespace internal
00216   {
00217 
00218     template <typename P, typename V, typename G>
00219     template <typename F>
00220     inline
00221     data< mln::vertex_image<P,V,G> >::data(const fun::i2v::array<V>& f,
00222                                            const p_vertices<G,F>& ps)
00223       : f_(f),
00224         domain_(ps)
00225     {
00226     }
00227 
00228   } // end of namespace mln::internal
00229 
00230 
00231 
00232   // vertex_image<P,V,G>
00233 
00234   template <typename P, typename V, typename G>
00235   inline
00236   vertex_image<P,V,G>::vertex_image()
00237   {
00238   }
00239 
00240   template <typename P, typename V, typename G>
00241   inline
00242   vertex_image<P,V,G>::vertex_image(const p_vertices<G,site_function_t>& pv)
00243     : super_(fun::i2v::array<V>(pv.nsites()), pv)
00244   {
00245   }
00246 
00247   template <typename P, typename V, typename G>
00248   inline
00249   vertex_image<P,V,G>::vertex_image(const p_vertices<G,site_function_t>& pv,
00250                                     const Function_v2v< fun::i2v::array<V> >& vertex_values)
00251     : super_(exact(vertex_values), pv)
00252   {
00253   }
00254 
00255   template <typename P, typename V, typename G>
00256   template <typename FV>
00257   inline
00258   vertex_image<P,V,G>::vertex_image(const p_vertices<G,site_function_t>& pv,
00259                                     const Function_v2v<FV>& vertex_values)
00260     : super_(convert::to<fun::i2v::array<V> >(exact(vertex_values)), pv)
00261   {
00262     mlc_equal(mln_result(FV),V)::check();
00263   }
00264 
00265 //  template <typename P, typename V, typename G>
00266 //  typename vertex_image<P,V,G>::rvalue
00267 //  vertex_image<P,V,G>::operator()(const util::vertex<G>& v) const
00268 //  {
00269 //    return this->data_->f_(v.id());
00270 //  }
00271 
00272 //  template <typename P, typename V, typename G>
00273 //  typename vertex_image<P,V,G>::lvalue
00274 //  vertex_image<P,V,G>::operator()(const util::vertex<G>& v)
00275 //  {
00276 //    return this->data_->f_(v.id());
00277 //  }
00278 
00279   template <typename P, typename V, typename G>
00280   typename vertex_image<P,V,G>::rvalue
00281   vertex_image<P,V,G>::operator()(unsigned v_id) const
00282   {
00283     return this->data_->f_(v_id);
00284   }
00285 
00286   template <typename P, typename V, typename G>
00287   typename vertex_image<P,V,G>::lvalue
00288   vertex_image<P,V,G>::operator()(unsigned v_id)
00289   {
00290     return this->data_->f_(v_id);
00291   }
00292 
00293   template <typename P, typename V, typename G>
00294   typename vertex_image<P,V,G>::rvalue
00295   vertex_image<P,V,G>::operator()(const typename vertex_image<P,V,G>::psite& p) const
00296   {
00297     return this->super_::operator()(p);
00298   }
00299 
00300   template <typename P, typename V, typename G>
00301   typename vertex_image<P,V,G>::lvalue
00302   vertex_image<P,V,G>::operator()(const typename vertex_image<P,V,G>::psite& p)
00303   {
00304     return this->super_::operator()(p);
00305   }
00306 
00307 # endif // ! MLN_INCLUDE_ONLY
00308 
00309 } // end of namespace mln
00310 
00311 
00312 #endif // ! MLN_CORE_IMAGE_VERTEX_IMAGE_HH

Generated on Thu Sep 8 2011 18:33:03 for Milena (Olena) by  doxygen 1.7.1