3 #include <Eigen/Geometry>
4 #include <bench/BenchTimer.h>
17 typedef SCALAR Scalar
;
18 typedef NumTraits
<Scalar
>::Real RealScalar
;
19 typedef Matrix
<RealScalar
,Dynamic
,Dynamic
> A
;
20 typedef Matrix
</*Real*/Scalar
,Dynamic
,Dynamic
> B
;
21 typedef Matrix
<Scalar
,Dynamic
,Dynamic
> C
;
22 typedef Matrix
<RealScalar
,Dynamic
,Dynamic
> M
;
24 template<typename Transformation
, typename Data
>
25 EIGEN_DONT_INLINE
void transform(const Transformation
& t
, Data
& data
)
27 EIGEN_ASM_COMMENT("begin");
29 EIGEN_ASM_COMMENT("end");
32 template<typename Scalar
, typename Data
>
33 EIGEN_DONT_INLINE
void transform(const Quaternion
<Scalar
>& t
, Data
& data
)
35 EIGEN_ASM_COMMENT("begin quat");
36 for(int i
=0;i
<data
.cols();++i
)
37 data
.col(i
) = t
* data
.col(i
);
38 EIGEN_ASM_COMMENT("end quat");
41 template<typename T
> struct ToRotationMatrixWrapper
44 typedef typename
T::Scalar Scalar
;
45 ToRotationMatrixWrapper(const T
& o
) : object(o
) {}
49 template<typename QType
, typename Data
>
50 EIGEN_DONT_INLINE
void transform(const ToRotationMatrixWrapper
<QType
>& t
, Data
& data
)
52 EIGEN_ASM_COMMENT("begin quat via mat");
53 data
= t
.object
.toRotationMatrix() * data
;
54 EIGEN_ASM_COMMENT("end quat via mat");
57 template<typename Scalar
, int Dim
, typename Data
>
58 EIGEN_DONT_INLINE
void transform(const Transform
<Scalar
,Dim
,Projective
>& t
, Data
& data
)
60 data
= (t
* data
.colwise().homogeneous()).template block
<Dim
,Data::ColsAtCompileTime
>(0,0);
63 template<typename T
> struct get_dim
{ enum { Dim
= T::Dim
}; };
64 template<typename S
, int R
, int C
, int O
, int MR
, int MC
>
65 struct get_dim
<Matrix
<S
,R
,C
,O
,MR
,MC
> > { enum { Dim
= R
}; };
67 template<typename Transformation
, int N
>
70 static EIGEN_DONT_INLINE
void run(const Transformation
& t
)
72 Matrix
<typename
Transformation::Scalar
,get_dim
<Transformation
>::Dim
,N
> data
;
74 bench_impl
<Transformation
,N
-1>::run(t
);
76 BENCH(timer
,10,100000,transform(t
,data
));
78 cout
<< timer
.best() << " ";
83 template<typename Transformation
>
84 struct bench_impl
<Transformation
,0>
86 static EIGEN_DONT_INLINE
void run(const Transformation
&) {}
89 template<typename Transformation
>
90 EIGEN_DONT_INLINE
void bench(const std::string
& msg
, const Transformation
& t
)
93 bench_impl
<Transformation
,SIZE
>::run(t
);
97 int main(int argc
, char ** argv
)
99 Matrix
<Scalar
,3,4> mat34
; mat34
.setRandom();
100 Transform
<Scalar
,3,Isometry
> iso3(mat34
);
101 Transform
<Scalar
,3,Affine
> aff3(mat34
);
102 Transform
<Scalar
,3,AffineCompact
> caff3(mat34
);
103 Transform
<Scalar
,3,Projective
> proj3(mat34
);
104 Quaternion
<Scalar
> quat
;quat
.setIdentity();
105 ToRotationMatrixWrapper
<Quaternion
<Scalar
> > quatmat(quat
);
106 Matrix
<Scalar
,3,3> mat33
; mat33
.setRandom();
111 for(int i
=0;i
<SIZE
;++i
)
118 bench("matrix 3x3", mat33
);
119 bench("quaternion", quat
);
120 bench("quat-mat ", quatmat
);
121 bench("isometry3 ", iso3
);
122 bench("affine3 ", aff3
);
123 bench("c affine3 ", caff3
);
124 bench("proj3 ", proj3
);