$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
x2x/translation.hh
1 // Copyright (C) 2007, 2008, 2009 EPITA Research and Development Laboratory (LRDE)
2 //
3 // This file is part of Olena.
4 //
5 // Olena is free software: you can redistribute it and/or modify it under
6 // the terms of the GNU General Public License as published by the Free
7 // Software Foundation, version 2 of the License.
8 //
9 // Olena is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with Olena. If not, see <http://www.gnu.org/licenses/>.
16 //
17 // As a special exception, you may use this file as part of a free
18 // software project without restriction. Specifically, if other files
19 // instantiate templates or use macros or inline functions from this
20 // file, or you compile this file and link it with other files to produce
21 // an executable, this file does not by itself cause the resulting
22 // executable to be covered by the GNU General Public License. This
23 // exception does not however invalidate any other reasons why the
24 // executable file might be covered by the GNU General Public License.
25 
26 #ifndef MLN_FUN_X2X_TRANSLATION_HH
27 # define MLN_FUN_X2X_TRANSLATION_HH
28 
32 
33 # include <mln/core/concept/function.hh>
34 # include <mln/fun/internal/x2x_linear_impl.hh>
35 # include <mln/algebra/vec.hh>
36 # include <mln/algebra/h_mat.hh>
37 # include <mln/fun/i2v/all.hh>
38 
39 
40 namespace mln
41 {
42 
43  namespace fun
44  {
45 
46  namespace x2x
47  {
48 
50  //
51  template <unsigned n, typename C>
52  struct translation
53  :
54  fun::internal::x2x_linear_impl_< algebra::vec<n,C>, C,
55  translation<n,C> >,
56  public Function_v2v< translation<n,C> >
57  {
59  typedef C data_t;
60 
64  invert inv() const;
65 
67  translation();
70 
74 
75 
77  void set_t(const algebra::vec<n,C>& t);
78 
80  const algebra::vec<n,C>& t() const;
81 
82  protected:
83  void update();
84 
86  };
87 
88 
89 # ifndef MLN_INCLUDE_ONLY
90 
91  template <unsigned n, typename C>
92  inline
94  {
95  }
96 
97  template <unsigned n, typename C>
98  inline
100  :t_(t)
101  {
102  this->update();
103  }
104 
105  template <unsigned n, typename C>
106  inline
109  {
110  return v + t_;
111  }
112 
113  template <unsigned n, typename C>
114  inline
115  algebra::vec<n,C>
116  translation<n,C>::inverse(const algebra::vec<n,C>& v) const
117  {
118  return v - t_;
119  }
120 
121  template <unsigned n, typename C>
122  inline
123  translation<n,C>
124  translation<n,C>::inv() const
125  {
126  typename translation::invert res(-t_);
127 
128  return res;
129  }
130 
131  template <unsigned n, typename C>
132  inline
133  void
134  translation<n,C>::set_t(const algebra::vec<n,C>& t)
135  {
136  this->t_ = t;
137  this->update();
138  }
139 
140  template <unsigned n, typename C>
141  inline
142  const algebra::vec<n,C>&
143  translation<n,C>::t() const
144  {
145  return this->t_;
146  }
147 
148  template <unsigned n, typename C>
149  inline
150  void
152  {
153  this->m_ = algebra::h_mat<n,C>::Id;
154  for (unsigned i = 0; i < n; ++i)
155  this->m_(i,n) = this->t_[i];
156  }
157 
158 # endif // ! MLN_INCLUDE_ONLY
159 
160 
161  } // end of namespace mln::fun::x2x
162 
163  } // end of namespace mln::fun
164 
165 } // end of namespace mln
166 
167 
168 #endif // ! MLN_FUN_X2X_TRANSLATION_HH