$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
image_morpher.hh
1 // Copyright (C) 2007, 2008, 2009, 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_INTERNAL_IMAGE_MORPHER_HH
28 # define MLN_CORE_INTERNAL_IMAGE_MORPHER_HH
29 
35 
36 # include <mln/core/internal/image_base.hh>
37 # include <mln/metal/const.hh>
38 # include <mln/metal/is_const.hh>
39 # include <mln/metal/is_not_const.hh>
40 
41 
42 namespace mln
43 {
44 
45  namespace internal
46  {
47 
54  template <typename I, typename T, typename S, typename E>
55  class image_morpher : public image_base<T, S, E>
56  {
57  public:
58 
60  typedef I delegatee;
61 
64  mlc_const(I)* delegatee_() const;
65 
67  I* delegatee_();
69 
70 
72  typedef I unmorph;
73 
76  I& unmorph_();
77 
79  mlc_const(I)& unmorph_() const;
81 
82  /* \brief Test if this image has been initialized; default impl.
83  *
84  * This default impl is stronger than the one inherited from
85  * image_base because it also tests that the morphed image is
86  * also initialized.
87  */
88  bool is_valid() const;
89 
90 
93  E& rw();
94 
95 
96  protected:
97  image_morpher();
98  };
99 
100  } // end of namespace mln::internal
101 
102 
103 
104  namespace impl
105  {
106 
107  // Default is delegation for morphers.
108 
109 // template <typename Subject, typename T,
110 // typename I, typename S, typename E>
111 // void init_(Subject s, T& target,
112 // const internal::image_morpher<I,S,E>& model);
113 
114 // FIXME: Lines above have been inactivated because they are either
115 // prioritary or ambiguous.
117  template <typename Subject, typename T,
118  typename J>
119  void init_(Subject s, T& target, const Image<J>& model);
121 
122  } // end of namespace mln::impl
123 
124 
125 
126 # ifndef MLN_INCLUDE_ONLY
127 
128  namespace internal
129  {
130 
131  template <typename I, typename T, typename S, typename E>
132  inline
134  {
135  }
136 
137  template <typename I, typename T, typename S, typename E>
138  inline
139  mlc_const(I)*
141  {
142  return this->data_ == 0 ? 0 : & this->data_->ima_;
143  }
144 
145  template <typename I, typename T, typename S, typename E>
146  inline
147  I*
149  {
150  return this->data_ == 0 ? 0 : & this->data_->ima_;
151  }
152 
153  template <typename I, typename T, typename S, typename E>
154  inline
155  I&
157  {
158  I* ptr = delegatee_();
159  mln_assertion(ptr != 0);
160  return *ptr;
161  }
162 
163  template <typename I, typename T, typename S, typename E>
164  inline
165  mlc_const(I)&
167  {
168  mlc_const(I)* ptr = delegatee_();
169  mln_assertion(ptr != 0);
170  return *ptr;
171  }
172 
173  template <typename I, typename T, typename S, typename E>
174  inline
175  bool
177  {
178  return
179  this->data_ != 0 &&
180  this->delegatee_() != 0 &&
181  this->delegatee_()->is_valid();
182  }
183 
184  template <typename I, typename T, typename S, typename E>
185  inline
186  E&
188  {
189  mlc_is_not_const(I)::check();
190  mlc_equal(mln_trait_image_value_io(I),
191  mln::trait::image::value_io::read_write)::check();
192  // FIXME Nicolas: pw_io == read_write OR vw_io == read_write...
193  return exact(*this);
194  }
195 
196  } // end of namespace mln::internal
197 
198 
199 
200 // template <typename Subject, typename T,
201 // typename I, typename S, typename E>
202 // void init_(Subject s, T& target,
203 // const internal::image_morpher<I,S,E>& model)
204 // {
205 // // FIXME: Precondition.
206 // init_(s, target, * model.delegatee_());
207 // }
208 
209  template <typename Subject, typename T,
210  typename J>
211  inline
212  void init_(Subject s, T& target, const Image<J>& model_)
213  {
214  mlc_is(mln_trait_image_category(J),
215  trait::image::category::morpher)::check();
216  const J& model = exact(model_);
217  init_(s, target, * model.delegatee_());
218  }
219 
220 # endif // ! MLN_INCLUDE_ONLY
221 
222 } // end of namespace mln
223 
224 
225 #endif // ! MLN_CORE_INTERNAL_IMAGE_MORPHER_HH