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

transformed_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_DMORPH_TRANSFORMED_IMAGE_HH
00027 # define MLN_CORE_IMAGE_DMORPH_TRANSFORMED_IMAGE_HH
00028 
00035 
00036 # include <mln/core/internal/image_domain_morpher.hh>
00037 # include <mln/core/site_set/p_transformed.hh>
00038 
00039 
00040 namespace mln
00041 {
00042 
00043 
00044   // Forward declaration.
00045   template <typename I, typename F> class transformed_image;
00046 
00047 
00048   namespace internal
00049   {
00050 
00052     template <typename I, typename F>
00053     struct data< transformed_image<I,F> >
00054     {
00055       data(I& ima, const F& f);
00056 
00057       I ima_;
00058       F f_;
00059       p_transformed< mln_domain(I), F> domain_;
00060     };
00061 
00062   } // end of namespace mln::internal
00063 
00064 
00065 
00066   namespace trait
00067   {
00068 
00069     template <typename I, typename F>
00070     struct image_< transformed_image<I,F> > : default_image_morpher< I,
00071                                                                      mln_value(I),
00072                                                                      transformed_image<I,F> >
00073     {
00074       typedef trait::image::category::domain_morpher category;
00075 
00076       typedef trait::image::ext_domain::none      ext_domain;  // No extension of domain.
00077       typedef trait::image::ext_value::irrelevant ext_value;
00078       typedef trait::image::ext_io::irrelevant    ext_io;
00079 
00080       typedef trait::image::vw_io::none                    vw_io;
00081       typedef trait::image::vw_set::none                   vw_set;
00082       typedef trait::image::value_alignment::not_aligned   value_alignment;
00083       typedef trait::image::value_storage::disrupted value_storage;
00084     };
00085 
00086   } // end of namespace mln::trait
00087 
00088 
00089 
00093   //
00094   template <typename I, typename F>
00095   struct transformed_image : public internal::image_domain_morpher< I,
00096                                                                     p_transformed< mln_domain(I), F>,
00097                                                                     transformed_image<I,F> >
00098   {
00100     typedef transformed_image< tag::image_<I>, tag::function_<F> > skeleton;
00101 
00103     transformed_image();
00104 
00106     transformed_image(I& ima, const F& f);
00107 
00109     void init_(I& ima, const F& f);
00110 
00111 
00113     const p_transformed< mln_domain(I), F>& domain() const;
00114 
00115 
00117     mln_rvalue(I) operator()(const mln_psite(I)& p) const;
00118 
00121     mln_morpher_lvalue(I) operator()(const mln_psite(I)& p);
00122 
00123 
00125     operator transformed_image<const I, F>() const;
00126   };
00127 
00128 
00129 
00130   // Morpher creation.
00131 
00132   template <typename I, typename F>
00133   transformed_image<const I, F>
00134   transform_domain(const Image<I>& ima, const Function_v2v<F>& f);
00135 
00136   template <typename I, typename F>
00137   transformed_image<I, F>
00138   transform_domain(Image<I>& ima, const Function_v2v<F>& f);
00139 
00140 
00141 
00142 
00143 # ifndef MLN_INCLUDE_ONLY
00144 
00145   // init_
00146 
00147   template <typename I, typename F, typename J>
00148   inline
00149   void init_(tag::image_t, transformed_image<I,F>& target, const J& model)
00150   {
00151     I ima;
00152     init_(tag::image, ima, exact(model));
00153     F f;
00154     init_(tag::function, f, exact(model));
00155     target.init_(ima, f);
00156   }
00157 
00158   template <typename I, typename F>
00159   void init_(tag::function_t, F& f, const transformed_image<I,F>& model)
00160   {
00161     f = model.domain().function();
00162   }
00163 
00164 
00165   // internal::data< transformed_image<I,F> >
00166 
00167   namespace internal
00168   {
00169 
00170     template <typename I, typename F>
00171     inline
00172     data< transformed_image<I,F> >::data(I& ima, const F& f)
00173       : ima_(ima),
00174         f_(f),
00175         domain_(ima.domain(), f)
00176     {
00177     }
00178 
00179   } // end of namespace mln::internal
00180 
00181 
00182   // transformed_image<I,F>
00183 
00184   template <typename I, typename F>
00185   inline
00186   transformed_image<I,F>::transformed_image()
00187   {
00188   }
00189 
00190   template <typename I, typename F>
00191   inline
00192   transformed_image<I,F>::transformed_image(I& ima, const F& f)
00193   {
00194     init_(ima, f);
00195   }
00196 
00197   template <typename I, typename F>
00198   inline
00199   void
00200   transformed_image<I,F>::init_(I& ima, const F& f)
00201   {
00202     mln_precondition(! this->is_valid());
00203     this->data_ = new internal::data< transformed_image<I,F> >(ima, f);
00204   }
00205 
00206   template <typename I, typename F>
00207   inline
00208   const p_transformed< mln_domain(I), F>&
00209   transformed_image<I,F>::domain() const
00210   {
00211     return this->data_->domain_;
00212   }
00213 
00214   template <typename I, typename F>
00215   inline
00216   mln_rvalue(I)
00217   transformed_image<I,F>::operator()(const mln_psite(I)& p) const
00218   {
00219     mln_precondition(this->delegatee_() != 0);
00220     mln_precondition(exact(this)->has(p));
00221     mln_precondition(this->delegatee_()->has(this->data_->f_(p)));
00222     return this->delegatee_()->operator()(this->data_->f_(p));
00223   }
00224   
00225   template <typename I, typename F>
00226   inline
00227   mln_morpher_lvalue(I)
00228   transformed_image<I,F>::operator()(const mln_psite(I)& p)
00229   {
00230     mln_precondition(this->delegatee_() != 0);
00231     mln_precondition(exact(this)->has(p));
00232     mln_precondition(this->delegatee_()->has(this->data_->f_(p)));
00233     return this->delegatee_()->operator()(this->data_->f_(p));
00234   }
00235 
00236 
00237   template <typename I, typename F>
00238   inline
00239   transformed_image<I,F>::operator transformed_image<const I, F>() const
00240   {
00241     transformed_image<const I, F> tmp(this->data_->ima_,
00242                                       this->data_->f_);
00243     return tmp;
00244   }
00245 
00246 
00247   // Morpher creation.
00248 
00249   template <typename I, typename F>
00250   inline
00251   transformed_image<const I, F>
00252   transform_domain(const Image<I>& ima, const Function_v2v<F>& f)
00253   {
00254     transformed_image<const I, F> tmp(exact(ima), exact(f));
00255     return tmp;
00256   }
00257 
00258   template <typename I, typename F>
00259   inline
00260   transformed_image<I, F>
00261   transform_domain(Image<I>& ima, const Function_v2v<F>& f)
00262   {
00263     transformed_image<I, F> tmp(exact(ima), exact(f));
00264     return tmp;
00265   }
00266 
00267 # endif // ! MLN_INCLUDE_ONLY
00268 
00269 } // end of namespace mln
00270 
00271 
00272 #endif // ! MLN_CORE_IMAGE_DMORPH_TRANSFORMED_IMAGE_HH

Generated on Tue Oct 4 2011 15:24:45 for Milena (Olena) by  doxygen 1.7.1