$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
pmin_pmax.hh
1 // Copyright (C) 2007, 2008, 2009, 2012 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_GEOM_PMIN_PMAX_HH
28 # define MLN_GEOM_PMIN_PMAX_HH
29 
34 
35 # include <utility>
36 
37 # include <mln/core/concept/site_set.hh>
38 # include <mln/core/concept/box.hh>
39 
40 
41 
42 namespace mln
43 {
44 
45  namespace geom
46  {
47 
48 
54  template <typename S>
55  std::pair<mln_site(S), mln_site(S)>
56  pmin_pmax(const Site_Set<S>& s);
57 
58 
64  template <typename S>
65  void
66  pmin_pmax(const Site_Set<S>& s, mln_site(S)& pmin, mln_site(S)& pmax);
67 
68 
74  template <typename I>
75  std::pair<mln_site(I), mln_site(I)>
76  pmin_pmax(const Site_Iterator<I>& p);
77 
78 
84  template <typename I>
85  void
86  pmin_pmax(const Site_Iterator<I>& p, mln_site(I)& pmin, mln_site(I)& pmax);
87 
88 
89 
90 # ifndef MLN_INCLUDE_ONLY
91 
92 
93  // Versions with point iterator.
94 
95  template <typename I>
96  inline
97  void
98  pmin_pmax(const Site_Iterator<I>& p_, mln_site(I)& pmin, mln_site(I)& pmax)
99  {
100  I p = exact(p_); // a copy of p_
101 
102  // init with first point
103  p.start();
104  mln_precondition(p.is_valid());
105  pmin = pmax = p;
106 
107  // update with remaining points
108  typedef mln_site(I) P;
109  for_all_remaining(p)
110  for (unsigned i = 0; i < P::dim; ++i)
111  if (p[i] < pmin[i])
112  pmin[i] = p[i];
113  else if (p[i] > pmax[i])
114  pmax[i] = p[i];
115  }
116 
117  template <typename I>
118  inline
119  std::pair<mln_site(I), mln_site(I)>
120  pmin_pmax(const Site_Iterator<I>& p)
121  {
122  typedef mln_site(I) P;
123  std::pair<P, P> tmp;
124  pmin_pmax(p, tmp.first, tmp.second); // Calls the previous version.
125  return tmp;
126  }
127 
128 
129  // Versions with point set.
130 
131  namespace impl
132  {
133 
134  // General case.
135 
136  template <typename S>
137  inline
138  void
139  pmin_pmax_(const Site_Set<S>& s, mln_site(S)& pmin, mln_site(S)& pmax)
140  {
141  mln_piter(S) it(exact(s));
142  pmin_pmax(it, pmin, pmax);
143  }
144 
145  // Box.
146 
147  template <typename B>
148  inline
149  void
150  pmin_pmax_(const Box<B>& b, mln_site(B)& pmin, mln_site(B)& pmax)
151  {
152  pmin = exact(b).pmin();
153  pmax = exact(b).pmax();
154  }
155 
156  } // end of namespace mln::geom::impl
157 
158 
159  template <typename S>
160  inline
161  void
162  pmin_pmax(const Site_Set<S>& s, mln_site(S)& pmin, mln_site(S)& pmax)
163  {
164  mln_precondition(exact(s).nsites() != 0);
165  impl::pmin_pmax_(exact(s), pmin, pmax);
166  }
167 
168  template <typename S>
169  inline
170  std::pair<mln_site(S), mln_site(S)>
171  pmin_pmax(const Site_Set<S>& s)
172  {
173  mln_precondition(exact(s).nsites() != 0);
174  typedef mln_site(S) P;
175  std::pair<P, P> tmp;
176  pmin_pmax(s, tmp.first, tmp.second); // Calls the previous version.
177  return tmp;
178  }
179 
180 # endif // ! MLN_INCLUDE_ONLY
181 
182  } // end of namespace mln::geom
183 
184 } // end of namespace mln
185 
186 
187 #endif // ! MLN_GEOM_PMIN_PMAX_HH