subq_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 
00030 #ifndef OLENA_MORPHER_SUBQ_MORPHER_HH
00031 # define OLENA_MORPHER_SUBQ_MORPHER_HH
00032 
00033 # include "generic_morpher.hh"
00034 
00035 namespace oln {
00036 
00037   namespace morpher {
00038 
00039     template <class SrcType, unsigned N, class Exact = mlc::final>
00040     struct subq_morpher;
00041 
00042 
00055     template <class T, unsigned N>
00056     struct color_mute
00057     {
00058     };
00059 
00061     template <unsigned nbcomps_,
00062               unsigned nbits_,
00063               template <unsigned> class color_system,
00064               unsigned N>
00065     struct color_mute<ntg::color<nbcomps_, nbits_, color_system>, N>
00066     {
00067       typedef ntg::color<nbcomps_, N, color_system> ret;
00069       enum { nbcomps = nbcomps_ };
00071     };
00072 
00073 
00074 
00075   } // end of namespace morpher
00076 
00085   template <class SrcType, unsigned N, class Exact>
00086   struct image_id<oln::morpher::subq_morpher<SrcType, N, Exact> >
00087   {
00088     enum {dim = SrcType::dim};
00090     typedef oln_impl_type(SrcType) impl_type;
00092     typedef typename oln::morpher::color_mute<oln_value_type(SrcType), N>::ret value_type;
00094     typedef typename mlc::exact_vt<oln::morpher::subq_morpher<SrcType, N, Exact>,
00095                                     Exact>::ret exact_type;
00096 
00097     typedef oln_point_type(SrcType) point_type;
00098   };
00099 
00108   template <class SrcType, unsigned N, class Exact>
00109   struct image_traits <oln::morpher::subq_morpher<SrcType, N, Exact> > :
00110     public image_traits<oln::morpher::abstract::generic_morpher<SrcType,
00111                                                                 typename image_id<oln::morpher::subq_morpher<SrcType, N, Exact> >::exact_type> >
00112   {
00113   };
00114 
00115   namespace morpher {
00116 
00117 
00118 
00132     template <class SrcType, unsigned N, class Exact>
00133     struct subq_morpher:
00134       public abstract::generic_morpher<SrcType,
00135                                        typename oln::image_id<subq_morpher<SrcType, N, Exact> >::exact_type>
00136     {
00137 
00139       typedef typename oln::image_id<subq_morpher<SrcType, N, Exact> >::exact_type exact_type;
00140 
00141 
00143       typedef abstract::generic_morpher<SrcType,
00144                                         exact_type> super_type;
00145 
00147       typedef typename image_id<exact_type>::value_type value_type;
00148       typedef typename image_id<exact_type>::point_type point_type;
00149       typedef typename image_id<exact_type>::impl_type impl_type;
00150       enum { nbcomps = color_mute<oln_value_type(SrcType), N>::nbcomps };
00151 
00153       subq_morpher(const SrcType &ima)
00154         : super_type(ima)
00155       {}
00156 
00158       subq_morpher(const subq_morpher<SrcType, N>& r)
00159         : super_type(r.get_ima())
00160       {}
00161 
00166       subq_morpher() {}
00167 
00169       const value_type
00170       at(const point_type& p) const
00171       {
00172         value_type      tmp;
00173         unsigned int    i;
00174 
00175         for (i = 0; i < nbcomps; i++)
00176           {
00177             tmp[i] = this->ima_[p][i] / ((ntg_max_val(ntg_comp_type(oln_value_type(SrcType))) + 1)
00178                                          / (ntg_max_val(ntg_comp_type(value_type)) + 1));
00179           }
00180         return tmp;
00181       }
00182 
00184       const impl_type*
00185       impl() const
00186       {
00187         return ima_.impl();
00188       }
00189 
00190       static std::string
00191       name()
00192       {
00193         return "subq_morpher<" + SrcType::name() + ">";
00194       }
00195 
00196     };
00197 
00221     template <unsigned S, class I>
00222     const subq_morpher<I, S> sqmorph(I &ima)
00223     {
00224       return subq_morpher<I, S>(ima);
00225     }
00226 
00227   } // end of namespace morpher
00228 
00229 } // end of namespace morpher
00230 
00231 
00232 
00233 
00234 #endif // !OLENA_MORPHER_SUBQ_MORPHER_HH
00235 

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