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