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