Milena (Olena)  User documentation 2.0a Id
 All Classes Namespaces Functions Variables Typedefs Enumerator Groups Pages
relabel.hh
1 // Copyright (C) 2008, 2009, 2010 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_LABELING_RELABEL_HH
28 # define MLN_LABELING_RELABEL_HH
29 
33 
34 
35 # include <mln/core/concept/image.hh>
36 
37 # include <mln/make/relabelfun.hh>
38 
39 # include <mln/data/transform.hh>
40 # include <mln/data/transform_inplace.hh>
41 
42 
43 
44 namespace mln
45 {
46 
47  namespace labeling
48  {
49 
58  //
59  template <typename I, typename F>
60  mln_concrete(I)
61  relabel(const Image<I>& label,
62  const mln_value(I)& nlabels,
63  mln_value(I)& new_nlabels,
64  const Function_v2b<F>& fv2b);
65 
66 
74  //
75  template <typename I, typename F>
76  mln_concrete(I)
77  relabel(const Image<I>& label,
78  const mln_value(I)& nlabels,
79  const Function_v2v<F>& fv2v);
80 
81 
87  //
88  template <typename I, typename F>
89  void
90  relabel_inplace(Image<I>& label,
91  const mln_value(I)& nlabels,
92  const Function_v2b<F>& fv2b);
93 
94 
100  //
101  template <typename I, typename F>
102  void
103  relabel_inplace(Image<I>& label,
104  const mln_value(I)& nlabels,
105  const Function_v2v<F>& fv2v);
106 
107 
108 # ifndef MLN_INCLUDE_ONLY
109 
110 
111 
112  namespace internal
113  {
114 
115  template <typename I>
116  void
117  relabel_tests(const Image<I>& label,
118  mln_value(I)& new_nlabels)
119  {
120  // FIXME: we may want to check that it is exactly a label.
121 // mlc_is_a(mln_value(I), mln::value::Symbolic)::check();
122  mln_precondition(exact(label).is_valid());
123  (void) label;
124  (void) new_nlabels;
125  }
126 
127  template <typename I, typename F>
128  void
129  relabel_tests(const Image<I>& label,
130  const mln_value(I)& nlabels,
131  mln_value(I)& new_nlabels,
132  const Function<F>& f)
133  {
134  // FIXME: we may want to check that it is exactly a label.
135 // mlc_is_a(mln_value(I), mln::value::Symbolic)::check();
136  mln_precondition(exact(label).is_valid());
137  (void) label;
138  (void) nlabels;
139  (void) new_nlabels;
140  (void) f;
141  }
142 
143  template <typename I, typename F>
144  void
145  relabel_tests(const Image<I>& label,
146  const mln_value(I)& nlabels,
147  const Function<F>& f)
148  {
149  // FIXME: we may want to check that it is exactly a label.
150 // mlc_is_a(mln_value(I), mln::value::Symbolic)::check();
151  mln_precondition(exact(label).is_valid());
152  (void) label;
153  (void) nlabels;
154  (void) f;
155  }
156 
157  template <typename I, typename F>
158  inline
159  void
160  relabel_inplace_tests(Image<I>& label,
161  const mln_value(I)& nlabels,
162  const Function<F>& f)
163  {
164  // FIXME: we may want to check that it is exactly a label.
165 // mlc_is_a(mln_value(I), mln::value::Symbolic)::check();
166  mln_precondition(exact(label).is_valid());
167  (void) label;
168  (void) nlabels;
169  (void) f;
170  }
171 
172  } // end of namespace mln::labeling::internal
173 
174 
175 
176  template <typename I, typename F>
177  inline
178  mln_concrete(I)
179  relabel(const Image<I>& label,
180  const mln_value(I)& nlabels,
181  const Function_v2v<F>& fv2v)
182  {
183  trace::entering("labeling::relabel");
184 
185 
186  mlc_not_equal(mln_result(F),bool)::check();
187  internal::relabel_tests(label, nlabels, fv2v);
188 
189  mln_concrete(I) output = data::transform(label, fv2v);
190 
191  trace::exiting("labeling::relabel");
192  return output;
193  }
194 
195 
196 
197  template <typename I, typename F>
198  inline
199  mln_concrete(I)
200  relabel(const Image<I>& label,
201  const mln_value(I)& nlabels,
202  mln_value(I)& new_nlabels,
203  const Function_v2b<F>& fv2b)
204  {
205  trace::entering("labeling::relabel");
206 
207  internal::relabel_tests(label, nlabels, new_nlabels, fv2b);
208 
209  typedef fun::i2v::array<mln_value(I)> fv2v_t;
210  fv2v_t fv2v = make::relabelfun(fv2b, nlabels, new_nlabels);
211  mln_concrete(I) output = labeling::relabel(label, new_nlabels, fv2v);
212 
213  trace::exiting("labeling::relabel");
214  return output;
215  }
216 
217 
218  template <typename I, typename F>
219  inline
220  void
222  const mln_value(I)& nlabels,
223  const Function_v2v<F>& fv2v)
224  {
225  trace::entering("labeling::relabel_inplace");
226 
227  mlc_not_equal(mln_result(F),bool)::check();
228  internal::relabel_inplace_tests(label, nlabels, fv2v);
229 
230  data::transform_inplace(label, fv2v);
231 
232  trace::exiting("labeling::relabel_inplace");
233  }
234 
235 
236 
237  template <typename I, typename F>
238  inline
239  void
241  const mln_value(I)& nlabels,
242  const Function_v2b<F>& fv2b)
243  {
244  trace::entering("labeling::relabel_inplace");
245 
246  internal::relabel_inplace_tests(label, nlabels, fv2b);
247 
248  typedef fun::i2v::array<mln_value(I)> fv2v_t;
249  mln_value(I) tmp;
250  fv2v_t fv2v = make::relabelfun(fv2b, nlabels, tmp);
251  labeling::relabel_inplace(label, tmp, fv2v);
252 
253  trace::exiting("labeling::relabel_inplace");
254  }
255 
256 # endif // ! MLN_INCLUDE_ONLY
257 
258  } // end of namespace mln::labeling
259 
260 } // end of namespace mln
261 
262 
263 #endif // ! MLN_LABELING_RELABEL_HH