$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
slice_image.hh
1 // Copyright (C) 2008, 2009, 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_DMORPH_SLICE_IMAGE_HH
28 # define MLN_CORE_IMAGE_DMORPH_SLICE_IMAGE_HH
29 
35 
36 # include <mln/core/internal/image_domain_morpher.hh>
37 # include <mln/core/alias/box3d.hh>
38 # include <mln/core/image/image2d.hh>
39 # include <mln/data/paste.hh>
40 
41 
42 namespace mln
43 {
44 
45  // Forward declaration.
46  template <typename I> struct slice_image;
47 
48 
49  namespace internal
50  {
51 
55  template <typename I>
56  struct data< slice_image<I> >
57  {
58  data(I& ima, def::coord sli);
59 
60  I ima_;
61  def::coord sli_;
62  box2d b_;
63  };
64 
65  } // end of namespace mln::internal
66 
67 
68  namespace trait
69  {
70 
71  template <typename I>
72  struct image_< slice_image<I> > : default_image_morpher< I,
73  mln_value(I),
74  slice_image<I> >
75  {
76  typedef trait::image::category::domain_morpher category;
77 
78  typedef trait::image::dimension::two_d dimension;
79 
80 // typedef trait::image::ext_domain::none ext_domain; // No extension of domain.
81 // typedef trait::image::ext_value::irrelevant ext_value;
82 // typedef trait::image::ext_io::irrelevant ext_io;
83 
84  typedef trait::image::vw_io::none vw_io;
85  typedef trait::image::vw_set::none vw_set;
86  typedef trait::image::value_alignment::not_aligned value_alignment;
87  typedef trait::image::value_storage::disrupted value_storage;
88  };
89 
90  } // end of namespace mln::trait
91 
92 
93 
97  //
98  template <typename I>
100  box2d,
101  slice_image<I> >
102  {
105 
107  slice_image();
108 
110  slice_image(I& ima, def::coord sli);
111 
113  void init_(I& ima, def::coord sli);
115 
116  template <typename V>
117  void operator=(const image2d<V>& rhs);
118 
120  const box2d& domain() const;
121 
123  def::coord sli() const;
124 
126  mln_rvalue(I) operator()(const point2d& p) const;
127 
129  mln_morpher_lvalue(I) operator()(const point2d& p);
130 
131 
133  operator slice_image<const I>() const;
134  };
135 
136 
137 
138  template <typename I>
139  slice_image<I>
140  slice(Image<I>& ima, def::coord sli);
141 
142  template <typename I>
143  slice_image<const I>
144  slice(const Image<I>& ima, def::coord sli);
145 
146 
147 
148 
149  namespace trait
150  {
151 
152  template <typename I, typename V>
153  struct ch_value< slice_image<I>, V >
154  {
155  typedef image2d<V> ret;
156  };
157 
158  } // end of namespace mln::trait
159 
160 
161 
162 # ifndef MLN_INCLUDE_ONLY
163 
164 
165 // // init_.
166 
167 // template <typename I, typename J>
168 // void init_(tag::image_t, slice_image<I>& target, const J& model)
169 // {
170 // I ima;
171 // init_(tag::image, ima, exact(model));
172 // def::coord sli;
173 // // FIXME
174 // // init_(tag::???, sli, exact(model));
175 // target.init_(ima, sli);
176 // }
177 
178 
179  // internal::data< slice_image<I> >
180 
181  namespace internal
182  {
183 
184  template <typename I>
185  inline
187  : ima_(ima),
188  sli_(sli)
189  {
190  b_ = make::box2d(ima.domain().pmin().row(), ima.domain().pmin().col(),
191  ima.domain().pmax().row(), ima.domain().pmax().col());
192  }
193 
194  }
195 
196 
197  // slice_image<I>
198 
199  template <typename I>
200  inline
202  {
203  }
204 
205  template <typename I>
206  inline
208  {
209  init_(ima, sli);
210  }
211 
212  template <typename I>
213  inline
214  void
216  {
217  mln_precondition(! this->is_valid());
218  this->data_ = new internal::data< slice_image<I> >(ima, sli);
219  }
220 
221  template <typename I>
222  template <typename V>
223  void
224  slice_image<I>::operator=(const image2d<V>& rhs)
225  {
226  data::paste(rhs, *this);
227  }
228 
229  template <typename I>
230  inline
231  const box2d&
232  slice_image<I>::domain() const
233  {
234  mln_precondition(this->is_valid());
235  return this->data_->b_;
236  }
237 
238  template <typename I>
239  inline
240  def::coord
241  slice_image<I>::sli() const
242  {
243  mln_precondition(this->is_valid());
244  return this->data_->sli_;
245  }
246 
247  template <typename I>
248  inline
249  mln_rvalue(I)
250  slice_image<I>::operator()(const point2d& p) const
251  {
252  mln_precondition(this->has(p));
253  point3d p_(this->data_->sli_, p.row(), p.col());
254  mln_precondition(this->data_->ima_.has(p_));
255  return this->data_->ima_(p_);
256  }
257 
258  template <typename I>
259  inline
260  mln_morpher_lvalue(I)
261  slice_image<I>::operator()(const point2d& p)
262  {
263  mln_precondition(this->has(p));
264  point3d p_(this->data_->sli_, p.row(), p.col());
265  mln_precondition(this->data_->ima_.has(p_));
266  return this->data_->ima_(p_);
267  }
268 
269  template <typename I>
270  inline
271  slice_image<I>::operator slice_image<const I>() const
272  {
273  mln_precondition(this->is_valid());
274  slice_image<const I> tmp(this->data_->ima_,
275  this->data_->sli_);
276  return tmp;
277  }
278 
279 
280  // Routines.
281 
282  template <typename I>
283  inline
284  slice_image<I>
285  slice(Image<I>& ima_, def::coord sli)
286  {
287  mlc_equal(mln_domain(I), box3d)::check();
288 
289  I& ima = exact(ima_);
290  mln_precondition(ima.is_valid());
291  mln_precondition(sli >= ima.domain().pmin().sli() &&
292  sli <= ima.domain().pmax().sli());
293 
294  slice_image<I> tmp(ima, sli);
295  return tmp;
296  }
297 
298  template <typename I>
299  inline
300  slice_image<const I>
301  slice(const Image<I>& ima_, def::coord sli)
302  {
303  mlc_equal(mln_domain(I), box3d)::check();
304 
305  const I& ima = exact(ima_);
306  mln_precondition(ima.is_valid());
307  mln_precondition(sli >= ima.domain().pmin().sli() &&
308  sli <= ima.domain().pmax().sli());
309 
310  slice_image<const I> tmp(ima, sli);
311  return tmp;
312  }
313 
314 
315 # endif // ! MLN_INCLUDE_ONLY
316 
317 } // end of namespace mln
318 
319 
320 
321 #endif // ! MLN_CORE_IMAGE_DMORPH_SLICE_IMAGE_HH