00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
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