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 #include "main.h"
00026 #include <Eigen/StdVector>
00027 #include <Eigen/Geometry>
00028
00029 template<typename MatrixType>
00030 void check_stdvector_matrix(const MatrixType& m)
00031 {
00032 typename MatrixType::Index rows = m.rows();
00033 typename MatrixType::Index cols = m.cols();
00034 MatrixType x = MatrixType::Random(rows,cols), y = MatrixType::Random(rows,cols);
00035 std::vector<MatrixType,Eigen::aligned_allocator<MatrixType> > v(10, MatrixType(rows,cols)), w(20, y);
00036 v[5] = x;
00037 w[6] = v[5];
00038 VERIFY_IS_APPROX(w[6], v[5]);
00039 v = w;
00040 for(int i = 0; i < 20; i++)
00041 {
00042 VERIFY_IS_APPROX(w[i], v[i]);
00043 }
00044
00045 v.resize(21);
00046 v[20] = x;
00047 VERIFY_IS_APPROX(v[20], x);
00048 v.resize(22,y);
00049 VERIFY_IS_APPROX(v[21], y);
00050 v.push_back(x);
00051 VERIFY_IS_APPROX(v[22], x);
00052 VERIFY((size_t)&(v[22]) == (size_t)&(v[21]) + sizeof(MatrixType));
00053
00054
00055
00056 MatrixType* ref = &w[0];
00057 for(int i=0; i<30 || ((ref==&w[0]) && i<300); ++i)
00058 v.push_back(w[i%w.size()]);
00059 for(unsigned int i=23; i<v.size(); ++i)
00060 {
00061 VERIFY(v[i]==w[(i-23)%w.size()]);
00062 }
00063 }
00064
00065 template<typename TransformType>
00066 void check_stdvector_transform(const TransformType&)
00067 {
00068 typedef typename TransformType::MatrixType MatrixType;
00069 TransformType x(MatrixType::Random()), y(MatrixType::Random());
00070 std::vector<TransformType,Eigen::aligned_allocator<TransformType> > v(10), w(20, y);
00071 v[5] = x;
00072 w[6] = v[5];
00073 VERIFY_IS_APPROX(w[6], v[5]);
00074 v = w;
00075 for(int i = 0; i < 20; i++)
00076 {
00077 VERIFY_IS_APPROX(w[i], v[i]);
00078 }
00079
00080 v.resize(21);
00081 v[20] = x;
00082 VERIFY_IS_APPROX(v[20], x);
00083 v.resize(22,y);
00084 VERIFY_IS_APPROX(v[21], y);
00085 v.push_back(x);
00086 VERIFY_IS_APPROX(v[22], x);
00087 VERIFY((size_t)&(v[22]) == (size_t)&(v[21]) + sizeof(TransformType));
00088
00089
00090
00091 TransformType* ref = &w[0];
00092 for(int i=0; i<30 || ((ref==&w[0]) && i<300); ++i)
00093 v.push_back(w[i%w.size()]);
00094 for(unsigned int i=23; i<v.size(); ++i)
00095 {
00096 VERIFY(v[i].matrix()==w[(i-23)%w.size()].matrix());
00097 }
00098 }
00099
00100 template<typename QuaternionType>
00101 void check_stdvector_quaternion(const QuaternionType&)
00102 {
00103 typedef typename QuaternionType::Coefficients Coefficients;
00104 QuaternionType x(Coefficients::Random()), y(Coefficients::Random());
00105 std::vector<QuaternionType,Eigen::aligned_allocator<QuaternionType> > v(10), w(20, y);
00106 v[5] = x;
00107 w[6] = v[5];
00108 VERIFY_IS_APPROX(w[6], v[5]);
00109 v = w;
00110 for(int i = 0; i < 20; i++)
00111 {
00112 VERIFY_IS_APPROX(w[i], v[i]);
00113 }
00114
00115 v.resize(21);
00116 v[20] = x;
00117 VERIFY_IS_APPROX(v[20], x);
00118 v.resize(22,y);
00119 VERIFY_IS_APPROX(v[21], y);
00120 v.push_back(x);
00121 VERIFY_IS_APPROX(v[22], x);
00122 VERIFY((size_t)&(v[22]) == (size_t)&(v[21]) + sizeof(QuaternionType));
00123
00124
00125
00126 QuaternionType* ref = &w[0];
00127 for(int i=0; i<30 || ((ref==&w[0]) && i<300); ++i)
00128 v.push_back(w[i%w.size()]);
00129 for(unsigned int i=23; i<v.size(); ++i)
00130 {
00131 VERIFY(v[i].coeffs()==w[(i-23)%w.size()].coeffs());
00132 }
00133 }
00134
00135 void test_stdvector()
00136 {
00137
00138 CALL_SUBTEST_1(check_stdvector_matrix(Vector2f()));
00139 CALL_SUBTEST_1(check_stdvector_matrix(Matrix3f()));
00140 CALL_SUBTEST_2(check_stdvector_matrix(Matrix3d()));
00141
00142
00143 CALL_SUBTEST_1(check_stdvector_matrix(Matrix2f()));
00144 CALL_SUBTEST_1(check_stdvector_matrix(Vector4f()));
00145 CALL_SUBTEST_1(check_stdvector_matrix(Matrix4f()));
00146 CALL_SUBTEST_2(check_stdvector_matrix(Matrix4d()));
00147
00148
00149 CALL_SUBTEST_3(check_stdvector_matrix(MatrixXd(1,1)));
00150 CALL_SUBTEST_3(check_stdvector_matrix(VectorXd(20)));
00151 CALL_SUBTEST_3(check_stdvector_matrix(RowVectorXf(20)));
00152 CALL_SUBTEST_3(check_stdvector_matrix(MatrixXcf(10,10)));
00153
00154
00155 CALL_SUBTEST_4(check_stdvector_transform(Projective2f()));
00156 CALL_SUBTEST_4(check_stdvector_transform(Projective3f()));
00157 CALL_SUBTEST_4(check_stdvector_transform(Projective3d()));
00158
00159
00160
00161 CALL_SUBTEST_5(check_stdvector_quaternion(Quaternionf()));
00162 CALL_SUBTEST_5(check_stdvector_quaternion(Quaterniond()));
00163 }