$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
gdpoint.hh
1 // Copyright (C) 2007, 2008, 2009, 2011, 2012, 2013 EPITA Research and
2 // Development Laboratory (LRDE)
3 //
4 // This file is part of Olena.
5 //
6 // Olena is free software: you can redistribute it and/or modify it under
7 // the terms of the GNU General Public License as published by the Free
8 // Software Foundation, version 2 of the License.
9 //
10 // Olena is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with Olena. If not, see <http://www.gnu.org/licenses/>.
17 //
18 // As a special exception, you may use this file as part of a free
19 // software project without restriction. Specifically, if other files
20 // instantiate templates or use macros or inline functions from this
21 // file, or you compile this file and link it with other files to produce
22 // an executable, this file does not by itself cause the resulting
23 // executable to be covered by the GNU General Public License. This
24 // exception does not however invalidate any other reasons why the
25 // executable file might be covered by the GNU General Public License.
26 
27 #ifndef MLN_CORE_CONCEPT_GDPOINT_HH
28 # define MLN_CORE_CONCEPT_GDPOINT_HH
29 
33 
34 # include <mln/core/concept/object.hh>
35 # include <mln/core/grids.hh>
36 # include <mln/trait/all.hh>
37 # include <mln/value/scalar.hh>
38 # include <mln/debug/format.hh>
39 
40 
41 namespace mln
42 {
43 
44  // Forward declaration.
45  template <typename E> struct Gdpoint;
46 
47 
49  namespace trait
50  {
51 
52  // FIXME: Add promotion.
53 
54  template < typename L, typename R >
55  struct set_binary_< op::plus,
56  mln::Gdpoint, L, mln::Gdpoint, R >
57  {
58  typedef L ret;
59  };
60 
61  template < typename L, typename R >
62  struct set_binary_< op::minus,
63  mln::Gdpoint, L, mln::Gdpoint, R >
64  {
65  typedef L ret;
66  };
67 
68  template < typename D, typename S >
69  struct set_binary_< op::times,
70  mln::Gdpoint, D,
72  {
73  typedef D ret;
74  };
75 
76  template <typename D>
77  struct set_unary_< op::ord, mln::Gdpoint, D >
78  {
80  };
81 
82  } // end of namespace mln::trait
84 
85 
88  template <>
89  struct Gdpoint<void>
90  {
92  };
94 
95 
100  template <typename E>
101  struct Gdpoint : public Object<E>
102  {
104 
105  /*
106  typedef grid;
107  typedef vec;
108  const vec& to_vec() const;
109  */
110 
111  protected:
112  Gdpoint();
113  };
114 
115 
116 
117  // Operators.
118 
119  template <typename D>
120  std::ostream&
121  operator<<(std::ostream& ostr, const Gdpoint<D>& dp);
122 
123 
124  template <typename L, typename R>
125  bool
126  operator==(const Gdpoint<L>& lhs, const Gdpoint<R>& rhs);
127 
128 
129  template <typename L, typename R>
130  L // FIXME: promote!
131  operator+(const Gdpoint<L>& lhs, const Gdpoint<R>& rhs);
132 
133  template <typename L, typename R>
134  L // FIXME: promote!
135  operator-(const Gdpoint<L>& lhs, const Gdpoint<R>& rhs);
136 
137  template <typename D, typename S>
138  D // FIXME: promote!
139  operator*(const Gdpoint<D>& lhs, const value::Scalar<S>& rhs);
140 
141 
146  template <typename D>
147  void
148  from_to_(const Gdpoint<D>& from, mln_site(D)& to);
149 
150 
151 # ifndef MLN_INCLUDE_ONLY
152 
153  template <typename E>
154  inline
156  {
157  typedef mln_grid(E) grid;
158  typedef mln_vec(E) vec;
159  vec (E::*m)() const = & E::to_vec;
160  (void) m;
161  }
162 
163 
164  template <typename D>
165  inline
166  std::ostream& operator<<(std::ostream& ostr, const Gdpoint<D>& dp)
167  {
168  enum { n = D::dim };
169  ostr << '(';
170  for (unsigned i = 0; i < n; ++i)
171  ostr << debug::format(exact(dp)[i]) << (i == n - 1 ? ')' : ',');
172  return ostr;
173  }
174 
175 
176  template <typename L, typename R>
177  inline
178  bool operator==(const Gdpoint<L>& lhs, const Gdpoint<R>& rhs)
179  {
180  mlc_equal(mln_grid(L), mln_grid(R))::check();
181  return exact(lhs).to_vec() == exact(rhs).to_vec();
182  }
183 
184  template <typename L, typename R>
185  inline
186  L // FIXME: promote!
187  operator+(const Gdpoint<L>& lhs, const Gdpoint<R>& rhs)
188  {
189  mlc_equal(mln_grid(L), mln_grid(R))::check();
190  L tmp = exact(lhs).to_vec() + exact(rhs).to_vec();
191  return tmp;
192  }
193 
194  template <typename L, typename R>
195  inline
196  L // FIXME: promote!
197  operator-(const Gdpoint<L>& lhs, const Gdpoint<R>& rhs)
198  {
199  mlc_equal(mln_grid(L), mln_grid(R))::check();
200  L tmp = exact(lhs).to_vec() - exact(rhs).to_vec();
201  return tmp;
202  }
203 
204  template <typename D, typename S>
205  D // FIXME: promote!
206  operator*(const Gdpoint<D>& lhs, const value::Scalar<S>& rhs)
207  {
208  D tmp = exact(lhs).to_vec() * exact(rhs);
209  return tmp;
210  }
211 
212 
213  // Conversions
214 
215  template <typename D>
216  inline
217  void
218  from_to_(const Gdpoint<D>& dp_, mln_site(D)& p)
219  {
220  enum { n = D::dim };
221  const D& dp = exact(dp_);
222  for (unsigned i = 0; i < n; ++i)
223  p[i] = dp[i];
224  }
225 
226 # endif // ! MLN_INCLUDE_ONLY
227 
228 } // end of namespace mln
229 
230 
231 #endif // ! MLN_CORE_CONCEPT_GDPOINT_HH