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, Inc., 51 Franklin Street, Fifth Floor,
00016 // Boston, MA 02110-1301, 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(this->ima_.size())), impl_(size_)
00209       {}
00210 
00217       super_slicing_morpher()
00218         : super_type(), slice_(), size_(), impl_()
00219       {}
00220 
00221       coord slice_; 
00222       const size_type size_; 
00223       impl_type impl_;
00224 
00225     };
00226 
00235     template <class SrcType, class Exact>
00236     struct slicing_morpher
00237       : public super_slicing_morpher<
00238           SrcType,
00239           typename image_id<slicing_morpher<SrcType, Exact> >::exact_type
00240         >
00241     {
00242       typedef slicing_morpher<SrcType, Exact> self_type;
00243       typedef typename image_id<self_type>::exact_type exact_type;
00244       typedef super_slicing_morpher<SrcType, exact_type> super_type;
00245 
00246       typedef typename image_id<exact_type>::point_type point_type;
00247       typedef typename image_id<exact_type>::img_type img_type;
00248       typedef typename image_id<exact_type>::value_type value_type;
00249 
00255       slicing_morpher(const SrcType &ima, coord slice)
00256         : super_type(ima, slice) {}
00257 
00259       slicing_morpher(const self_type& r)
00260         : super_type(r.get_ima(), r.get_slice()) {}
00261 
00267       slicing_morpher() {}
00268 
00274       value_type&
00275       at(const point_type &p)
00276       {
00277         typename SrcType::point_type tmp_p(p, this->slice_);
00278         return const_cast<value_type &>(this->ima_)[tmp_p];
00279       }
00280 
00281       const value_type at(const point_type& p) const
00282       {
00283         typename SrcType::point_type tmp_p(p, this->slice_);
00284         return this->ima_[tmp_p];
00285       }
00286 
00292       self_type&
00293       assign(self_type& rhs)
00294       {
00295         oln_iter_type(SrcType)  it(rhs);
00296 
00297         for_all(it)
00298           this->at(it) = rhs[it];
00299         return this->exact();
00300       }
00301 
00305       self_type&
00306       operator=(self_type& rhs)
00307       {
00308         return this->exact().assign(rhs);
00309       }
00310 
00312       static std::string
00313       name()
00314       {
00315         return "slicing_morpher<" + super_type::name() + ">";
00316       }
00317 
00318     };
00319 
00321     template <class SrcType, class Exact>
00322     struct slicing_morpher<const SrcType, Exact>
00323       : public super_slicing_morpher<
00324           const SrcType,
00325           typename image_id<slicing_morpher<const SrcType, Exact> >::exact_type
00326         >
00327     {
00328 
00329       typedef slicing_morpher<const SrcType, Exact> self_type;
00330       typedef typename image_id<self_type>::exact_type exact_type;
00331       typedef super_slicing_morpher<const SrcType, exact_type> super_type;
00332 
00333       typedef typename image_id<exact_type>::point_type point_type;
00334       typedef typename image_id<exact_type>::value_type value_type;
00335 
00336 
00342       slicing_morpher(const SrcType &ima, coord slice)
00343         : super_type(ima, slice)
00344       {}
00345 
00347       slicing_morpher(const self_type& r)
00348         : super_type(r.get_ima(), r.get_slice())
00349       {}
00350 
00356       slicing_morpher()
00357       {}
00358 
00364       const value_type
00365       at(const point_type &p) const
00366       {
00367         typename SrcType::point_type tmp_p(p, this->slice_);
00368         return this->ima_[tmp_p];
00369       }
00370 
00372       static std::string
00373       name()
00374       {
00375         return "slicing_morpher<" + super_type::name() + ">";
00376       }
00377 
00378     };
00379 
00404     template <class I>
00405     const slicing_morpher<I>
00406     slicing_morph(I &ima, coord slice)
00407     {
00408       return slicing_morpher<I>(ima, slice);
00409     }
00410 
00411   } // end of morpher namespace
00412 
00413 } // end of oln namespace
00414 
00415 #endif // !SLICING_MORPHER

Generated on Tue Feb 20 20:20:32 2007 for Olena by  doxygen 1.5.1