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_INTERNAL_NEIGHBORHOOD_BASE_HH
00027 # define MLN_CORE_INTERNAL_NEIGHBORHOOD_BASE_HH
00028 
00035 
00036 # include <mln/core/concept/neighborhood.hh>
00037 # include <mln/core/concept/window.hh>
00038 
00039 
00040 namespace mln
00041 {
00042 
00043 
00044   
00045   namespace win
00046   {
00047     template <unsigned n, typename W, typename F>
00048     class multiple_size;
00049   }
00050 
00051 
00052   namespace internal
00053   {
00054 
00055     template <typename W, typename E>
00056     struct neighborhood_extra_impl
00057       : public Neighborhood<E>
00058     {
00059     };
00060 
00061     template <typename W, typename F, typename E>
00062     struct neighborhood_extra_impl< win::multiple_size<2,W,F>, E >
00063       : public Neighborhood<E>
00064     {
00065 
00069       
00070       neighb<W> foreground() const
00071       {
00072         W win = internal::force_exact<E>(*this).win().window_(1); 
00073         neighb<W> nbh(win);
00074         return nbh;
00075       }
00076       
00080       
00081       neighb<W> background() const
00082       {
00083         W win = internal::force_exact<E>(*this).win().window_(0); 
00084         neighb<W> nbh(win);
00085         return nbh;
00086       }
00087       
00088     };
00089 
00090 
00091 
00092 
00093     template <typename W, typename E>
00094     struct neighborhood_impl : public neighborhood_extra_impl<W,E>
00095     {
00096       
00097 
00100       unsigned size() const;
00101 
00104       unsigned delta() const;
00105 
00108       const mln_dpsite(W)& dp(unsigned i) const;
00109 
00110       
00111     };
00112 
00113 
00117 
00118     template <typename W, typename E>
00119     struct neighborhood_base : public neighborhood_impl<W,E>
00120     {
00122       typedef W window;
00123 
00125       typedef mln_dpsite(W) dpsite;
00126 
00128       typedef mln_psite(W) psite;
00129 
00131       typedef mln_site(W) site;
00132 
00134       bool is_valid() const;
00135 
00136     protected:
00137       neighborhood_base();
00138     };
00139 
00140 
00141 
00142 
00143 # ifndef MLN_INCLUDE_ONLY
00144 
00145 
00146     
00147 
00148     template <typename W, typename E>
00149     inline
00150     neighborhood_base<W,E>::neighborhood_base()
00151     {
00152     }
00153 
00154     template <typename W, typename E>
00155     inline
00156     bool
00157     neighborhood_base<W,E>::is_valid() const
00158     {
00159       return true;
00160     }
00161 
00162     
00163 
00164     template <typename W, typename E>
00165     inline
00166     unsigned
00167     neighborhood_impl<W,E>::size() const
00168     {
00169       mlc_is(mln_trait_window_size(W),
00170              trait::window::size::fixed)::check();
00171       return exact(this)->win().size();
00172     }
00173 
00174     template <typename W, typename E>
00175     inline
00176     unsigned
00177     neighborhood_impl<W,E>::delta() const
00178     {
00179       mlc_is(mln_trait_window_support(W),
00180              trait::window::support::regular)::check();
00181       mlc_is_not(mln_trait_window_definition(W),
00182                  trait::window::definition::varying)::check();
00183       return exact(this)->win().delta();
00184     }
00185 
00186     template <typename W, typename E>
00187     inline
00188     const mln_dpsite(W)&
00189     neighborhood_impl<W,E>::dp(unsigned i) const
00190     {
00191       mlc_is(mln_trait_window_support(W),
00192              trait::window::support::regular)::check();
00193       mlc_is(mln_trait_window_definition(W),
00194              trait::window::definition::unique)::check();
00195       return exact(this)->win().dp(i);
00196     }
00197 
00198 # endif // ! MLN_INCLUDE_ONLY
00199 
00200   } 
00201 
00202 } 
00203 
00204 
00205 #endif // ! MLN_CORE_INTERNAL_NEIGHBORHOOD_BASE_HH