Milena (Olena)  User documentation 2.0a Id
 All Classes Namespaces Functions Variables Typedefs Enumerator Groups Pages
labeled_image.hh
1 // Copyright (C) 2009, 2010, 2011 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_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 
66  template <typename I>
67  struct data< labeled_image<I> >
68  : data< labeled_image_base<I, labeled_image<I> > >
69  {
71 
72  data(const I& ima, const mln_value(I)& nlabels);
73  data(const I& ima, const mln_value(I)& nlabels,
74  const util::array<mln_box(I)>& bboxes);
75  };
76 
77  } // end of namespace mln::internal
78 
79 
80  namespace trait
81  {
82 
83  template <typename I>
84  struct image_< labeled_image<I> >
85  : image_< labeled_image_base<I, labeled_image<I> > >
86  {
87  };
88 
89  } // end of namespace mln::trait
90 
91 
92 
104  //
105  template <typename I>
107  : public labeled_image_base<I, labeled_image<I> >
108  {
110 
111  public:
112 
115 
119  labeled_image();
120 
122  labeled_image(const I& ima, const mln_value(I)& nlabels);
123 
126  labeled_image(const I& ima, const mln_value(I)& nlabels,
127  const util::array<mln_box(I)>& bboxes);
129 
132  void init_(const I& ima, const mln_value(I)& nlabels);
133 
135  void init_from_(const labeled_image<I>& model);
136 
137  };
138 
139 
140  // init_
141 
142  //FIXME: not enough generic? We would like 'J' instead of
143  // 'labeled_image<I>'.
144  template <typename I, typename J>
145  void init_(tag::image_t, labeled_image<I>& target,
146  const labeled_image<J>& model);
147 
148 
149 
150  namespace make
151  {
152 
153  template <typename I>
155  labeled_image(const Image<I>& ima, const mln_value(I)& nlabels);
156 
157  } // end of namespace mln::make
158 
159 
160 
161 
162 # ifndef MLN_INCLUDE_ONLY
163 
164 
165  // internal::data< labeled_image<I> >
166 
167  namespace internal
168  {
169 
170 
171  // data< labeled_image<I> >
172 
173  template <typename I>
174  inline
175  data< labeled_image<I> >::data(const I& ima, const mln_value(I)& nlabels)
176  : super_(ima, nlabels)
177  {
178  }
179 
180  template <typename I>
181  inline
182  data< labeled_image<I> >::data(const I& ima, const mln_value(I)& nlabels,
183  const util::array<mln_box(I)>& bboxes)
184  : super_(ima, nlabels, bboxes)
185  {
186  }
187 
188 
189  } // end of namespace mln::internal
190 
191 
192  template <typename I>
193  inline
195  {
196  }
197 
198  template <typename I>
199  inline
200  labeled_image<I>::labeled_image(const I& ima, const mln_value(I)& nlabels)
201  {
202  init_(ima, nlabels);
203  }
204 
205  template <typename I>
206  inline
207  labeled_image<I>::labeled_image(const I& ima, const mln_value(I)& nlabels,
208  const util::array<mln_box(I)>& bboxes)
209  {
210  mln_precondition(data::compute(accu::meta::stat::max(), ima) == nlabels);
211  this->data_ = new internal::data< labeled_image<I> >(ima, nlabels, bboxes);
212  }
213 
214 
215  template <typename I>
216  inline
217  void
218  labeled_image<I>::init_(const I& ima, const mln_value(I)& nlabels)
219  {
220  mln_precondition(data::compute(accu::meta::stat::max(), ima) == nlabels);
221  this->data_ = new internal::data< labeled_image<I> >(ima, nlabels);
222  this->data_->bboxes_ = labeling::compute(accu::meta::shape::bbox(),
223  this->data_->ima_,
224  this->data_->nlabels_);
225  }
226 
227  template <typename I>
228  inline
229  void
230  labeled_image<I>::init_from_(const labeled_image<I>& model)
231  {
232  this->data_
233  = new internal::data< labeled_image<I> >(duplicate(model.hook_data_()->ima_),
234  model.nlabels());
235  this->data_->bboxes_ = model.hook_data_()->bboxes_;
236  }
237 
238  // init_
239 
240  template <typename I, typename J>
241  void init_(tag::image_t, labeled_image<I>& target,
242  const labeled_image<J>& model)
243  {
244  I ima;
245  init_(tag::image, ima, model);
246  target.init_(ima, model.nlabels());
247  }
248 
249 
250  // Make routines.
251 
252  namespace make
253  {
254 
255  template <typename I>
257  labeled_image(const Image<I>& ima, const mln_value(I)& nlabels)
258  {
259  mln_precondition(exact(ima).is_valid());
260  mln::labeled_image<I> tmp(exact(ima), nlabels);
261  return tmp;
262  }
263 
264  } // end of namespace mln::make
265 
266 
267 # endif // ! MLN_INCLUDE_ONLY
268 
269 } // end of namespace mln
270 
271 
272 #endif // ! MLN_CORE_IMAGE_IMORPH_LABELED_IMAGE_HH