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