$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
util/pix.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_UTIL_PIX_HH
27 # define MLN_UTIL_PIX_HH
28 
39 
40 # include <mln/core/concept/image.hh>
41 
42 
43 namespace mln
44 {
45 
47  namespace select
48  {
49 
51  template <typename P>
52  struct p_of : P
53  {
54  operator typename P::psite() const
55  {
56  return this->p();
57  }
58  };
59 
60  }
61 
62  namespace util
63  {
64 
68  template <typename I>
69  struct pix
70  {
71 
73  typedef mln_psite(I) psite;
74 
76  typedef mln_value(I) value;
77 
82  pix(const Image<I>& ima, const mln_psite(I)& p);
83 
87  const I& ima() const;
88 
92  const mln_psite(I)& p() const;
93 
97  mln_rvalue(I) v() const;
98 
99  private:
100 
102  const I& ima_;
103 
105  //
106  // FIXME: Do we want a reference here?
107  // I (Z) guess we don't since I got invalid values
108  // when converting a pixter to a util::pix.
109  // The automatic conversion creates a temporary psite which invalided
110  // this reference once it was destroyed. see 'operator util::pix()' in
111  // core/pixter2d.hh.
112  //
113  const mln_psite(I) p_;
114  };
115 
116 
117 # ifndef MLN_INCLUDE_ONLY
118 
119  template <typename I>
120  inline
121  pix<I>::pix(const Image<I>& ima, const mln_psite(I)& p)
122  : ima_(exact(ima)),
123  p_(p)
124  {
125  mln_postcondition(exact(ima).is_valid());
126  }
127 
128  template <typename I>
129  inline
130  const I&
131  pix<I>::ima() const
132  {
133  mln_precondition(ima_.is_valid());
134  return ima_;
135  }
136 
137  template <typename I>
138  inline
139  const mln_psite(I)&
140  pix<I>::p() const
141  {
142  mln_precondition(ima_.is_valid());
143  mln_precondition(ima_.has(p_));
144  return p_;
145  }
146 
147  template <typename I>
148  inline
149  mln_rvalue(I)
150  pix<I>::v() const
151  {
152  mln_precondition(ima_.is_valid());
153  mln_precondition(ima_.has(p_));
154  return ima_(p_);
155  }
156 
157 # endif // ! MLN_INCLUDE_ONLY
158 
159  } // end of namespace mln::util
160 
161 } // end of namespace mln
162 
163 
164 # include <mln/make/pix.hh>
165 
166 
167 #endif // ! MLN_UTIL_PIX_HH