$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
to_p_set.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_P_SET_HH
27 # define MLN_CONVERT_TO_P_SET_HH
28 
32 
33 # include <set>
34 
35 # include <mln/core/concept/neighborhood.hh>
36 # include <mln/core/concept/window.hh>
37 # include <mln/core/concept/point_site.hh>
38 # include <mln/core/site_set/p_set.hh>
39 # include <mln/pw/image.hh>
40 # include <mln/pw/cst.hh>
41 # include <mln/metal/templated_by.hh>
42 # include <mln/metal/is_a.hh>
43 
44 
45 namespace mln
46 {
47 
48  namespace convert
49  {
50 
52  template <typename N>
53  p_set<mln_psite(N)>
54  to_p_set(const Neighborhood<N>& nbh);
55 
57  template <typename I>
58  p_set<mln_psite(I)>
59  to_p_set(const Image<I>& ima);
60 
62  template <typename W>
63  p_set<mln_psite(W)>
64  to_p_set(const Window<W>& win);
65 
68  template <typename P, typename C>
69  p_set<P>
70  to_p_set(const std::set<P, C>& s);
71 
73  template <typename S>
74  p_set<mln_psite(S)>
75  to_p_set(const Site_Set<S>& ps);
76 
77 
78 # ifndef MLN_INCLUDE_ONLY
79 
80  template <typename N>
81  inline
82  p_set<mln_psite(N)>
83  to_p_set(const Neighborhood<N>& nbh_)
84  {
85  const N& nbh = exact(nbh_);
86  typedef mln_psite(N) P;
87  p_set<P> pset;
88  mln_niter(N) n(nbh, P::origin);
89  for_all(n)
90  pset.insert(n);
91  return pset;
92  }
93 
94  template <typename I>
95  inline
96  p_set<mln_psite(I)>
97  to_p_set(const Image<I>& ima_)
98  {
99  const I& ima = exact(ima_);
100  mln_precondition(ima.is_valid());
101 
102  // FIXME: Check that ima is binary!
103 // mln::metal::templated_by<mln_value(I), bool >::check();
104 
105  typedef mln_psite(I) P;
106  p_set<P> pset;
107  mln_piter(I) p(ima.domain());
108  for_all(p)
109  if (ima(p))
110  pset.insert(p);
111  return pset;
112  }
113 
114  template <typename W>
115  inline
116  p_set<mln_psite(W)>
117  to_p_set(const Window<W>& win)
118  {
119  typedef mln_psite(W) P;
120  p_set<P> pset;
121  mln_qiter(W) q(exact(win), P::origin);
122  for_all(q)
123  pset.insert(q);
124  return pset;
125  }
126 
127  template <typename P, typename C>
128  inline
129  p_set<P>
130  to_p_set(const std::set<P, C>& s)
131  {
132  P titi;
133  mln::metal::is_a<P, Site>::check();
134  p_set<P> pset;
135  for (typename std::set<P, C>::const_iterator i = s.begin();
136  i != s.end(); ++i)
137  pset.insert(*i);
138  return pset;
139  }
140 
141  template <typename S>
142  inline
143  p_set<mln_psite(S)>
144  to_p_set(const Site_Set<S>& ps_)
145  {
146  const S& ps = exact(ps_);
147  p_set<mln_psite(S)> tmp;
148  mln_piter(S) p(ps);
149  for_all(p)
150  tmp.insert(p);
151  return tmp;
152  }
153 
154 # endif // ! MLN_INCLUDE_ONLY
155 
156  } // end of namespace mln::convert
157 
158 } // end of namespace mln
159 
160 
161 #endif // ! MLN_CONVERT_TO_P_SET_HH