toon-members
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Toon-members] TooN so2.h test/SXX_test.cc


From: Gerhard Reitmayr
Subject: [Toon-members] TooN so2.h test/SXX_test.cc
Date: Thu, 26 Mar 2009 19:28:31 +0000

CVSROOT:        /cvsroot/toon
Module name:    TooN
Changes by:     Gerhard Reitmayr <gerhard>      09/03/26 19:28:31

Modified files:
        .              : so2.h 
        test           : SXX_test.cc 

Log message:
        clean up for So2

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/TooN/so2.h?cvsroot=toon&r1=1.4&r2=1.5
http://cvs.savannah.gnu.org/viewcvs/TooN/test/SXX_test.cc?cvsroot=toon&r1=1.3&r2=1.4

Patches:
Index: so2.h
===================================================================
RCS file: /cvsroot/toon/TooN/so2.h,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -b -r1.4 -r1.5
--- so2.h       25 Mar 2009 22:33:21 -0000      1.4
+++ so2.h       26 Mar 2009 19:28:30 -0000      1.5
@@ -17,8 +17,6 @@
      51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 */
 
-/* This code mostly made by copying from so2.h !! */
-
 #ifndef __SO2_H
 #define __SO2_H
 
@@ -30,27 +28,42 @@
 #endif
 
 template<class Precision> class SO2;
-template<class Precision> class SE2;
 
-template<class Precision> inline std::ostream & operator<<(std::ostream &, 
const SO2<Precision> & );
 template<class Precision> inline std::istream & operator>>(std::istream &, 
SO2<Precision> & );
 
 template<class Precision = double>
 class SO2 {
 public:
   friend std::istream& operator>> <Precision>(std::istream&, SO2& );
-  friend std::ostream& operator<< <Precision>(std::ostream&, const SO2&);
-  friend class SE2<Precision>;
        SO2() : my_matrix(Identity) {} 
   
        SO2(const Matrix<2,2,Precision>& rhs) {  *this = rhs; }
 
        SO2(const Precision l) { *this = exp(l); }
   
-  template <int R, int C, class P, class A> inline SO2& operator=(const 
Matrix<R,C,P,A>& rhs);
-  template <int R, int C, class P, class A> static inline void 
coerce(Matrix<R,C,P,A>& M);
+       template <int R, int C, class P, class A> 
+       inline SO2& operator=(const Matrix<R,C,P,A>& rhs){
+               my_matrix = rhs;
+               coerce(my_matrix);
+               return *this;
+       }
 
-  inline static SO2 exp(const Precision);
+       template <int R, int C, class P, class A> 
+       static inline void coerce(Matrix<R,C,P,A>& M){
+               SizeMismatch<2,R>::test(2, M.num_rows());
+               SizeMismatch<2,C>::test(2, M.num_cols());
+               M[0] = unit(M[0]);
+               M[1] -= M[0] * (M[0]*M[1]);
+               M[1] = unit(M[1]);
+       }
+
+       inline static SO2 exp(const Precision & d){
+               SO2<Precision> result;
+               result.my_matrix[0][0] = result.my_matrix[1][1] = cos(d);
+               result.my_matrix[1][0] = sin(d);
+               result.my_matrix[0][1] = -result.my_matrix[1][0];
+               return result;
+       }
 
   Precision ln() const { return atan2(my_matrix[1][0], my_matrix[0][0]); }
 
@@ -60,13 +73,17 @@
     my_matrix=my_matrix*rhs.my_matrix;
     return *this;
   }
-
   SO2 operator *(const SO2& rhs) const { return SO2(*this,rhs); }
 
   const Matrix<2,2,Precision>& get_matrix() const {return my_matrix;}
   
   /// returns generator matrix
-  static Matrix<2,2,Precision> generator() {return my_generator;}
+       static Matrix<2,2,Precision> generator() {
+               Matrix<2,2,Precision> result;
+               result[0] = makeVector(0,-1);
+               result[1] = makeVector(1,0);
+               return result;
+       }
 
  private:
   struct Invert {};
@@ -74,7 +91,6 @@
   inline SO2(const SO2& a, const SO2& b) : my_matrix(a.my_matrix*b.my_matrix) 
{}
       
   Matrix<2,2,Precision> my_matrix;
-  static Matrix<2,2,Precision> my_generator;
 };
 
 template <class Precision>
@@ -87,60 +103,26 @@
   return is >> rhs.my_matrix;
 }
 
-template<int D, class P1, class PV, class Accessor> inline
-Vector<2, typename Internal::MultiplyType<P1, PV>::type> operator*(const 
SO2<P1> & lhs, const Vector<D, PV, Accessor> & rhs){
+template<int D, class P1, class PV, class Accessor>
+inline Vector<2, typename Internal::MultiplyType<P1, PV>::type> 
operator*(const SO2<P1> & lhs, const Vector<D, PV, Accessor> & rhs){
   return lhs.get_matrix() * rhs;
 }
 
-template<int D, class P1, class PV, class Accessor>  inline
-Vector<2, typename Internal::MultiplyType<PV,P1>::type> operator*(const 
Vector<D, PV, Accessor>& lhs, const SO2<P1> & rhs){
+template<int D, class P1, class PV, class Accessor>
+inline Vector<2, typename Internal::MultiplyType<PV,P1>::type> operator*(const 
Vector<D, PV, Accessor>& lhs, const SO2<P1> & rhs){
   return lhs * rhs.get_matrix();
 }
 
-template <int R, int C, class P1, class P2, class Accessor> inline
-Matrix<2,C,typename Internal::MultiplyType<P1,P2>::type> operator*(const 
SO2<P1> & lhs, const Matrix<R,C,P2,Accessor>& rhs){
+template <int R, int C, class P1, class P2, class Accessor> 
+inline Matrix<2,C,typename Internal::MultiplyType<P1,P2>::type> 
operator*(const SO2<P1> & lhs, const Matrix<R,C,P2,Accessor>& rhs){
   return lhs.get_matrix() * rhs;
 }
 
-template <int R, int C, class P1, class P2, class Accessor> inline
-Matrix<R,2,typename Internal::MultiplyType<P1,P2>::type> operator*(const 
Matrix<R,C,P1,Accessor>& lhs, const SO2<P2>& rhs){
+template <int R, int C, class P1, class P2, class Accessor>
+inline Matrix<R,2,typename Internal::MultiplyType<P1,P2>::type> 
operator*(const Matrix<R,C,P1,Accessor>& lhs, const SO2<P2>& rhs){
   return lhs * rhs.get_matrix();
 }
 
-template <class P1>
-template <int R, int C, class P2, class A>
-inline SO2<P1> & SO2<P1>::operator=(const Matrix<R,C,P2,A>& rhs){
-  my_matrix = rhs;
-  coerce(my_matrix);
-  return *this;
-}
-
-template <class Precision>
-template <int R, int C, class P, class A> 
-inline void SO2<Precision>::coerce(Matrix<R,C,P,A>& M){
-  SizeMismatch<2,R>::test(2, M.num_rows());
-  SizeMismatch<2,C>::test(2, M.num_cols());
-  M[0] = unit(M[0]);
-  M[1] -= M[0] * (M[0]*M[1]);
-  M[1] = unit(M[1]);
-}
-
-template <class Precision>
-inline SO2<Precision> SO2<Precision>::exp(const Precision d){
-  SO2<Precision> result;
-  result.my_matrix[0][0] = result.my_matrix[1][1] = cos(d);
-  result.my_matrix[1][0] = sin(d);
-  result.my_matrix[0][1] = -result.my_matrix[1][0];
-  return result;
-}
-
-namespace SO2static
-{
-  static double generator[4] = {0,-1,1,0};
-}
-
-template <class Precision> Matrix<2,2, Precision> 
SO2<Precision>::my_generator(SO2static::generator, 2, 2, 
Operator<Internal::Copy>());
-
 #ifndef TOON_NO_NAMESPACE
 }
 #endif

Index: test/SXX_test.cc
===================================================================
RCS file: /cvsroot/toon/TooN/test/SXX_test.cc,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -b -r1.3 -r1.4
--- test/SXX_test.cc    25 Mar 2009 21:24:20 -0000      1.3
+++ test/SXX_test.cc    26 Mar 2009 19:28:31 -0000      1.4
@@ -3,31 +3,73 @@
 using namespace std;
 
 #include <TooN/so2.h>
+#include <TooN/se2.h>
 
-int main(int, char* *){
+void test_so2(){
     TooN::SO2<> r1;
+    cout << "default constructor\n";
     cout << r1 << endl;
+    cout << "default constructor <int>\n";
     TooN::SO2<int> r2;
     cout << r2 << endl;
     TooN::SO2<> r(0.1);
+    cout << "constructor with 0.1\n";
     cout << r << endl;
+    cout << "generator\n";
     cout << r.generator() << endl;
+    cout << "ln()\n";
     cout << r.ln() << endl;
+    cout << "inverse\n";
+    cout << r.inverse() << endl;
+    cout << "times\n";
+    cout << r * r.inverse() << endl;
+    cout << (r *= r.inverse()) << endl;
+    r = TooN::SO2<>::exp(0.1);
 
-    TooN::Vector<2, float> t = TooN::makeVector(0,1);
+    TooN::Vector<2> t = TooN::makeVector(0,1);
+    cout << "right and left multiply with vector " << t << "\n";
     cout << r * t << endl;
     cout << t * r << endl;
-    TooN::Matrix<2> l;
+    TooN::Matrix<2> l = TooN::Identity;
+    cout << "right and left multiply with matrix\n" << l << "\n";
     cout << r * l << endl;
     cout << l * r << endl;
+    TooN::Matrix<2,3> l2(TooN::Zero);
+    l2[0] = TooN::makeVector(0,1,2);
+    cout << "right with rectangular matrix\n";
+    cout << r * l2 << endl;
     
     TooN::Matrix<2> m;
     m[0] = TooN::makeVector(0.5, 1);
     m[1] = TooN::makeVector(1,1);
+    cout << "set from matrix (uses coerce) " << m << "\n";
     r = m;
     cout << r << endl;
+}
+
+void test_se2(){
+    TooN::SE2<> r1;
+    cout << "default constructor\n";
+    cout << r1 << endl;
+    cout << "default constructor <int>\n";
+    TooN::SE2<int> r2;
+    cout << r2 << endl;
+    
+    TooN::SE2<> r3(TooN::makeVector(1,1,1));
+    cout << "from vector 1 1 1\n";
+    cout << r3 << endl;
+    cout << r3.ln() << endl;
+    
+    cout << "generators 0,1,2\n";
+    cout << TooN::SE2<>::generator(0) ;
+    cout << TooN::SE2<>::generator(1) ;
+    cout << TooN::SE2<>::generator(2) << endl;
+}
+
+int main(int, char* *){
  
-    TooN::Matrix<> test(TooN::Identity);
+    test_so2();
+    test_se2();
  
  return 0;
 }




reply via email to

[Prev in Thread] Current Thread [Next in Thread]