$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
labeling/value.hh
1 // Copyright (C) 2007, 2008, 2009, 2010, 2013 EPITA Research and
2 // Development 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_LABELING_VALUE_HH
28 # define MLN_LABELING_VALUE_HH
29 
33 
34 # include <mln/core/concept/image.hh>
35 # include <mln/core/concept/neighborhood.hh>
36 # include <mln/canvas/labeling/video.hh>
37 # include <mln/data/fill.hh>
38 
39 
40 
41 namespace mln
42 {
43 
44  namespace labeling
45  {
46 
58  template <typename I, typename N, typename L>
59  mln_ch_value(I, L)
60  value(const Image<I>& input, const mln_value(I)& val,
61  const Neighborhood<N>& nbh, L& nlabels);
62 
63 
64 # ifndef MLN_INCLUDE_ONLY
65 
66 
67  // Tests.
68 
69  namespace internal
70  {
71 
72  template <typename I, typename N, typename L>
73  void
74  value_tests(const Image<I>& input, const mln_value(I)& val, const Neighborhood<N>& nbh,
75  L& nlabels)
76  {
77  mln_precondition(exact(input).is_valid());
78  mln_precondition(exact(nbh).is_valid());
79 
80  (void) input;
81  (void) val;
82  (void) nbh;
83  (void) nlabels;
84  }
85 
86  } // end of namespace mln::labeling::internal
87 
88 
89 
90  namespace impl
91  {
92 
93  // Generic functor.
94 
95  template <typename I, typename L>
96  struct value_functor
97  {
98  typedef mln_psite(I) P;
99 
100  const I& input;
101  const mln_value(I)& val;
102 
103  // Requirements from mln::canvas::labeling.
104 
105  typedef mln_domain(I) S;
106 
107  // Generic implementation
108 
109  void init() {}
110  bool handles(const P& p) const { return input(p) == val; }
111  bool equiv(const P& n, const P&) const { return input(n) == val; }
112  bool labels(const P&) const { return true; }
113  void do_no_union(const P&, const P&) {}
114  void init_attr(const P&) {}
115  void merge_attr(const P&, const P&) {}
116  void set_new_label(const P&, const L&) {}
117  void set_label(const P&, const L&) {}
118  void finalize() {}
119 
120  // Fastest implementation
121 
122  void init_() {}
123  bool handles_(unsigned p) const { return input.element(p) == val; }
124  bool equiv_(unsigned n, unsigned) const { return input.element(n) == val; }
125  bool labels_(unsigned) const { return true; }
126  void do_no_union_(unsigned, unsigned) {}
127  void init_attr_(unsigned) {}
128  void merge_attr_(unsigned, unsigned) {}
129  void set_new_label_(unsigned, const L&) {}
130  void set_label_(unsigned, const L&) {}
131  void finalize_() {}
132 
133  // end of Requirements.
134 
135  value_functor(const Image<I>& input_, const mln_value(I)& val)
136  : input(exact(input_)),
137  val(val)
138  {
139  }
140  };
141 
142  } // end of namespace mln::labeling::impl
143 
144 
145 
146 
147  // Facade.
148 
149  template <typename I, typename N, typename L>
150  mln_ch_value(I, L)
151  value(const Image<I>& input, const mln_value(I)& val,
152  const Neighborhood<N>& nbh, L& nlabels)
153  {
154  mln_trace("labeling::value");
155 
156  internal::value_tests(input, val, nbh, nlabels);
157 
158  mln_ch_value(I, L) output;
159  impl::value_functor<I,L> f(input, val);
160  output = canvas::labeling::video(input, nbh, nlabels, f);
161 
162  return output;
163  }
164 
165 # endif // ! MLN_INCLUDE_ONLY
166 
167  } // end of namespace mln::labeling
168 
169 } // end of namespace mln
170 
171 
172 #endif // ! MLN_LABELING_VALUE_HH