Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #define EIGEN_WORK_AROUND_QT_BUG_CALLING_WRONG_OPERATOR_NEW_FIXED_IN_QT_4_5
00027
00028 #include "main.h"
00029
00030 #include <Eigen/Geometry>
00031 #include <Eigen/QtAlignedMalloc>
00032
00033 #include <QtCore/QVector>
00034
00035 template<typename MatrixType>
00036 void check_qtvector_matrix(const MatrixType& m)
00037 {
00038 int rows = m.rows();
00039 int cols = m.cols();
00040 MatrixType x = MatrixType::Random(rows,cols), y = MatrixType::Random(rows,cols);
00041 QVector<MatrixType> v(10, MatrixType(rows,cols)), w(20, y);
00042 for(int i = 0; i < 20; i++)
00043 {
00044 VERIFY_IS_APPROX(w[i], y);
00045 }
00046 v[5] = x;
00047 w[6] = v[5];
00048 VERIFY_IS_APPROX(w[6], v[5]);
00049 v = w;
00050 for(int i = 0; i < 20; i++)
00051 {
00052 VERIFY_IS_APPROX(w[i], v[i]);
00053 }
00054
00055 v.resize(21);
00056 v[20] = x;
00057 VERIFY_IS_APPROX(v[20], x);
00058 v.fill(y,22);
00059 VERIFY_IS_APPROX(v[21], y);
00060 v.push_back(x);
00061 VERIFY_IS_APPROX(v[22], x);
00062 VERIFY((size_t)&(v[22]) == (size_t)&(v[21]) + sizeof(MatrixType));
00063
00064
00065
00066 MatrixType* ref = &w[0];
00067 for(int i=0; i<30 || ((ref==&w[0]) && i<300); ++i)
00068 v.push_back(w[i%w.size()]);
00069 for(int i=23; i<v.size(); ++i)
00070 {
00071 VERIFY(v[i]==w[(i-23)%w.size()]);
00072 }
00073 }
00074
00075 template<typename TransformType>
00076 void check_qtvector_transform(const TransformType&)
00077 {
00078 typedef typename TransformType::MatrixType MatrixType;
00079 TransformType x(MatrixType::Random()), y(MatrixType::Random());
00080 QVector<TransformType> v(10), w(20, y);
00081 v[5] = x;
00082 w[6] = v[5];
00083 VERIFY_IS_APPROX(w[6], v[5]);
00084 v = w;
00085 for(int i = 0; i < 20; i++)
00086 {
00087 VERIFY_IS_APPROX(w[i], v[i]);
00088 }
00089
00090 v.resize(21);
00091 v[20] = x;
00092 VERIFY_IS_APPROX(v[20], x);
00093 v.fill(y,22);
00094 VERIFY_IS_APPROX(v[21], y);
00095 v.push_back(x);
00096 VERIFY_IS_APPROX(v[22], x);
00097 VERIFY((size_t)&(v[22]) == (size_t)&(v[21]) + sizeof(TransformType));
00098
00099
00100
00101 TransformType* ref = &w[0];
00102 for(int i=0; i<30 || ((ref==&w[0]) && i<300); ++i)
00103 v.push_back(w[i%w.size()]);
00104 for(unsigned int i=23; int(i)<v.size(); ++i)
00105 {
00106 VERIFY(v[i].matrix()==w[(i-23)%w.size()].matrix());
00107 }
00108 }
00109
00110 template<typename QuaternionType>
00111 void check_qtvector_quaternion(const QuaternionType&)
00112 {
00113 typedef typename QuaternionType::Coefficients Coefficients;
00114 QuaternionType x(Coefficients::Random()), y(Coefficients::Random());
00115 QVector<QuaternionType> v(10), w(20, y);
00116 v[5] = x;
00117 w[6] = v[5];
00118 VERIFY_IS_APPROX(w[6], v[5]);
00119 v = w;
00120 for(int i = 0; i < 20; i++)
00121 {
00122 VERIFY_IS_APPROX(w[i], v[i]);
00123 }
00124
00125 v.resize(21);
00126 v[20] = x;
00127 VERIFY_IS_APPROX(v[20], x);
00128 v.fill(y,22);
00129 VERIFY_IS_APPROX(v[21], y);
00130 v.push_back(x);
00131 VERIFY_IS_APPROX(v[22], x);
00132 VERIFY((size_t)&(v[22]) == (size_t)&(v[21]) + sizeof(QuaternionType));
00133
00134
00135
00136 QuaternionType* ref = &w[0];
00137 for(int i=0; i<30 || ((ref==&w[0]) && i<300); ++i)
00138 v.push_back(w[i%w.size()]);
00139 for(unsigned int i=23; int(i)<v.size(); ++i)
00140 {
00141 VERIFY(v[i].coeffs()==w[(i-23)%w.size()].coeffs());
00142 }
00143 }
00144
00145 void test_eigen2_qtvector()
00146 {
00147
00148 CALL_SUBTEST_1(check_qtvector_matrix(Vector2f()));
00149 CALL_SUBTEST_1(check_qtvector_matrix(Matrix3f()));
00150 CALL_SUBTEST_1(check_qtvector_matrix(Matrix3d()));
00151
00152
00153 CALL_SUBTEST_2(check_qtvector_matrix(Matrix2f()));
00154 CALL_SUBTEST_2(check_qtvector_matrix(Vector4f()));
00155 CALL_SUBTEST_2(check_qtvector_matrix(Matrix4f()));
00156 CALL_SUBTEST_2(check_qtvector_matrix(Matrix4d()));
00157
00158
00159 CALL_SUBTEST_3(check_qtvector_matrix(MatrixXd(1,1)));
00160 CALL_SUBTEST_3(check_qtvector_matrix(VectorXd(20)));
00161 CALL_SUBTEST_3(check_qtvector_matrix(RowVectorXf(20)));
00162 CALL_SUBTEST_3(check_qtvector_matrix(MatrixXcf(10,10)));
00163
00164
00165 CALL_SUBTEST_4(check_qtvector_transform(Transform2f()));
00166 CALL_SUBTEST_4(check_qtvector_transform(Transform3f()));
00167 CALL_SUBTEST_4(check_qtvector_transform(Transform3d()));
00168
00169
00170
00171 CALL_SUBTEST_5(check_qtvector_quaternion(Quaternionf()));
00172 CALL_SUBTEST_5(check_qtvector_quaternion(Quaternionf()));
00173 }