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

edge_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_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   // Forward declaration.
00045   template <typename P, typename V, typename G> class edge_image;
00046   namespace util { class graph; }
00047 
00048 
00049   // Properties
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   } // end of namespace mln::traits.
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   } // end of namespace mln::internal
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   // Vertex_image_fsite_selector
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   } // end of namespace mln::internal
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> > win_t;
00153     typedef graph_elt_neighborhood<G,p_edges<G,site_function_t> > nbh_t;
00154 
00157     edge_image();
00158     edge_image(const p_edges<G, site_function_t>& pe);
00159     edge_image(const Graph<G>& g,
00160                const Function_v2v< site_function_t >& edge_sites,
00161                const Function_v2v< fun::i2v::array<V> >& edge_values);
00162 
00163     edge_image(const p_edges<G, site_function_t >& pe,
00164                const Function_v2v< fun::i2v::array<V> >& edge_values);
00165 
00166     template <typename FP, typename FV>
00167     edge_image(const Graph<G>& g,
00168                const Function_v2v<FP>& edge_sites,
00169                const Function_v2v<FV>& edge_values);
00170 
00171     template <typename FV>
00172     edge_image(const p_edges<G,site_function_t>& pe,
00173                const Function_v2v<FV>& edge_values);
00175 
00178     rvalue operator()(unsigned e_id) const;
00179     lvalue operator()(unsigned e_id);
00181 
00182     // Just to help g++-2.95...
00183     rvalue operator()(const psite& p) const;
00184     lvalue operator()(const psite& p);
00185     // ...because "using super_::operator()" does not properly work.
00186 
00187   };
00188 
00189   template <typename P, typename V, typename G, typename J>
00190   void init_(tag::image_t, edge_image<P,V,G>& target, const Image<J>& model);
00191 
00192 
00193 # ifndef MLN_INCLUDE_ONLY
00194 
00195   template <typename P, typename V, typename G, typename J>
00196   void init_(tag::image_t, edge_image<P,V,G>& target, const Image<J>& model)
00197   {
00198     fun::i2v::array<V> f;
00199     init_(tag::function, f, exact(model));
00200     p_edges<G, typename edge_image<P,V,G>::site_function_t> s;
00201     init_(tag::domain, s, exact(model));
00202     target.init_(f, s);
00203   }
00204 
00205   // Operator.
00206 
00207   template <typename V, typename G, typename P>
00208   inline
00209   edge_image<P,V,G>
00210   operator | (const fun::i2v::array<V>& edge_values,
00211               const p_edges<G,fun::i2v::array<P> >& pe)
00212   {
00213     edge_image<P,V,G> tmp(edge_values, pe);
00214     return tmp;
00215   }
00216 
00217 
00218 
00219   // data< pw::image >
00220 
00221   namespace internal
00222   {
00223 
00224     template <typename P, typename V, typename G>
00225     inline
00226     data< mln::edge_image<P,V,G> >::data(const fun::i2v::array<V>& f,
00227                                          const p_edges<G,site_function_t>& ps)
00228       : f_(exact(f)),
00229         domain_(ps)
00230     {
00231     }
00232 
00233   } // end of namespace mln::internal
00234 
00235 
00236 
00237   // edge_image<P,V,G>
00238 
00239   template <typename P, typename V, typename G>
00240   inline
00241   edge_image<P,V,G>::edge_image()
00242   {
00243   }
00244 
00245   template <typename P, typename V, typename G>
00246   inline
00247   edge_image<P,V,G>::edge_image(const p_edges<G,site_function_t>& pe)
00248     : super_(fun::i2v::array<V>(pe.nsites()), pe)
00249   {
00250   }
00251 
00252   template <typename P, typename V, typename G>
00253   inline
00254   edge_image<P,V,G>::edge_image(const Graph<G>& g,
00255                                 const Function_v2v< site_function_t >& edge_sites,
00256                                 const Function_v2v< fun::i2v::array<V> >& edge_values)
00257     : super_(exact(edge_values),
00258              p_edges<G,site_function_t>(g, exact(edge_sites)))
00259   {
00260   }
00261 
00262   template <typename P, typename V, typename G>
00263   inline
00264   edge_image<P,V,G>::edge_image(const p_edges<G,site_function_t>& pe,
00265                                 const Function_v2v< fun::i2v::array<V> >& edge_values)
00266     : super_(exact(edge_values), pe)
00267   {
00268   }
00269 
00270   template <typename P, typename V, typename G>
00271   template <typename FP, typename FV>
00272   inline
00273   edge_image<P,V,G>::edge_image(const Graph<G>& g,
00274                                 const Function_v2v<FP>& edge_sites,
00275                                 const Function_v2v<FV>& edge_values)
00276     : super_(convert::to<fun::i2v::array<V> >(exact(edge_values)),
00277              p_edges<G,site_function_t>(g, exact(edge_sites)))
00278   {
00279     mlc_equal(mln_result(FP),P)::check();
00280     mlc_equal(mln_result(FV),V)::check();
00281   }
00282 
00283   template <typename P, typename V, typename G>
00284   template <typename FV>
00285   inline
00286   edge_image<P,V,G>::edge_image(const p_edges<G,site_function_t>& pe,
00287                                 const Function_v2v<FV>& edge_values)
00288     : super_(convert::to<fun::i2v::array<V> >(exact(edge_values)), pe)
00289   {
00290     mlc_equal(mln_result(FV),V)::check();
00291   }
00292 
00293   template <typename P, typename V, typename G>
00294   typename edge_image<P,V,G>::rvalue
00295   edge_image<P,V,G>::operator()(unsigned e_id) const
00296   {
00297     return this->data_->f_(e_id);
00298   }
00299 
00300   template <typename P, typename V, typename G>
00301   typename edge_image<P,V,G>::lvalue
00302   edge_image<P,V,G>::operator()(unsigned e_id)
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>::rvalue
00309   edge_image<P,V,G>::operator()(const typename edge_image<P,V,G>::psite& p) const
00310   {
00311     return this->super_::operator()(p);
00312   }
00313 
00314   template <typename P, typename V, typename G>
00315   typename edge_image<P,V,G>::lvalue
00316   edge_image<P,V,G>::operator()(const typename edge_image<P,V,G>::psite& p)
00317   {
00318     return this->super_::operator()(p);
00319   }
00320 
00321 # endif // ! MLN_INCLUDE_ONLY
00322 
00323 } // end of namespace mln
00324 
00325 
00326 #endif // ! MLN_CORE_IMAGE_EDGE_IMAGE_HH

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