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_DMORPH_SUB_IMAGE_IF_HH
00027 # define MLN_CORE_IMAGE_DMORPH_SUB_IMAGE_IF_HH
00028 
00029 
00035 
00036 
00037 # include <mln/core/internal/image_domain_morpher.hh>
00038 # include <mln/core/site_set/p_if.hh>
00039 # include <mln/fun/p2b/has.hh>
00040 
00041 # include <mln/debug/println.hh>
00042 
00043 
00044 namespace mln
00045 {
00046 
00047 
00048   
00049   template <typename I, typename S> class sub_image_if;
00050 
00051 
00052   namespace internal
00053   {
00054 
00056     template <typename I, typename S>
00057     struct data< sub_image_if<I,S> >
00058     {
00059       data(I& ima, const S& s);
00060 
00061       I ima_;
00062       p_if< S, fun::p2b::has<I> > s_;
00063     };
00064 
00065   } 
00066 
00067 
00068 
00069   namespace trait
00070   {
00071 
00072     template <typename I, typename S>
00073     struct image_< sub_image_if<I,S> > : default_image_morpher< I,
00074                                                                 mln_value(I),
00075                                                                 sub_image_if<I,S> >
00076     {
00077 
00078 
00079 
00080 
00081 
00082       typedef trait::image::category::domain_morpher category;
00083 
00084       typedef trait::image::ext_domain::none      ext_domain;  
00085       typedef trait::image::ext_value::irrelevant ext_value;
00086       typedef trait::image::ext_io::irrelevant    ext_io;
00087 
00088       typedef trait::image::value_storage::disrupted value_storage;
00089       
00090     };
00091 
00092   } 
00093 
00094 
00095 
00099   
00100   template <typename I, typename S>
00101   struct sub_image_if : public internal::image_domain_morpher< I,
00102                                                                p_if< S, fun::p2b::has<I> >,
00103                                                                sub_image_if<I,S> >
00104   {
00106     typedef sub_image_if< tag::image_<I>, tag::domain_<S> > skeleton;
00107 
00109     sub_image_if();
00110 
00112     sub_image_if(I& ima, const S& s);
00113 
00115     void init_(I& ima, const S& s);
00116 
00118     const p_if< S, fun::p2b::has<I> >& domain() const;
00119 
00120 
00121 
00122   };
00123 
00124 
00125 
00126 
00127 
00128   template <typename I, typename S>
00129   sub_image_if<const I, S>
00130   operator / (const Image<I>& ima, const Site_Set<S>& s);
00131 
00132 
00133   template <typename I, typename S>
00134   sub_image_if<I, S>
00135   operator / (Image<I>& ima, const Site_Set<S>& s);
00136 
00137 
00138   template <typename I, typename S, typename J>
00139   void init_(tag::image_t, sub_image_if<I,S>& target, const J& model);
00140 
00141 
00142 
00143 # ifndef MLN_INCLUDE_ONLY
00144 
00145   
00146 
00147   template <typename I, typename S, typename J>
00148   inline
00149   void init_(tag::image_t, sub_image_if<I,S>& target, const J& model)
00150   {
00151     I ima;
00152     init_(tag::image, ima, model);
00153     S s;
00154     init_(tag::domain, s, model);
00155     target.init_(ima, s);
00156   }
00157 
00158 
00159   
00160 
00161   namespace internal
00162   {
00163 
00164     template <typename I, typename S>
00165     inline
00166     data< sub_image_if<I,S> >::data(I& ima, const S& s)
00167       : ima_(ima)
00168     {
00169       typedef fun::p2b::has<I> F;
00170       F f(ima);
00171       s_ = p_if<S,F>(s, f); 
00172     }
00173 
00174   } 
00175 
00176 
00177   
00178 
00179   template <typename I, typename S>
00180   inline
00181   sub_image_if<I,S>::sub_image_if()
00182   {
00183   }
00184 
00185   template <typename I, typename S>
00186   inline
00187   sub_image_if<I,S>::sub_image_if(I& ima, const S& s)
00188   {
00189     init_(ima, s);
00190   }
00191 
00192   template <typename I, typename S>
00193   inline
00194   void
00195   sub_image_if<I,S>::init_(I& ima, const S& s)
00196   {
00197     mln_precondition(! this->is_valid());
00198     this->data_ = new internal::data< sub_image_if<I,S> >(ima, s);
00199   }
00200 
00201   template <typename I, typename S>
00202   inline
00203   const p_if< S, fun::p2b::has<I> >&
00204   sub_image_if<I,S>::domain() const
00205   {
00206     return this->data_->s_;
00207   }
00208 
00209 
00210 
00211 
00212 
00213 
00214 
00215 
00216 
00217 
00218 
00219   
00220 
00221   template <typename I, typename S>
00222   inline
00223   sub_image_if<const I, S>
00224   operator / (const Image<I>& ima, const Site_Set<S>& s)
00225   {
00226     
00227     sub_image_if<const I, S> tmp(exact(ima), exact(s));
00228     return tmp;
00229   }
00230 
00231   template <typename I, typename S>
00232   inline
00233   sub_image_if<I, S>
00234   operator / (Image<I>& ima, const Site_Set<S>& s)
00235   {
00236     
00237     sub_image_if<I, S> tmp(exact(ima), exact(s));
00238     return tmp;
00239   }
00240 
00241 # endif // ! MLN_INCLUDE_ONLY
00242 
00243 } 
00244 
00245 
00246 #endif // ! MLN_CORE_IMAGE_DMORPH_SUB_IMAGE_IF_HH