$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
make/h_mat.hh
1 // Copyright (C) 2009, 2012 EPITA Research and Development Laboratory
2 // (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_MAKE_H_MAT_HH
28 # define MLN_MAKE_H_MAT_HH
29 
33 
34 # include <mln/algebra/h_mat.hh>
35 # include <mln/metal/math/sqrt.hh>
36 
37 
38 namespace mln
39 {
40 
41  namespace make
42  {
43 
44 
46  /*
47  * \param[in] tab C-array of values.
48  *
49  * \pre The array dimension N has to be square (N = n * n).
50  */
51  template <typename T, unsigned N>
52  algebra::h_mat<mlc_sqrt_int(N), T> h_mat(const T (&tab)[N]);
53 
54 
61  template <typename C>
62  algebra::h_mat<3, C> h_mat(const C& v, const algebra::quat& q);
63 
64 # ifndef MLN_INCLUDE_ONLY
65 
66  template <typename T, unsigned N>
67  inline
68  algebra::h_mat<mlc_sqrt_int(N), T>
69  h_mat(const T (&tab)[N])
70  {
71  enum { n = mlc_sqrt_int(N) };
72  mlc_bool(N == n * n)::check();
73  algebra::h_mat<n,T> tmp;
74  for (unsigned i = 0; i < N; ++i)
75  tmp(i / n, i % n) = tab[i];
76  return tmp;
77  }
78 
79 
80  template <typename C>
81  inline
82  algebra::h_mat<3, C>
83  h_mat(const C& v, const algebra::quat& q)
84  {
85  mln_precondition(q.is_unit());
86  (void) v;
87 
88  algebra::h_mat<3, C> m;
89  C
90  w = q.to_vec()[0],
91  x = q.to_vec()[1], x2 = 2*x*x, xw = 2*x*w,
92  y = q.to_vec()[2], y2 = 2*y*y, xy = 2*x*y, yw = 2*y*w,
93  z = q.to_vec()[3], z2 = 2*z*z, xz = 2*x*z, yz = 2*y*z, zw = 2*z*w;
94 
95  C t[9] = {1.f - y2 - z2, xy - zw, xz + yw,
96  xy + zw, 1.f - x2 - z2, yz - xw,
97  xz - yw, yz + xw, 1.f - x2 - y2};
98 
99  m = mln::make::h_mat(t);
100  return m;
101  }
102 
103 
104 # endif // ! MLN_INCLUDE_ONLY
105 
106  } // end of namespace mln::make
107 
108 } // end of namespace mln
109 
110 
111 #endif // ! MLN_MAKE_H_MAT_HH