color_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 
00029 #ifndef OLENA_MORPHER_COLOR_MORPHER_HH
00030 # define OLENA_MORPHER_COLOR_MORPHER_HH
00031 
00032 # include <oln/morpher/generic_morpher.hh>
00033 
00034 namespace oln {
00035 
00036   namespace morpher {
00037 
00038     template <class I, class Exact = mlc::final>
00039     class color_morpher;
00040 
00041   } // end of namespace morpher
00042 
00043 
00050   template <class I, class Exact>
00051   struct image_id<morpher::color_morpher<I, Exact> >
00052   {
00053     enum {dim = I::dim};
00055     typedef oln_impl_type(I) impl_type;
00057     typedef ntg_comp_type(oln_value_type(I)) value_type;
00062     typedef typename mlc::exact_vt<morpher::color_morpher<I, Exact>,
00063                                    Exact>::ret exact_type;
00068     typedef oln_point_type(I) point_type;
00069     typedef oln_iter_type(I) iter_type;
00070   };
00071 
00072 
00079   template <class SrcType, class Exact>
00080   struct image_traits <morpher::color_morpher<SrcType, Exact> > :
00081     public image_traits<morpher::abstract::generic_morpher<SrcType,
00082                                                            typename image_id<morpher::color_morpher<SrcType, Exact> >::exact_type> >
00083   {
00084 
00085   };
00086 
00087   namespace morpher {
00088 
00096     template <class SrcType, class Exact>
00097     class super_color_morpher :
00098       public abstract::generic_morpher<SrcType, Exact>
00099     {
00100     protected:
00101 
00108       unsigned n_;
00109 
00116       super_color_morpher(const SrcType &ima, unsigned n) : super_type(ima)
00117       {
00118         assert(n == ntg::rgb_R || n == ntg::rgb_G || n == ntg::rgb_B);
00119         n_ = n;
00120       }
00121 
00126       super_color_morpher()
00127       {}
00128 
00129     public:
00130       typedef abstract::generic_morpher<SrcType, Exact> super_type;
00131       typedef typename image_id<Exact>::impl_type impl_type;
00132 
00134       unsigned
00135       get_comp() const
00136       {
00137         return n_;
00138       }
00139 
00141       impl_type*
00142       impl()
00143       {
00144         return ima_.impl();
00145       }
00146 
00148       const impl_type*
00149       impl() const
00150       {
00151         return ima_.impl();
00152       }
00153 
00154 
00155 
00156       static std::string
00157       name()
00158       {
00159         return "super_color_morpher<" + super_type::name() + ">";
00160       }
00161 
00162 
00163     };
00164 
00176     template <class SrcType, class Exact>
00177     struct color_morpher :
00178       public super_color_morpher<SrcType,
00179                                  typename image_id<color_morpher<SrcType, Exact> >::exact_type>
00180     {
00182       typedef typename image_id<color_morpher<SrcType, Exact> >::exact_type exact_type;
00183 
00184 
00185       typedef color_morpher<SrcType, Exact> self_type;
00186       typedef typename image_id<exact_type>::iter_type iter_type;
00188       typedef typename image_id<exact_type>::point_type point_type;
00190       typedef typename image_id<exact_type>::value_type value_type;
00192       typedef super_color_morpher<SrcType, exact_type> super_type;
00195 
00196       color_morpher(const SrcType &ima, unsigned n) : super_type(ima, n)
00197       {}
00198 
00200       color_morpher(const color_morpher<SrcType, Exact>& r) : super_type(r.get_ima(), r.get_comp())
00201       {}
00202 
00207       color_morpher()
00208       {}
00209 
00216       value_type&
00217       at(const point_type& p)
00218       {
00219         return const_cast<SrcType &>(this->ima_)[p][this->n_];
00220       }
00221 
00227       const value_type
00228       at(const point_type& p) const
00229       {
00230         return this->ima_[p][this->n_];
00231       }
00232 
00237       self_type&
00238       assign(self_type& rhs)
00239       {
00240         oln_iter_type(SrcType)  it(rhs);
00241 
00242         for_all(it)
00243           this->at(it) = rhs[it];
00244         return this->exact();
00245       }
00246 
00247       static std::string
00248       name()
00249       {
00250         return "color_morpher<" + SrcType::name() + "," + Exact::name() + ">";
00251       }
00252 
00253     };
00254 
00263     template <class SrcType, class Exact>
00264     struct color_morpher<const SrcType, Exact> :
00265       public super_color_morpher<const SrcType,
00266                                  typename image_id<color_morpher<const SrcType,
00267                                                                  Exact> >::exact_type>
00268     {
00270       typedef typename image_id<color_morpher<const SrcType, Exact> >::exact_type exact_type;
00271 
00272       typedef typename image_id<exact_type>::point_type point_type;
00274       typedef typename image_id<exact_type>::iter_type iter_type;
00276       typedef typename image_id<exact_type>::value_type value_type;
00279       typedef super_color_morpher<const SrcType, exact_type> super_type;
00282 
00283       color_morpher(const SrcType &ima, unsigned n) : super_type(ima, n)
00284       {}
00285 
00287       color_morpher(const color_morpher<const SrcType, Exact>& r) :
00288       super_type(r.get_ima(), r.get_comp())
00289       {}
00290 
00295       color_morpher()
00296       {}
00297 
00303       const value_type
00304       at(const point_type& p) const
00305       {
00306         return this->ima_[p][this->n_];
00307       }
00308 
00309       static std::string
00310       name()
00311       {
00312         return "color_morpher<" + SrcType::name() + ">";
00313       }
00314 
00315     };
00316 
00317 
00340     template <class I>
00341     const color_morpher<I> rmorph(I &ima)
00342     {
00343       return color_morpher<I>(ima, ntg::rgb_R);
00344     }
00345 
00368     template <class I>
00369     const color_morpher<I> gmorph(I &ima)
00370     {
00371       return color_morpher<I>(ima, ntg::rgb_G);
00372     }
00373 
00396     template <class I>
00397     const color_morpher<I> bmorph(I &ima)
00398     {
00399       return color_morpher<I>(ima, ntg::rgb_B);
00400     }
00401 
00402   } // end of namespace morpher
00403 
00404 } // end of namespace oln
00405 
00406 #endif // !OLENA_MORPHER_COLOR_MORPHER_HH

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