aimstil  5.0.5
affineTransformTools.h
Go to the documentation of this file.
1 #ifndef TIL_AFFINETOOLS_H
2 #define TIL_AFFINETOOLS_H
3 
5 
6 // includes from STL
7 #include <cassert>
8 #include <iostream>
9 
10 
11 // Namespace
12 namespace til
13 {
14  //namespace linalg {
15 
17 template < typename T >
18 void computeAffineTransformBetween(const Box<T,3> & from, const Box<T,3> & to, Affine<T> & a)
19 {
20  assert(all_greater_equal(size(from), 128*std::numeric_limits<T>::epsilon()));
21 
22  numeric_array<T,3> diag = size(to) / size(from);
23  // TODO: create a function that initializes a matrix to a diagonal from a vector
24  a.reset();
25  a.getMatrix()(0,0) = diag[0];
26  a.getMatrix()(1,1) = diag[1];
27  a.getMatrix()(2,2) = diag[2];
28 
29  apply(a.getMatrix(), from.min_bounds(), a.getTransl());
30 
31  //print(a.transl());
32 
33  a.getTransl() -= to.min_bounds();
34  neg(a.getTransl());
35 }
36 
37 // TODO: is it really different from out = a*in?
38 template < typename T1, typename T2 >
39 INLINE
40 void apply
41 (
42  const Affine<T1> & a,
43  const numeric_array<T2,3> & in,
44  numeric_array<typename combine<T1,T2>::type,3> & out
45 )
46 {
47  apply(a.getMatrix(), in, out);
48  out += a.getTransl();
49 }
50 
51 
52 template < typename T >
53 void print(const Affine<T> & a)
54 {
55  for (int i = 0; i < 3; ++i)
56  {
57  for (int j = 0; j < 3; ++j)
58  {
59  std::cout << a.getMatrix()(i,j) << " ";
60  }
61  std::cout << a.getTransl()[i] << std::endl;
62  }
63 }
64  //} // namespace linalg
65 } // namespace til
66 
67 #endif
68 
void computeAffineTransformBetween(const Box< T, 3 > &from, const Box< T, 3 > &to, Affine< T > &a)
Compute the affine transform that would send a Box on another Box.
A affine mathematical object.
INLINE void apply(const Affine< T1 > &a, const numeric_array< T2, 3 > &in, numeric_array< typename combine< T1, T2 >::type, 3 > &out)
void print(const Affine< T > &a)
Belongs to package Box Do not include directly, include til/Box.h instead.
Definition: Accumulator.h:10
const Matrix3< T > & getMatrix() const
numeric_array< T, D > size(const Box< T, D > &box)
Return the size of a box.
Definition: boxTools.h:56
const numeric_array< T, D > & min_bounds() const
Get min bounds.
Definition: Box.h:41
const numeric_array< T, 3 > & getTransl() const
#define INLINE
Definition: til_common.h:26
void neg(TImage &im)
Definition: imageArith.h:32
type_if<(!std::numeric_limits< T1 >::is_integer &&std::numeric_limits< T2 >::is_integer)||((!std::numeric_limits< T1 >::is_integer||std::numeric_limits< T2 >::is_integer) &&(sizeof(T1) >=sizeof(T2))), T1, T2 >::type type
Definition: traits.h:171
A 3D box parallel to canonical axes.
Definition: Box.h:25