$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
composed.hh
1 // Copyright (C) 2007, 2008, 2009, 2010, 2012 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_FUN_X2X_COMPOSED_HH
28 # define MLN_FUN_X2X_COMPOSED_HH
29 
33 
34 # include <mln/core/concept/function.hh>
35 # include <mln/fun/internal/x2x_linear_impl.hh>
36 # include <mln/algebra/vec.hh>
37 # include <mln/metal/is.hh>
38 # include <mln/metal/bexpr.hh>
39 # include <mln/algebra/h_mat.hh>
40 
41 
42 namespace mln
43 {
44 
45  namespace fun
46  {
47 
48  namespace x2x
49  {
50 
51  // Forward declaration.
52  template <typename T2, typename T1>
53  struct composed;
54 
55  namespace internal
56  {
57  template <typename T2, typename T1, typename E, bool is_bij>
58  struct helper_composed_;
59 
60 
65  template <typename T2, typename T1, typename E>
66  struct helper_composed_<T2,T1,E,true>
67  : public fun::internal::x2x_linear_impl_<mln_result(T2), typename T2::data_t, E >,
68  public Function_v2v<E>
69  {
71 
73  typedef typename T2::data_t data_t;
74 
75  using super_::dim;
76 
80  helper_composed_(const T2& f, const T1& g);
81 
82  using super_::operator();
83 
85  const T2& second() const;
87  const T1& first() const;
88 
90  void set_second(const T2& f);
92  void set_first(const T1& g);
93 
97  invert inv() const;
98 
99  //protected:
100 
101  T2 f_;
102  T1 g_;
103  };
104 
109  template <typename T2, typename T1, typename E>
110  struct helper_composed_<T2,T1,E,false>
111  : public fun::internal::x2x_linear_impl_<mln_result(T2), typename T2::data_t, E >,
112  public Function_v2v<E>
113  {
115 
116 
118  typedef typename T2::data_t data_t;
119 
120  using super_::dim;
121 
125  helper_composed_(const T2& f, const T1& g);
126 
127  using super_::operator();
128 
130  void set_second(const T2& f);
132  void set_first(const T1& g);
133 
135  const T2& second() const;
137  const T1& first() const;
138 
139  //protected:
140 
141  T2 f_;
142  T1 g_;
143  };
144 
145  } // end of namespace mln::fun::x2x::internal
146 
147 
149  template <typename T2, typename T1>
150  struct composed
151  : public internal::helper_composed_< T2, T1, composed<T2,T1>,
152  (mlc_is(T2, Function_v2v<T2>)::value &&
153  mlc_is(T1, Function_v2v<T1>)::value) >,
154  private metal::and_< metal::bool_<(T2::dim == T1::dim)>,
155  metal::is<mln_argument(T2), mln_result(T1)>
156  >::check_t
157  {
159  composed() {}
160 
162  composed(const T2& f, const T1& g)
163  : internal::helper_composed_< T2, T1, composed<T2,T1>,
164  (mlc_is(T2, Function_v2v<T2>)::value &&
165  mlc_is(T1, Function_v2v<T1>)::value) >(f, g)
166  {}
167  };
168 
169  } // end of namespace mln::fun::x2x
170 
171  } // end of namespace mln::fun
172 
173 
180  template <typename T2, typename T1>
181  fun::x2x::composed<T2,T1> compose(T2 f, T1 g);
182 
183 # ifndef MLN_INCLUDE_ONLY
184 
185  namespace fun
186  {
187 
188  namespace x2x
189  {
190 
191  namespace internal
192  {
193 
194  // Implementation of the bijective version.
195 
196  template <typename T2, typename T1, typename E>
197  inline
199  {
200  }
201 
202  template <typename T2, typename T1, typename E>
203  inline
204  helper_composed_<T2,T1,E,true>::helper_composed_(const T2& f, const T1& g)
205  :f_(f),
206  g_(g)
207  {
208  this->m_ = f_.mat() * g_.mat();
209  }
210 
211  template <typename T2, typename T1, typename E>
212  inline
215  {
216  return compose(g_.inv(), f_.inv());
217  }
218 
219  template <typename T2, typename T1, typename E>
220  inline
221  void
223  {
224  this->f_ = f;
225  this->m_ = this->f_.mat() * this->g_.mat();
226  }
227 
228  template <typename T2, typename T1, typename E>
229  inline
230  void
232  {
233  this->g_ = g;
234  this->m_ = this->f_.mat() * this->g_.mat();
235  }
236 
237  template <typename T2, typename T1, typename E>
238  inline
239  const T2&
241  {
242  return this->f_;
243  }
244 
245  template <typename T2, typename T1, typename E>
246  inline
247  const T1&
249  {
250  return this->g_;
251  }
252 
253  // Implementation of the non bijective version.
254  template <typename T2, typename T1, typename E>
255  inline
257  {
258  }
259 
260  template <typename T2, typename T1, typename E>
261  inline
262  helper_composed_<T2,T1,E,false>::helper_composed_(const T2& f, const T1& g)
263  :f_(f),
264  g_(g)
265  {
266  this->m_ = f_.mat() * g_.mat();
267  }
268 
269  template <typename T2, typename T1, typename E>
270  inline
271  void
273  {
274  this->f_ = f;
275  this->m_ = this->f_.mat() * this->g_.mat();
276  }
277 
278  template <typename T2, typename T1, typename E>
279  inline
280  void
282  {
283  this->g_ = g;
284  this->m_ = this->f_.mat() * this->g_.mat();
285  }
286 
287  template <typename T2, typename T1, typename E>
288  inline
289  const T2&
291  {
292  return this->f_;
293  }
294 
295  template <typename T2, typename T1, typename E>
296  inline
297  const T1&
299  {
300  return this->g_;
301  }
302 
303 
304  } // end of namespace mln::fun::x2x::internal
305 
306  } // end of namespace mln::fun::x2x
307 
308  } // end of namespace mln::fun
309 
310  template <typename T2, typename T1>
311  inline
312  fun::x2x::composed<T2,T1> compose(T2 f, T1 g)
313  {
314  mln_trace("fun::x2x::compose");
315  fun::x2x::composed<T2,T1> comp(f, g);
316  return comp;
317  }
318 
319 # endif // ! MLN_INCLUDE_ONLY
320 
321 } // end of namespace mln
322 
323 
324 #endif // ! MLN_FUN_X2X_COMPOSED_HH