$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
sub_image_if.hh
1 // Copyright (C) 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_DMORPH_SUB_IMAGE_IF_HH
28 # define MLN_CORE_IMAGE_DMORPH_SUB_IMAGE_IF_HH
29 
30 
36 
37 
38 # include <mln/core/internal/image_domain_morpher.hh>
39 # include <mln/core/site_set/p_if.hh>
40 # include <mln/fun/p2b/has.hh>
41 
42 # include <mln/debug/println.hh>
43 
44 
45 namespace mln
46 {
47 
48 
49  // Forward declaration.
50  template <typename I, typename S> struct sub_image_if;
51 
52 
53  namespace internal
54  {
55 
60  template <typename I, typename S>
61  struct data< sub_image_if<I,S> >
62  {
63  data(I& ima, const S& s);
64 
65  I ima_;
66  p_if< S, fun::p2b::has<I> > s_;
67  };
68 
69  } // end of namespace mln::internal
70 
71 
72 
73  namespace trait
74  {
75 
76  template <typename I, typename S>
77  struct image_< sub_image_if<I,S> > : default_image_morpher< I,
78  mln_value(I),
79  sub_image_if<I,S> >
80  {
81 // private:
82 // typedef mln_trait_image_data(I) I_data_;
83 // typedef mlc_equal(I_data_, trait::data::linear) I_data_are_linear_;
84 // public:
85 
86  typedef trait::image::category::domain_morpher category;
87 
88  typedef trait::image::ext_domain::none ext_domain; // No extension of domain.
89  typedef trait::image::ext_value::irrelevant ext_value;
90  typedef trait::image::ext_io::irrelevant ext_io;
91 
92  typedef trait::image::value_storage::disrupted value_storage;
93  // HOT FIXME: except if S is a Box
94  };
95 
96  } // end of namespace mln::trait
97 
98 
99 
103  //
104  template <typename I, typename S>
106  p_if< S, fun::p2b::has<I> >,
107  sub_image_if<I,S> >
108  {
110  typedef sub_image_if< tag::image_<I>, tag::domain_<S> > skeleton;
111 
113  sub_image_if();
114 
116  sub_image_if(I& ima, const S& s);
117 
120  void init_(I& ima, const S& s);
122 
124  const p_if< S, fun::p2b::has<I> >& domain() const;
125 
126 // /// Const promotion via conversion.
127 // operator sub_image_if<const I, S>() const;
128  };
129 
130 
131 
132 
133 
134  template <typename I, typename S>
136  operator / (const Image<I>& ima, const Site_Set<S>& s);
137 
138 
139  template <typename I, typename S>
141  operator / (Image<I>& ima, const Site_Set<S>& s);
142 
143 
145  template <typename I, typename S, typename J>
146  void init_(tag::image_t, sub_image_if<I,S>& target, const J& model);
148 
149 
150 
151 # ifndef MLN_INCLUDE_ONLY
152 
153  // init_
154 
155  template <typename I, typename S, typename J>
156  inline
157  void init_(tag::image_t, sub_image_if<I,S>& target, const J& model)
158  {
159  I ima;
160  init_(tag::image, ima, model);
161  S s;
162  init_(tag::domain, s, model);
163  target.init_(ima, s);
164  }
165 
166 
167  // internal::data< sub_image_if<I,S> >
168 
169  namespace internal
170  {
171 
172  template <typename I, typename S>
173  inline
174  data< sub_image_if<I,S> >::data(I& ima, const S& s)
175  : ima_(ima)
176  {
177  typedef fun::p2b::has<I> F;
178  F f(ima);
179  s_ = p_if<S,F>(s, f);
180  }
181 
182  } // end of namespace mln::internal
183 
184 
185  // sub_image_if<I,S>
186 
187  template <typename I, typename S>
188  inline
189  sub_image_if<I,S>::sub_image_if()
190  {
191  }
192 
193  template <typename I, typename S>
194  inline
195  sub_image_if<I,S>::sub_image_if(I& ima, const S& s)
196  {
197  init_(ima, s);
198  }
199 
200  template <typename I, typename S>
201  inline
202  void
203  sub_image_if<I,S>::init_(I& ima, const S& s)
204  {
205  mln_precondition(! this->is_valid());
206  this->data_ = new internal::data< sub_image_if<I,S> >(ima, s);
207  }
208 
209  template <typename I, typename S>
210  inline
211  const p_if< S, fun::p2b::has<I> >&
212  sub_image_if<I,S>::domain() const
213  {
214  return this->data_->s_;
215  }
216 
217 // template <typename I, typename S>
218 // inline
219 // sub_image_if<I,S>::operator sub_image_if<const I, S>() const
220 // {
221 // sub_image_if<const I, S> tmp(this->data_->ima_,
222 // this->data_->s_);
223 // return tmp;
224 // }
225 
226 
227  // Operators.
228 
229  template <typename I, typename S>
230  inline
231  sub_image_if<const I, S>
232  operator / (const Image<I>& ima, const Site_Set<S>& s)
233  {
234  // FIXME: mln_precondition(set::inter(ima.domain(), s) != 0);
235  sub_image_if<const I, S> tmp(exact(ima), exact(s));
236  return tmp;
237  }
238 
239  template <typename I, typename S>
240  inline
241  sub_image_if<I, S>
242  operator / (Image<I>& ima, const Site_Set<S>& s)
243  {
244  // FIXME: mln_precondition(set::inter(ima.domain(), s) != 0);
245  sub_image_if<I, S> tmp(exact(ima), exact(s));
246  return tmp;
247  }
248 
249 # endif // ! MLN_INCLUDE_ONLY
250 
251 } // end of namespace mln
252 
253 
254 #endif // ! MLN_CORE_IMAGE_DMORPH_SUB_IMAGE_IF_HH