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 #ifndef MLN_HISTO_POINT_FROM_VALUE_HH
00027 # define MLN_HISTO_POINT_FROM_VALUE_HH
00028
00032
00033 # include <mln/core/grids.hh>
00034 # include <mln/core/point.hh>
00035 # include <mln/fun/v2i/index_of_value.hh>
00036 # include <mln/fun/v2v/component.hh>
00037 # include <mln/trait/value/comp.hh>
00038
00039
00040 # define mln_histo_point_type_from(T) typename mln::histo::point_type_from<T>::ret
00041
00042
00043 namespace mln
00044 {
00045
00046 namespace histo
00047 {
00048
00049
00050 template <typename T>
00051 struct point_type_from
00052 {
00053 private:
00054 enum { d = mln_dim(T) };
00055 typedef mln_regular_grid_from_dim(d) G;
00056
00057 public:
00058 typedef mln::point<G, def::coord> ret;
00059 };
00060
00061
00062 template <typename T>
00063 struct point_from_value : Function_v2v< point_from_value<T> >
00064 {
00065 typedef mln_histo_point_type_from(T) result;
00066 result operator()(const T& v) const;
00067 };
00068
00069 template <typename T>
00070 mln_histo_point_type_from(T)
00071 meta_point_from_value(const T& v);
00072
00073
00074 # ifndef MLN_INCLUDE_ONLY
00075
00076 namespace internal
00077 {
00078
00079 template <unsigned d>
00080 struct point_from_value;
00081
00082 template <>
00083 struct point_from_value< 1 >
00084 {
00085 template <typename T, typename P>
00086 static void run(const T& v, P& p)
00087 {
00088 p[0] = fun::v2i::meta_index_of_value(v);
00089 }
00090 };
00091
00092 template <>
00093 struct point_from_value< 2 >
00094 {
00095 template <typename T, typename P>
00096 static void run(const T& v, P& p)
00097 {
00098 p[0] = fun::v2i::meta_index_of_value( fun::v2v::component<T,0>()(v) );
00099 p[1] = fun::v2i::meta_index_of_value( fun::v2v::component<T,1>()(v) );
00100 }
00101 };
00102
00103 template <>
00104 struct point_from_value< 3 >
00105 {
00106 template <typename T, typename P>
00107 static void run(const T& v, P& p)
00108 {
00109 p[0] = fun::v2i::meta_index_of_value( fun::v2v::component<T,0>()(v) );
00110 p[1] = fun::v2i::meta_index_of_value( fun::v2v::component<T,1>()(v) );
00111 p[2] = fun::v2i::meta_index_of_value( fun::v2v::component<T,2>()(v) );
00112 }
00113 };
00114
00115 }
00116
00117
00118 template <typename T>
00119 inline
00120 typename point_from_value<T>::result
00121 point_from_value<T>::operator()(const T& v) const
00122 {
00123 mln_histo_point_type_from(T) p;
00124 internal::point_from_value<mln_dim(T)>::run(v, p);
00125 return p;
00126 }
00127
00128 template <typename T>
00129 mln_histo_point_type_from(T)
00130 meta_point_from_value(const T& v)
00131 {
00132 point_from_value<T> f;
00133 return f(v);
00134 }
00135
00136 # endif // ! MLN_INCLUDE_ONLY
00137
00138 }
00139
00140 }
00141
00142
00143 #endif // ! MLN_HISTO_POINT_FROM_VALUE_HH