$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
concept/point.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_HH
28 # define MLN_CORE_CONCEPT_POINT_HH
29 
35 # include <mln/core/concept/point_site.hh>
36 # include <mln/core/concept/dpoint.hh>
37 # include <mln/value/concept/scalar.hh>
38 
39 
40 namespace mln
41 {
42 
43  // Fwd decl.
44  template <typename E> struct Point;
45 
46 
49  template <>
50  struct Point<void>
51  {
53  };
55 
56 
67  template <typename P>
68  struct Point : public Point_Site<P>
69  {
72  typedef P point;
73 
76  const P& to_point() const;
77 
78  protected:
79  Point();
80  };
81 
82 
94  template <typename P, typename D>
95  P& operator+=(Point<P>& p, const Dpoint<D>& dp);
96 
97 
109  template <typename P, typename D>
110  P& operator-=(Point<P>& p, const Dpoint<D>& dp);
111 
120  template <typename P, typename D>
121  P& operator/(Point<P>& p, const value::Scalar<D>& dp);
122 
123  // FIXME : add operators and traits?
124 
125 # ifndef MLN_INCLUDE_ONLY
126 
127  template <typename P>
128  inline
130  {
131  }
132 
133  template <typename P>
134  inline
135  const P&
136  Point<P>::to_point() const
137  {
138  return exact(*this);
139  }
140 
141  template <typename P, typename D>
142  inline
143  P& operator+=(Point<P>& p_, const Dpoint<D>& dp_)
144  {
145  P& p = exact(p_);
146  const D& dp = exact(dp_);
147  // FIXME: Use to_vec()!
148  for (unsigned i = 0; i < P::dim; ++i)
149  p[i] += dp[i];
150  return p;
151  }
152 
153  template <typename P, typename D>
154  inline
155  P& operator-=(Point<P>& p_, const Dpoint<D>& dp_)
156  {
157  P& p = exact(p_);
158  const D& dp = exact(dp_);
159  // FIXME: Use to_vec()!
160  for (unsigned i = 0; i < P::dim; ++i)
161  p[i] -= dp[i];
162  return p;
163  }
164 
165 
166  template <typename P, typename D>
167  inline
168  P&
169  operator/(Point<P>& p_, const value::Scalar<D>& s_)
170  {
171  P& p = exact(p_);
172  const D& s = exact(s_);
173  for (unsigned i = 0; i < P::dim; ++i)
174  p[i] /= s;
175  return p;
176  }
177 
178 # endif // ! MLN_INCLUDE_ONLY
179 
180 } // end of namespace mln
181 
182 
183 
184 #endif // ! MLN_CORE_CONCEPT_POINT_HH