$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
delta_point_site.hh
1 // Copyright (C) 2007, 2009, 2012, 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_DELTA_POINT_SITE_HH
28 # define MLN_CORE_CONCEPT_DELTA_POINT_SITE_HH
29 
35 # include <mln/core/concept/object.hh>
36 # include <mln/core/grids.hh>
37 # include <mln/trait/all.hh>
38 
39 
40 namespace mln
41 {
42 
43  // Fwd decl.
44  template <typename E> struct Delta_Point_Site;
45 
46 
48  namespace trait
49  {
50 
51  template < typename L, typename R >
52  struct set_binary_< op::plus,
54  {
55  typedef mln_dpoint(L) ret;
56  };
57 
58  template < typename L, typename R >
59  struct set_binary_< op::minus,
60  mln::Delta_Point_Site, L, mln::Delta_Point_Site, R >
61  {
62  typedef mln_dpoint(L) ret;
63  };
64 
65  } // end of namespace mln::trait
67 
68 
71  template <>
72  struct Delta_Point_Site<void>
73  {
75  };
77 
78 
83  template <typename E>
84  struct Delta_Point_Site : public Object<E>
85  {
87 
88  /*
89  enum { dim };
90  typedef mesh;
91 
92  typedef point;
93  typedef dpoint;
94  typedef coord;
95 
96  const dpoint& to_dpoint() const;
97  coord operator[](unsigned i) const;
98  */
99 
100  protected:
101  Delta_Point_Site();
102  };
103 
104 
105 
106  // Operators.
107 
108  template <typename D>
109  std::ostream&
110  operator<<(std::ostream& ostr, const Delta_Point_Site<D>& dp);
111 
112 
113  template <typename L, typename R>
114  bool
116 
117  template <typename L, typename R>
118  bool
119  operator<(const Delta_Point_Site<L>& lhs, const Delta_Point_Site<R>& rhs);
120 
121 
122  template <typename L, typename R>
123  mln_dpoint(L) // FIXME: promote!
124  operator+(const Delta_Point_Site<L>& lhs, const Delta_Point_Site<R>& rhs);
125 
126  template <typename L, typename R>
127  mln_dpoint(L) // FIXME: promote!
128  operator-(const Delta_Point_Site<L>& lhs, const Delta_Point_Site<R>& rhs);
129 
130 
131 
132 
133 # ifndef MLN_INCLUDE_ONLY
134 
135  template <typename E>
136  inline
138  {
139  int dim = E::dim;
140  mln_invariant(dim > 0);
141  dim = 0;
142  typedef mln_mesh(E) mesh;
143  typedef mln_point(E) point;
144  typedef mln_dpoint(E) dpoint;
145  typedef mln_coord(E) coord;
146  const dpoint& (E::*m1)() const = & E::to_dpoint;
147  m1 = 0;
148  coord (E::*m2)(unsigned i) const = & E::operator[];
149  m2 = 0;
150  }
151 
152 
153  template <typename D>
154  inline
155  std::ostream& operator<<(std::ostream& ostr, const Delta_Point_Site<D>& dp_)
156  {
157  const D& dp = exact(dp_);
158  ostr << '(';
159  for (unsigned i = 0; i < D::dim; ++i)
160  ostr << dp[i] << (i == D::dim - 1 ? ')' : ',');
161  return ostr;
162  }
163 
164 
165  template <typename L, typename R>
166  inline
167  bool operator==(const Delta_Point_Site<L>& lhs_, const Delta_Point_Site<R>& rhs_)
168  {
169  mln::metal::bool_<(int(L::dim) == int(R::dim))>::check();
170  const L& lhs = exact(lhs_);
171  const R& rhs = exact(rhs_);
172  for (unsigned i = 0; i < L::dim; ++i)
173  if (lhs[i] != rhs[i])
174  return false;
175  return true;
176  }
177 
178  template <typename L, typename R>
179  inline
180  bool operator<(const Delta_Point_Site<L>& lhs_, const Delta_Point_Site<R>& rhs_)
181  {
182  mln::metal::bool_<(int(L::dim) == int(R::dim))>::check();
183  const L& lhs = exact(lhs_);
184  const R& rhs = exact(rhs_);
185  for (unsigned i = 0; i < L::dim; ++i)
186  {
187  if (lhs[i] == rhs[i])
188  continue;
189  return lhs[i] < rhs[i];
190  }
191  return false;
192  }
193 
194  template <typename L, typename R>
195  inline
196  mln_dpoint(L) // FIXME: promote!
197  operator+(const Delta_Point_Site<L>& lhs_, const Delta_Point_Site<R>& rhs_)
198  {
199  mln::metal::bool_<(int(L::dim) == int(R::dim))>::check();
200  const L& lhs = exact(lhs_);
201  const R& rhs = exact(rhs_);
202  mln_dpoint(L) tmp;
203  for (unsigned i = 0; i < L::dim; ++i)
204  tmp[i] = lhs[i] + rhs[i];
205  return tmp;
206  }
207 
208  template <typename L, typename R>
209  inline
210  mln_dpoint(L) // FIXME: promote!
211  operator-(const Delta_Point_Site<L>& lhs_, const Delta_Point_Site<R>& rhs_)
212  {
213  mln::metal::bool_<(int(L::dim) == int(R::dim))>::check();
214  const L& lhs = exact(lhs_);
215  const R& rhs = exact(rhs_);
216  mln_dpoint(L) tmp;
217  for (unsigned i = 0; i < L::dim; ++i)
218  tmp[i] = lhs[i] - rhs[i];
219  return tmp;
220  }
221 
222 # endif // ! MLN_INCLUDE_ONLY
223 
224 } // end of namespace mln
225 
226 
227 #endif // ! MLN_CORE_CONCEPT_DELTA_POINT_SITE_HH