Milena (Olena)  User documentation 2.0a Id
 All Classes Namespaces Functions Variables Typedefs Enumerator Groups Pages
sub_image.hh
1 // Copyright (C) 2007, 2008, 2009, 2010, 2011 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_HH
28 # define MLN_CORE_IMAGE_DMORPH_SUB_IMAGE_HH
29 
37 
38 # include <mln/core/internal/image_domain_morpher.hh>
39 
40 
41 
42 namespace mln
43 {
44 
45 
46  // Forward declaration.
47  template <typename I, typename S> class sub_image;
48 
49 
50  namespace internal
51  {
52 
54  template <typename I, typename S>
55  struct data< sub_image<I,S> >
56  {
57  data(const I& ima, const S& pset);
58 
59  I ima_;
60  S domain_;
61  };
62 
63  } // end of namespace mln::internal
64 
65 
66 
67  namespace trait
68  {
69 
70  template <typename I, typename S>
71  struct image_< sub_image<I,S> > : default_image_morpher< I,
72  mln_value(I),
73  sub_image<I,S> >
74  {
75 // private:
76 // typedef mln_trait_image_data(I) I_data_;
77 // typedef mlc_equal(I_data_, trait::data::linear) I_data_are_linear_;
78 // public:
79 
80  typedef trait::image::category::domain_morpher category;
81 
82  typedef trait::image::ext_domain::none ext_domain; // No extension of domain.
83  typedef trait::image::ext_value::irrelevant ext_value;
84  typedef trait::image::ext_io::irrelevant ext_io;
85 
86  typedef trait::image::vw_io::none vw_io;
87  typedef trait::image::vw_set::none vw_set;
88  typedef trait::image::value_alignment::not_aligned value_alignment;
89  typedef trait::image::value_storage::disrupted value_storage;
90  // HOT FIXME: except if S is a Box
91  };
92 
93  } // end of namespace mln::trait
94 
95 
96 
100  //
101  template <typename I, typename S>
102  class sub_image : public internal::image_domain_morpher< I,
103  S,
104  sub_image<I,S> >
105  {
106  public:
108  typedef sub_image< tag::image_<I>, tag::domain_<S> > skeleton;
109 
111  sub_image();
112 
114  sub_image(const I& ima, const S& pset);
115 
117  void init_(const I& ima, const S& pset);
118 
120  const S& domain() const;
121 
123  operator sub_image<const I, S>() const;
124  };
125 
126 
127 
128 
129 
130  template <typename I, typename S>
132  operator|(const Image<I>& ima, const Site_Set<S>& pset);
133 
134 
135  template <typename I, typename S>
137  operator|(Image<I>& ima, const Site_Set<S>& pset);
138 
139 
140 
141  template <typename I, typename S, typename J>
142  void init_(tag::image_t, sub_image<I,S>& target, const J& model);
143 
144 
145 
146 # ifndef MLN_INCLUDE_ONLY
147 
148  // init_
149 
150  template <typename I, typename S, typename J>
151  inline
152  void init_(tag::image_t, sub_image<I,S>& target, const J& model)
153  {
154  I ima;
155  init_(tag::image, ima, model);
156  S pset;
157  init_(tag::domain, pset, model);
158  target.init_(ima, pset);
159  }
160 
161 
162  // internal::data< sub_image<I,S> >
163 
164  namespace internal
165  {
166 
167  template <typename I, typename S>
168  inline
169  data< sub_image<I,S> >::data(const I& ima, const S& pset)
170  : ima_(ima),
171  domain_(pset)
172  {
173  }
174 
175  } // end of namespace mln::internal
176 
177 
178  // sub_image<I,S>
179 
180  template <typename I, typename S>
181  inline
183  {
184  }
185 
186  template <typename I, typename S>
187  inline
188  sub_image<I,S>::sub_image(const I& ima, const S& pset)
189  {
190  init_(ima, pset);
191  }
192 
193  template <typename I, typename S>
194  inline
195  void
196  sub_image<I,S>::init_(const I& ima, const S& pset)
197  {
198  mln_precondition(! this->is_valid());
199  this->data_ = new internal::data< sub_image<I,S> >(ima, pset);
200  }
201 
202  template <typename I, typename S>
203  inline
204  const S&
206  {
207  return this->data_->domain_;
208  }
209 
210  template <typename I, typename S>
211  inline
213  {
214  sub_image<const I, S> tmp(this->data_->ima_,
215  this->data_->domain_);
216  return tmp;
217  }
218 
219 
220  // Operators.
221 
222  template <typename I, typename S>
223  inline
225  operator|(const Image<I>& ima, const Site_Set<S>& pset)
226  {
227  sub_image<const I, S> tmp(exact(ima), exact(pset));
228  return tmp;
229  }
230 
231  template <typename I, typename S>
232  inline
233  sub_image<I, S>
234  operator|(Image<I>& ima, const Site_Set<S>& pset)
235  {
236  sub_image<I, S> tmp(exact(ima), exact(pset));
237  return tmp;
238  }
239 
240 # endif // ! MLN_INCLUDE_ONLY
241 
242 } // end of namespace mln
243 
244 
245 #endif // ! MLN_CORE_IMAGE_DMORPH_SUB_IMAGE_HH