$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
geom/bbox.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_BBOX_HH
28 # define MLN_GEOM_BBOX_HH
29 
43 # include <mln/core/site_set/box.hh>
44 # include <mln/core/concept/image.hh>
45 # include <mln/core/concept/window.hh>
46 # include <mln/core/concept/weighted_window.hh>
47 # include <mln/literal/zero.hh>
48 # include <mln/accu/shape/bbox.hh>
49 
50 
51 namespace mln
52 {
53 
54  namespace geom
55  {
56 
62  template <typename S>
63  box<mln_site(S)> bbox(const Site_Set<S>& pset);
64 
65 
71  template <typename I>
72  box<mln_site(I)> bbox(const Image<I>& ima);
73 
74 
79  template <typename W>
80  box<mln_psite(W)> bbox(const Window<W>& win);
81 
87  template <typename W>
88  box<mln_psite(W)> bbox(const Weighted_Window<W>& win);
89 
90 
91 
92 # ifndef MLN_INCLUDE_ONLY
93 
94  namespace impl
95  {
96 
97  template <typename S>
98  box<mln_site(S)> bbox_(const trait::site_set::bbox::known&,
99  const S& pset)
100  {
101  return pset.bbox();
102  }
103 
104  template <typename S>
105  box<mln_site(S)> bbox_(trait::site_set::bbox::unknown,
106  const S& pset)
107  {
108  typedef mln_site(S) P;
109  P pmin, pmax;
110 
111  // Init with first point.
112  mln_piter(S) p(pset);
113  p.start();
114  mln_precondition(p.is_valid());
115  pmin = pmax = p;
116 
117  // Update with remaining points.
118  for_all_remaining(p)
119  for (unsigned i = 0; i < P::dim; ++i)
120  if (p[i] < pmin[i])
121  pmin[i] = p[i];
122  else
123  if (p[i] > pmax[i])
124  pmax[i] = p[i];
125 
126  box<P> bb(pmin, pmax);
127  return bb;
128  }
129 
130  } // end of namespace mln::geom::impl
131 
132 
133  // Facade.
134 
135  template <typename S>
136  inline
137  box<mln_site(S)> bbox(const Site_Set<S>& pset)
138  {
139 // mln_precondition(set::is_empty(pset) != 0);
140 
141  box<mln_site(S)> b = impl::bbox_(mln_trait_site_set_bbox(S)(),
142  exact(pset));
143 
144  return b;
145  }
146 
147  template <typename I>
148  box<mln_site(I)> bbox(const Image<I>& ima_)
149  {
150  const I& ima = exact(ima_);
151  mln_precondition(ima.is_valid());
152  box<mln_site(I)> b = geom::bbox(ima.domain());
153 
154  return b;
155  }
156 
157  template <typename W>
158  box<mln_psite(W)> bbox(const Window<W>& win)
159  {
160  typedef mln_psite(W) P;
161  accu::shape::bbox<P> b;
162  P O = literal::origin;
163  mln_qiter(W) q(exact(win), O);
164  for_all(q)
165  b.take(q);
166 
167  return b;
168  }
169 
170  template <typename W>
171  box<mln_psite(W)> bbox(const Weighted_Window<W>& win)
172  {
173  box<mln_psite(W)> b = bbox(exact(win).win());
174 
175  return b;
176  }
177 
178 
179 # endif // ! MLN_INCLUDE_ONLY
180 
181  } // end of namespace mln::geom
182 
183 } // end of namespace mln
184 
185 
186 #endif // ! MLN_GEOM_BBOX_HH