beobotmap.cpp

Go to the documentation of this file.
00001 /*!@file Qt/beobotmap.cpp */
00002 
00003 // //////////////////////////////////////////////////////////////////// //
00004 // The iLab Neuromorphic Vision C++ Toolkit - Copyright (C) 2001 by the //
00005 // University of Southern California (USC) and the iLab at USC.         //
00006 // See http://iLab.usc.edu for information about this project.          //
00007 // //////////////////////////////////////////////////////////////////// //
00008 // Major portions of the iLab Neuromorphic Vision Toolkit are protected //
00009 // under the U.S. patent ``Computation of Intrinsic Perceptual Saliency //
00010 // in Visual Environments, and Applications'' by Christof Koch and      //
00011 // Laurent Itti, California Institute of Technology, 2001 (patent       //
00012 // pending; application number 09/912,225 filed July 23, 2001; see      //
00013 // http://pair.uspto.gov/cgi-bin/final/home.pl for current status).     //
00014 // //////////////////////////////////////////////////////////////////// //
00015 // This file is part of the iLab Neuromorphic Vision C++ Toolkit.       //
00016 //                                                                      //
00017 // The iLab Neuromorphic Vision C++ Toolkit is free software; you can   //
00018 // redistribute it and/or modify it under the terms of the GNU General  //
00019 // Public License as published by the Free Software Foundation; either  //
00020 // version 2 of the License, or (at your option) any later version.     //
00021 //                                                                      //
00022 // The iLab Neuromorphic Vision C++ Toolkit is distributed in the hope  //
00023 // that it will be useful, but WITHOUT ANY WARRANTY; without even the   //
00024 // implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      //
00025 // PURPOSE.  See the GNU General Public License for more details.       //
00026 //                                                                      //
00027 // You should have received a copy of the GNU General Public License    //
00028 // along with the iLab Neuromorphic Vision C++ Toolkit; if not, write   //
00029 // to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,   //
00030 // Boston, MA 02111-1307 USA.                                           //
00031 // //////////////////////////////////////////////////////////////////// //
00032 //
00033 // Primary maintainer for this file:
00034 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/Qt/beobotmap.cpp $
00035 // $Id: beobotmap.cpp 5735 2005-10-18 16:00:27Z rjpeters $
00036 //
00037 
00038 #include "beobotmap.h"
00039 #include <cmath>
00040 
00041 BeoBotMap::BeoBotMap(QWidget *parent, const char *name)
00042                 :QGLWidget(parent, name)
00043 {
00044         setFormat(QGLFormat(DoubleBuffer | DepthBuffer));
00045         // init position
00046         iconlistx=100; iconlisty=100;
00047         iconlistgx = 0; iconlistgy= 0;
00048         colors[0] = yellow;
00049         colors[1] = blue;
00050         colors[2] = green;
00051         colors[3] = white;
00052         colors[4] = red;
00053         colors[5] = QColor(255,85,0);
00054         colors[6] = QColor(0,170,255);
00055 
00056         // create the icon
00057         createIcon(2);
00058 }
00059 
00060 void BeoBotMap::createIcon(int num)
00061 {
00062   int i;
00063   sizeOfList = num;
00064 
00065   listOfIcon = (BeoBotIcon *)malloc(sizeof(BeoBotIcon)*sizeOfList);
00066   for(i=0 ; i<sizeOfList ; i++)
00067   {
00068     listOfIcon[i].x = 100;
00069     listOfIcon[i].y = 100;
00070     listOfIcon[i].glx = 0.0;
00071     listOfIcon[i].gly = 0.0;
00072     listOfIcon[i].edgeSize = 30;
00073     listOfIcon[i].selected = 0;
00074 
00075     // FIXME for test. should be delete after finishing
00076     if(i==1)
00077     {
00078     listOfIcon[i].x = 140;
00079     listOfIcon[i].y = 140;
00080     listOfIcon[i].glx = 1.0;
00081     listOfIcon[i].gly = -1.0;
00082     listOfIcon[i].edgeSize = 30;
00083     listOfIcon[i].selected = 0;
00084 
00085     }
00086   }
00087   updateGL();
00088 }
00089 
00090 void BeoBotMap::initializeGL()
00091 {
00092         qglClearColor(black);
00093         glShadeModel(GL_FLAT);
00094         glEnable(GL_DEPTH_TEST);
00095         glEnable(GL_CULL_FACE);
00096 }
00097 
00098 void BeoBotMap::resizeGL(int w, int h)
00099 {
00100         glViewport(0, 0, w, h);
00101         glMatrixMode(GL_PROJECTION);
00102         glLoadIdentity();
00103         GLfloat x = (GLfloat)w/h;
00104         glFrustum(-x, x, -1.0, 1.0, 4.0, 15.0);
00105         glMatrixMode(GL_MODELVIEW);
00106 }
00107 
00108 void BeoBotMap::paintGL()
00109 {
00110         glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
00111         draw();
00112 }
00113 
00114 void BeoBotMap::draw()
00115 {
00116     int i,j;
00117 
00118               GLfloat coords[4][2] =
00119           {{-0.125,-0.125},{0.125,-0.125},
00120            {0.125,0.125},{-0.125,0.125}};  // define the view point
00121 
00122         glMatrixMode(GL_MODELVIEW);
00123         glLoadIdentity();
00124         glTranslatef(0.0,0.0,-10.0);
00125 
00126         // drawgl the objects
00127         qglColor(red);
00128         glBegin(GL_QUADS);
00129         for(i=0 ; i<sizeOfList ; i++)
00130         for(j=0 ; j<4 ; j++)
00131           glVertex3f(coords[j][0]+listOfIcon[i].glx,coords[j][1]+listOfIcon[i].gly,0.0);
00132         glEnd();
00133 
00134         // FIXME just for testing
00135         qglColor(white);
00136         glBegin(GL_TRIANGLES);
00137         glVertex2f(0.0,0.1);
00138         glVertex2f(-0.1,-0.1);
00139         glVertex2f(0.1,-0.1);
00140         glEnd();
00141         glBegin(GL_QUADS);
00142         glVertex2f(-0.025,-0.2);
00143         glVertex2f(0.025,-0.2);
00144         glVertex2f(0.025,-0.1);
00145         glVertex2f(-0.025,-0.1);
00146         glEnd();
00147 
00148 }
00149 
00150 void BeoBotMap::mousePressEvent(QMouseEvent *event)
00151 {
00152         lastPos = event->pos();
00153    //     printf("press:%d,%d\n", event->x(),event->y());
00154 }
00155 
00156 void BeoBotMap::mouseDoubleClickEvent(QMouseEvent *event)
00157 {
00158         int i;
00159         lastPos = event->pos();
00160         // double click to select the desired square
00161 
00162         // find the selected one in the list
00163         for(i=0 ; i<sizeOfList; i++)
00164         {
00165           if(lastPos.x() < (listOfIcon[i].x)+15 &&
00166              lastPos.x() > (listOfIcon[i].x)-15 &&
00167              lastPos.y() < (listOfIcon[i].y)+15 &&
00168              lastPos.y() > (listOfIcon[i].y)-15
00169             )
00170                 listOfIcon[i].selected = 1;
00171           else
00172                 listOfIcon[i].selected = 0;
00173         }
00174 }
00175 
00176 void BeoBotMap::mouseReleaseEvent(QMouseEvent *event)
00177 {
00178 }
00179 
00180 void BeoBotMap::mouseMoveEvent(QMouseEvent *event)
00181 {
00182         int dx = event->x() - lastPos.x();
00183         int dy = event->y() - lastPos.y();
00184         lastPos = event->pos();
00185  //       printf("press on and move:%d,%d\n", event->x(),event->y());
00186           if(event->state() & LeftButton)
00187           {
00188             for(int i=0 ; i<sizeOfList ; i++)
00189             if(lastPos.x() < (listOfIcon[i].x)+15 &&
00190                lastPos.x() > (listOfIcon[i].x)-15 &&
00191                lastPos.y() < (listOfIcon[i].y)+15 &&
00192                lastPos.y() > (listOfIcon[i].y)-15 &&
00193                listOfIcon[i].selected == 1
00194               )
00195             {
00196               listOfIcon[i].x += dx;
00197               listOfIcon[i].y += dy;
00198               listOfIcon[i].glx += GLfloat(dx) * 0.025;
00199               listOfIcon[i].gly -= GLfloat(dy) * 0.025;
00200                // updateGL();
00201 
00202        //         printf("in and move!");
00203             }
00204           }
00205           updateGL();
00206 }
00207 
00208 void BeoBotMap::returnSelectedCoord(float &fx, float &fy)
00209 {
00210         int i;
00211         fx = fy = 0.0F;
00212         for(i=0 ; i<sizeOfList ; i++)
00213           if(listOfIcon[i].selected == 1)
00214           {
00215              fx = listOfIcon[i].x;
00216              fy = listOfIcon[i].y;
00217           }
00218 }
Generated on Sun May 8 08:05:33 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3