Milena (Olena)  User documentation 2.0a Id
 All Classes Namespaces Functions Variables Typedefs Enumerator Groups Pages
geom/bbox.hh
1 // Copyright (C) 2007, 2008, 2009 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 
58  template <typename S>
59  box<mln_site(S)> bbox(const Site_Set<S>& pset);
60 
61 
63  template <typename I>
64  box<mln_site(I)> bbox(const Image<I>& ima);
65 
66 
68  template <typename W>
69  box<mln_psite(W)> bbox(const Window<W>& win);
70 
72  template <typename W>
73  box<mln_psite(W)> bbox(const Weighted_Window<W>& win);
74 
75 
76 
77 # ifndef MLN_INCLUDE_ONLY
78 
79  namespace impl
80  {
81 
82  template <typename S>
83  box<mln_site(S)> bbox_(const trait::site_set::bbox::known&,
84  const S& pset)
85  {
86  return pset.bbox();
87  }
88 
89  template <typename S>
90  box<mln_site(S)> bbox_(trait::site_set::bbox::unknown,
91  const S& pset)
92  {
93  typedef mln_site(S) P;
94  P pmin, pmax;
95 
96  // Init with first point.
97  mln_piter(S) p(pset);
98  p.start();
99  mln_precondition(p.is_valid());
100  pmin = pmax = p;
101 
102  // Update with remaining points.
103  for_all_remaining(p)
104  for (unsigned i = 0; i < P::dim; ++i)
105  if (p[i] < pmin[i])
106  pmin[i] = p[i];
107  else
108  if (p[i] > pmax[i])
109  pmax[i] = p[i];
110 
111  box<P> bb(pmin, pmax);
112  return bb;
113  }
114 
115  } // end of namespace mln::geom::impl
116 
117 
118  // Facade.
119 
120  template <typename S>
121  inline
122  box<mln_site(S)> bbox(const Site_Set<S>& pset)
123  {
124 // mln_precondition(set::is_empty(pset) != 0);
125 
126  box<mln_site(S)> b = impl::bbox_(mln_trait_site_set_bbox(S)(),
127  exact(pset));
128 
129  return b;
130  }
131 
132  template <typename I>
134  {
135  const I& ima = exact(ima_);
136  mln_precondition(ima.is_valid());
137  box<mln_site(I)> b = geom::bbox(ima.domain());
138 
139  return b;
140  }
141 
142  template <typename W>
144  {
145  typedef mln_psite(W) P;
147  P O = literal::origin;
148  mln_qiter(W) q(exact(win), O);
149  for_all(q)
150  b.take(q);
151 
152  return b;
153  }
154 
155  template <typename W>
157  {
158  box<mln_psite(W)> b = bbox(exact(win).win());
159 
160  return b;
161  }
162 
163 
164 # endif // ! MLN_INCLUDE_ONLY
165 
166  } // end of namespace mln::geom
167 
168 } // end of namespace mln
169 
170 
171 #endif // ! MLN_GEOM_BBOX_HH