toon-members
[Top][All Lists]
Advanced

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

[Toon-members] TooN helpers.h so2.h internal/matrix.hh test/SX...


From: Gerhard Reitmayr
Subject: [Toon-members] TooN helpers.h so2.h internal/matrix.hh test/SX...
Date: Wed, 25 Mar 2009 21:24:20 +0000

CVSROOT:        /cvsroot/toon
Module name:    TooN
Changes by:     Gerhard Reitmayr <gerhard>      09/03/25 21:24:20

Modified files:
        .              : helpers.h so2.h 
        internal       : matrix.hh 
        test           : SXX_test.cc 

Log message:
        SO2 works now. some modifications to the guts where:
        - added unit function in helpers
        - Matrix constructor from 0-ary operator, allows M<2>(Identity)
        - Fill operator to set Matrix from data source for internal use

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/TooN/helpers.h?cvsroot=toon&r1=1.29&r2=1.30
http://cvs.savannah.gnu.org/viewcvs/TooN/so2.h?cvsroot=toon&r1=1.2&r2=1.3
http://cvs.savannah.gnu.org/viewcvs/TooN/internal/matrix.hh?cvsroot=toon&r1=1.17&r2=1.18
http://cvs.savannah.gnu.org/viewcvs/TooN/test/SXX_test.cc?cvsroot=toon&r1=1.2&r2=1.3

Patches:
Index: helpers.h
===================================================================
RCS file: /cvsroot/toon/TooN/helpers.h,v
retrieving revision 1.29
retrieving revision 1.30
diff -u -b -r1.29 -r1.30
--- helpers.h   25 Mar 2009 21:16:22 -0000      1.29
+++ helpers.h   25 Mar 2009 21:24:20 -0000      1.30
@@ -53,7 +53,11 @@
                        m[i][j] = p;
 }
 
-
+template<int Size, class Precision, class Base> inline Vector<Size, Precision> 
unit(const Vector<Size, Precision, Base> & v)
+{
+       using std::sqrt;
+       return v/sqrt(v*v);
+}
 
 namespace Internal{
 
@@ -71,6 +75,17 @@
                        m[i][i] = 1;
        }
 };
+
+struct Fill
+{
+       template<int R, int C, class P, class B, class Data> static void 
eval(Matrix<R, C, P, B>& m, const Data * data)
+       {
+               for(int r=0; r < m.num_rows(); r++)
+                       for(int c=0; c < m.num_rows(); c++)
+                               m[r][c] = *data++;
+       }
+};
+
 }
 static Operator<Internal::Identity> Identity;
 

Index: so2.h
===================================================================
RCS file: /cvsroot/toon/TooN/so2.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -b -r1.2 -r1.3
--- so2.h       25 Mar 2009 17:40:30 -0000      1.2
+++ so2.h       25 Mar 2009 21:24:20 -0000      1.3
@@ -38,38 +38,30 @@
 template<class Precision = double>
 class SO2 {
 public:
-  friend std::istream& operator>><Precision>(std::istream& is, SO2& rhs);
-  friend std::ostream& operator<< <Precision>(std::ostream& is, const SO2& 
rhs);
+  friend std::istream& operator>> <Precision>(std::istream&, SO2& );
+  friend std::ostream& operator<< <Precision>(std::ostream&, const SO2&);
   friend class SE2<Precision>;
-  inline SO2(); 
-  SO2(const Matrix<2,2,Precision>& rhs) { 
-      *this = rhs;
-  }
-  SO2(const Precision l) {
-    *this = exp(l);
-  }
+       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);
 
   inline static SO2 exp(const Precision);
 
-  Precision ln() const {
-      return atan2(my_matrix[1][0], my_matrix[0][0]);
-  }
+  Precision ln() const { return atan2(my_matrix[1][0], my_matrix[0][0]); }
 
-  SO2 inverse() const {
-    return SO2(*this, Invert());
-  }
+  SO2 inverse() const { return SO2(*this, Invert()); }
 
   SO2& operator *=(const SO2& rhs){
     my_matrix=my_matrix*rhs.my_matrix;
     return *this;
   }
 
-  SO2 operator *(const SO2& rhs) const {
-      return SO2(*this,rhs);
-  }
+  SO2 operator *(const SO2& rhs) const { return SO2(*this,rhs); }
 
   const Matrix<2,2,Precision>& get_matrix() const {return my_matrix;}
   
@@ -101,7 +93,7 @@
 }
 
 template<int D, class P1, class PV, class Accessor>  inline
-Vector<2, typename Internal::MultiplyType<P1,PV>::type> operator*(const 
Vector<D, PV, Accessor>& lhs, const SO2<P1> & rhs){
+Vector<2, typename Internal::MultiplyType<PV,P1>::type> operator*(const 
Vector<D, PV, Accessor>& lhs, const SO2<P1> & rhs){
   return lhs * rhs.get_matrix();
 }
 
@@ -115,17 +107,6 @@
   return lhs * rhs.get_matrix();
 }
 
-namespace SO2static
-{
-  static double identity[4] = {1,0,0,1};
-  static double generator[4] = {0,-1,1,0};
-}
-
-template <class Precision> 
-inline SO2<Precision>::SO2() //:
-  //my_matrix(SO2static::identity,2,2, RowMajor::Layout<2,2,Precision>())
-{}
-
 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){
@@ -139,9 +120,9 @@
 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());
-  normalize(M[0]);
+  M[0] = unit(M[0]);
   M[1] -= M[0] * (M[0]*M[1]);
-  normalize(M[1]);
+  M[1] = unit(M[1]);
 }
 
 template <class Precision>
@@ -153,7 +134,12 @@
   return result;
 }
 
-template <class Precision> Matrix<2,2, Precision> 
SO2<Precision>::my_generator; //(SO2static::generator, 2, 2, 
RowMajor::Layout<2,2,Precision>());
+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::Fill>());
 
 #ifndef TOON_NO_NAMESPACE
 }

Index: internal/matrix.hh
===================================================================
RCS file: /cvsroot/toon/TooN/internal/matrix.hh,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -b -r1.17 -r1.18
--- internal/matrix.hh  20 Mar 2009 18:24:27 -0000      1.17
+++ internal/matrix.hh  25 Mar 2009 21:24:20 -0000      1.18
@@ -26,7 +26,12 @@
        
        //See vector.hh and allocator.hh for details about why the
        //copy constructor should be default.
-
+       template <class Op>
+       inline Matrix(const Operator<Op> &, int rows = Rows, int cols = Cols )
+       :Layout::template Layout<Rows,Cols,Precision>(rows, cols)
+       {
+               Op::eval(*this);
+       }
        // constructors to allow return value optimisations
        // construction from 1-ary operator
        template <class T, class Op>

Index: test/SXX_test.cc
===================================================================
RCS file: /cvsroot/toon/TooN/test/SXX_test.cc,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -b -r1.2 -r1.3
--- test/SXX_test.cc    25 Mar 2009 19:46:11 -0000      1.2
+++ test/SXX_test.cc    25 Mar 2009 21:24:20 -0000      1.3
@@ -5,9 +5,14 @@
 #include <TooN/so2.h>
 
 int main(int, char* *){
-    TooN::SO2<> r(M_PI_2);
+    TooN::SO2<> r1;
+    cout << r1 << endl;
+    TooN::SO2<int> r2;
+    cout << r2 << endl;
+    TooN::SO2<> r(0.1);
     cout << r << endl;
     cout << r.generator() << endl;
+    cout << r.ln() << endl;
 
     TooN::Vector<2, float> t = TooN::makeVector(0,1);
     cout << r * t << endl;
@@ -15,5 +20,14 @@
     TooN::Matrix<2> l;
     cout << r * l << endl;
     cout << l * r << endl;
+    
+    TooN::Matrix<2> m;
+    m[0] = TooN::makeVector(0.5, 1);
+    m[1] = TooN::makeVector(1,1);
+    r = m;
+    cout << r << endl;
+ 
+    TooN::Matrix<> test(TooN::Identity);
+ 
     return 0;
 }




reply via email to

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