$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
to_window.hh
1 // Copyright (C) 2007, 2008, 2009 EPITA Research and Development Laboratory (LRDE)
2 //
3 // This file is part of Olena.
4 //
5 // Olena is free software: you can redistribute it and/or modify it under
6 // the terms of the GNU General Public License as published by the Free
7 // Software Foundation, version 2 of the License.
8 //
9 // Olena is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with Olena. If not, see <http://www.gnu.org/licenses/>.
16 //
17 // As a special exception, you may use this file as part of a free
18 // software project without restriction. Specifically, if other files
19 // instantiate templates or use macros or inline functions from this
20 // file, or you compile this file and link it with other files to produce
21 // an executable, this file does not by itself cause the resulting
22 // executable to be covered by the GNU General Public License. This
23 // exception does not however invalidate any other reasons why the
24 // executable file might be covered by the GNU General Public License.
25 
26 #ifndef MLN_CONVERT_TO_WINDOW_HH
27 # define MLN_CONVERT_TO_WINDOW_HH
28 
32 
33 # include <set>
34 
35 # include <mln/core/concept/gdpoint.hh>
36 # include <mln/core/concept/neighborhood.hh>
37 # include <mln/core/window.hh>
38 # include <mln/pw/image.hh>
39 # include <mln/pw/cst.hh>
40 # include <mln/metal/is_a.hh>
41 
42 
43 namespace mln
44 {
45 
46  namespace convert
47  {
48 
50  template <typename N>
51  mln_window(N) to_window(const Neighborhood<N>& nbh);
52 
54  template <typename I>
55  window<mln_site(I)::dpsite> to_window(const Image<I>& ima);
56 
58  template <typename S>
59  window<mln_site(S)::dpsite> to_window(const Site_Set<S>& pset);
60 
62  template <typename D, typename C>
63  window<D> to_window(const std::set<D, C>& s);
64 
65 
66 # ifndef MLN_INCLUDE_ONLY
67 
68  /*-------------------------------------.
69  | Neighborhood-to-window conversions. |
70  `-------------------------------------*/
71 
72  template <typename N>
73  inline
74  mln_window(N) to_window(const Neighborhood<N>& nbh)
75  {
76  return exact(nbh).win();
77  }
78 
79  /*------------------------------.
80  | Image-to-window conversions. |
81  `------------------------------*/
82 
83  /* FIXME: According to milena/core/concepts/README, windows are
84  not necessarily based on a set of dpsites. So the current
85  algorithm won't work on non dpsite-set-based windows. In the
86  general case (of windows not being a set of dpsites), the
87  window resulting from this conversion (as well as the iterators
88  based on such windows!) should depend on the initial
89  neighborhood (i.e., delegate the actual iteration to the
90  aggregated neighborhood). When this is fixed, document this in
91  depth in milena/core/concepts/README. */
92  template <typename I>
93  inline
94  window<mln_site(I)::dpsite> to_window(const Image<I>& ima_)
95  {
96  const I& ima = exact(ima_);
97  mln_precondition(ima.is_valid());
98  // FIXME: Check that ima is binary!
99  typedef mln_site(I) P;
100  typedef mln_dpsite(P) D;
101 
102  window<D> win;
103  mln_piter(I) p(ima.domain());
104  for_all(p)
105  if (ima(p))
106  win.insert(p - P::origin);
107  return win;
108  }
109 
110 
111  /*----------------------------------.
112  | Point set-to-window conversions. |
113  `----------------------------------*/
114 
115  template <typename S>
116  inline
117  window<mln_site(S)::dpsite> to_window(const Site_Set<S>& pset)
118  {
119  return to_window(pw::cst(true) | pset);
120  }
121 
122  /*---------------------------------.
123  | std::set-to-window conversions. |
124  `---------------------------------*/
125 
126  template <typename D, typename C>
127  inline
128  window<D> to_window(const std::set<D, C>& s)
129  {
130  // FIXME: Was: mln::metal::is_a<D, Dpoint>::check();
131  // OR mln::metal::is_a<D, Delta_Point_Site>::check();
132  mln::metal::is_a<D, Gdpoint>::check();
133  window<D> win;
134  for (typename std::set<D, C>::const_iterator i = s.begin();
135  i != s.end(); ++i)
136  win.insert(*i);
137  return win;
138  }
139 
140 # endif // ! MLN_INCLUDE_ONLY
141 
142  } // end of namespace mln::convert
143 
144 } // end of namespace mln
145 
146 
147 #endif // ! MLN_CONVERT_TO_WINDOW_HH