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