$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
to_p_array.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_ARRAY_HH
27 # define MLN_CONVERT_TO_P_ARRAY_HH
28 
34 
35 # include <mln/core/site_set/p_array.hh>
36 # include <mln/core/concept/image.hh>
37 # include <mln/core/concept/window.hh>
38 
39 
40 namespace mln
41 {
42 
43  namespace convert
44  {
45 
47  template <typename S>
48  p_array<mln_psite(S)> to_p_array(const Site_Set<S>& pset);
49 
50 
53  template <typename W>
54  p_array<mln_psite(W)> to_p_array(const Window<W>& win,
55  const mln_psite(W)& p);
56 
58  template <typename I>
59  p_array<mln_psite(I)>
60  to_p_array(const Image<I>& img);
61 
62 
63 
64 # ifndef MLN_INCLUDE_ONLY
65 
66  template <typename S>
67  inline
68  p_array<mln_psite(S)> to_p_array(const Site_Set<S>& pset_)
69  {
70  const S& pset = exact(pset_);
71  p_array<mln_psite(S)> v;
72 // v.reserve(pset.nsites());
73  // FIXME: Why mln_fwd_piter and not mln_piter?
74  mln_fwd_piter(S) p(pset);
75  for_all(p)
76  v.append(p);
77  return v;
78  }
79 
80  template <typename W>
81  inline
82  p_array<mln_psite(W)> to_p_array(const Window<W>& win_,
83  const mln_psite(W)& p)
84  {
85  const W& win = exact(win_);
86  p_array<mln_psite(W)> v;
87  v.reserve(win.size());
88  mln_qiter(W) q(win, p);
89  for_all(q)
90  v.append(q);
91  return v;
92  }
93 
94  //FIXME: to remove, already added to from_image_to_site_set.hh.
95  template <typename I>
96  inline
97  p_array<mln_psite(I)>
98  to_p_array(const Image<I>& img_)
99  {
100  const I& img = exact(img_);
101 
102  p_array<mln_psite(I)> a;
103 
104  mln_piter(I) p(img.domain());
105  for_all(p)
106  if (img(p))
107  a.append(p);
108 
109  return a;
110  }
111 
112 # endif // ! MLN_INCLUDE_ONLY
113 
114  } // end of namespace mln::convert
115 
116 } // end of namespace mln
117 
118 
119 #endif // ! MLN_CONVERT_TO_P_ARRAY_HH