Milena (Olena)  User documentation 2.0a Id
 All Classes Namespaces Functions Variables Typedefs Enumerator Groups Pages
compute_image.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_COMPUTE_IMAGE_HH
27 # define MLN_LABELING_COMPUTE_IMAGE_HH
28 
38 
39 # include <mln/core/concept/image.hh>
40 # include <mln/core/concept/accumulator.hh>
41 # include <mln/core/concept/meta_accumulator.hh>
42 
43 # include <mln/labeling/compute.hh>
44 
45 
46 namespace mln
47 {
48 
49  namespace labeling
50  {
51 
62  template <typename A, typename I, typename L>
63  mln_ch_value(L, mln_result(A))
64  compute_image(const util::array<mln_result(A)>& a,
65  const Image<I>& input,
66  const Image<L>& labels,
67  const mln_value(L)& nlabels);
68 
80  template <typename A, typename I, typename L>
81  inline
82  mln_ch_value(L, mln_result(A))
83  compute_image(const Accumulator<A>& accu,
84  const Image<I>& input,
85  const Image<L>& labels,
86  const mln_value(L)& nlabels);
87 
88 
100  template <typename A, typename I, typename L>
101  inline
102  mln_ch_value(L, mln_meta_accu_result(A, mln_value(I)))
103  compute_image(const Meta_Accumulator<A>& accu,
104  const Image<I>& input,
105  const Image<L>& labels,
106  const mln_value(L)& nlabels);
107 
108 
109 # ifndef MLN_INCLUDE_ONLY
110 
111  namespace internal
112  {
113 
114  template <typename A, typename L>
115  mln_ch_value(L, A)
116  compute_image(const util::array<A>& a,
117  const Image<L>& labels_,
118  const mln_value(L)& nlabels)
119  {
120  const L& labels = exact(labels_);
121  (void) nlabels;
122 
123  typedef mln_ch_value(L, A) O;
124  O output;
125  initialize(output, labels);
126 
127  mln_piter(L) p(labels.domain());
128  for_all(p)
129  {
130  mln_assertion(labels(p) <= nlabels);
131  output(p) = a[labels(p)];
132  }
133 
134  return output;
135  }
136 
137  } // end of namespace mln::labeling::internal
138 
139 
140  template <typename A, typename I, typename L>
141  inline
142  mln_ch_value(L, mln_result(A))
143  compute_image(const util::array<mln_result(A)>& a,
144  const Image<L>& labels,
145  const mln_value(L)& nlabels)
146  {
147  (void) nlabels;
148 
149  trace::entering("labeling::compute_image");
150 
151  mln_ch_value(L, mln_result(A)) output =
152  labeling::internal::compute_image(a, labels, nlabels);
153 
154  trace::exiting("labeling::compute_image");
155  return output;
156  }
157 
158  template <typename A, typename I, typename L>
159  inline
160  mln_ch_value(L, mln_result(A))
161  compute_image(const Accumulator<A>& accu,
162  const Image<I>& input,
163  const Image<L>& labels,
164  const mln_value(L)& nlabels)
165  {
166  trace::entering("labeling::compute_image");
167 
169  compute(accu, input, labels, nlabels);
170 
171  mln_ch_value(L, mln_result(A)) output =
172  internal::compute_image(res, labels, nlabels);
173 
174  trace::exiting("labeling::compute_image");
175  return output;
176  }
177 
178  template <typename A, typename I, typename L>
179  inline
180  mln_ch_value(L, mln_meta_accu_result(A, mln_value(I)))
182  const Image<I>& input,
183  const Image<L>& labels,
184  const mln_value(L)& nlabels)
185  {
186  trace::entering("labeling::compute_image");
187 
188  typedef mln_meta_accu_result(A, mln_value(I)) T;
189 
190  util::array<T> res =
191  compute(accu, input, labels, nlabels);
192 
193  mln_ch_value(L, T) output =
194  labeling::internal::compute_image(res, labels, nlabels);
195 
196  trace::exiting("labeling::compute_image");
197  return output;
198  }
199 
200 # endif // ! MLN_INCLUDE_ONLY
201 
202  } // end of namespace mln::labeling
203 
204 } // end of namespace mln
205 
206 #endif // ! MLN_LABELING_COMPUTE_IMAGE_HH