Milena (Olena)  User documentation 2.0a Id
transformed_image.hh
00001 // Copyright (C) 2009, 2011 EPITA Research and Development Laboratory
00002 // (LRDE)
00003 //
00004 // This file is part of Olena.
00005 //
00006 // Olena is free software: you can redistribute it and/or modify it under
00007 // the terms of the GNU General Public License as published by the Free
00008 // Software Foundation, version 2 of the License.
00009 //
00010 // Olena is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013 // General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU General Public License
00016 // along with Olena.  If not, see <http://www.gnu.org/licenses/>.
00017 //
00018 // As a special exception, you may use this file as part of a free
00019 // software project without restriction.  Specifically, if other files
00020 // instantiate templates or use macros or inline functions from this
00021 // file, or you compile this file and link it with other files to produce
00022 // an executable, this file does not by itself cause the resulting
00023 // executable to be covered by the GNU General Public License.  This
00024 // exception does not however invalidate any other reasons why the
00025 // executable file might be covered by the GNU General Public License.
00026 
00027 #ifndef MLN_CORE_IMAGE_DMORPH_TRANSFORMED_IMAGE_HH
00028 # define MLN_CORE_IMAGE_DMORPH_TRANSFORMED_IMAGE_HH
00029 
00036 
00037 # include <mln/core/internal/image_domain_morpher.hh>
00038 # include <mln/core/site_set/p_transformed.hh>
00039 
00040 
00041 namespace mln
00042 {
00043 
00044 
00045   // Forward declaration.
00046   template <typename I, typename F> struct transformed_image;
00047 
00048 
00049   namespace internal
00050   {
00051 
00053     template <typename I, typename F>
00054     struct data< transformed_image<I,F> >
00055     {
00056       data(I& ima, const F& f);
00057 
00058       I ima_;
00059       F f_;
00060       p_transformed< mln_domain(I), F> domain_;
00061     };
00062 
00063   } // end of namespace mln::internal
00064 
00065 
00066 
00067   namespace trait
00068   {
00069 
00070     template <typename I, typename F>
00071     struct image_< transformed_image<I,F> > : default_image_morpher< I,
00072                                                                      mln_value(I),
00073                                                                      transformed_image<I,F> >
00074     {
00075       typedef trait::image::category::domain_morpher category;
00076 
00077       typedef trait::image::ext_domain::none      ext_domain;  // No extension of domain.
00078       typedef trait::image::ext_value::irrelevant ext_value;
00079       typedef trait::image::ext_io::irrelevant    ext_io;
00080 
00081       typedef trait::image::vw_io::none                    vw_io;
00082       typedef trait::image::vw_set::none                   vw_set;
00083       typedef trait::image::value_alignment::not_aligned   value_alignment;
00084       typedef trait::image::value_storage::disrupted value_storage;
00085     };
00086 
00087   } // end of namespace mln::trait
00088 
00089 
00090 
00094   //
00095   template <typename I, typename F>
00096   struct transformed_image : public internal::image_domain_morpher< I,
00097                                                                     p_transformed< mln_domain(I), F>,
00098                                                                     transformed_image<I,F> >
00099   {
00101     typedef transformed_image< tag::image_<I>, tag::function_<F> > skeleton;
00102 
00104     transformed_image();
00105 
00107     transformed_image(I& ima, const F& f);
00108 
00110     void init_(I& ima, const F& f);
00111 
00112 
00114     const p_transformed< mln_domain(I), F>& domain() const;
00115 
00116 
00118     mln_rvalue(I) operator()(const mln_psite(I)& p) const;
00119 
00122     mln_morpher_lvalue(I) operator()(const mln_psite(I)& p);
00123 
00124 
00126     operator transformed_image<const I, F>() const;
00127   };
00128 
00129 
00130 
00131   // Morpher creation.
00132 
00133   template <typename I, typename F>
00134   transformed_image<const I, F>
00135   transform_domain(const Image<I>& ima, const Function_v2v<F>& f);
00136 
00137   template <typename I, typename F>
00138   transformed_image<I, F>
00139   transform_domain(Image<I>& ima, const Function_v2v<F>& f);
00140 
00141 
00142 
00143 
00144 # ifndef MLN_INCLUDE_ONLY
00145 
00146   // init_
00147 
00148   template <typename I, typename F, typename J>
00149   inline
00150   void init_(tag::image_t, transformed_image<I,F>& target, const J& model)
00151   {
00152     I ima;
00153     init_(tag::image, ima, exact(model));
00154     F f;
00155     init_(tag::function, f, exact(model));
00156     target.init_(ima, f);
00157   }
00158 
00159   template <typename I, typename F>
00160   void init_(tag::function_t, F& f, const transformed_image<I,F>& model)
00161   {
00162     f = model.domain().function();
00163   }
00164 
00165 
00166   // internal::data< transformed_image<I,F> >
00167 
00168   namespace internal
00169   {
00170 
00171     template <typename I, typename F>
00172     inline
00173     data< transformed_image<I,F> >::data(I& ima, const F& f)
00174       : ima_(ima),
00175         f_(f),
00176         domain_(ima.domain(), f)
00177     {
00178     }
00179 
00180   } // end of namespace mln::internal
00181 
00182 
00183   // transformed_image<I,F>
00184 
00185   template <typename I, typename F>
00186   inline
00187   transformed_image<I,F>::transformed_image()
00188   {
00189   }
00190 
00191   template <typename I, typename F>
00192   inline
00193   transformed_image<I,F>::transformed_image(I& ima, const F& f)
00194   {
00195     init_(ima, f);
00196   }
00197 
00198   template <typename I, typename F>
00199   inline
00200   void
00201   transformed_image<I,F>::init_(I& ima, const F& f)
00202   {
00203     mln_precondition(! this->is_valid());
00204     this->data_ = new internal::data< transformed_image<I,F> >(ima, f);
00205   }
00206 
00207   template <typename I, typename F>
00208   inline
00209   const p_transformed< mln_domain(I), F>&
00210   transformed_image<I,F>::domain() const
00211   {
00212     return this->data_->domain_;
00213   }
00214 
00215   template <typename I, typename F>
00216   inline
00217   mln_rvalue(I)
00218   transformed_image<I,F>::operator()(const mln_psite(I)& p) const
00219   {
00220     mln_precondition(this->delegatee_() != 0);
00221     mln_precondition(exact(this)->has(p));
00222     mln_precondition(this->delegatee_()->has(this->data_->f_(p)));
00223     return this->delegatee_()->operator()(this->data_->f_(p));
00224   }
00225 
00226   template <typename I, typename F>
00227   inline
00228   mln_morpher_lvalue(I)
00229   transformed_image<I,F>::operator()(const mln_psite(I)& p)
00230   {
00231     mln_precondition(this->delegatee_() != 0);
00232     mln_precondition(exact(this)->has(p));
00233     mln_precondition(this->delegatee_()->has(this->data_->f_(p)));
00234     return this->delegatee_()->operator()(this->data_->f_(p));
00235   }
00236 
00237 
00238   template <typename I, typename F>
00239   inline
00240   transformed_image<I,F>::operator transformed_image<const I, F>() const
00241   {
00242     transformed_image<const I, F> tmp(this->data_->ima_,
00243                                       this->data_->f_);
00244     return tmp;
00245   }
00246 
00247 
00248   // Morpher creation.
00249 
00250   template <typename I, typename F>
00251   inline
00252   transformed_image<const I, F>
00253   transform_domain(const Image<I>& ima, const Function_v2v<F>& f)
00254   {
00255     transformed_image<const I, F> tmp(exact(ima), exact(f));
00256     return tmp;
00257   }
00258 
00259   template <typename I, typename F>
00260   inline
00261   transformed_image<I, F>
00262   transform_domain(Image<I>& ima, const Function_v2v<F>& f)
00263   {
00264     transformed_image<I, F> tmp(exact(ima), exact(f));
00265     return tmp;
00266   }
00267 
00268 # endif // ! MLN_INCLUDE_ONLY
00269 
00270 } // end of namespace mln
00271 
00272 
00273 #endif // ! MLN_CORE_IMAGE_DMORPH_TRANSFORMED_IMAGE_HH
 All Classes Namespaces Functions Variables Typedefs Enumerator