libcvd-members
[Top][All Lists]
Advanced

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

[libcvd-members] libcvd/cvd camera.h vision.h internal/builtin_c...


From: Gerhard Reitmayr
Subject: [libcvd-members] libcvd/cvd camera.h vision.h internal/builtin_c...
Date: Fri, 08 Apr 2011 10:54:57 +0000

CVSROOT:        /cvsroot/libcvd
Module name:    libcvd
Changes by:     Gerhard Reitmayr <gerhard>      11/04/08 10:54:56

Modified files:
        cvd            : camera.h vision.h 
        cvd/internal   : builtin_components.h gl_types.h 
Added files:
        cvd            : gles1_helpers.h 
        cvd/internal   : gles1_types.h 

Log message:
        added gl_helpers for OpenGLES1 and split up gl_types as well. made CVD 
respect TooN::DefaultPrecision in some functions and cameras to make porting to 
mobile phones easier. Let me know, if there are any issues

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/libcvd/cvd/camera.h?cvsroot=libcvd&r1=1.27&r2=1.28
http://cvs.savannah.gnu.org/viewcvs/libcvd/cvd/vision.h?cvsroot=libcvd&r1=1.38&r2=1.39
http://cvs.savannah.gnu.org/viewcvs/libcvd/cvd/gles1_helpers.h?cvsroot=libcvd&rev=1.1
http://cvs.savannah.gnu.org/viewcvs/libcvd/cvd/internal/builtin_components.h?cvsroot=libcvd&r1=1.10&r2=1.11
http://cvs.savannah.gnu.org/viewcvs/libcvd/cvd/internal/gl_types.h?cvsroot=libcvd&r1=1.5&r2=1.6
http://cvs.savannah.gnu.org/viewcvs/libcvd/cvd/internal/gles1_types.h?cvsroot=libcvd&rev=1.1

Patches:
Index: camera.h
===================================================================
RCS file: /cvsroot/libcvd/libcvd/cvd/camera.h,v
retrieving revision 1.27
retrieving revision 1.28
diff -u -b -r1.27 -r1.28
--- camera.h    8 Mar 2011 15:11:11 -0000       1.27
+++ camera.h    8 Apr 2011 10:54:56 -0000       1.28
@@ -49,7 +49,7 @@
     inline void save(std::ostream& os) const; 
 
     /// Fast linear projection for working out what's there
-    inline TooN::Vector<2> linearproject(const TooN::Vector<2>& camframe, 
double scale=1) const;
+    inline TooN::Vector<2> linearproject(const TooN::Vector<2>& camframe, 
TooN::DefaultPrecision scale=1) const;
        /// Project from Euclidean camera frame to image plane
     inline TooN::Vector<2> project(const TooN::Vector<2>& camframe) const;
        /// Project from image plane to a Euclidean camera
@@ -98,7 +98,7 @@
     inline void save(std::ostream& os) const;
 
     /// Fast linear projection for working out what's there
-    inline TooN::Vector<2> linearproject(const TooN::Vector<2>& camframe, 
double scale=1) const; 
+    inline TooN::Vector<2> linearproject(const TooN::Vector<2>& camframe, 
TooN::DefaultPrecision scale=1) const; 
        /// Project from Euclidean camera frame to image plane
     inline TooN::Vector<2> project(const TooN::Vector<2>& camframe) const; 
        /// Project from image plane to a Euclidean camera
@@ -147,13 +147,13 @@
     inline void save(std::ostream& os) const;
 
     /// Fast linear projection for working out what's there
-    inline TooN::Vector<2> linearproject(const TooN::Vector<2>& camframe, 
double scale=1) const ;
+    inline TooN::Vector<2> linearproject(const TooN::Vector<2>& camframe, 
TooN::DefaultPrecision scale=1) const ;
        /// Project from Euclidean camera frame to image plane
 
        inline TooN::Vector<2> project_vector(const TooN::Vector<2>& x, const 
TooN::Vector<2>& d) const {
-           const double xsq = x*x;
-           const double& a = my_camera_parameters[4];
-           const double& b = my_camera_parameters[5];
+           const TooN::DefaultPrecision xsq = x*x;
+           const TooN::DefaultPrecision& a = my_camera_parameters[4];
+           const TooN::DefaultPrecision& b = my_camera_parameters[5];
            return (2 * (a + 2*b*xsq) * (x*d) * 
TooN::diagmult(my_camera_parameters.slice<0,2>(), x) +
                    (1 + a*xsq + 
b*xsq*xsq)*TooN::diagmult(my_camera_parameters.slice<0,2>(), d));
        }
@@ -207,9 +207,9 @@
     TooN::Vector<num_parameters> my_camera_parameters; // f_u, f_v, u_0, v_0
     mutable TooN::Vector<2> my_last_camframe;
 
-       inline double sat(double x)
+       inline TooN::DefaultPrecision sat(TooN::DefaultPrecision x)
        {
-               double a;
+               TooN::DefaultPrecision a;
                a = (-3*my_camera_parameters[4] - 
sqrt(9*my_camera_parameters[4]*my_camera_parameters[4] - 20 * 
my_camera_parameters[5]))/(10*my_camera_parameters[5]);
 
                if(x < a)
@@ -234,7 +234,7 @@
                private:
                        TooN::Vector<2> radial_distort(const TooN::Vector<2>& 
camframe) const
                        {
-                               double r2 = camframe*camframe;
+                               TooN::DefaultPrecision r2 = camframe*camframe;
                                return camframe / sqrt(1 + 
my_camera_parameters[4] * r2);
                        }
                        
@@ -259,7 +259,7 @@
 
 
                        /// Fast linear projection for working out what's there
-                       inline TooN::Vector<2> linearproject(const 
TooN::Vector<2>& camframe, double scale=1) const
+                       inline TooN::Vector<2> linearproject(const 
TooN::Vector<2>& camframe, TooN::DefaultPrecision scale=1) const
                        {
                                return TooN::Vector<2>(scale * 
diagmult(camframe, my_camera_parameters.slice<0,2>()) + 
my_camera_parameters.slice<2,2>());
                        }
@@ -278,7 +278,7 @@
                                TooN::Vector<2> mod_camframe;
                                mod_camframe[0] = 
(imframe[0]-my_camera_parameters[2])/my_camera_parameters[0];
                                mod_camframe[1] = 
(imframe[1]-my_camera_parameters[3])/my_camera_parameters[1];
-                               double rprime2 = mod_camframe*mod_camframe;
+                               TooN::DefaultPrecision rprime2 = 
mod_camframe*mod_camframe;
                                my_last_camframe =  mod_camframe / sqrt(1 - 
my_camera_parameters[4] * rprime2);
                                return my_last_camframe;
                        }
@@ -296,15 +296,15 @@
                        {
                                TooN::Matrix<2,2> J;
 
-                               double xc = pt[0];
-                               double yc = pt[1];
+                               TooN::DefaultPrecision xc = pt[0];
+                               TooN::DefaultPrecision yc = pt[1];
 
-                               double fu= my_camera_parameters[0];
-                               double fv= my_camera_parameters[1];
-                               double a = my_camera_parameters[4];
+                               TooN::DefaultPrecision fu= 
my_camera_parameters[0];
+                               TooN::DefaultPrecision fv= 
my_camera_parameters[1];
+                               TooN::DefaultPrecision a = 
my_camera_parameters[4];
 
-                               double g = 1/sqrt(1 + a * (xc*xc + yc*yc));
-                               double g3= g*g*g;
+                               TooN::DefaultPrecision g = 1/sqrt(1 + a * 
(xc*xc + yc*yc));
+                               TooN::DefaultPrecision g3= g*g*g;
                                
                                J[0][0] = fu * (g - a * xc*xc*g3);
                                J[0][1] = - fu * a * xc * yc * g3;
@@ -328,16 +328,16 @@
 
                                TooN::Matrix<5, 2> result;
 
-                               double xc = pt[0];
-                               double yc = pt[1];
-                               double r2 = xc*xc + yc*yc;
-
-                               double fu= my_camera_parameters[0];
-                               double fv= my_camera_parameters[1];
-                               double a = my_camera_parameters[4];
+                               TooN::DefaultPrecision xc = pt[0];
+                               TooN::DefaultPrecision yc = pt[1];
+                               TooN::DefaultPrecision r2 = xc*xc + yc*yc;
+
+                               TooN::DefaultPrecision fu= 
my_camera_parameters[0];
+                               TooN::DefaultPrecision fv= 
my_camera_parameters[1];
+                               TooN::DefaultPrecision a = 
my_camera_parameters[4];
 
-                               double g = 1/sqrt(1 + a * r2);
-                               double g3= g*g*g;
+                               TooN::DefaultPrecision g = 1/sqrt(1 + a * r2);
+                               TooN::DefaultPrecision g3= g*g*g;
 
                                //Derivatives of x_image:
                                result[0][0] = mod_camframe[0];
@@ -392,7 +392,7 @@
                private:
                        TooN::Vector<2> radial_distort(const TooN::Vector<2>& 
camframe) const
                        {
-                               double r2 = camframe*camframe;
+                               TooN::DefaultPrecision r2 = camframe*camframe;
                                return camframe / sqrt(1 + 
my_camera_parameters[4] * r2);
                        }
                        
@@ -417,7 +417,7 @@
 
 
                        /// Fast linear projection for working out what's there
-                       inline TooN::Vector<2> linearproject(const 
TooN::Vector<2>& camframe, double scale=1) const
+                       inline TooN::Vector<2> linearproject(const 
TooN::Vector<2>& camframe, TooN::DefaultPrecision scale=1) const
                        {
                                return TooN::Vector<2>(scale * (camframe* 
my_camera_parameters[0]) + my_camera_parameters.slice<2,2>());
                        }
@@ -436,7 +436,7 @@
                                TooN::Vector<2> mod_camframe;
                                mod_camframe[0] = 
(imframe[0]-my_camera_parameters[2])/my_camera_parameters[0];
                                mod_camframe[1] = 
(imframe[1]-my_camera_parameters[3])/my_camera_parameters[0];
-                               double rprime2 = mod_camframe*mod_camframe;
+                               TooN::DefaultPrecision rprime2 = 
mod_camframe*mod_camframe;
                                my_last_camframe =  mod_camframe / sqrt(1 - 
my_camera_parameters[4] * rprime2);
                                return my_last_camframe;
                        }
@@ -447,14 +447,14 @@
                        {
                                TooN::Matrix<2,2> J;
 
-                               double xc = my_last_camframe[0];
-                               double yc = my_last_camframe[1];
+                               TooN::DefaultPrecision xc = my_last_camframe[0];
+                               TooN::DefaultPrecision yc = my_last_camframe[1];
 
-                               double f= my_camera_parameters[0];
-                               double a = my_camera_parameters[4];
+                               TooN::DefaultPrecision f= 
my_camera_parameters[0];
+                               TooN::DefaultPrecision a = 
my_camera_parameters[4];
 
-                               double g = 1/sqrt(1 + a * (xc*xc + yc*yc));
-                               double g3= g*g*g;
+                               TooN::DefaultPrecision g = 1/sqrt(1 + a * 
(xc*xc + yc*yc));
+                               TooN::DefaultPrecision g3= g*g*g;
                                
                                J[0][0] = f * (g - 2 * a * xc*xc*g3);
                                J[0][1] = -2 * f * a * xc * yc * g3;
@@ -471,15 +471,15 @@
 
                                TooN::Matrix<5, 2> result;
 
-                               double xc = my_last_camframe[0];
-                               double yc = my_last_camframe[1];
-                               double r2 = xc*xc + yc*yc;
+                               TooN::DefaultPrecision xc = my_last_camframe[0];
+                               TooN::DefaultPrecision yc = my_last_camframe[1];
+                               TooN::DefaultPrecision r2 = xc*xc + yc*yc;
 
-                               double f= my_camera_parameters[0];
-                               double a = my_camera_parameters[4];
+                               TooN::DefaultPrecision f= 
my_camera_parameters[0];
+                               TooN::DefaultPrecision a = 
my_camera_parameters[4];
 
-                               double g = 1/sqrt(1 + a * r2);
-                               double g3= g*g*g;
+                               TooN::DefaultPrecision g = 1/sqrt(1 + a * r2);
+                               TooN::DefaultPrecision g3= g*g*g;
 
                                //Derivatives of x_image:
                                result[0][0] = mod_camframe[0];
@@ -540,11 +540,11 @@
        private:
          TooN::Vector<2> radial_distort(const TooN::Vector<2>& camframe) const
          {
-               const double r2 = camframe*camframe;
-               const double w2 = my_camera_parameters[4] * 
my_camera_parameters[4];
-               const double factor = w2*r2;
-               double term = 1.0;
-               double scale = term;
+               const TooN::DefaultPrecision r2 = camframe*camframe;
+               const TooN::DefaultPrecision w2 = my_camera_parameters[4] * 
my_camera_parameters[4];
+               const TooN::DefaultPrecision factor = w2*r2;
+               TooN::DefaultPrecision term = 1.0;
+               TooN::DefaultPrecision scale = term;
                term *= factor;
                scale -= term/3.0;
                term *= factor;
@@ -574,7 +574,7 @@
          }
        
          /// Fast linear projection for working out what's there
-         inline TooN::Vector<2> linearproject(const TooN::Vector<2>& camframe, 
double scale=1) const
+         inline TooN::Vector<2> linearproject(const TooN::Vector<2>& camframe, 
TooN::DefaultPrecision scale=1) const
          {
                return TooN::Vector<2>(scale * diagmult(camframe, 
my_camera_parameters.slice<0,2>()) + my_camera_parameters.slice<2,2>());
          }
@@ -593,21 +593,21 @@
                TooN::Vector<2> mod_camframe;
                mod_camframe[0] = 
(imframe[0]-my_camera_parameters[2])/my_camera_parameters[0];
                mod_camframe[1] = 
(imframe[1]-my_camera_parameters[3])/my_camera_parameters[1];
-               const double rprime2 = mod_camframe*mod_camframe;
+               const TooN::DefaultPrecision rprime2 = 
mod_camframe*mod_camframe;
        
                // first guess
-               double scale = mod_camframe*mod_camframe;
+               TooN::DefaultPrecision scale = mod_camframe*mod_camframe;
        
-               const double w2 = my_camera_parameters[4]* 
my_camera_parameters[4];
-               const double k3 = -w2/ 3.0;
-               const double k5 = w2*w2/ 5.0;
-               const double k7 = -w2*w2*w2/ 7.0;
+               const TooN::DefaultPrecision w2 = my_camera_parameters[4]* 
my_camera_parameters[4];
+               const TooN::DefaultPrecision k3 = -w2/ 3.0;
+               const TooN::DefaultPrecision k5 = w2*w2/ 5.0;
+               const TooN::DefaultPrecision k7 = -w2*w2*w2/ 7.0;
        
                // 3 iterations of Newton-Raphson
                for(int i=0; i<3; i++){
-                 double temp=1+scale*(k3 + scale*(k5 + scale*k7));
-                 double error = rprime2 - scale*temp*temp;
-                 double deriv = temp*(temp+2*scale*(k3 + 2*scale*(k5 + 
1.5*scale*k7)));
+                 TooN::DefaultPrecision temp=1+scale*(k3 + scale*(k5 + 
scale*k7));
+                 TooN::DefaultPrecision error = rprime2 - scale*temp*temp;
+                 TooN::DefaultPrecision deriv = temp*(temp+2*scale*(k3 + 
2*scale*(k5 + 1.5*scale*k7)));
                  scale += error/deriv;
                }
                my_last_camframe = 
mod_camframe/(1+scale*(k3+scale*(k5+scale*k7)));
@@ -627,11 +627,11 @@
          inline TooN::Matrix<2,2> get_derivative(const TooN::Vector<2>& pt) 
const
          {
                TooN::Matrix<2,2> J = TooN::Identity;
-               double r2=pt*pt;
-               const double w2 = my_camera_parameters[4]* 
my_camera_parameters[4];
-               const double k3 = -w2/ 3.0;
-               const double k5 = w2*w2/ 5.0;
-               const double k7 = -w2*w2*w2/ 7.0;
+               TooN::DefaultPrecision r2=pt*pt;
+               const TooN::DefaultPrecision w2 = my_camera_parameters[4]* 
my_camera_parameters[4];
+               const TooN::DefaultPrecision k3 = -w2/ 3.0;
+               const TooN::DefaultPrecision k5 = w2*w2/ 5.0;
+               const TooN::DefaultPrecision k7 = -w2*w2*w2/ 7.0;
                J *= (1 + k3*r2 + k5*r2*r2 + k7*r2*r2*r2);
                J += ((2*k3 + 4*k5*r2 + 6*k7*r2*r2) * pt.as_col()) * 
pt.as_row();
                J[0] *= my_camera_parameters[0];
@@ -653,22 +653,22 @@
        
                TooN::Matrix<5, 2> result;
        
-               const double xc = pt[0];
-               const double yc = pt[1];
-               const double r2 = xc*xc + yc*yc;
-               const double r4 = r2*r2;
-               const double r6 = r4*r2;
-       
-               const double fu= my_camera_parameters[0];
-               const double fv= my_camera_parameters[1];
-       
-               const double w = my_camera_parameters[4];
-               const double w3 = w*w*w;
-               const double w5 = w3*w*w;
-       
-               const double k1 = -(2.0/3.0)*w*r2;
-               const double k2 = (4.0/5.0)*w3*r4;
-               const double k3 = -(6.0/7.0)*w5*r6;
+               const TooN::DefaultPrecision xc = pt[0];
+               const TooN::DefaultPrecision yc = pt[1];
+               const TooN::DefaultPrecision r2 = xc*xc + yc*yc;
+               const TooN::DefaultPrecision r4 = r2*r2;
+               const TooN::DefaultPrecision r6 = r4*r2;
+       
+               const TooN::DefaultPrecision fu= my_camera_parameters[0];
+               const TooN::DefaultPrecision fv= my_camera_parameters[1];
+       
+               const TooN::DefaultPrecision w = my_camera_parameters[4];
+               const TooN::DefaultPrecision w3 = w*w*w;
+               const TooN::DefaultPrecision w5 = w3*w*w;
+       
+               const TooN::DefaultPrecision k1 = -(2.0/3.0)*w*r2;
+               const TooN::DefaultPrecision k2 = (4.0/5.0)*w3*r4;
+               const TooN::DefaultPrecision k3 = -(6.0/7.0)*w5*r6;
        
                //Derivatives of x_image:
                result[0][0] = mod_camframe[0];
@@ -733,7 +733,7 @@
   os << my_camera_parameters;
 }
 
-inline TooN::Vector<2> Camera::Linear::linearproject(const TooN::Vector<2>& 
camframe, double scale) const {
+inline TooN::Vector<2> Camera::Linear::linearproject(const TooN::Vector<2>& 
camframe, TooN::DefaultPrecision scale) const {
   return TooN::Vector<2>(scale * diagmult(camframe, 
my_camera_parameters.slice<0,2>()) + my_camera_parameters.slice<2,2>());
 }
 
@@ -796,7 +796,7 @@
   os << my_camera_parameters;
 }
 
-inline TooN::Vector<2> Camera::Cubic::linearproject(const TooN::Vector<2>& 
camframe, double scale) const {
+inline TooN::Vector<2> Camera::Cubic::linearproject(const TooN::Vector<2>& 
camframe, TooN::DefaultPrecision scale) const {
   return TooN::Vector<2>(scale * diagmult(camframe, 
my_camera_parameters.slice<0,2>()) + my_camera_parameters.slice<2,2>());
 }
 
@@ -812,12 +812,12 @@
   mod_camframe[1] = 
(imframe[1]-my_camera_parameters[3])/my_camera_parameters[1];
 
   // first guess
-  double scale = 1+my_camera_parameters[4]*(mod_camframe*mod_camframe);
+  TooN::DefaultPrecision scale = 
1+my_camera_parameters[4]*(mod_camframe*mod_camframe);
 
   // 3 iterations of Newton-Rapheson
   for(int i=0; i<3; i++){
-    double error = my_camera_parameters[4]*(mod_camframe*mod_camframe) - 
scale*scale*(scale-1);
-    double deriv = (3*scale -2)*scale;
+    TooN::DefaultPrecision error = 
my_camera_parameters[4]*(mod_camframe*mod_camframe) - scale*scale*(scale-1);
+    TooN::DefaultPrecision deriv = (3*scale -2)*scale;
     scale += error/deriv;
   }  
   my_last_camframe = mod_camframe/scale;
@@ -861,8 +861,8 @@
 }
 
 void Camera::Cubic::update(const TooN::Vector<num_parameters>& updates){
-  double fu=my_camera_parameters[0];
-  double fv=my_camera_parameters[1];
+  TooN::DefaultPrecision fu=my_camera_parameters[0];
+  TooN::DefaultPrecision fv=my_camera_parameters[1];
   my_camera_parameters[0]+=fu*updates[0];
   my_camera_parameters[1]+=fv*updates[1];
   my_camera_parameters[2]+=fu*updates[2];
@@ -883,13 +883,13 @@
   os << my_camera_parameters;
 }
 
-inline TooN::Vector<2> Camera::Quintic::linearproject(const TooN::Vector<2>& 
camframe, double scale) const {
+inline TooN::Vector<2> Camera::Quintic::linearproject(const TooN::Vector<2>& 
camframe, TooN::DefaultPrecision scale) const {
   return TooN::Vector<2>(scale * diagmult(camframe, 
my_camera_parameters.slice<0,2>()) + my_camera_parameters.slice<2,2>());
 }
 
 inline TooN::Vector<2> Camera::Quintic::project(const TooN::Vector<2>& 
camframe) const {
   my_last_camframe = camframe;
-  double sc = /*sat*/(camframe*camframe);
+  TooN::DefaultPrecision sc = /*sat*/(camframe*camframe);
   TooN::Vector<2> mod_camframe = camframe * (1 + sc*(my_camera_parameters[4] + 
sc*my_camera_parameters[5]));
   return TooN::Vector<2>(diagmult(mod_camframe, 
my_camera_parameters.slice<0,2>()) + my_camera_parameters.slice<2,2>());
 }
@@ -909,13 +909,13 @@
   mod_camframe[1] = 
(imframe[1]-my_camera_parameters[3])/my_camera_parameters[1];
 
   // first guess
-  double scale = mod_camframe*mod_camframe;
+  TooN::DefaultPrecision scale = mod_camframe*mod_camframe;
 
   // 3 iterations of Newton-Rapheson
   for(int i=0; i<3; i++){
-    double 
temp=1+scale*(my_camera_parameters[4]+my_camera_parameters[5]*scale);
-    double error = mod_camframe*mod_camframe - scale*temp*temp;
-    double deriv = 
temp*(temp+2*scale*(my_camera_parameters[4]+2*my_camera_parameters[5]*scale));
+    TooN::DefaultPrecision 
temp=1+scale*(my_camera_parameters[4]+my_camera_parameters[5]*scale);
+    TooN::DefaultPrecision error = mod_camframe*mod_camframe - scale*temp*temp;
+    TooN::DefaultPrecision deriv = 
temp*(temp+2*scale*(my_camera_parameters[4]+2*my_camera_parameters[5]*scale));
     scale += error/deriv;
   }  
   my_last_camframe = 
mod_camframe/(1+scale*(my_camera_parameters[4]+my_camera_parameters[5]*scale));
@@ -930,7 +930,7 @@
     std::pair<TooN::Vector<2>, TooN::Matrix<2> > result;
     result.first = this->unproject(imframe);
     TooN::Matrix<2> J = get_derivative();
-    double rdet = 1.0/ (J[0][0] * J[1][1] - J[0][1] * J[1][0]);
+    TooN::DefaultPrecision rdet = 1/ (J[0][0] * J[1][1] - J[0][1] * J[1][0]);
     TooN::Matrix<2> Jinv;
     Jinv[0][0] = rdet * J[1][1];
     Jinv[1][1] = rdet * J[0][0];
@@ -943,8 +943,8 @@
 
 TooN::Matrix<2,2> Camera::Quintic::get_derivative() const {
   TooN::Matrix<2,2> result = TooN::Identity;
-  double temp1=my_last_camframe*my_last_camframe;
-  double temp2=my_camera_parameters[5]*temp1;
+  TooN::DefaultPrecision temp1=my_last_camframe*my_last_camframe;
+  TooN::DefaultPrecision temp2=my_camera_parameters[5]*temp1;
   result *= 1+temp1*(my_camera_parameters[4]+temp2);
   result += (2*(my_camera_parameters[4]+2*temp2)*my_last_camframe.as_col()) * 
my_last_camframe.as_row();
   result[0] *= my_camera_parameters[0];
@@ -956,9 +956,9 @@
 
 TooN::Matrix<2,2> Camera::Quintic::get_inv_derivative() const {
   TooN::Matrix<2,2> result = TooN::Identity;
-  double temp1=my_last_camframe*my_last_camframe;
-  double temp2=my_camera_parameters[5]*temp1;
-  double temp3=2.0*(my_camera_parameters[4]+2.0*temp2);
+  TooN::DefaultPrecision temp1=my_last_camframe*my_last_camframe;
+  TooN::DefaultPrecision temp2=my_camera_parameters[5]*temp1;
+  TooN::DefaultPrecision temp3=2*(my_camera_parameters[4]+2*temp2);
    
   result *= 1+temp1*(my_camera_parameters[4]+temp2);
 
@@ -980,9 +980,9 @@
 {
 
   TooN::Matrix<2,2> result = TooN::Identity;
-  double temp1=x*x;
-  double temp2=my_camera_parameters[5]*temp1;
-  double temp3=2.0*(my_camera_parameters[4]+2.0*temp2);
+  TooN::DefaultPrecision temp1=x*x;
+  TooN::DefaultPrecision temp2=my_camera_parameters[5]*temp1;
+  TooN::DefaultPrecision temp3=2*(my_camera_parameters[4]+2*temp2);
 
     result *= 1+temp1*(my_camera_parameters[4]+temp2);
   //Identity(result,1+temp1*(my_camera_parameters[4]+temp2));
@@ -1004,8 +1004,8 @@
 
 TooN::Matrix<2,2> Camera::Quintic::get_derivative(const TooN::Vector<2>& x) 
const {
     TooN::Matrix<2,2> result = TooN::Identity;
-    double temp1=x*x;
-    double temp2=my_camera_parameters[5]*temp1;
+    TooN::DefaultPrecision temp1=x*x;
+    TooN::DefaultPrecision temp2=my_camera_parameters[5]*temp1;
     result *= 1+temp1*(my_camera_parameters[4]+temp2);
     //Identity(result,1+temp1*(my_camera_parameters[4]+temp2));
     result += (2*(my_camera_parameters[4]+2*temp2)*x.as_col()) * x.as_row();
@@ -1016,8 +1016,8 @@
 
 TooN::Matrix<Camera::Quintic::num_parameters,2> 
Camera::Quintic::get_parameter_derivs() const {
   TooN::Matrix<num_parameters,2> result;
-  double r2 = my_last_camframe * my_last_camframe;
-  double r4 = r2 * r2;
+  TooN::DefaultPrecision r2 = my_last_camframe * my_last_camframe;
+  TooN::DefaultPrecision r4 = r2 * r2;
   TooN::Vector<2> mod_camframe = my_last_camframe * (1+ r2 * 
(my_camera_parameters[4] + r2 * my_camera_parameters[5]));
 
   result(0,0) = mod_camframe[0];
@@ -1046,8 +1046,8 @@
 }
 
 void Camera::Quintic::update(const TooN::Vector<num_parameters>& updates){
-  double fu = my_camera_parameters[0];
-  double fv = my_camera_parameters[1];
+  TooN::DefaultPrecision fu = my_camera_parameters[0];
+  TooN::DefaultPrecision fv = my_camera_parameters[1];
 
   my_camera_parameters[0]+=updates[0]*fu;
   my_camera_parameters[1]+=updates[1]*fv;

Index: vision.h
===================================================================
RCS file: /cvsroot/libcvd/libcvd/cvd/vision.h,v
retrieving revision 1.38
retrieving revision 1.39
diff -u -b -r1.38 -r1.39
--- vision.h    4 Mar 2011 09:40:46 -0000       1.38
+++ vision.h    8 Apr 2011 10:54:56 -0000       1.39
@@ -270,7 +270,7 @@
 #endif
 
 
-template <class T, class S> inline void sample(const SubImage<S>& im, double 
x, double y, T& result)
+template <class T, class S, typename Precision> inline void sample(const 
SubImage<S>& im, Precision x, Precision y, T& result)
 {
   typedef typename Pixel::Component<S>::type SComp;
   typedef typename Pixel::Component<T>::type TComp;
@@ -285,7 +285,7 @@
   }
  }
 
-template <class T, class S> inline T sample(const SubImage<S>& im, double x, 
double y){
+template <class T, class S, typename Precision> inline T sample(const 
SubImage<S>& im, Precision x, Precision y){
     T result;
     sample( im, x, y, result);
     return result;
@@ -319,24 +319,24 @@
  * @return the number of pixels not in the in image 
  * @Note: this will collide with transform in the std namespace
  */
-template <class T, class S>
-int transform(const BasicImage<S>& in, BasicImage<T>& out, const 
TooN::Matrix<2>& M, const TooN::Vector<2>& inOrig, const TooN::Vector<2>& 
outOrig, const T defaultValue = T())
+template <typename T, typename S, typename P>
+int transform(const BasicImage<S>& in, BasicImage<T>& out, const 
TooN::Matrix<2, 2, P>& M, const TooN::Vector<2, P>& inOrig, const 
TooN::Vector<2, P>& outOrig, const T defaultValue = T())
 {
     const int w = out.size().x, h = out.size().y, iw = in.size().x, ih = 
in.size().y; 
-    const TooN::Vector<2> across = M.T()[0];
-    const TooN::Vector<2> down =   M.T()[1];
+    const TooN::Vector<2, P> across = M.T()[0];
+    const TooN::Vector<2, P> down =   M.T()[1];
    
-    const TooN::Vector<2> p0 = inOrig - M*outOrig;
-    const TooN::Vector<2> p1 = p0 + w*across;
-    const TooN::Vector<2> p2 = p0 + h*down;
-    const TooN::Vector<2> p3 = p0 + w*across + h*down;
+    const TooN::Vector<2, P> p0 = inOrig - M*outOrig;
+    const TooN::Vector<2, P> p1 = p0 + w*across;
+    const TooN::Vector<2, P> p2 = p0 + h*down;
+    const TooN::Vector<2, P> p3 = p0 + w*across + h*down;
         
     // ul --> p0
     // ur --> w*across + p0
     // ll --> h*down + p0
     // lr --> w*across + h*down + p0
-    double min_x = p0[0], min_y = p0[1];
-    double max_x = min_x, max_y = min_y;
+    P min_x = p0[0], min_y = p0[1];
+    P max_x = min_x, max_y = min_y;
    
     // Minimal comparisons needed to determine bounds
     if (across[0] < 0)
@@ -357,13 +357,13 @@
        max_y += h*down[1];
    
     // This gets from the end of one row to the beginning of the next
-    const TooN::Vector<2> carriage_return = down - w*across;
+    const TooN::Vector<2, P> carriage_return = down - w*across;
 
     //If the patch being extracted is completely in the image then no 
     //check is needed with each point.
     if (min_x >= 0 && min_y >= 0 && max_x < iw-1 && max_y < ih-1) 
     {
-       TooN::Vector<2> p = p0;
+       TooN::Vector<2, P> p = p0;
        for (int i=0; i<h; ++i, p+=carriage_return)
            for (int j=0; j<w; ++j, p+=across) 
                sample(in,p[0],p[1],out[i][j]);
@@ -372,10 +372,10 @@
     else // Check each source location
     {
        // Store as doubles to avoid conversion cost for comparison
-       const double x_bound = iw-1;
-       const double y_bound = ih-1;
+       const P x_bound = iw-1;
+       const P y_bound = ih-1;
        int count = 0;
-       TooN::Vector<2> p = p0;
+       TooN::Vector<2, P> p = p0;
        for (int i=0; i<h; ++i, p+=carriage_return) {
            for (int j=0; j<w; ++j, p+=across) {
                //Make sure that we are extracting pixels in the image

Index: internal/builtin_components.h
===================================================================
RCS file: /cvsroot/libcvd/libcvd/cvd/internal/builtin_components.h,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -b -r1.10 -r1.11
--- internal/builtin_components.h       29 Oct 2008 12:29:36 -0000      1.10
+++ internal/builtin_components.h       8 Apr 2011 10:54:56 -0000       1.11
@@ -87,33 +87,33 @@
     };
 
 #if defined (CVD_HAVE_TOON)
-    template<int N> struct Component<TooN::Vector<N> >
+    template<int N, typename P> struct Component<TooN::Vector<N, P> >
     {
-      typedef double type;
+      typedef P type;
       static const size_t count=N;
       
-      static const type& get(const TooN::Vector<N>& pixel, size_t i)
+      static inline const P & get(const TooN::Vector<N, P>& pixel, size_t i)
       {
        return pixel[i];
       }
 
-      static inline type& get(TooN::Vector<N>& pixel, size_t i)
+      static inline P& get(TooN::Vector<N, P>& pixel, size_t i)
       {
        return pixel[i];
       }
     };
 
-    template<int N, int M> struct Component<TooN::Matrix<N,M> >
+    template<int N, int M, typename P> struct Component<TooN::Matrix<N,M, P> >
     {
-      typedef double type;
+      typedef P type;
       static const size_t count=N*M;
       
-      static const type& get(const TooN::Matrix<N,M>& pixel, size_t i)
+      static const P& get(const TooN::Matrix<N,M,P>& pixel, size_t i)
       {
        return pixel[i/M][i%M];
       }
 
-      static inline type& get(TooN::Matrix<N,M>& pixel, size_t i)
+      static inline P& get(TooN::Matrix<N,M,P>& pixel, size_t i)
       {
        return pixel[i/M][i%M];
       }

Index: internal/gl_types.h
===================================================================
RCS file: /cvsroot/libcvd/libcvd/cvd/internal/gl_types.h,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -b -r1.5 -r1.6
--- internal/gl_types.h 22 Oct 2008 15:43:36 -0000      1.5
+++ internal/gl_types.h 8 Apr 2011 10:54:56 -0000       1.6
@@ -24,12 +24,7 @@
 #ifndef CVD_GL_TYPES_H
 #define CVD_GL_TYPES_H
 
-#include <cvd/byte.h>
-#include <cvd/rgb.h>
-#include <cvd/byte.h>
-#include <cvd/rgb8.h>
-#include <cvd/rgba.h>
-#include <cvd/la.h>
+#include <cvd/internal/gles1_types.h>
 
 namespace CVD
 {
@@ -39,31 +34,6 @@
                template<class C> struct data;
 
                //Scalar types
-
-               template<> struct data<unsigned char>
-               {
-                       static const int format=GL_LUMINANCE;
-                       static const int type  =GL_UNSIGNED_BYTE;
-               };
-
-               template<> struct data<signed char>
-               {
-                       static const int format=GL_LUMINANCE;
-                       static const int type  =GL_BYTE;
-               };
-               
-               template<> struct data<unsigned  short>
-               {
-                       static const int format=GL_LUMINANCE;
-                       static const int type  =GL_UNSIGNED_SHORT;
-               };
-
-               template<> struct data<short>
-               {
-                       static const int format=GL_LUMINANCE;
-                       static const int type  =GL_SHORT;
-               };
-
                template<> struct data<unsigned int>
                {
                        static const int format=GL_LUMINANCE;
@@ -76,46 +46,14 @@
                        static const int type  =GL_INT;
                };
                
-               template<> struct data<float>
-               {
-                       static const int format=GL_LUMINANCE;
-                       static const int type  =GL_FLOAT;
-               };
-
                template<> struct data<double>
                {
                        static const int format=GL_LUMINANCE;
                        static const int type  =GL_DOUBLE;
                };
        
-       
-
                //Rgb<*> types
        
-               template<> struct data<Rgb<unsigned char> >
-               {
-                       static const int format=GL_RGB;
-                       static const int type  =GL_UNSIGNED_BYTE;
-               };
-
-               template<> struct data<Rgb<signed char> >
-               {
-                       static const int format=GL_RGB;
-                       static const int type  =GL_BYTE;
-               };
-               
-               template<> struct data<Rgb<unsigned  short> >
-               {
-                       static const int format=GL_RGB;
-                       static const int type  =GL_UNSIGNED_SHORT;
-               };
-
-               template<> struct data<Rgb<short> >
-               {
-                       static const int format=GL_RGB;
-                       static const int type  =GL_SHORT;
-               };
-
                template<> struct data<Rgb<unsigned int> >
                {
                        static const int format=GL_RGB;
@@ -128,45 +66,14 @@
                        static const int type  =GL_INT;
                };
                
-               template<> struct data<Rgb<float> >
-               {
-                       static const int format=GL_RGB;
-                       static const int type  =GL_FLOAT;
-               };
-
                template<> struct data<Rgb<double> >
                {
                        static const int format=GL_RGB;
                        static const int type  =GL_DOUBLE;
                };
                
-               
                //Rgba<*> types
        
-               template<> struct data<Rgba<unsigned char> >
-               {
-                       static const int format=GL_RGBA;
-                       static const int type  =GL_UNSIGNED_BYTE;
-               };
-
-               template<> struct data<Rgba<signed char> >
-               {
-                       static const int format=GL_RGBA;
-                       static const int type  =GL_BYTE;
-               };
-               
-               template<> struct data<Rgba<unsigned  short> >
-               {
-                       static const int format=GL_RGBA;
-                       static const int type  =GL_UNSIGNED_SHORT;
-               };
-
-               template<> struct data<Rgba<short> >
-               {
-                       static const int format=GL_RGBA;
-                       static const int type  =GL_SHORT;
-               };
-
                template<> struct data<Rgba<unsigned int> >
                {
                        static const int format=GL_RGBA;
@@ -179,43 +86,13 @@
                        static const int type  =GL_INT;
                };
                
-               template<> struct data<Rgba<float> >
-               {
-                       static const int format=GL_RGBA;
-                       static const int type  =GL_FLOAT;
-               };
-
                template<> struct data<Rgba<double> >
                {
                        static const int format=GL_RGBA;
                        static const int type  =GL_DOUBLE;
                };
 
-
                //La<*> types
-               template<> struct data<La<unsigned char> >
-               {
-                       static const int format=GL_LUMINANCE_ALPHA;
-                       static const int type  =GL_UNSIGNED_BYTE;
-               };
-
-               template<> struct data<La<signed char> >
-               {
-                       static const int format=GL_LUMINANCE_ALPHA;
-                       static const int type  =GL_BYTE;
-               };
-               
-               template<> struct data<La<unsigned  short> >
-               {
-                       static const int format=GL_LUMINANCE_ALPHA;
-                       static const int type  =GL_UNSIGNED_SHORT;
-               };
-
-               template<> struct data<La<short> >
-               {
-                       static const int format=GL_LUMINANCE_ALPHA;
-                       static const int type  =GL_SHORT;
-               };
 
                template<> struct data<La<unsigned int> >
                {
@@ -229,29 +106,14 @@
                        static const int type  =GL_INT;
                };
                
-               template<> struct data<La<float> >
-               {
-                       static const int format=GL_LUMINANCE_ALPHA;
-                       static const int type  =GL_FLOAT;
-               };
-
                template<> struct data<La<double> >
                {
                        static const int format=GL_LUMINANCE_ALPHA;
                        static const int type  =GL_DOUBLE;
                };
 
-               //Rgb8 type
-
-               template<> struct data<Rgb8>
-               {
-                       static const int format=GL_RGBA;
-                       static const int type  =GL_UNSIGNED_BYTE;
                };
                
-       };
-
-
 };
 
 #endif

Index: gles1_helpers.h
===================================================================
RCS file: gles1_helpers.h
diff -N gles1_helpers.h
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ gles1_helpers.h     8 Apr 2011 10:54:56 -0000       1.1
@@ -0,0 +1,423 @@
+/*
+       This file is part of the CVD Library.
+
+       Copyright (C) 2005 The Authors
+
+       This library is free software; you can redistribute it and/or
+       modify it under the terms of the GNU Lesser General Public
+       License as published by the Free Software Foundation; either
+       version 2.1 of the License, or (at your option) any later version.
+
+       This library is distributed in the hope that it will be useful,
+       but WITHOUT ANY WARRANTY; without even the implied warranty of
+       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+       Lesser General Public License for more details.
+
+       You should have received a copy of the GNU Lesser General Public
+       License along with this library; if not, write to the Free Software
+       Foundation, Inc.,
+    51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+*/
+#ifndef CVD_GLES1_HELPERS_H
+#define CVD_GLES1_HELPERS_H
+
+#include <iostream>
+#include <map>
+#include <utility>
+
+#include <cvd/image_ref.h>
+#include <cvd/image.h>
+#include <cvd/byte.h>
+#include <cvd/rgb.h>
+#include <cvd/byte.h>
+#include <cvd/rgb8.h>
+#include <cvd/rgba.h>
+#include <cvd/config.h>
+// #include <OpenGLES/ES1/gl.h>
+#include <cvd/internal/gles1_types.h>
+
+#ifdef CVD_HAVE_TOON
+#include <TooN/TooN.h>
+#include <cvd/se3.h>
+#include <cvd/so3.h>
+#include <cvd/se2.h>
+#include <cvd/so2.h>
+#endif
+
+namespace CVD
+{
+
+    /// add a translation specified by an ImageRef
+    /// @param v the translation ImageRef
+    /// @ingroup gGL
+    inline void glTranslate( const ImageRef & v )
+    {
+        glTranslatef(v.x, v.y, 0);
+    }
+
+       /// add a translation specified from the first three coordinates of a 
vector
+       /// @param v the translation vector
+       /// @ingroup gGL
+       template <int N, typename P, typename A> inline void glTranslate( const 
TooN::Vector<N, P, A> & v)
+       {
+               glTranslatef(v[0], v[1], v[2]);
+       }
+
+       /// add a translation specified from the first two coordinates of a 
2-vector
+       /// z is set to zero here
+       /// @param v the translation vector
+       /// @ingroup gGL
+       template <typename P, typename A> inline void glTranslate( const 
TooN::Vector<2, P, A> & v)
+       {
+               glTranslatef(v[0], v[1], 0);
+       }
+
+       /// add a translation specified from the first coordinate of a 1-vector
+       /// Y and Z are zero here
+       /// @param v the translation vector
+       /// @ingroup gGL
+       template <typename P, typename A> inline void glTranslate( const 
TooN::Vector<1, P, A> & v)
+       {
+               glTranslatef(v[0], 0, 0);
+       }
+
+       /// multiply a TooN matrix onto the current matrix stack. Works for 
matrizes
+       /// of size n >= 4 and uses the upper left 4x4 submatrix. The matrix is 
also
+       /// transposed to account for GL's column major format.
+       /// @param m the transformation matrix
+       /// @ingroup gGL
+       template <int N, class P, class A> inline void glMultMatrix( const 
TooN::Matrix<N,N,P,A> & m )
+       {
+               GLfloat glm[16];
+               glm[0] = m[0][0]; glm[1] = m[1][0]; glm[2] = m[2][0]; glm[3] = 
m[3][0];
+               glm[4] = m[0][1]; glm[5] = m[1][1]; glm[6] = m[2][1]; glm[7] = 
m[3][1];
+               glm[8] = m[0][2]; glm[9] = m[1][2]; glm[10] = m[2][2]; glm[11] 
= m[3][2];
+               glm[12] = m[0][3]; glm[13] = m[1][3]; glm[14] = m[2][3]; 
glm[15] = m[3][3];
+               glMultMatrixf(glm);
+       }
+
+       /// multiply a TooN 3x3 matrix onto the current matrix stack. The GL 
matrix
+       /// last column and row are set to 0 with the lower right element to 1.
+       /// The matrix is also transposed to account for GL's column major 
format.
+       /// @param m the transformation matrix
+       /// @ingroup gGL
+       template <class P, class A> inline void glMultMatrix( const 
TooN::Matrix<3,3,P,A> & m )
+       {
+               GLfloat glm[16];
+               glm[0] = m[0][0]; glm[1] = m[1][0]; glm[2] = m[2][0]; glm[3] = 
0;
+               glm[4] = m[0][1]; glm[5] = m[1][1]; glm[6] = m[2][1]; glm[7] = 
0;
+               glm[8] = m[0][2]; glm[9] = m[1][2]; glm[10] = m[2][2]; glm[11] 
= 0;
+               glm[12] = 0; glm[13] = 0; glm[14] = 0; glm[15] = 1;
+               glMultMatrixf(glm);
+       }
+
+       /// multiply a TooN 2x2 matrix onto the current matrix stack. The TooN 
matrix
+       /// will only occupy the upper left hand block, the remainder will be 
from the
+       /// identity matrix. The matrix is also transposed to account for GL's 
column major format.
+       /// @param m the transformation matrix
+       /// @ingroup gGL
+       template <class P, class A> inline void glMultMatrix( const 
TooN::Matrix<2,2,P,A> & m )
+       {
+               GLfloat glm[16];
+               glm[0] = m[0][0]; glm[1] = m[1][0]; glm[2] = 0; glm[3] = 0;
+               glm[4] = m[0][1]; glm[5] = m[1][1]; glm[6] = 0; glm[7] = 0;
+               glm[8] = 0; glm[9] = 0; glm[10] = 1; glm[11] = 0;
+               glm[12] = 0; glm[13] = 0; glm[14] = 0; glm[15] = 1;
+               glMultMatrixf(glm);
+       }
+
+       /// multiplies a SO3 onto the current matrix stack
+       /// @param so3 the SO3
+       /// @ingroup gGL
+       template <typename P>
+       inline void glMultMatrix( const TooN::SO3<P> & so3 )
+       {
+               glMultMatrix( so3.get_matrix());
+       }
+
+       /// multiplies a SE3 onto the current matrix stack. This multiplies
+       /// the SO3 and the translation in order.
+       /// @param se3 the SE3
+       /// @ingroup gGL
+       template <typename P>
+       inline void glMultMatrix( const TooN::SE3<P> & se3 )
+       {
+               glTranslate( se3.get_translation());
+               glMultMatrix( se3.get_rotation());
+       }
+
+       /// multiplies a SO2 onto the current matrix stack
+       /// @param so2 the SO2
+       /// @ingroup gGL
+       template <typename P>
+       inline void glMultMatrix( const TooN::SO2<P> & so2 )
+       {
+               glMultMatrix( so2.get_matrix());
+       }
+
+       /// multiplies a SE2 onto the current matrix stack. This multiplies
+       /// the SO2 and the translation in order.
+       /// @param se3 the SE2
+       /// @ingroup gGL
+       template <typename P>
+       inline void glMultMatrix( const TooN::SE2<P> & se2 )
+       {
+               glTranslate( se2.get_translation());
+               glMultMatrix( se2.get_rotation());
+       }
+
+       /// Sets up an ortho projection suitable for drawing onto individual 
pixels of a
+       /// gl window (or video image.) glVertex2f(0.0,0.0) will be the top 
left pixel and
+       /// glVertex2f(xsize-1.0, ysize-1.0) will be the bottom right pixel. 
Depth is set
+       /// from -1 to 1.
+        /// n.b. You first need to set up the matrix environment yourself,
+       /// e.g. glMatrixMode(GL_PROJECTION); glLoadIdentity();
+       /// @param size ImageRef containing the size of the GL window.
+       template <typename P> inline void glOrtho( const CVD::ImageRef & size, 
const P nearPlane = -1.0, const P farPlane = 1.0)
+       {
+           ::glOrthof( -0.375, size.x - 0.375, size.y - 0.375, -0.375, 
nearPlane, farPlane );
+       }
+
+       /// Sets up an ortho projection from a simple Vector<6>
+        /// n.b. You first need to set up the matrix environment yourself,
+       /// e.g. glMatrixMode(GL_PROJECTION); glLoadIdentity();
+       /// @param param 6-vector containing the parameters of the projection
+       template <typename P, typename A> inline void glOrtho( const 
TooN::Vector<6, P, A> & param)
+       {
+               ::glOrthof( param[0], param[1], param[2], param[3], param[4], 
param[5]);
+       }
+
+       /// sets a gl frustum from the linear camera parameters, image size and 
near and far plane.
+       /// The camera will be in OpenGL style with camera center in the origin 
and the viewing direction
+       /// down the negative z axis, with y pointing upwards and x pointing to 
the left and the image plane
+       /// at z=-1.
+       /// Images coordinates need to be rotated around the x axis to make 
sense here, because typically
+       /// the camera is described as y going down (pixel lines) and image 
plane at z=1.
+       /// @param params vector containing fu, fv, pu, pv as in the linear 
part of camera parameters
+       /// @param width width of the image plane in pixels, here the viewport 
for example
+       /// @param height height of the image plane in pixels, here the 
viewport for example
+       /// @param near near clipping plane
+       /// @param far far clipping plane
+       /// @ingroup gGL
+       template <typename P, typename A>
+       inline void glFrustum( const TooN::Vector<4, P, A> & params, const 
float width, const float height, const float nearPlane = 0.1, const float 
farPlane = 100)
+       {
+               GLfloat left, right, bottom, top;
+               left = -nearPlane * params[2] / params[0];
+               top = nearPlane * params[3] / params[1];
+               right = nearPlane * ( width - params[2] ) / params[0];
+               bottom = - nearPlane * ( height - params[3] ) / params[1];
+               ::glFrustumf( left, right, bottom, top, nearPlane, farPlane );
+       }
+
+       /// sets a gl frustum taking the first 4 parameters from the camera 
model. see @see glFrustum for
+       /// details on the created frustum.
+       /// @param camera camera supplying the parameters for the frustum
+       /// @param width width of the image plane in pixels, here the viewport 
for example
+       /// @param height height of the image plane in pixels, here the 
viewport for example
+       /// @param near near clipping plane
+       /// @param far far clipping plane
+       /// @ingroup gGL
+       template <class CAMERA> inline void glFrustum( const CAMERA & camera, 
const float width, const float height, const float nearPlane = 0.1, const float 
farPlane = 100)
+       {
+               glFrustum( camera.get_parameters().template slice<0,4>(), 
width, height, nearPlane, farPlane);
+       }
+
+       /// Sets up an ortho projection from a simple Vector<6>
+       /// n.b. You first need to set up the matrix environment yourself,
+       /// e.g. glMatrixMode(GL_PROJECTION); glLoadIdentity();
+       /// @param param 6-vector containing the parameters of the projection
+       template <typename P, typename A> inline void glFrustum( const 
TooN::Vector<6, P, A> & param)
+       {
+               ::glFrustumf( param[0], param[1], param[2], param[3], param[4], 
param[5]);
+       }
+    
+       /// Set the new colour to the red, green and blue components given in 
the Vector
+       /// (where 0.0 represents zero intensity and 1.0 full intensity)
+       /// @param v The new colour
+       ///  @ingroup gGL
+       template <typename P, typename A> inline void glColor(const 
TooN::Vector<3, P, A> & v)
+       {
+               glColor4f(v[0], v[1], v[2], 1);
+       }
+
+       /// Set the new colour to the red, green, blue and alpha components 
given in the Vector
+       /// (where 0.0 represents zero intensity and 1.0 full intensity)
+       /// @param v The new colour
+       ///@ingroup gGL
+       template <typename P, typename A> inline void glColor(const 
TooN::Vector<4, P, A>& v)
+       {
+               glColor4f(v[0], v[1], v[2], v[3]);
+       }
+    
+       /// Set the new clear colour to the red, green, blue and alpha 
components given in the Vector
+       /// (where 0.0 represents zero intensity and 1.0 full intensity)
+       /// @param v The new colour
+       ///@ingroup gGL
+       template <typename P, typename A> inline void glClearColor(const 
TooN::Vector<4, P, A> & v)
+       {
+               ::glClearColor((GLclampf)v[0], (GLclampf)v[1], (GLclampf)v[2], 
(GLclampf)v[3]);
+       }
+
+       /// Set the new clear colour to the red, green, blue components given 
in the Vector
+       /// alpha is set to 1
+       /// @param v The new colour
+       ///@ingroup gGL
+       template <typename P, typename A> inline void glClearColor(const 
TooN::Vector<3, P, A>& v)
+       {
+               ::glClearColor((GLclampf)v[0], (GLclampf)v[1], (GLclampf)v[2], 
1);
+       }
+
+       /// glColor version for dynamic TooN::Vector, will test for 3 or 4 
components
+       /// @param v The new colour
+       /// @ingroup gGL
+       template <typename P, typename A> inline void glColor(const 
TooN::Vector<-1, P, A> & v)
+       {
+               switch(v.size()){
+               case 3: glColor4f(v[0], v[1], v[2], 1);
+                       break;
+               case 4: glColor4f(v[0], v[1], v[2], v[3]);
+                       break;
+               }
+       }
+
+       /// Set the new colour to the red, green, blue components given
+       /// (where 0 represents zero intensity and 255 full intensity)
+       /// @param c The new colour
+       ///@ingroup gGL
+       inline void glColor(const CVD::Rgb<byte>& c)
+       {
+               glColor4ub(c.red, c.green, c.blue, 255);
+       }
+
+       /// Set the new colour to the red, green and blue components given
+       /// (where 0.0 represents zero intensity and 1.0 full intensity)
+       /// @param c The new colour
+       ///@ingroup gGL
+       inline void glColor(const CVD::Rgb<float>& c)
+       {
+               glColor4f(c.red, c.green, c.blue, 1);
+       }
+
+       /// Set the new colour to the red, green and blue components given
+       /// (where 0.0 represents zero intensity and 255 full intensity). The 
Rgb8::dummy member is ignored
+       /// @param c The new colour
+       ///@ingroup gGL
+       inline void glColor3(const CVD::Rgb8& c)
+       {
+               glColor4ub(c.red, c.green, c.blue, 255);
+       }
+
+       /// Set the new colour to the red, green, blue and alpha components 
given
+       /// (where 0.0 represents zero intensity and 255 full intensity)
+       /// @param c The new colour
+       ///@ingroup gGL
+       inline void glColor4(const CVD::Rgb8& c)
+       {
+               glColor4ub(c.red, c.green, c.blue, c.dummy);
+       }
+
+       /// Set the new colour to the red, green, blue and alpha components 
given
+       /// (where 0 represents zero intensity and 255 full intensity)
+       /// @param c The new colour
+       ///@ingroup gGL
+       inline void glColor(const CVD::Rgba<unsigned char>& c)
+       {
+               glColor4ub(c.red, c.green, c.blue, c.alpha);
+       }
+
+       /// Set the new colour to the red, green, blue and alpha components 
given
+       /// (where 0.0 represents zero intensity and 1.0 full intensity)
+       /// @param c The new colour
+       ///@ingroup gGL
+       inline void glColor(const CVD::Rgba<float>& c)
+       {
+               glColor4f(c.red, c.green, c.blue, c.alpha);
+       }
+
+       /// Read the current image from the colour buffer specified by 
glReadBuffer
+       /// @param i The image to write the image data into. This must already 
be initialised to be an BasicImage (or Image) of the right size.
+       /// @param origin The window co-ordinate of the first pixel to be read 
from the frame buffer
+       ///@ingroup gGL
+       template<class C> inline void glReadPixels(BasicImage<C>& i, const 
ImageRef origin=ImageRef(0,0))
+       {
+               ::glReadPixels(origin.x, origin.y, i.size().x, i.size().y, 
gl::data<C>::format, gl::data<C>::type, i.data());
+       }
+
+       /// Read the current image from the colour buffer specified by 
glReadBuffer
+       /// @param size   The size of the area to read.
+       /// @param origin The window co-ordinate of the first pixel to be read 
from the frame buffer
+       ///@ingroup gGL
+       template<class C> inline Image<C> glReadPixels(ImageRef size, const 
ImageRef origin=ImageRef(0,0))
+       {
+               Image<C> i(size);
+               ::glReadPixels(origin.x, origin.y, i.size().x, i.size().y, 
gl::data<C>::format, gl::data<C>::type, i.data());
+               return i;
+       }
+
+       /// Sets an image as a texture sub region.
+       /// note the reordering of the various parameters to make better use of 
default parameters
+       /// @param i the image to set as texture
+       /// @ingroup gGL
+       template<class C> inline void glTexSubImage2D( const SubImage<C> &i, 
GLint xoffset = 0, GLint yoffset = 0, GLenum target = GL_TEXTURE_2D, GLint 
level = 0)
+       {
+               ::glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
+               ::glTexSubImage2D(target, level, xoffset, yoffset, i.size().x, 
i.size().y, gl::data<C>::format, gl::data<C>::type, i.data());
+       }
+
+       /// Sets an image as a texture.
+       /// note the reordering of the various parameters to make better use of 
default parameters
+       /// @param i the image to set as texture
+       /// @ingroup gGL
+       template<class C> inline void glTexImage2D( const SubImage<C> &i, GLint 
border = 0, GLenum target = GL_TEXTURE_2D, GLint level = 0)
+       {
+               ::glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
+               ::glTexImage2D(target, level, gl::data<C>::format, i.size().x, 
i.size().y, border, gl::data<C>::format, gl::data<C>::type, i.data());
+       }
+
+    /// Prints the current errors on the gl error stack
+    ///@ingroup gGL
+    inline void glPrintErrors(void){
+        GLenum code;
+        while((code = glGetError()) != GL_NO_ERROR){
+            std::cout << "GL:" << code << std::endl;
+        }
+    }
+
+    /// @defgroup gGLText OpenGL text rendering
+    /// @ingroup gGL
+    /// @{
+
+    /// sets the font to use for future font rendering commands. currently 
sans, serif and mono are available.
+    /// @param fontname string containing font name
+    void glSetFont( const std::string & fontname );
+
+    /// returns the name of the currently active font
+    const std::string & glGetFont();
+
+    /// different style for font rendering
+    enum TEXT_STYLE {
+        FILL = 0,       ///< renders glyphs as filled polygons
+        OUTLINE = 1,    ///< renders glyphs as outlines with GL_LINES
+        NICE = 2        ///< renders glyphs filled with antialiased outlines
+    };
+
+    /// renders a string in GL using the current settings.
+    /// Font coordinates are +X along the line and +Y along the up direction 
of glyphs.
+    /// The origin is at the top baseline at the left of the first character. 
Characters have a maximum size of 1.
+    /// linefeed is interpreted as a new line and the start is offset in -Y 
direction by @ref spacing . Individual characters
+    /// are separated by @ref kerning + plus their individual with.
+    /// @param text string to be rendered, unknown characters are replaced 
with '?'
+    /// @param style rendering style
+    /// @param spacing distance between individual text lines
+    /// @param kerning distance between characters
+    std::pair<double, double> glDrawText(const std::string & text, enum 
TEXT_STYLE style = NICE, double spacing = 1.5, double kerning = 0.1);
+
+    /// returns the size of the bounding box of a text to be rendered, similar 
to @ref glDrawText but without any visual output
+    std::pair<double, double> glGetExtends(const std::string & text, double 
spacing = 1.5, double kerning = 0.1);
+
+    ///@}
+
+};
+
+#endif

Index: internal/gles1_types.h
===================================================================
RCS file: internal/gles1_types.h
diff -N internal/gles1_types.h
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ internal/gles1_types.h      8 Apr 2011 10:54:56 -0000       1.1
@@ -0,0 +1,180 @@
+/*                       
+       This file is part of the CVD Library.
+
+       Copyright (C) 2005 The Authors
+
+       This library is free software; you can redistribute it and/or
+       modify it under the terms of the GNU Lesser General Public
+       License as published by the Free Software Foundation; either
+       version 2.1 of the License, or (at your option) any later version.
+
+       This library is distributed in the hope that it will be useful,
+       but WITHOUT ANY WARRANTY; without even the implied warranty of
+       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+       Lesser General Public License for more details.
+
+       You should have received a copy of the GNU Lesser General Public
+       License along with this library; if not, write to the Free Software
+       Foundation, Inc., 
+    51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+*/
+// Pulled out of gl_helpers to make documentation neater
+// Paul Smith 20/4/05
+
+#ifndef CVD_GLES1_TYPES_H
+#define CVD_GLES1_TYPES_H
+
+#include <cvd/byte.h>
+#include <cvd/rgb.h>
+#include <cvd/byte.h>
+#include <cvd/rgb8.h>
+#include <cvd/rgba.h>
+#include <cvd/la.h>
+
+namespace CVD
+{
+       
+       namespace gl
+       {
+               template<class C> struct data;
+
+               //Scalar types
+
+               template<> struct data<unsigned char>
+               {
+                       static const int format=GL_LUMINANCE;
+                       static const int type  =GL_UNSIGNED_BYTE;
+               };
+
+               template<> struct data<signed char>
+               {
+                       static const int format=GL_LUMINANCE;
+                       static const int type  =GL_BYTE;
+               };
+               
+               template<> struct data<unsigned  short>
+               {
+                       static const int format=GL_LUMINANCE;
+                       static const int type  =GL_UNSIGNED_SHORT;
+               };
+
+               template<> struct data<short>
+               {
+                       static const int format=GL_LUMINANCE;
+                       static const int type  =GL_SHORT;
+               };
+
+               template<> struct data<float>
+               {
+                       static const int format=GL_LUMINANCE;
+                       static const int type  =GL_FLOAT;
+               };
+
+               //Rgb<*> types
+       
+               template<> struct data<Rgb<unsigned char> >
+               {
+                       static const int format=GL_RGB;
+                       static const int type  =GL_UNSIGNED_BYTE;
+               };
+
+               template<> struct data<Rgb<signed char> >
+               {
+                       static const int format=GL_RGB;
+                       static const int type  =GL_BYTE;
+               };
+               
+               template<> struct data<Rgb<unsigned  short> >
+               {
+                       static const int format=GL_RGB;
+                       static const int type  =GL_UNSIGNED_SHORT;
+               };
+
+               template<> struct data<Rgb<short> >
+               {
+                       static const int format=GL_RGB;
+                       static const int type  =GL_SHORT;
+               };
+
+               template<> struct data<Rgb<float> >
+               {
+                       static const int format=GL_RGB;
+                       static const int type  =GL_FLOAT;
+               };
+
+               //Rgba<*> types
+
+               template<> struct data<Rgba<unsigned char> >
+               {
+                       static const int format=GL_RGBA;
+                       static const int type  =GL_UNSIGNED_BYTE;
+               };
+
+               template<> struct data<Rgba<signed char> >
+               {
+                       static const int format=GL_RGBA;
+                       static const int type  =GL_BYTE;
+               };
+               
+               template<> struct data<Rgba<unsigned  short> >
+               {
+                       static const int format=GL_RGBA;
+                       static const int type  =GL_UNSIGNED_SHORT;
+               };
+
+               template<> struct data<Rgba<short> >
+               {
+                       static const int format=GL_RGBA;
+                       static const int type  =GL_SHORT;
+               };
+
+               template<> struct data<Rgba<float> >
+               {
+                       static const int format=GL_RGBA;
+                       static const int type  =GL_FLOAT;
+               };
+
+               //La<*> types
+               template<> struct data<La<unsigned char> >
+               {
+                       static const int format=GL_LUMINANCE_ALPHA;
+                       static const int type  =GL_UNSIGNED_BYTE;
+               };
+
+               template<> struct data<La<signed char> >
+               {
+                       static const int format=GL_LUMINANCE_ALPHA;
+                       static const int type  =GL_BYTE;
+               };
+               
+               template<> struct data<La<unsigned  short> >
+               {
+                       static const int format=GL_LUMINANCE_ALPHA;
+                       static const int type  =GL_UNSIGNED_SHORT;
+               };
+
+               template<> struct data<La<short> >
+               {
+                       static const int format=GL_LUMINANCE_ALPHA;
+                       static const int type  =GL_SHORT;
+               };
+               
+               template<> struct data<La<float> >
+               {
+                       static const int format=GL_LUMINANCE_ALPHA;
+                       static const int type  =GL_FLOAT;
+               };
+
+               //Rgb8 type
+
+               template<> struct data<Rgb8>
+               {
+                       static const int format=GL_RGBA;
+                       static const int type  =GL_UNSIGNED_BYTE;
+               };
+               
+       };
+
+};
+
+#endif



reply via email to

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