examples/openGL/openGL.cpp

Go to the documentation of this file.
00001 /*
00002  *      Copyright (C) 2007. PARP Research Group.
00003  *      <http://perception.inf.um.es>
00004  *      University of Murcia, Spain.
00005  *
00006  *      This file is part of the QVision library.
00007  *
00008  *      QVision is free software: you can redistribute it and/or modify
00009  *      it under the terms of the GNU Lesser General Public License as
00010  *      published by the Free Software Foundation, version 3 of the License.
00011  *
00012  *      QVision is distributed in the hope that it will be useful,
00013  *      but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  *      GNU Lesser General Public License for more details.
00016  *
00017  *      You should have received a copy of the GNU Lesser General Public
00018  *      License along with QVision. If not, see <http://www.gnu.org/licenses/>.
00019  */
00020 
00042 #include <stdio.h>
00043 #include <stdlib.h>
00044 #include <iostream>
00045 #include <math.h>
00046 
00047 #include <QDebug>
00048 #include <QVector>
00049 #include <QThread>
00050 
00051 #include <qvcore/qvapplication.h>
00052 #include <qvcameras/qvmplayercamera.h>
00053 #include <qvgui/qvgui.h>
00054 #include<qvgui/qvglcanvas.h>
00055 
00056 #include <models3D.h>
00057 #define PI      3.1415926535
00058 
00060 
00061 class MyGLCanvas : public QVGLCanvas
00062 {
00063 public:
00064         MyGLCanvas(const QString &title,float worldx1,float worldy1,float worldz1,float worldx2, float worldy2, float worldz2, QWidget* parent = 0):
00065                 QVGLCanvas(title, parent), wx1(worldx1), wy1(worldy1), wz1(worldz1), wx2(worldx2), wy2(worldy2), wz2(worldz2)
00066                 { }
00067 
00068 protected:
00069 
00070         virtual void display()
00071                 {
00072                 glClearColor(.5, .5, .75, 1.0); // Background color.
00073                 glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
00074                 geobot3D(50.0, -100.0, 0.0);
00075                 glBegin(GL_LINES);
00076                         glColor3ub(255,255,0);
00077                 
00078                         glVertex3f(cx-maxwide/20,cy,cz);
00079                         glVertex3f(cx+maxwide/20,cy,cz);
00080                 
00081                         glVertex3f(cx,cy-maxwide/20,cz);
00082                         glVertex3f(cx,cy+maxwide/20,cz);
00083                 
00084                         glVertex3f(cx,cy,cz-maxwide/20);
00085                         glVertex3f(cx,cy,cz+maxwide/20);
00086                 glEnd();
00087                 
00088                 glBegin(GL_LINES);
00089                 glColor3ub(255,255,255);
00090         
00091                 glVertex3f(wx2,wy1,wz1);
00092                 glVertex3f(wx2,wy2,wz1);
00093         
00094                 glVertex3f(wx2,wy1,wz1);
00095                 glVertex3f(wx2,wy1,wz2);
00096         
00097                 glVertex3f(wx1,wy2,wz1);
00098                 glVertex3f(wx2,wy2,wz1);
00099         
00100                 glVertex3f(wx1,wy2,wz1);
00101                 glVertex3f(wx1,wy2,wz2);
00102         
00103                 glVertex3f(wx1,wy1,wz2);
00104                 glVertex3f(wx1,wy2,wz2);
00105         
00106                 glVertex3f(wx1,wy1,wz2);
00107                 glVertex3f(wx2,wy1,wz2);
00108         
00109                 glVertex3f(wx1,wy2,wz2);
00110                 glVertex3f(wx2,wy2,wz2);
00111         
00112                 glVertex3f(wx2,wy1,wz2);
00113                 glVertex3f(wx2,wy2,wz2);
00114         
00115                 glVertex3f(wx2,wy2,wz1);
00116                 glVertex3f(wx2,wy2,wz2);
00117         
00118                 glVertex3f(wx1,wy1,wz1);
00119                 glVertex3f(wx2,wy1,wz1);
00120         
00121                 glVertex3f(wx1,wy1,wz1);
00122                 glVertex3f(wx1,wy2,wz1); 
00123         
00124                 glVertex3f(wx1,wy1,wz1);
00125                 glVertex3f(wx1,wy1,wz2);
00126         
00127                 glEnd();
00128                 
00129                 glFlush();
00130                 }
00131 
00132         virtual void init()
00133                 {
00134                 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
00135 
00136                 glDisable(GL_CULL_FACE);
00137                 glEnable(GL_DEPTH_TEST);
00138                 
00139 
00140                 glEnable(GL_DITHER);
00141                 glShadeModel(GL_SMOOTH);
00142                 glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST);
00143                 glHint(GL_POLYGON_SMOOTH_HINT, GL_FASTEST);
00144                 
00145                 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); 
00146                 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); 
00147                 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
00148                 }
00149 
00150 
00151 private:
00152         float wx1,wy1,wz1,wx2,wy2,wz2;
00153 };
00154 
00155 class MyWorker: public QVWorker
00156         {
00157         public:
00158                 MyWorker(QString name): QVWorker(name)
00159                         {
00160                         addProperty< QVImage<uChar,1> >("Input image", inputFlag|outputFlag);
00161                         addProperty< QVImage<uChar,3> >("Corners", outputFlag);
00162                         }
00163 
00164                 void iterate()
00165                         {
00166                         const QVImage<uChar> image = getPropertyValue< QVImage<uChar,1> >("Input image");
00167                         QVImage<uChar,3> destino = image;
00168                         timeFlag("grab Frame");
00169                         setPropertyValue< QVImage<uChar,3> >("Corners", destino);
00170                         }
00171         };
00172 
00173 int main(int argc, char *argv[])
00174         {
00175         QVApplication app(argc, argv,
00176                 "Example program for QVision library. Applies corner detection over an input video."
00177                 );
00178 
00179         QVMPlayerCamera camera("Video");
00180         MyWorker worker("Corners Worker");
00181         camera.link(&worker,"Input image");
00182 
00183         QVGUI interface;
00184 
00185         QVImageCanvas imageCanvas("Corners");
00186         imageCanvas.linkProperty(worker, "Corners");
00187 
00188         MyGLCanvas glCanvas(QString("Hi"), 1.0,1.0,1.0,-1.0,-1.0,-1.0,0);
00189         MyGLCanvas glCanvas2(QString("Hi2"), 1.0,1.0,1.0,-1.0,-1.0,-1.0,0);
00190         return app.exec();
00191         }
00192 
00194 

Generated on Thu Mar 13 19:18:16 2008 for QVision by  doxygen 1.5.3