$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
cast_image.hh
1 // Copyright (C) 2007, 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_VMORPH_CAST_IMAGE_HH
28 # define MLN_CORE_IMAGE_VMORPH_CAST_IMAGE_HH
29 
36 
37 # include <mln/core/internal/image_value_morpher.hh>
38 # include <mln/value/set.hh>
39 # include <mln/value/cast.hh>
40 
41 
42 namespace mln
43 {
44 
45  // Fwd decl.
46  template <typename T, typename I> struct cast_image_;
47 
48 
49  namespace internal
50  {
54  template <typename T, typename I>
55  struct data< cast_image_<T,I> >
56  {
57  data(const I& ima);
58  const I& ima_;
59  };
60 
61  } // end of namespace mln::internal
62 
63 
64 
65  namespace trait
66  {
67 
68  template <typename T, typename I, typename value_io>
70  default_image_morpher< I, T, cast_image_<T,I> >
71  {
72  typedef trait::image::vw_io::none vw_io;
73  typedef trait::image::vw_set::none vw_set;
74  };
75 
76  template <typename T, typename I>
77  struct cast_image_trait_selector<T, I, trait::image::vw_io::read> :
78  default_image_morpher< I, T, cast_image_<T,I> >
79  {
80  typedef trait::image::vw_io::read vw_io;
81  };
82 
83  template <typename T, typename I>
84  struct cast_image_trait_selector<T, I, trait::image::vw_io::read_write> :
85  default_image_morpher< I, T, cast_image_<T,I> >
86  {
87  typedef trait::image::vw_io::read vw_io;
88  };
89 
90  template <typename T, typename I>
91  struct image_< cast_image_<T,I> > :
92  cast_image_trait_selector<T, I, mln_trait_image_vw_io(I)>
93  {
94  private:
95  typedef mlc_equal(mln_trait_value_quant(T),
96  trait::value::quant::high) is_high_quant_;
97  public:
98  typedef mlc_if(is_high_quant_,
99  trait::image::quant::high,
100  trait::image::quant::low) quant;
101 
102  typedef trait::image::category::value_morpher category;
103  typedef trait::image::value_io::read_only value_io;
104  typedef trait::image::pw_io::read pw_io;
105  typedef trait::image::value_access::indirect value_access;
106 
108  typedef trait::image::ext_domain::none ext_domain;
109  };
110 
111  } // end of namespace mln::trait
112 
113 
114 
119  template <typename T, typename I>
120  struct cast_image_ :
121  public internal::image_value_morpher< I, T, cast_image_<T,I> >
122  {
124  typedef T value;
125 
127  typedef T rvalue;
128 
130  typedef T lvalue;
131 
133  typedef cast_image_< tag::value_<T>, tag::image_<I> > skeleton;
134 
136  cast_image_(const Image<I>& ima);
137 
140  void init_(const Image<I>& ima);
142 
144  T operator()(const mln_psite(I)& p) const;
145 
147  T operator()(const mln_psite(I)& p);
148  };
149 
150 
151  template <typename T, typename I>
153  cast_image(const Image<I>& ima)
154  {
155  mln_precondition(exact(ima).is_valid());
156  cast_image_<T,I> tmp(ima);
157  return tmp;
158  }
159 
160 
161 # ifndef MLN_INCLUDE_ONLY
162 
163 
164  // internal::data< cast_image_<T,I> >
165 
166  namespace internal
167  {
168 
169  template <typename T, typename I>
170  inline
171  data< cast_image_<T,I> >::data(const I& ima)
172  : ima_(ima)
173  {
174  }
175 
176  } // end of namespace mln::internal
177 
178  // cast_image_<T,I>
179 
180  template <typename T, typename I>
181  inline
182  cast_image_<T,I>::cast_image_(const Image<I>& ima)
183  {
184  mln_precondition(exact(ima).is_valid());
185  this->data_ = new internal::data< cast_image_<T,I> >(exact(ima));
186  }
187 
188  template <typename T, typename I>
189  inline
190  void
191  cast_image_<T,I>::init_(const Image<I>& ima)
192  {
193  mln_precondition(exact(ima).is_valid());
194  this->data_ = new internal::data<cast_image_<T,I> >(exact(ima));
195  }
196 
197  template <typename T, typename I>
198  inline
199  T
200  cast_image_<T,I>::operator()(const mln_psite(I)& p) const
201  {
202  mln_precondition(this->data_->ima_.has(p));
203  return mln::value::cast<T>( this->data_->ima_(p) );
204  }
205 
206  template <typename T, typename I>
207  inline
208  T
209  cast_image_<T,I>::operator()(const mln_psite(I)& p)
210  {
211  return mln::value::cast<T>( this->data_->ima_(p) );
212  }
213 
214 # endif // ! MLN_INCLUDE_ONLY
215 
216 } // end of namespace mln
217 
218 
219 #endif // ! MLN_CORE_IMAGE_VMORPH_CAST_IMAGE_HH