Milena (Olena)  User documentation 2.0a Id
 All Classes Namespaces Functions Variables Typedefs Enumerator Groups Pages
pack.hh
1 // Copyright (C) 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_LABELING_PACK_HH
27 # define MLN_LABELING_PACK_HH
28 
33 
34 # include <mln/core/concept/image.hh>
35 
36 # include <mln/make/relabelfun.hh>
37 
38 # include <mln/data/compute.hh>
39 # include <mln/data/transform.hh>
40 
41 # include <mln/accu/label_used.hh>
42 
43 
44 
45 namespace mln
46 {
47 
48  namespace labeling
49  {
50 
58  //
59  template <typename I>
60  mln_concrete(I)
61  pack(const Image<I>& label, mln_value(I)& new_nlabels,
62  fun::i2v::array<mln_value(I)>& repack_fun);
63 
64 
66  template <typename I>
67  mln_concrete(I)
68  pack(const Image<I>& label, mln_value(I)& new_nlabels);
69 
70 
71 
78  //
79  template <typename I>
80  void
81  pack_inplace(Image<I>& label, mln_value(I)& new_nlabels,
82  fun::i2v::array<mln_value(I)>& repack_fun);
83 
84 
86  template <typename I>
87  void
88  pack_inplace(Image<I>& label, mln_value(I)& new_nlabels);
89 
90 
91 
92 # ifndef MLN_INCLUDE_ONLY
93 
94 
95  namespace internal
96  {
97 
98  template <typename I>
99  void
100  pack_tests(const Image<I>& label, mln_value(I)& new_nlabels)
101  {
102  // FIXME: we may want to check that it is exactly a label.
103  //mlc_is_a(mln_value(I), mln::value::Symbolic)::check();
104  mln_precondition(exact(label).is_valid());
105  (void) label;
106  (void) new_nlabels;
107  }
108 
109  } // end of mln::labeling::internal
110 
111 
112 
113  template <typename I>
114  mln_concrete(I)
115  pack(const Image<I>& label, mln_value(I)& new_nlabels)
116  {
117  fun::i2v::array<mln_value(I)> repack_fun;
118  return pack(label, new_nlabels, repack_fun);
119  }
120 
121 
122  template <typename I>
123  mln_concrete(I)
124  pack(const Image<I>& label, mln_value(I)& new_nlabels,
125  fun::i2v::array<mln_value(I)>& repack_fun)
126  {
127  trace::entering("labeling::pack");
128 
129  internal::pack_tests(label, new_nlabels);
130 
131  fun::i2v::array<bool>
132  fv2b = data::compute(accu::meta::label_used(), label);
133 
134  mln_value(I) tmp_nlabels = fv2b.size() - 1;
135 
136  repack_fun = make::relabelfun(fv2b, tmp_nlabels, new_nlabels);
137 
138  mln_concrete(I)
139  output = data::transform(label, repack_fun);
140 
141  trace::exiting("labeling::pack");
142  return output;
143  }
144 
145 
146  template <typename I>
147  void
148  pack_inplace(Image<I>& label, mln_value(I)& new_nlabels)
149  {
150  fun::i2v::array<mln_value(I)> repack_fun;
151  pack_inplace(label, new_nlabels, repack_fun);
152  }
153 
154 
155  template <typename I>
156  void
157  pack_inplace(Image<I>& label, mln_value(I)& new_nlabels,
158  fun::i2v::array<mln_value(I)>& repack_fun)
159  {
160  trace::entering("labeling::pack_inplace");
161 
162  internal::pack_tests(label, new_nlabels);
163 
164  fun::i2v::array<bool>
165  fv2b = data::compute(accu::meta::label_used(), label);
166 
167  mln_value(I) tmp_nlabels = fv2b.size() - 1;
168  repack_fun = make::relabelfun(fv2b, tmp_nlabels, new_nlabels);
169 
170  exact(label) = data::transform(label, repack_fun);
171 
172  trace::exiting("labeling::pack_inplace");
173  }
174 
175 
176 # endif // ! MLN_INCLUDE_ONLY
177 
178  } // end of namespace mln::labeling
179 
180 } // end of namespace mln
181 
182 
183 #endif // ! MLN_LABELING_PACK_HH