$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
from_image_to_site_set.hh
1 // Copyright (C) 2008, 2009, 2011, 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_CONVERT_IMPL_FROM_IMAGE_TO_SITE_SET_HH
28 # define MLN_CONVERT_IMPL_FROM_IMAGE_TO_SITE_SET_HH
29 
37 
38 # include <utility>
39 # include <mln/core/site_set/p_run.hh>
40 # include <mln/core/site_set/p_array.hh>
41 # include <mln/metal/converts_to.hh>
42 
43 
44 
45 namespace mln
46 {
47 
48  // Forward declarations.
49  template <typename E> struct Site_Set;
50  template <typename E> struct Image;
51  template <typename E> struct Gpoint;
52 
53  namespace convert
54  {
55 
56  namespace impl
57  {
58 
60  template <typename I, typename S>
61  void
63 
64 
65 
66 # ifndef MLN_INCLUDE_ONLY
67 
68  namespace internal
69  {
70 
71  // Case: binary image -> set of point runs.
72 
73  template <typename I, typename P, typename S>
74  void
75  from_image_to_site_set(const I& input, const Gpoint<P>&,
76  S& s, const mln::p_run<P>&)
77  {
78  s.clear();
79  mln_fwd_piter(I) p(input.domain());
80  p.start();
81  for (;;)
82  {
83  // Skip background.
84  while (p.is_valid() && input(p) == false)
85  p.next();
86  if (! p.is_valid()) // The end.
87  break;
88  mln_invariant(input(p) == true);
89  P start = p, q;
90  // Go to run end.
91  do
92  {
93  q = p;
94  p.next();
95  }
96  while (p.is_valid() && input(p) == true &&
97  // p follows q in a run, i.e., "p == q + right":
98  cut_(p.to_site()) == cut_(q) && p.last_coord() == q.last_coord() + 1);
99  s.insert(p_run<P>(start, q));
100  }
101  }
102 
103 
104  template <typename I, typename P, typename S>
105  void
106  from_image_to_site_set(const I& input, const Gpoint<P>&,
107  S& s,
108  const std::pair< mln_value(I), p_run<P> >&)
109  {
110  s.clear();
111  mln_fwd_piter(I) p(input.domain());
112  p.start();
113  for (;;)
114  {
115  if (! p.is_valid()) // The end.
116  break;
117  mln_value(I) v = input(p);
118  P start = p, q;
119  // Go to run end.
120  do
121  {
122  q = p;
123  p.next();
124  }
125  while (p.is_valid() && input(p) == v &&
126  cut_(p.to_site()) == cut_(q) && p.last_coord() == q.last_coord() + 1);
127  s.insert(v, p_run<P>(start, q));
128  }
129  }
130 
131 
132  template <typename I, typename P, typename S>
133  void
134  from_image_to_site_set(const I& input, const Gpoint<P>&,
135  S& s,
136  const std::pair< mln_value(I), P >&)
137  {
138  s.clear();
139  mln_fwd_piter(I) p(input.domain());
140  for_all(p)
141  s.insert(input(p), p);
142  }
143 
144 
145  template <typename I, typename S>
146  inline
147  void
149  {
150  from_image_to_site_set(exact(from), mln_deduce(I, domain_t, element)(),
151  exact(to), mln_i_element(S)());
152  }
153 
154  template <typename I>
155  inline
156  void
157  from_image_to_site_set(const Image<I>& from_, p_array<mln_psite(I)>& to)
158  {
159  const I& from = exact(from_);
160 
161  mln_piter(I) p(from.domain());
162  for_all(p)
163  if (from(p))
164  to.append(p);
165  }
166 
167 
168  } // end of namespace mln::convert::impl::internal
169 
170 
171  // Facade.
172 
173  template <typename I, typename S>
174  inline
175  void
177  {
179  }
180 
181 # endif // ! MLN_INCLUDE_ONLY
182 
183  } // end of namespace mln::convert::impl
184 
185  } // end of namespace mln::convert
186 
187 } // end of namespace mln
188 
189 
190 #endif // ! MLN_CONVERT_IMPL_FROM_IMAGE_TO_SITE_SET_HH