Milena (Olena)  User documentation 2.0a Id
 All Classes Namespaces Functions Variables Typedefs Enumerator Groups Pages
core/pixel.hh
1 // Copyright (C) 2007, 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_PIXEL_HH
27 # define MLN_CORE_PIXEL_HH
28 
36 
37 # include <mln/core/concept/generalized_pixel.hh>
38 # include <mln/core/internal/pixel_impl.hh>
39 
40 
41 namespace mln
42 {
43 
44 
49  template <typename I>
50  struct pixel : public Object< pixel<I> >,
51  public Generalized_Pixel< pixel<I> >,
52  internal::pixel_impl_< I, pixel<I> >
53  {
55  pixel(I& image);
56 
58  pixel(I& image, const mln_psite(I)& p);
59 
61  void change_to(const mln_psite(I)& p);
62 
64  bool is_valid() const;
65 
66  private:
67  typedef internal::pixel_impl_<I, pixel<I> > super;
68  };
69 
70 
71 # ifndef MLN_INCLUDE_ONLY
72 
73  template <typename I>
74  inline
75  pixel<I>::pixel(I& image)
76  : super(image)
77  {
78  }
79 
80  template <typename I>
81  inline
82  pixel<I>::pixel(I& image, const mln_psite(I)& p)
83  : super(image)
84  {
85  mln_precondition(this->image_.has(p));
86  change_to(p);
87  }
88 
89  template <typename I>
90  inline
91  void
92  pixel<I>::change_to(const mln_psite(I)& p)
93  {
94  mln_precondition(this->image_.has(p));
95  this->value_ptr_ = & this->image_(p);
96  }
97 
98  template <typename I>
99  inline
100  bool
102  {
103  if (this->value_ptr_ == 0 || ! this->image_.is_valid())
104  return false;
105  int o = this->value_ptr_ - this->image_.buffer();
106  mln_psite(I) p = this->image_.point_at_index(o);
107  return this->image_.has(p);
108  }
109 
110 # endif // ! MLN_INCLUDE_ONLY
111 
112 } // end of namespace mln
113 
114 
115 # include <mln/make/pixel.hh>
116 
117 
118 #endif // ! MLN_CORE_PIXEL_HH