value_to_point.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 OLENA_VALUE_TO_POINT
00029 # define OLENA_VALUE_TO_POINT
00030 # include <oln/core/point1d.hh>
00031 # include <oln/core/point3d.hh>
00032 # include <ntg/int.hh>
00033 # include <ntg/color/color.hh>
00034 # include <oln/convert/conversion.hh>
00035 namespace oln {
00036 
00037   namespace convert {
00050     template <typename Argument_type,
00051               class Exact = mlc::final>
00052     struct value_to_point:
00053       public abstract::conversion_from_type_to_type
00054         <Argument_type,
00055          point1d,
00056          typename mlc::exact_vt<value_to_point<Argument_type,
00057                                                Exact>,
00058                                 Exact>::ret>
00059     {
00060     private:
00063       typedef typename ntg_is_a(Argument_type, ntg::non_vectorial)::ensure_type ensure_type;
00064     public:
00066       typedef point1d result_type;
00067       typedef Argument_type argument_type;
00068 
00070       template <typename O, typename I>
00071       struct doit_binary
00072       {
00073         static
00074         O
00075         doit(const I &input)
00076         {
00077           return input ? O(1) : O(0);
00078         }
00079       };
00081       template <typename O, typename I>
00082       struct doit_not_binary
00083       {
00084         static
00085         O
00086         doit(const I &input)
00087         {
00088           return O(input - ntg_min_val(I));
00089         }
00090       };
00091 
00092       result_type
00093       doit(const argument_type &input) const
00094       {
00095         typedef typename mlc::if_<ntg_is_a(argument_type, ntg::binary)::ret,
00096                                   doit_binary<result_type, argument_type>,
00097           doit_not_binary<result_type, argument_type> >::ret doit_type;
00098           return doit_type::doit(input);
00099       }
00100     };
00101 
00107     template <unsigned Qbits, template <unsigned> class S, class Exact>
00108     struct value_to_point<ntg::color<3, Qbits, S>, Exact>:
00109       public abstract::conversion_from_type_to_type
00110         <typename ntg::color<3, Qbits, S>,
00111          point3d,
00112          typename mlc::exact_vt<value_to_point<typename ntg::color<3, Qbits, S>,
00113                                                Exact>,
00114                                 Exact>::ret>
00115     {
00116     public:
00117       typedef point3d result_type;
00118       typedef typename ntg::color<3, Qbits, S> argument_type;
00119 
00120       result_type
00121       doit(const argument_type &input) const
00122       {
00123         result_type r;
00124         for (unsigned i = 0; i < 3; ++i)
00125           r.nth(i) = oln::coord(input[i]);
00126         return r;
00127       }
00128     };
00129   }
00130 }
00131 #endif

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