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_FLAT_IMAGE_HH
00027 # define MLN_CORE_IMAGE_FLAT_IMAGE_HH
00028 
00034 
00035 # include <mln/core/internal/image_primary.hh>
00036 # include <mln/value/set.hh>
00037 
00038 
00039 namespace mln
00040 {
00041 
00042 
00043   
00044   template <typename T, typename S> class flat_image;
00045 
00046 
00047   namespace internal
00048   {
00049 
00051     template <typename T, typename S>
00052     struct data< flat_image<T,S> >
00053     {
00054       data(const T& val, const S& pset);
00055 
00056       T val_;
00057       S domain_;
00058     };
00059 
00060   } 
00061 
00062 
00063 
00064   namespace trait
00065   {
00066 
00067     template <typename T, typename S>
00068     struct image_< flat_image<T,S> > : default_image_< T, flat_image<T,S> >
00069     {
00070       
00071       typedef trait::image::category::primary category;
00072       typedef trait::image::speed::fast       speed;
00073       typedef trait::image::size::regular     size;
00074 
00075       
00076       typedef trait::image::vw_io::read_write               vw_io;
00078       typedef trait::image::vw_set::none                    vw_set;
00079       typedef trait::image::value_access::direct            value_access;
00080       typedef trait::image::value_storage::singleton        value_storage;
00081       typedef mln::trait::image::value_browsing::value_wise value_browsing;
00082       typedef trait::image::value_alignment::with_grid      value_alignment;
00083       typedef trait::image::value_io::read_only             value_io;
00084 
00085       
00086       typedef trait::image::pw_io::read              pw_io;
00087       typedef trait::image::localization::basic_grid localization; 
00088       typedef trait::image::dimension::two_d         dimension;    
00089 
00090       
00091       typedef trait::image::ext_domain::infinite ext_domain;
00092       typedef trait::image::ext_value::single    ext_value;
00093       typedef trait::image::ext_io::read_only    ext_io;
00094     };
00095 
00096   } 
00097 
00098 
00099 
00103   
00104   template <typename T, typename S>
00105   struct flat_image : public internal::image_primary< T, S, flat_image<T,S> >
00106   {
00108     typedef flat_image< tag::value_<T>, tag::domain_<S> > skeleton;
00109 
00110 
00112     typedef T value;
00113 
00115     typedef const T& rvalue;
00116 
00118     typedef T& lvalue;
00119 
00120 
00122     flat_image();
00123 
00125     flat_image(const T& val, const S& pset);
00126 
00128     void init_(const T& val, const S& pset);
00129 
00131     const S& domain() const;
00132 
00134     bool has(const mln_psite(S)& p) const;
00135 
00136 
00138     const T& operator()(const mln_psite(S)& p) const;
00139 
00141     T& operator()(const mln_psite(S)& p);
00142 
00143 
00145     const T& value_() const;
00146     T& value_();
00147   };
00148 
00149 
00150 
00151   template <typename T, typename S, typename J>
00152   void init_(tag::image_t, flat_image<T,S>& target, const J& model);
00153 
00154 
00155 
00156 # ifndef MLN_INCLUDE_ONLY
00157 
00158   
00159 
00160   template <typename T, typename S, typename J>
00161   inline
00162   void init_(tag::image_t, flat_image<T,S>& target, const J& model)
00163   {
00164     S pset;
00165     init_(tag::domain, pset, model);
00166     T dummy;
00167     target.init_(dummy, pset);
00168   }
00169 
00170 
00171   
00172 
00173   namespace internal
00174   {
00175 
00176     template <typename T, typename S>
00177     inline
00178     data< flat_image<T,S> >::data(const T& val, const S& pset)
00179       : val_(val),
00180         domain_(pset)
00181     {
00182     }
00183 
00184   } 
00185 
00186 
00187   
00188 
00189   template <typename T, typename S>
00190   inline
00191   flat_image<T,S>::flat_image()
00192   {
00193   }
00194 
00195   template <typename T, typename S>
00196   inline
00197   flat_image<T,S>::flat_image(const T& val, const S& pset)
00198   {
00199     init_(val, pset);
00200   }
00201 
00202   template <typename T, typename S>
00203   inline
00204   void
00205   flat_image<T,S>::init_(const T& val, const S& pset)
00206   {
00207     mln_precondition(! this->is_valid());
00208     this->data_ = new internal::data< flat_image<T,S> >(val, pset);
00209   }
00210 
00211   template <typename T, typename S>
00212   inline
00213   const S&
00214   flat_image<T,S>::domain() const
00215   {
00216     return this->data_->domain_;
00217   }
00218 
00219   template <typename T, typename S>
00220   inline
00221   bool
00222   flat_image<T,S>::has(const mln_psite(S)&) const
00223   {
00224     return true;
00225   }
00226 
00227   template <typename T, typename S>
00228   inline
00229   const T&
00230   flat_image<T,S>::operator()(const mln_psite(S)&) const
00231   {
00232     mln_precondition(this->is_valid());
00233     return this->data_->val_;
00234   }
00235 
00236   template <typename T, typename S>
00237   inline
00238   T&
00239   flat_image<T,S>::operator()(const mln_psite(S)&)
00240   {
00241     mln_precondition(this->is_valid());
00242     return this->data_->val_;
00243   }
00244 
00245   template <typename T, typename S>
00246   inline
00247   const T&
00248   flat_image<T,S>::value_() const
00249   {
00250     mln_precondition(this->is_valid());
00251     return this->data_->val_;
00252   }
00253 
00254   template <typename T, typename S>
00255   inline
00256   T&
00257   flat_image<T,S>::value_()
00258   {
00259     mln_precondition(this->is_valid());
00260     return this->data_->val_;
00261   }
00262 
00263 
00264 
00265 # endif // ! MLN_INCLUDE_ONLY
00266 
00267 } 
00268 
00269 
00270 #endif // ! MLN_CORE_IMAGE_FLAT_IMAGE_HH