$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
hexa.hh
1 // Copyright (C) 2007, 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_HEXA_HH
28 # define MLN_CORE_IMAGE_DMORPH_HEXA_HH
29 
30 
35 
36 # include <mln/core/internal/image_domain_morpher.hh>
37 # include <mln/core/alias/point2d_h.hh>
38 # include <mln/core/alias/box2d_h.hh>
39 # include <mln/core/image/dmorph/hexa_piter.hh>
40 
41 
42 namespace mln
43 {
44 
45  // Forward declaration.
46  template <typename I> struct hexa;
47 
48 
49  namespace internal
50  {
54  template <typename I>
55  struct data< hexa<I> >
56  {
57  data(I& ima, box2d_h b);
58 
59  I ima_;
60  mln::box2d_h b_;
61  };
62 
63  } // end of namespace mln::internal
64 
65 
66  namespace trait
67  {
71  template <typename I>
72  struct image_< hexa<I> > : default_image_morpher< I, mln_value(I),
73  hexa<I> >
74  {
75  // private:
76  // typedef mln_trait_image_data(I) I_data_;
77  // typedef mlc_equal(I_data_, trait::data::linear) I_data_are_linear_;
78  // public:
79 
80  typedef trait::image::category::domain_morpher category;
81 
82  typedef mln_trait_image_pw_io(I) pw_io; // un-write when I const
83  typedef mln_trait_image_dimension(I) dimension;
84 
85  // Extended domain
86  typedef mln_trait_image_ext_domain(I) ext_domain; // have a border only if I does.
87  typedef mln_trait_image_ext_value(I) ext_value;
88  typedef mln_trait_image_ext_io(I) ext_io; // un-write when I const
89 
90  // typedef mlc_if( I_data_are_linear_,
91  // trait::data::stored, // if linear then just stored
92  // I_data_ ) data; // otherwise like I
93  };
94 
95  } // end of namespace mln::trait
96 
97 
120  template <typename I>
121  struct hexa :
122  public internal::image_domain_morpher< I, box2d_h, hexa<I> >
123  {
126 
128  typedef mln_value(I) value;
129 
131  typedef mln_lvalue(I) lvalue;
132 
134  typedef mln_rvalue(I) rvalue;
135 
137  typedef point2d_h psite;
138 
142 
146 
147 
149  hexa();
150 
152  hexa(I& ima);
153 
156  void init_(I& ima);
158 
160  const box2d_h& domain() const;
161 
163  bool has(const psite& p) const;
164 
166  rvalue operator()(const point2d_h& p) const;
167 
169  lvalue operator()(const point2d_h& p);
170  };
171 
172 
174  template <typename I, typename J>
175  void init_(tag::image_t, hexa<I>& target, const J& model);
177 
178 # ifndef MLN_INCLUDE_ONLY
179 
180 
181  // init_
182 
183  template <typename I, typename J>
184  inline
185  void init_(tag::image_t, hexa<I>& target, const J& model)
186  {
187  I ima;
188  init_(tag::image, ima, model);
189  target.init_(ima);
190  }
191 
192 
193 
194  // internal::data< hexa<I> >
195 
196  namespace internal
197  {
198 
199  template <typename I>
200  inline
201  data< hexa<I> >::data(I& ima, box2d_h b)
202  : ima_(ima),
203  b_(b)
204  {
205  }
206 
207  } // end of namespace mln::internal
208 
209 
210  template <typename I>
211  inline
212  void
213  hexa<I>::init_(I& ima)
214  {
215  mln_precondition(! this->is_valid());
216  box2d b_in = ima.bbox();
217  box2d_h b = make::box2d_h(b_in.pmin()[0] * 2, b_in.pmin()[1],
218  b_in.pmax()[0] * 2, (b_in.pmax()[1] + 1) * 2 - 1);
219  this->data_ = new internal::data< hexa<I> >(ima, b);
220  }
221 
222 
223  template <typename I>
224  inline
225  hexa<I>::hexa()
226  {
227  }
228 
229 
230  template <typename I>
231  inline
232  hexa<I>::hexa(I& ima)
233  {
234  this->init_(ima);
235  }
236 
237  template <typename I>
238  inline
239  typename hexa<I>::rvalue
240  hexa<I>::operator()(const point2d_h& p) const
241  {
242  mln_precondition(this->is_valid());
243  mln_precondition(this->has(p));
244  return this->data_->ima_(point2d(p[0] / 2, p[1] / 2));
245  }
246 
247  template <typename I>
248  inline
249  typename hexa<I>::lvalue
250  hexa<I>::operator()(const point2d_h& p)
251  {
252  mln_precondition(this->is_valid());
253  mln_precondition(this->has(p));
254  return this->data_->ima_(point2d(p[0] / 2, p[1] / 2));
255  }
256 
257  template <typename I>
258  inline
259  const box2d_h&
260  hexa<I>::domain() const
261  {
262  mln_precondition(this->is_valid());
263  return this->data_->b_;
264  }
265 
266  template <typename I>
267  inline
268  bool
269  hexa<I>::has(const psite& p) const
270  {
271  mln_precondition(this->is_valid());
272  return this->data_->ima_.has(point2d(p[0] / 2, p[1] / 2));
273  }
274 
275 
276 # endif // ! MLN_INCLUDE_ONLY
277 
278 } // end of namespace mln
279 
280 
281 #endif // ! MLN_CORE_IMAGE_DMORPH_HEXA_HH