$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
labeled_image.hh
1 // Copyright (C) 2009, 2010, 2011, 2012, 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_CORE_IMAGE_IMORPH_LABELED_IMAGE_HH
28 # define MLN_CORE_IMAGE_IMORPH_LABELED_IMAGE_HH
29 
33 
34 # include <mln/core/internal/labeled_image_base.hh>
35 
36 # include <mln/core/routine/duplicate.hh>
37 
38 # include <mln/data/compute.hh>
39 
40 # include <mln/util/array.hh>
41 
42 # include <mln/accu/center.hh>
43 # include <mln/accu/shape/bbox.hh>
44 # include <mln/accu/stat/max.hh>
45 
46 # include <mln/data/compute.hh>
47 
48 # include <mln/labeling/compute.hh>
49 
50 namespace mln
51 {
52 
53  // Forward declarations.
54  template <typename I> class labeled_image;
55  namespace accu
56  {
57  template <typename T> struct nil;
58  template <typename T> struct bbox;
59  }
60 
61 
62  namespace internal
63  {
64 
68  template <typename I>
69  struct data< labeled_image<I> >
70  : data< labeled_image_base<I, labeled_image<I> > >
71  {
73 
74  data(const I& ima, const mln_value(I)& nlabels);
75  data(const I& ima, const mln_value(I)& nlabels,
76  const util::array<mln_box(I)>& bboxes);
77  };
78 
79  } // end of namespace mln::internal
80 
81 
82  namespace trait
83  {
84 
85  template <typename I>
86  struct image_< labeled_image<I> >
87  : image_< labeled_image_base<I, labeled_image<I> > >
88  {
89  };
90 
91  } // end of namespace mln::trait
92 
93 
94 
106  //
107  template <typename I>
109  : public labeled_image_base<I, labeled_image<I> >
110  {
112 
113  public:
114 
117 
120 
122  labeled_image();
123 
125  labeled_image(const I& ima, const mln_value(I)& nlabels);
126 
129  labeled_image(const I& ima, const mln_value(I)& nlabels,
130  const util::array<mln_box(I)>& bboxes);
131 
133 
137  void init_(const I& ima, const mln_value(I)& nlabels);
138 
140  void init_from_(const labeled_image<I>& model);
142 
143  };
144 
145 
147 
148  // init_
149 
150  //FIXME: not enough generic? We would like 'J' instead of
151  // 'labeled_image<I>'.
152  template <typename I, typename J>
153  void init_(tag::image_t, labeled_image<I>& target,
154  const labeled_image<J>& model);
156 
157 
158  namespace make
159  {
160 
161  template <typename I>
163  labeled_image(const Image<I>& ima, const mln_value(I)& nlabels);
164 
165  } // end of namespace mln::make
166 
167 
168 
169 
170 # ifndef MLN_INCLUDE_ONLY
171 
172 
173  // internal::data< labeled_image<I> >
174 
175  namespace internal
176  {
177 
178 
179  // data< labeled_image<I> >
180 
181  template <typename I>
182  inline
183  data< labeled_image<I> >::data(const I& ima, const mln_value(I)& nlabels)
184  : super_(ima, nlabels)
185  {
186  }
187 
188  template <typename I>
189  inline
190  data< labeled_image<I> >::data(const I& ima, const mln_value(I)& nlabels,
191  const util::array<mln_box(I)>& bboxes)
192  : super_(ima, nlabels, bboxes)
193  {
194  }
195 
196 
197  } // end of namespace mln::internal
198 
199 
200  template <typename I>
201  inline
202  labeled_image<I>::labeled_image()
203  {
204  }
205 
206  template <typename I>
207  inline
208  labeled_image<I>::labeled_image(const I& ima, const mln_value(I)& nlabels)
209  {
210  init_(ima, nlabels);
211  }
212 
213  template <typename I>
214  inline
215  labeled_image<I>::labeled_image(const I& ima, const mln_value(I)& nlabels,
216  const util::array<mln_box(I)>& bboxes)
217  {
218  mln_precondition(data::compute(accu::meta::stat::max(), ima) == nlabels);
219  this->data_ = new internal::data< labeled_image<I> >(ima, nlabels, bboxes);
220  }
221 
222 
223  template <typename I>
224  inline
225  void
226  labeled_image<I>::init_(const I& ima, const mln_value(I)& nlabels)
227  {
228  mln_precondition(data::compute(accu::meta::stat::max(), ima) == nlabels);
229  this->data_ = new internal::data< labeled_image<I> >(ima, nlabels);
230  this->data_->bboxes_ = labeling::compute(accu::meta::shape::bbox(),
231  this->data_->ima_,
232  this->data_->nlabels_);
233  }
234 
235  template <typename I>
236  inline
237  void
238  labeled_image<I>::init_from_(const labeled_image<I>& model)
239  {
240  this->data_
241  = new internal::data< labeled_image<I> >(duplicate(model.hook_data_()->ima_),
242  model.nlabels());
243  this->data_->bboxes_ = model.hook_data_()->bboxes_;
244  }
245 
246  // init_
247 
248  template <typename I, typename J>
249  void init_(tag::image_t, labeled_image<I>& target,
250  const labeled_image<J>& model)
251  {
252  I ima;
253  init_(tag::image, ima, model);
254  target.init_(ima, model.nlabels());
255  }
256 
257 
258  // Make routines.
259 
260  namespace make
261  {
262 
263  template <typename I>
265  labeled_image(const Image<I>& ima, const mln_value(I)& nlabels)
266  {
267  mln_precondition(exact(ima).is_valid());
268  mln::labeled_image<I> tmp(exact(ima), nlabels);
269  return tmp;
270  }
271 
272  } // end of namespace mln::make
273 
274 
275 # endif // ! MLN_INCLUDE_ONLY
276 
277 } // end of namespace mln
278 
279 
280 #endif // ! MLN_CORE_IMAGE_IMORPH_LABELED_IMAGE_HH