Milena (Olena)  User documentation 2.0a Id
 All Classes Namespaces Functions Variables Typedefs Enumerator Groups Pages
hexa.hh
1 // Copyright (C) 2007, 2008, 2009, 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_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  {
52  template <typename I>
53  struct data< hexa<I> >
54  {
55  data(I& ima, box2d_h b);
56 
57  I ima_;
58  mln::box2d_h b_;
59  };
60 
61  } // end of namespace mln::internal
62 
63 
64  namespace trait
65  {
67  template <typename I>
68  struct image_< hexa<I> > : default_image_morpher< I, mln_value(I),
69  hexa<I> >
70  {
71  // private:
72  // typedef mln_trait_image_data(I) I_data_;
73  // typedef mlc_equal(I_data_, trait::data::linear) I_data_are_linear_;
74  // public:
75 
76  typedef trait::image::category::domain_morpher category;
77 
78  typedef mln_trait_image_pw_io(I) pw_io; // un-write when I const
79  typedef mln_trait_image_dimension(I) dimension;
80 
81  // Extended domain
82  typedef mln_trait_image_ext_domain(I) ext_domain; // have a border only if I does.
83  typedef mln_trait_image_ext_value(I) ext_value;
84  typedef mln_trait_image_ext_io(I) ext_io; // un-write when I const
85 
86  // typedef mlc_if( I_data_are_linear_,
87  // trait::data::stored, // if linear then just stored
88  // I_data_ ) data; // otherwise like I
89  };
90 
91  } // end of namespace mln::trait
92 
93 
116  template <typename I>
117  struct hexa :
118  public internal::image_domain_morpher< I, box2d_h, hexa<I> >
119  {
122 
124  typedef mln_value(I) value;
125 
127  typedef mln_lvalue(I) lvalue;
128 
130  typedef mln_rvalue(I) rvalue;
131 
133  typedef point2d_h psite;
134 
137  typedef hexa_fwd_piter_<box2d> fwd_piter;
138 
141  typedef hexa_bkd_piter_<box2d> bkd_piter;
142 
143 
145  hexa();
146 
148  hexa(I& ima);
149 
151  void init_(I& ima);
152 
154  const box2d_h& domain() const;
155 
157  bool has(const psite& p) const;
158 
160  rvalue operator()(const point2d_h& p) const;
161 
163  lvalue operator()(const point2d_h& p);
164  };
165 
166  template <typename I, typename J>
167  void init_(tag::image_t, hexa<I>& target, const J& model);
168 
169 # ifndef MLN_INCLUDE_ONLY
170 
171 
172  // init_
173 
174  template <typename I, typename J>
175  inline
176  void init_(tag::image_t, hexa<I>& target, const J& model)
177  {
178  I ima;
179  init_(tag::image, ima, model);
180  target.init_(ima);
181  }
182 
183 
184 
185  // internal::data< hexa<I> >
186 
187  namespace internal
188  {
189 
190  template <typename I>
191  inline
192  data< hexa<I> >::data(I& ima, box2d_h b)
193  : ima_(ima),
194  b_(b)
195  {
196  }
197 
198  } // end of namespace mln::internal
199 
200 
201  template <typename I>
202  inline
203  void
204  hexa<I>::init_(I& ima)
205  {
206  mln_precondition(! this->is_valid());
207  box2d b_in = ima.bbox();
208  box2d_h b = make::box2d_h(b_in.pmin()[0] * 2, b_in.pmin()[1],
209  b_in.pmax()[0] * 2, (b_in.pmax()[1] + 1) * 2 - 1);
210  this->data_ = new internal::data< hexa<I> >(ima, b);
211  }
212 
213 
214  template <typename I>
215  inline
217  {
218  }
219 
220 
221  template <typename I>
222  inline
224  {
225  this->init_(ima);
226  }
227 
228  template <typename I>
229  inline
230  typename hexa<I>::rvalue
232  {
233  mln_precondition(this->is_valid());
234  mln_precondition(this->has(p));
235  return this->data_->ima_(point2d(p[0] / 2, p[1] / 2));
236  }
237 
238  template <typename I>
239  inline
240  typename hexa<I>::lvalue
242  {
243  mln_precondition(this->is_valid());
244  mln_precondition(this->has(p));
245  return this->data_->ima_(point2d(p[0] / 2, p[1] / 2));
246  }
247 
248  template <typename I>
249  inline
250  const box2d_h&
252  {
253  mln_precondition(this->is_valid());
254  return this->data_->b_;
255  }
256 
257  template <typename I>
258  inline
259  bool
260  hexa<I>::has(const psite& p) const
261  {
262  mln_precondition(this->is_valid());
263  return this->data_->ima_.has(point2d(p[0] / 2, p[1] / 2));
264  }
265 
266 
267 # endif // ! MLN_INCLUDE_ONLY
268 
269 } // end of namespace mln
270 
271 
272 #endif // ! MLN_CORE_IMAGE_DMORPH_HEXA_HH