$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
point_from_value.hh
1 // Copyright (C) 2009 EPITA Research and Development Laboratory (LRDE)
2 //
3 // This file is part of Olena.
4 //
5 // Olena is free software: you can redistribute it and/or modify it under
6 // the terms of the GNU General Public License as published by the Free
7 // Software Foundation, version 2 of the License.
8 //
9 // Olena is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with Olena. If not, see <http://www.gnu.org/licenses/>.
16 //
17 // As a special exception, you may use this file as part of a free
18 // software project without restriction. Specifically, if other files
19 // instantiate templates or use macros or inline functions from this
20 // file, or you compile this file and link it with other files to produce
21 // an executable, this file does not by itself cause the resulting
22 // executable to be covered by the GNU General Public License. This
23 // exception does not however invalidate any other reasons why the
24 // executable file might be covered by the GNU General Public License.
25 
26 #ifndef MLN_HISTO_POINT_FROM_VALUE_HH
27 # define MLN_HISTO_POINT_FROM_VALUE_HH
28 
32 
33 # include <mln/core/grids.hh>
34 # include <mln/core/point.hh>
35 # include <mln/fun/v2i/index_of_value.hh>
36 # include <mln/fun/v2v/component.hh>
37 # include <mln/trait/value/comp.hh>
38 
39 
40 # define mln_histo_point_type_from(T) typename mln::histo::point_type_from<T>::ret
41 
42 
43 namespace mln
44 {
45 
46  namespace histo
47  {
48 
49 
50  template <typename T>
52  {
53  private:
54  enum { d = mln_dim(T) };
55  typedef mln_regular_grid_from_dim(d) G;
56 
57  public:
59  };
60 
61 
62  template <typename T>
63  struct point_from_value : Function_v2v< point_from_value<T> >
64  {
65  typedef mln_histo_point_type_from(T) result;
66  result operator()(const T& v) const;
67  };
68 
69  template <typename T>
70  mln_histo_point_type_from(T)
71  meta_point_from_value(const T& v);
72 
73 
74 # ifndef MLN_INCLUDE_ONLY
75 
76  namespace internal
77  {
78 
79  template <unsigned d>
80  struct point_from_value;
81 
82  template <>
83  struct point_from_value< 1 >
84  {
85  template <typename T, typename P>
86  static void run(const T& v, P& p)
87  {
89  }
90  };
91 
92  template <>
93  struct point_from_value< 2 >
94  {
95  template <typename T, typename P>
96  static void run(const T& v, P& p)
97  {
100  }
101  };
102 
103  template <>
104  struct point_from_value< 3 >
105  {
106  template <typename T, typename P>
107  static void run(const T& v, P& p)
108  {
112  }
113  };
114 
115  } // end of namespace mln::histo::internal
116 
117 
118  template <typename T>
119  inline
121  point_from_value<T>::operator()(const T& v) const
122  {
123  mln_histo_point_type_from(T) p;
124  internal::point_from_value<mln_dim(T)>::run(v, p);
125  return p;
126  }
127 
128  template <typename T>
129  mln_histo_point_type_from(T)
130  meta_point_from_value(const T& v)
131  {
133  return f(v);
134  }
135 
136 # endif // ! MLN_INCLUDE_ONLY
137 
138  } // end of namespace mln::histo
139 
140 } // end of namespace mln
141 
142 
143 #endif // ! MLN_HISTO_POINT_FROM_VALUE_HH