$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
image_if.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_IMAGE_DMORPH_IMAGE_IF_HH
28 # define MLN_CORE_IMAGE_DMORPH_IMAGE_IF_HH
29 
34 
35 # include <mln/core/internal/image_domain_morpher.hh>
36 # include <mln/core/site_set/p_if.hh>
37 # include <mln/pw/all.hh>
38 # include <mln/convert/to_fun.hh>
39 
40 
41 namespace mln
42 {
43 
44  // Forward declaration.
45  template <typename I, typename F> struct image_if;
46 
47 
48  namespace internal
49  {
50 
54  template <typename I, typename F>
55  struct data< image_if<I,F> >
56  {
57  data(I& ima, const F& f);
58 
59  I ima_;
60  p_if<mln_domain(I), F> domain_;
61  };
62 
63  } // end of namespace mln::internal
64 
65 
66  namespace trait
67  {
68 
69  template <typename I, typename F>
70  struct image_< image_if<I,F> > : default_image_morpher< I,
71  mln_value(I),
72  image_if<I,F> >
73  {
74  typedef trait::image::category::domain_morpher category;
75 
76  typedef trait::image::ext_domain::none ext_domain; // No extension of domain.
77  typedef trait::image::ext_value::irrelevant ext_value;
78  typedef trait::image::ext_io::irrelevant ext_io;
79 
80  typedef trait::image::vw_io::none vw_io;
81  typedef trait::image::vw_set::none vw_set;
82  typedef trait::image::value_alignment::not_aligned value_alignment;
83  typedef trait::image::value_storage::disrupted value_storage;
84  };
85 
86  } // end of namespace mln::trait
87 
88 
89 
94  //
95  template <typename I, typename F>
97  p_if<mln_domain(I), F>,
98  image_if<I, F> >
99  {
101  typedef image_if< tag::image_<I>, tag::function_<F> > skeleton;
102 
104  image_if();
105 
107  image_if(I& ima, const F& f);
108 
110  void init_(I& ima, const F& f);
112 
114  const p_if<mln_domain(I), F>& domain() const;
115 
117  operator image_if<const I, F>() const;
118  };
119 
120 
121 
122  // Operators.
123 
124 
125  // Image | Function_v2b.
126 
129  //
130  template <typename I, typename F>
132  operator | (Image<I>& ima, const Function_v2b<F>& f);
133 
136  //
137  template <typename I, typename F>
139  operator | (const Image<I>& ima, const Function_v2b<F>& f);
140 
141 
142 
143  template <typename I, typename A>
145  operator | (const Image<I>& ima, bool (*f)(A) );
146 
147  template <typename I, typename A>
149  operator | (Image<I>& ima, bool (*f)(A) );
150 
151 
152 
153 # ifndef MLN_INCLUDE_ONLY
154 
155  // init_.
156 
157  template <typename I, typename F>
158  void init_(tag::function_t, F& f, const image_if<I,F>& model)
159  {
160  f = model.domain().predicate();
161  }
162 
163  template <typename I, typename F, typename J>
164  void init_(tag::image_t, image_if<I,F>& target, const J& model)
165  {
166  I ima;
167  init_(tag::image, ima, exact(model));
168  F f;
169  init_(tag::function, f, exact(model));
170  target.init_(ima, f);
171  }
172 
173  // internal::data< image_if<I,F> >
174 
175  namespace internal
176  {
177 
178  template <typename I, typename F>
179  inline
180  data< image_if<I,F> >::data(I& ima, const F& f)
181  : ima_(ima),
182  domain_(ima.domain() | f)
183  {
184  }
185 
186  }
187 
188 
189  // image_if<I,F>
190 
191  template <typename I, typename F>
192  inline
193  image_if<I,F>::image_if()
194  {
195  }
196 
197  template <typename I, typename F>
198  inline
199  image_if<I,F>::image_if(I& ima, const F& f)
200  {
201  init_(ima, f);
202  }
203 
204  template <typename I, typename F>
205  inline
206  void
207  image_if<I,F>::init_(I& ima, const F& f)
208  {
209  mln_precondition(! this->is_valid());
210  this->data_ = new internal::data< image_if<I,F> >(ima, f);
211  }
212 
213  template <typename I, typename F>
214  inline
215  const p_if<mln_domain(I), F>&
216  image_if<I,F>::domain() const
217  {
218  mln_precondition(this->is_valid());
219  return this->data_->domain_;
220  }
221 
222  template <typename I, typename F>
223  inline
224  image_if<I,F>::operator image_if<const I,F>() const
225  {
226  mln_precondition(this->is_valid());
227  image_if<const I,F> tmp(this->data_->ima_,
228  this->data_->domain_.predicate());
229  return tmp;
230  }
231 
232 
233  // Operators.
234 
235  template <typename I, typename F>
236  inline
237  image_if<I,F>
238  operator | (Image<I>& ima, const Function_v2b<F>& f)
239  {
240  image_if<I,F> tmp(exact(ima), exact(f));
241  return tmp;
242  }
243 
244  template <typename I, typename F>
245  inline
246  image_if<const I, F>
247  operator | (const Image<I>& ima, const Function_v2b<F>& f)
248  {
249  image_if<const I, F> tmp(exact(ima), exact(f));
250  return tmp;
251  }
252 
253 
254  template <typename I, typename A>
255  image_if< const I, fun::C<bool(*)(A)> >
256  operator | (const Image<I>& ima, bool (*f)(A) )
257  {
258  return exact(ima) | convert::to_fun(f);
259  }
260 
261  template <typename I, typename A>
262  image_if< I, fun::C<bool(*)(A)> >
263  operator | (Image<I>& ima, bool (*f)(A) )
264  {
265  return exact(ima) | convert::to_fun(f);
266  }
267 
268 
269 # endif // ! MLN_INCLUDE_ONLY
270 
271 } // end of namespace mln
272 
273 
274 #endif // ! MLN_CORE_IMAGE_DMORPH_IMAGE_IF_HH