$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
point_site.hh
1 // Copyright (C) 2007, 2008, 2009, 2013 EPITA Research and Development
2 // 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_POINT_SITE_HH
28 # define MLN_CORE_CONCEPT_POINT_SITE_HH
29 
35 # include <mln/core/concept/object.hh>
36 # include <mln/core/concept/delta_point_site.hh>
37 # include <mln/core/grids.hh>
38 # include <mln/trait/all.hh>
39 
40 
41 
42 namespace mln
43 {
44 
45  // Fwd decls.
46  template <typename E> struct Point_Site;
47 
48 
50  namespace trait
51  {
52 
53  template < typename P, typename D >
54  struct set_binary_< op::plus,
56  {
57  typedef mln_point(P) ret;
58  };
59 
60  template < typename P, typename D >
61  struct set_binary_< op::minus,
62  mln::Point_Site, P, mln::Delta_Point_Site, D >
63  {
64  typedef mln_point(P) ret;
65  };
66 
67  template < typename L, typename R >
68  struct set_binary_< op::minus,
69  mln::Point_Site, L, mln::Point_Site, R >
70  {
71  typedef mln_dpoint(L) ret;
72  };
73 
74  } // end of namespace mln::trait
76 
77 
80  template <>
81  struct Point_Site<void>
82  {
84  };
86 
87 
110  template <typename E>
111  struct Point_Site : public Object<E>
112  {
114 
115  /*
116  enum { dim };
117  typedef mesh;
118 
119  typedef point;
120  typedef dpoint;
121  typedef coord;
122 
123  const point& to_point() const;
124 
125  coord operator[](unsigned i) const;
126  */
127 
128  protected:
129  Point_Site();
130  };
131 
132 
147  template <typename L, typename R>
148  bool operator==(const Point_Site<L>& lhs, const Point_Site<R>& rhs);
149 
150 
172  template <typename L, typename R>
173  mln_dpoint(L)
174  operator-(const Point_Site<L>& lhs, const Point_Site<R>& rhs);
175 
176 
190  template <typename P, typename D>
191  mln_point(P)
192  operator+(const Point_Site<P>& p, const Delta_Point_Site<D>& dp);
194 
195 
209  template <typename P, typename D>
210  mln_point(P)
211  operator-(const Point_Site<P>& p, const Delta_Point_Site<D>& dp);
213 
214 
224  template <typename P>
225  std::ostream& operator<<(std::ostream& ostr, const Point_Site<P>& p);
226 
227 
228 
229 
230 # ifndef MLN_INCLUDE_ONLY
231 
232  template <typename E>
233  inline
235  {
236  int dim = E::dim;
237  mln_invariant(dim > 0);
238  dim = 0;
239  typedef mln_mesh(E) mesh;
240  typedef mln_point(E) point;
241  typedef mln_dpoint(E) dpoint;
242  typedef mln_coord(E) coord;
243  const point& (E::*m1)() const = & E::to_point;
244  m1 = 0;
245  coord (E::*m2)(unsigned i) const = & E::operator[];
246  m2 = 0;
247  }
248 
249 
250  // Operators.
251 
252  // FIXME: Remove, or factor in a lower class (Théo removed it from
253  // the cleanup-2008 branch).
254  template <typename L, typename R>
255  inline
256  bool operator==(const Point_Site<L>& lhs_, const Point_Site<R>& rhs_)
257  {
258  mln::metal::bool_<(int(L::dim) == int(R::dim))>::check();
259  const L& lhs = exact(lhs_);
260  const R& rhs = exact(rhs_);
261  for (unsigned i = 0; i < L::dim; ++i)
262  if (lhs[i] != rhs[i])
263  return false;
264  return true;
265  }
266 
267  // FIXME: Remove, or factor in a lower class (Théo removed it from
268  // the cleanup-2008 branch).
269  template <typename L, typename R>
270  inline
271  mln_dpoint(L) // FIXME: promote!
272  operator-(const Point_Site<L>& lhs_, const Point_Site<R>& rhs_)
273  {
274  mln::metal::bool_<(int(L::dim) == int(R::dim))>::check();
275  const L& lhs = exact(lhs_);
276  const R& rhs = exact(rhs_);
277  mln_dpoint(L) tmp;
278  for (unsigned i = 0; i < L::dim; ++i)
279  tmp[i] = lhs[i] - rhs[i];
280  mln_postcondition(rhs_ + tmp == lhs_);
281  return tmp;
282  }
283 
284  template <typename P, typename D>
285  inline
286  mln_point(P) // FIXME: promote!
287  operator+(const Point_Site<P>& p_, const Delta_Point_Site<D>& dp_)
288  {
289  mln::metal::bool_<(int(P::dim) == int(D::dim))>::check();
290  const P& p = exact(p_);
291  const D& dp = exact(dp_);
292  mln_point(P) tmp;
293  for (unsigned i = 0; i < P::dim; ++i)
294  tmp[i] = p[i] + dp[i];
295  return tmp;
296  }
297 
298  template <typename P, typename D>
299  inline
300  mln_point(P) // FIXME: promote!
301  operator-(const Point_Site<P>& p_, const Delta_Point_Site<D>& dp_)
302  {
303  mln::metal::bool_<(int(P::dim) == int(D::dim))>::check();
304  const P& p = exact(p_);
305  const D& dp = exact(dp_);
306  mln_point(P) tmp;
307  for (unsigned i = 0; i < P::dim; ++i)
308  tmp[i] = p[i] - dp[i];
309  return tmp;
310  }
311 
312  // FIXME: We shall not rely on a point object associted to the point
313  // site! (Such an object does not always exist.)
314  template <typename P>
315  inline
316  std::ostream& operator<<(std::ostream& ostr, const Point_Site<P>& p_)
317  {
318  const P& p = exact(p_);
319  ostr << '(';
320  for (unsigned i = 0; i < P::dim; ++i)
321  ostr << p[i] << (i == P::dim - 1 ? ')' : ',');
322  return ostr;
323  }
324 
325 # endif // ! MLN_INCLUDE_ONLY
326 
327 } // end of namespace mln
328 
329 
330 #endif // ! MLN_CORE_CONCEPT_POINT_SITE_HH