slicing_morpher.hh

00001 // Copyright (C) 2004  EPITA Research and Development Laboratory
00002 //
00003 // This file is part of the Olena Library.  This library is free
00004 // software; you can redistribute it and/or modify it under the terms
00005 // of the GNU General Public License version 2 as published by the
00006 // Free Software Foundation.
00007 //
00008 // This library is distributed in the hope that it will be useful,
00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011 // General Public License for more details.
00012 //
00013 // You should have received a copy of the GNU General Public License
00014 // along with this library; see the file COPYING.  If not, write to
00015 // the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
00016 // MA 02111-1307, USA.
00017 //
00018 // As a special exception, you may use this file as part of a free
00019 // software library 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
00022 // produce an executable, this file does not by itself cause the
00023 // resulting executable to be covered by the GNU General Public
00024 // License.  This exception does not however invalidate any other
00025 // reasons why the executable file might be covered by the GNU General
00026 // Public License.
00027 
00028 #ifndef SLICING_MORPHER_HH
00029 # define SLICING_MORPHER_HH
00030 
00031 # include <oln/morpher/generic_morpher.hh>
00032 
00033 namespace oln {
00034 
00035   namespace morpher {
00036 
00037     template <class I, class Exact = mlc::final>
00038     struct slicing_morpher;
00039     template <class I, class Exact = mlc::final>
00040     struct super_slicing_morpher;
00041 
00042   } // end of namespace morpher
00043 
00045   template <class SrcType, class Exact>
00046   struct image_id< morpher::super_slicing_morpher<SrcType, Exact> >
00047   {
00048     typedef typename mlc::exact_vt<
00049       morpher::super_slicing_morpher<SrcType, Exact>,
00050       Exact>::ret
00051     exact_type;
00053     enum {dim = SrcType::dim - 1};
00054     typedef typename dim_traits<dim,
00055                                 typename image_id<SrcType>::value_type,
00056                                 exact_type
00057                                 >::img_type img_type;
00058     typedef typename image_traits<img_type>::size_type size_type;
00059     typedef typename image_traits<img_type>::impl_type impl_type;
00060   };
00061 
00063   template <class SrcType, class Exact>
00064   struct image_id< morpher::super_slicing_morpher<const SrcType, Exact> >
00065   {
00066     typedef typename mlc::exact_vt<
00067       morpher::super_slicing_morpher<SrcType, Exact>,
00068       Exact>::ret
00069     exact_type;
00071     enum {dim = SrcType::dim - 1};
00072     typedef typename dim_traits<dim,
00073                                 typename image_id<SrcType>::value_type,
00074                                 exact_type
00075                                 >::img_type img_type;
00076     typedef typename image_traits<img_type>::size_type size_type;
00077     typedef typename image_traits<img_type>::impl_type impl_type;
00078   };
00079 
00081   template <class SrcType, class Exact>
00082   struct image_id< morpher::slicing_morpher<SrcType, Exact> >
00083   {
00084     typedef typename mlc::exact_vt<morpher::slicing_morpher<SrcType, Exact>,
00085                                    Exact>::ret exact_type;
00087     enum {dim = SrcType::dim - 1};
00088     typedef typename dim_traits<dim,
00089                                 typename image_id<SrcType>::value_type,
00090                                 exact_type
00091                                 >::img_type img_type;
00092     typedef typename image_id<img_type>::value_type value_type;
00093     typedef typename image_id<img_type>::point_type point_type;
00094     typedef typename image_id<img_type>::size_type size_type;
00095     typedef typename image_id<img_type>::impl_type impl_type;
00096   };
00097 
00099   template <class SrcType, class Exact>
00100   struct image_id< morpher::slicing_morpher<const SrcType, Exact> >
00101   {
00102     typedef typename mlc::exact_vt<morpher::slicing_morpher<SrcType, Exact>,
00103                                    Exact>::ret exact_type;
00105     enum {dim = SrcType::dim - 1};
00106     typedef typename dim_traits<dim,
00107                                 typename image_id<SrcType>::value_type,
00108                                 exact_type
00109                                 >::img_type img_type;
00110     typedef typename image_id<img_type>::value_type value_type;
00111     typedef typename image_traits<img_type>::point_type point_type;
00112     typedef typename image_traits<img_type>::size_type size_type;
00113     typedef typename image_traits<img_type>::impl_type impl_type;
00114   };
00115 
00117   template <class SrcType, class Exact>
00118   struct image_traits< morpher::slicing_morpher<SrcType, Exact> >
00119     : public
00120   image_traits<
00121     morpher::abstract::generic_morpher<
00122       SrcType,
00123       typename image_id<morpher::slicing_morpher<SrcType,
00124                                                  Exact> >::exact_type
00125     >
00126   >
00127   {};
00128 
00129   namespace morpher {
00130 
00132     oln::image1d_size
00133     image_size_dec(const oln::image2d_size& image_size)
00134     {
00135       return oln::image1d_size(image_size.ncols(), image_size.border());
00136     }
00137 
00139     oln::image2d_size
00140     image_size_dec(const oln::image3d_size& image_size)
00141     {
00142       return oln::image2d_size(image_size.nrows(),
00143                                image_size.ncols(),
00144                                image_size.border());
00145     }
00146 
00148     template <class SrcType, class Exact>
00149     class super_slicing_morpher
00150       : public abstract::generic_morpher<SrcType, Exact>
00151     {
00152 
00153     public:
00154 
00155       typedef super_slicing_morpher<SrcType, Exact> self_type;
00156       typedef typename image_id<self_type>::exact_type exact_type;
00157       typedef abstract::generic_morpher<SrcType, Exact> super_type;
00158 
00159       typedef typename image_id<exact_type>::size_type size_type;
00160       typedef typename image_id<exact_type>::impl_type impl_type;
00161 
00163       const size_type&
00164       size() const
00165       {
00166         return size_;
00167       }
00168 
00170       const impl_type*
00171       impl() const
00172       {
00173         return &impl_;
00174       }
00175 
00177       impl_type*
00178       impl()
00179       {
00180         return &impl_;
00181       }
00182 
00184       coord
00185       get_slice() const
00186       {
00187         return slice_;
00188       }
00189 
00191       static std::string
00192       name()
00193       {
00194         return "super_slicing_morpher<" + super_type::name() + ">";
00195       }
00196 
00197     protected:
00198 
00207       super_slicing_morpher(const SrcType &ima, const coord slice)
00208         : super_type(ima), slice_(slice), size_(image_size_dec(ima_.size())), impl_(size_)
00209       {}
00210 
00217       super_slicing_morpher()
00218       {}
00219 
00220       coord slice_; 
00221       const size_type size_; 
00222       impl_type impl_;
00223 
00224     };
00225 
00234     template <class SrcType, class Exact>
00235     struct slicing_morpher
00236       : public super_slicing_morpher<
00237           SrcType,
00238           typename image_id<slicing_morpher<SrcType, Exact> >::exact_type
00239         >
00240     {
00241       typedef slicing_morpher<SrcType, Exact> self_type;
00242       typedef typename image_id<self_type>::exact_type exact_type;
00243       typedef super_slicing_morpher<SrcType, exact_type> super_type;
00244 
00245       typedef typename image_id<exact_type>::point_type point_type;
00246       typedef typename image_id<exact_type>::img_type img_type;
00247       typedef typename image_id<exact_type>::value_type value_type;
00248 
00254       slicing_morpher(const SrcType &ima, coord slice)
00255         : super_type(ima, slice) {}
00256 
00258       slicing_morpher(const self_type& r)
00259         : super_type(r.get_ima(), r.get_slice()) {}
00260 
00266       slicing_morpher() {}
00267 
00273       value_type&
00274       at(const point_type &p)
00275       {
00276         typename SrcType::point_type tmp_p(p, slice_);
00277         return const_cast<value_type &>(this->ima_)[tmp_p];
00278       }
00279 
00280       const value_type at(const point_type& p) const
00281       {
00282         typename SrcType::point_type tmp_p(p, slice_);
00283         return this->ima_[tmp_p];
00284       }
00285 
00291       self_type&
00292       assign(self_type& rhs)
00293       {
00294         oln_iter_type(SrcType)  it(rhs);
00295 
00296         for_all(it)
00297           this->at(it) = rhs[it];
00298         return this->exact();
00299       }
00300 
00304       self_type&
00305       operator=(self_type& rhs)
00306       {
00307         return this->exact().assign(rhs);
00308       }
00309 
00311       static std::string
00312       name()
00313       {
00314         return "slicing_morpher<" + super_type::name() + ">";
00315       }
00316 
00317     };
00318 
00320     template <class SrcType, class Exact>
00321     struct slicing_morpher<const SrcType, Exact>
00322       : public super_slicing_morpher<
00323           const SrcType,
00324           typename image_id<slicing_morpher<const SrcType, Exact> >::exact_type
00325         >
00326     {
00327 
00328       typedef slicing_morpher<const SrcType, Exact> self_type;
00329       typedef typename image_id<self_type>::exact_type exact_type;
00330       typedef super_slicing_morpher<const SrcType, exact_type> super_type;
00331 
00332       typedef typename image_id<exact_type>::point_type point_type;
00333       typedef typename image_id<exact_type>::value_type value_type;
00334 
00335 
00341       slicing_morpher(const SrcType &ima, coord slice)
00342         : super_type(ima, slice)
00343       {}
00344 
00346       slicing_morpher(const self_type& r)
00347         : super_type(r.get_ima(), r.get_slice())
00348       {}
00349 
00355       slicing_morpher()
00356       {}
00357 
00363       const value_type
00364       at(const point_type &p) const
00365       {
00366         typename SrcType::point_type tmp_p(p, slice_);
00367         return this->ima_[tmp_p];
00368       }
00369 
00371       static std::string
00372       name()
00373       {
00374         return "slicing_morpher<" + super_type::name() + ">";
00375       }
00376 
00377     };
00378 
00403     template <class I>
00404     const slicing_morpher<I>
00405     slicing_morph(I &ima, coord slice)
00406     {
00407       return slicing_morpher<I>(ima, slice);
00408     }
00409 
00410   } // end of morpher namespace
00411 
00412 } // end of oln namespace
00413 
00414 #endif // !SLICING_MORPHER

Generated on Thu Apr 15 20:13:14 2004 for Olena by doxygen 1.3.6-20040222