$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
pack.hh
1 // Copyright (C) 2009, 2013 EPITA Research and Development Laboratory
2 // (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_PACK_HH
28 # define MLN_LABELING_PACK_HH
29 
34 
35 # include <mln/core/concept/image.hh>
36 
37 # include <mln/make/relabelfun.hh>
38 
39 # include <mln/data/compute.hh>
40 # include <mln/data/transform.hh>
41 
42 # include <mln/accu/label_used.hh>
43 
44 
45 
46 namespace mln
47 {
48 
49  namespace labeling
50  {
51 
63  template <typename I>
64  mln_concrete(I)
65  pack(const Image<I>& label, mln_value(I)& new_nlabels,
66  fun::i2v::array<mln_value(I)>& repack_fun);
67 
68 
80  template <typename I>
81  mln_concrete(I)
82  pack(const Image<I>& label, mln_value(I)& new_nlabels);
83 
84 
85 
92  //
93  template <typename I>
94  void
95  pack_inplace(Image<I>& label, mln_value(I)& new_nlabels,
96  fun::i2v::array<mln_value(I)>& repack_fun);
97 
98 
100  template <typename I>
101  void
102  pack_inplace(Image<I>& label, mln_value(I)& new_nlabels);
103 
104 
105 
106 # ifndef MLN_INCLUDE_ONLY
107 
108 
109  namespace internal
110  {
111 
112  template <typename I>
113  void
114  pack_tests(const Image<I>& label, mln_value(I)& new_nlabels)
115  {
116  // FIXME: we may want to check that it is exactly a label.
117  //mlc_is_a(mln_value(I), mln::value::Symbolic)::check();
118  mln_precondition(exact(label).is_valid());
119  (void) label;
120  (void) new_nlabels;
121  }
122 
123  } // end of mln::labeling::internal
124 
125 
126 
127  template <typename I>
128  mln_concrete(I)
129  pack(const Image<I>& label, mln_value(I)& new_nlabels)
130  {
131  fun::i2v::array<mln_value(I)> repack_fun;
132  return pack(label, new_nlabels, repack_fun);
133  }
134 
135 
136  template <typename I>
137  mln_concrete(I)
138  pack(const Image<I>& label, mln_value(I)& new_nlabels,
139  fun::i2v::array<mln_value(I)>& repack_fun)
140  {
141  mln_trace("labeling::pack");
142 
143  internal::pack_tests(label, new_nlabels);
144 
145  fun::i2v::array<bool>
146  fv2b = data::compute(accu::meta::label_used(), label);
147 
148  mln_value(I) tmp_nlabels = fv2b.size() - 1;
149 
150  repack_fun = make::relabelfun(fv2b, tmp_nlabels, new_nlabels);
151 
152  mln_concrete(I)
153  output = data::transform(label, repack_fun);
154 
155  return output;
156  }
157 
158 
159  template <typename I>
160  void
161  pack_inplace(Image<I>& label, mln_value(I)& new_nlabels)
162  {
163  fun::i2v::array<mln_value(I)> repack_fun;
164  pack_inplace(label, new_nlabels, repack_fun);
165  }
166 
167 
168  template <typename I>
169  void
170  pack_inplace(Image<I>& label, mln_value(I)& new_nlabels,
171  fun::i2v::array<mln_value(I)>& repack_fun)
172  {
173  mln_trace("labeling::pack_inplace");
174 
175  internal::pack_tests(label, new_nlabels);
176 
177  fun::i2v::array<bool>
178  fv2b = data::compute(accu::meta::label_used(), label);
179 
180  mln_value(I) tmp_nlabels = fv2b.size() - 1;
181  repack_fun = make::relabelfun(fv2b, tmp_nlabels, new_nlabels);
182 
183  exact(label) = data::transform(label, repack_fun);
184 
185  }
186 
187 
188 # endif // ! MLN_INCLUDE_ONLY
189 
190  } // end of namespace mln::labeling
191 
192 } // end of namespace mln
193 
194 
195 #endif // ! MLN_LABELING_PACK_HH