00001 #include <iostream>
00002 #include <sstream>
00003
00004 using namespace std;
00005
00006 #include <TooN/so2.h>
00007 #include <TooN/se2.h>
00008 #include <TooN/so3.h>
00009 #include <TooN/se3.h>
00010
00011 void test_so2(){
00012 cout << "---------------SO2 Tests---------------\n";
00013
00014 TooN::SO2<> r1;
00015 cout << "default constructor\n";
00016 cout << r1 << endl;
00017 cout << "default constructor <int>\n";
00018 TooN::SO2<int> r2;
00019 cout << r2 << endl;
00020 TooN::SO2<> r(0.1);
00021 cout << "constructor with 0.1\n";
00022 cout << r << endl;
00023 cout << "generator\n";
00024 cout << r.generator() << endl;
00025 cout << "ln()\n";
00026 cout << r.ln() << endl;
00027 cout << "inverse\n";
00028 cout << r.inverse() << endl;
00029 cout << "times\n";
00030 cout << r * r.inverse() << endl;
00031 cout << (r *= r.inverse()) << endl;
00032 r = TooN::SO2<>::exp(0.1);
00033
00034 TooN::Vector<2> t = TooN::makeVector(0,1);
00035 cout << "right and left multiply with vector " << t << "\n";
00036 cout << r * t << endl;
00037 cout << t * r << endl;
00038 TooN::Matrix<2> l = TooN::Identity;
00039 cout << "right and left multiply with matrix\n" << l << "\n";
00040 cout << r * l << endl;
00041 cout << l * r << endl;
00042 TooN::Matrix<2,3> l2(TooN::Zeros);
00043 l2[0] = TooN::makeVector(0,1,2);
00044 cout << "right with rectangular matrix\n";
00045 cout << r * l2 << endl;
00046 cout << l2.T() * r << endl;
00047
00048 TooN::Matrix<2> m;
00049 m[0] = TooN::makeVector(0.5, 1);
00050 m[1] = TooN::makeVector(1,1);
00051 cout << "set from matrix (uses coerce) " << m << "\n";
00052 r = m;
00053 cout << r << endl;
00054
00055 cout << "read from istream\n";
00056 istringstream is("0 -1 1 0");
00057 is >> r;
00058 cout << r << endl;
00059 }
00060
00061 void test_se2(){
00062 cout << "---------------SE2 Tests---------------\n";
00063
00064 TooN::SE2<> r1;
00065 cout << "default constructor\n";
00066 cout << r1 << endl;
00067 cout << "default constructor <int>\n";
00068 TooN::SE2<int> r2;
00069 cout << r2 << endl;
00070
00071 cout << "from vector 1 1 0\n";
00072 cout << TooN::SE2<>::exp(TooN::makeVector(1,1,0)) << endl;
00073
00074 TooN::SE2<> r3(TooN::makeVector(1,1,1));
00075 cout << "from vector 1 1 1\n";
00076 cout << r3 << endl;
00077 cout << r3.ln() << endl;
00078
00079 cout << "generators 0,1,2\n";
00080 cout << TooN::SE2<>::generator(0) ;
00081 cout << TooN::SE2<>::generator(1) ;
00082 cout << TooN::SE2<>::generator(2) << endl;
00083
00084 TooN::Vector<2> t1 = TooN::makeVector(0,1);
00085 TooN::Vector<> t2(3); t2 = TooN::makeVector(1,0,1);
00086 cout << "se2 * vector\n";
00087 cout << r3 * t1 << endl;
00088 cout << r3 * t2 << endl;
00089 cout << "vector * se3\n";
00090
00091 cout << t2 * r3 << endl;
00092
00093 TooN::Matrix<3> m1;
00094 TooN::Matrix<> m2(3,3);
00095 TooN::Matrix<3,10> m3;
00096 cout << "se2 * matrix\n";
00097 cout << r3 * m1 << endl;
00098 cout << r3 * m2 << endl;
00099 cout << r3 * m3 << endl;
00100 cout << "matrix * se2\n";
00101 cout << m1 * r3 << endl;
00102 cout << m2 * r3 << endl;
00103 cout << m3.T() * r3 << endl;
00104
00105 TooN::SO2<> r(-1);
00106 cout << "so2 * se2\n";
00107 cout << r * r3 << endl;
00108
00109 cout << "read from istream\n";
00110 istringstream is("0 -1 2 1 0 3");
00111 is >> r3;
00112 cout << r3 << endl;
00113 }
00114
00115 void test_so3(){
00116 cout << "---------------SO3 Tests---------------\n";
00117
00118 TooN::SO3<> r1;
00119 cout << "default constructor\n";
00120 cout << r1 << endl;
00121 cout << "default constructor <int>\n";
00122 TooN::SO3<int> r2;
00123 cout << r2 << endl;
00124 TooN::SO3<> r(TooN::makeVector(0.1, 0.1, 0.1));
00125 cout << "constructor with 0.1\n";
00126 cout << r << endl;
00127 cout << "generator 0,1,2\n";
00128 cout << TooN::SO3<>::generator(0) ;
00129 cout << TooN::SO3<>::generator(1) ;
00130 cout << TooN::SO3<>::generator(2) << endl;
00131 cout << "ln()\n";
00132 cout << r.ln() << endl;
00133 cout << "inverse\n";
00134 cout << r.inverse() << endl;
00135 cout << "times\n";
00136 cout << r * r.inverse() << endl;
00137 cout << (r *= r.inverse()) << endl;
00138 r = TooN::SO3<>::exp(TooN::makeVector(0.1, 0.1, 0.1));
00139
00140 TooN::Vector<3> t = TooN::makeVector(0,1,2);
00141 cout << "right and left multiply with vector " << t << "\n";
00142 cout << r * t << endl;
00143 cout << t * r << endl;
00144 TooN::Matrix<3> l = TooN::Identity;
00145 cout << "right and left multiply with matrix\n" << l << "\n";
00146 cout << r * l << endl;
00147 cout << l * r << endl;
00148 TooN::Matrix<3,6> l2(TooN::Zeros);
00149 l2[0] = TooN::makeVector(0,1,2,3,4,5);
00150 cout << "right with rectangular matrix\n";
00151 cout << r * l2 << endl;
00152 cout << l2.T() * r << endl;
00153
00154 TooN::Matrix<3> m;
00155 m[0] = TooN::makeVector(0.5, 1,2);
00156 m[1] = TooN::makeVector(1,1,0);
00157 m[2] = TooN::makeVector(0,1,0);
00158 cout << "set from matrix (uses coerce)\n" << m << "\n";
00159 r = m;
00160 cout << r << endl;
00161 TooN::SO3<> r5(m);
00162 cout << r5 << endl;
00163
00164 cout << "read from istream\n";
00165 istringstream is("0 -1 0 1 0 0 0 0 1");
00166 is >> r;
00167 cout << r << endl;
00168
00169 cout << "test rotation constructor\n";
00170 TooN::Vector<3> a = TooN::makeVector(1,0,0), b = TooN::makeVector(0,1,1);
00171 TooN::SO3<> rr(a,b);
00172 cout << "a " << a << " to b " << b << " is\n" << rr << endl;
00173 cout << "R * a " << rr * a << endl;
00174 cout << "a " << a << " to itself is\n" << TooN::SO3<>(a,a) << endl;
00175 }
00176
00177 void test_se3(){
00178 cout << "---------------SE3 Tests---------------\n";
00179
00180 TooN::SE3<> r1;
00181 cout << "default constructor\n";
00182 cout << r1 << endl;
00183 cout << "default constructor <int>\n";
00184 TooN::SE3<int> r2;
00185 cout << r2 << endl;
00186 TooN::SE3<> r(TooN::makeVector(0.1, 0.1, 0.1, 0.2, -0.2, 0.2));
00187 cout << "constructor\n";
00188 cout << r << endl;
00189 cout << "generator 0,1,2,3,4,5\n";
00190 cout << TooN::SE3<>::generator(0) ;
00191 cout << TooN::SE3<>::generator(1) ;
00192 cout << TooN::SE3<>::generator(2) << endl;
00193 cout << TooN::SE3<>::generator(3) ;
00194 cout << TooN::SE3<>::generator(4) ;
00195 cout << TooN::SE3<>::generator(5) << endl;
00196 cout << "ln()\n";
00197 cout << r.ln() << endl;
00198 cout << "inverse\n";
00199 cout << r.inverse() << endl;
00200 cout << "times\n";
00201 cout << r * r.inverse() << endl;
00202 cout << (r *= r.inverse()) << endl;
00203 r = TooN::SE3<>::exp(TooN::makeVector(0.1, 0.1, 0.1, 0.2, -0.2, 0.2));
00204
00205 TooN::Vector<4> t = TooN::makeVector(0,1,2,3);
00206 cout << "right and left multiply with vector " << t << "\n";
00207 cout << r * t << endl;
00208 cout << t * r << endl;
00209 TooN::Vector<3> t3 = TooN::makeVector(0,1,2);
00210 cout << "right with a 3 vector " << t3 << "\n";
00211 cout << r * t3 << endl;
00212
00213 TooN::Matrix<4> l = TooN::Identity;
00214 cout << "right and left multiply with matrix\n" << l << "\n";
00215 cout << r * l << endl;
00216 cout << l * r << endl;
00217 TooN::Matrix<4,6> l2(TooN::Zeros);
00218 l2[0] = TooN::makeVector(0,1,2,3,4,5);
00219 cout << "right with rectangular matrix\n";
00220 cout << r * l2 << endl;
00221 cout << l2.T() * r << endl;
00222
00223 TooN::SO3<> rot(TooN::makeVector(-0.2, 0.2, -0.2));
00224 cout << "mult with SO3\n";
00225 cout << rot * r << endl;
00226
00227 TooN::Vector<6> a = TooN::makeVector(0,1,2,0.1, 0.2, 0.3);
00228 cout << "adjoint with a " << a << "\n";
00229 cout << r.adjoint(a) << endl;
00230 cout << "0 0 0 0 0 0 = " << r.adjoint(a) - (r * TooN::SE3<>(a) * r.inverse()).ln() << endl;
00231 cout << "trinvadjoint with a " << a << "\n";
00232 cout << r.trinvadjoint(a) << endl;
00233 cout << "0 = " << r.trinvadjoint(a) * r.adjoint(a) - a * a << endl;
00234
00235 TooN::Matrix<6> ma(TooN::Identity);
00236 ma[0] = TooN::makeVector(0.1, 0.2, 0.1, 0.2, 0.1, 0.3);
00237 ma = ma.T() * ma;
00238 cout << "adjoint with ma\n" << ma << "\n";
00239 cout << r.adjoint(ma) << endl;
00240 cout << "trinvadjoint with ma\n";
00241 cout << r.trinvadjoint(ma) << endl;
00242
00243 cout << "read from istream\n";
00244 istringstream is("0 -1 0 1 1 0 0 2 0 0 1 3");
00245 is >> r;
00246 cout << r << endl;
00247 }
00248
00249
00250 void test_se2_exp(){
00251 cout << "------------------SE2 check------------------\n";
00252
00253 TooN::SE2<> s2(TooN::makeVector(1,0,1));
00254 TooN::SE3<> s3(TooN::makeVector(0,1,0,1,0,0));
00255 cout << s2 << endl;
00256 cout << s3 << endl;
00257
00258 cout << s2.ln() << "\tvs\t" << s3.ln() << endl;
00259
00260 }
00261
00262 int main(int, char* *){
00263
00264 test_so2();
00265 test_so3();
00266 test_se2();
00267 test_se3();
00268
00269 test_se2_exp();
00270
00271 return 0;
00272 }