test-shader.C

Go to the documentation of this file.
00001 /*!@file SceneUnderstanding/test-shader.C test the opengl shader */
00002 
00003 // The iLab Neuromorphic Vision C++ Toolkit - Copyright (C) 2000-2003   //
00004 // by the University of Southern California (USC) and the iLab at USC.  //
00005 // See http://iLab.usc.edu for information about this project.          //
00006 // //////////////////////////////////////////////////////////////////// //
00007 // Major portions of the iLab Neuromorphic Vision Toolkit are protected //
00008 // under the U.S. patent ``Computation of Intrinsic Perceptual Saliency //
00009 // in Visual Environments, and Applications'' by Christof Koch and      //
00010 // Laurent Itti, California Institute of Technology, 2001 (patent       //
00011 // pending; application number 09/912,225 filed July 23, 2001; see      //
00012 // http://pair.uspto.gov/cgi-bin/final/home.pl for current status).     //
00013 // //////////////////////////////////////////////////////////////////// //
00014 // This file is part of the iLab Neuromorphic Vision C++ Toolkit.       //
00015 //                                                                      //
00016 // The iLab Neuromorphic Vision C++ Toolkit is free software; you can   //
00017 // redistribute it and/or modify it under the terms of the GNU General  //
00018 // Public License as published by the Free Software Foundation; either  //
00019 // version 2 of the License, or (at your option) any later version.     //
00020 //                                                                      //
00021 // The iLab Neuromorphic Vision C++ Toolkit is distributed in the hope  //
00022 // that it will be useful, but WITHOUT ANY WARRANTY; without even the   //
00023 // implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      //
00024 // PURPOSE.  See the GNU General Public License for more details.       //
00025 //                                                                      //
00026 // You should have received a copy of the GNU General Public License    //
00027 // along with the iLab Neuromorphic Vision C++ Toolkit; if not, write   //
00028 // to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,   //
00029 // Boston, MA 02111-1307 USA.                                           //
00030 // //////////////////////////////////////////////////////////////////// //
00031 // Primary maintainer for this file: Lior Elazary <elazary@usc.edu>
00032 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/AppMedia/test-viewport3D.C $
00033 // $Id: test-viewport3D.C 13054 2010-03-26 00:12:36Z lior $
00034 
00035 
00036 
00037 #include "GUI/ViewPort3D.H"
00038 #include "Util/log.H"
00039 #include "Util/WorkThreadServer.H"
00040 #include "Util/JobWithSemaphore.H"
00041 #include "Component/ModelManager.H"
00042 #include "Raster/GenericFrame.H"
00043 #include "Image/Layout.H"
00044 #include "Image/MatrixOps.H"
00045 #include "Image/DrawOps.H"
00046 #include "GUI/DebugWin.H"
00047 #include "Media/FrameSeries.H"
00048 #include "Transport/FrameInfo.H"
00049 #include <stdlib.h>
00050 #include <math.h>
00051 
00052 #include "GUI/XWinManaged.H"
00053 #include "GUI/ImageDisplayStream.H"
00054 
00055 
00056 int main(int argc, char *argv[]){
00057 
00058         ModelManager manager("Test Viewport");
00059 
00060         nub::ref<OutputFrameSeries> ofs(new OutputFrameSeries(manager));
00061         manager.addSubComponent(ofs);
00062 
00063         nub::ref<InputFrameSeries> ifs(new InputFrameSeries(manager));
00064         manager.addSubComponent(ifs);
00065 
00066 
00067         // Parse command-line:
00068         if (manager.parseCommandLine(argc, argv, "", 0, 0) == false) return(1);
00069         // let's get all our ModelComponent instances started:
00070         manager.start();
00071 
00072         ViewPort3D vp(320,240, false, false, false);
00073 
00074         //Load the shader
00075 
00076         vp.setCamera(Point3D<float>(0,0,100), Point3D<float>(0,0,0));
00077 
00078         vp.initFrame();
00079         Image<PixRGB<byte> > tmp(320,240,ZEROS);
00080         uint texId = vp.addTexture(tmp);
00081 
00082         GLhandleARB prog1 = vp.createShader("src/Image/OpenGlShaders/sobel.frag", GL_FRAGMENT_SHADER_ARB);
00083         GLhandleARB prog2 = vp.createShader("src/Image/OpenGlShaders/nonmaxsupp.frag", GL_FRAGMENT_SHADER_ARB);
00084 
00085         float texCoordOffsets[18];
00086         float xInc = 1.0/ float(320);
00087         float yInc = 1.0/ float(240);
00088         for(int i=0; i<3; i++)
00089                 for(int j=0; j<3; j++)
00090                 {
00091                         texCoordOffsets[(((i*3)+j)*2)+0] = (-1.0 * xInc) + ( float(i) * xInc);
00092                         texCoordOffsets[(((i*3)+j)*2)+1] = (-1.0 * yInc) + ( float(j) * yInc);
00093                 }
00094 
00095         glUseProgramObjectARB(prog1);
00096         int uniformLoc = glGetUniformLocationARB(prog1, "tc_offset" );
00097         if( uniformLoc != -1 )
00098                 glUniform2fvARB( uniformLoc, 9, texCoordOffsets );
00099         else
00100                 LINFO("error. could not find uniformLoc for variable tc_offset");
00101 
00102         glUseProgramObjectARB(prog2);
00103         uniformLoc = glGetUniformLocationARB(prog2, "tc_offset" );
00104         if( uniformLoc != -1 )
00105                 glUniform2fvARB( uniformLoc, 9, texCoordOffsets );
00106         else
00107                 LINFO("error. could not find uniformLoc for variable tc_offset");
00108 
00109         //glUseProgramObjectARB(prog2);
00110         //int uniformLoc = glGetUniformLocationARB(prog2, "testValue" );
00111 
00112         //int i=0;
00113  // float val=0.6;
00114         while(1)
00115         {
00116                 Image< PixRGB<byte> > inputImg;
00117                 ifs->updateNext();
00118                 const FrameState is = ifs->updateNext();
00119                 if (is == FRAME_COMPLETE)
00120                         break;
00121 
00122                 //grab the images
00123                 GenericFrame input = ifs->readFrame();
00124                 if (!input.initialized())
00125                         break;
00126                 inputImg = input.asRgb();
00127                 //i = (i+1)%90;
00128 
00129     Image<float> texImg = luminance(inputImg);
00130 
00131                 vp.loadTexture(texImg, texId);
00132     vp.progToTexture(prog1);
00133 
00134                 glUseProgramObjectARB(prog2);
00135 
00136                 vp.initProjection();
00137     glBegin(GL_QUADS);
00138     glTexCoord2f(0.0, 0.0); glVertex3f(0, 0, 0);
00139     glTexCoord2f(1.0, 0.0); glVertex3f(320, 0, 0);
00140     glTexCoord2f(1.0, 1.0); glVertex3f(320, 240 , 0);
00141     glTexCoord2f(0.0, 1.0); glVertex3f(0, 240, 0);
00142     glEnd();
00143     
00144                 //Image<PixRGB<float> > img = vp.getFrame();
00145                 Image<PixRGB<float> > img = vp.getFrameFloat();
00146 
00147                 Image<float> tmp(img.getDims(), ZEROS);
00148                 for(uint i=0; i < img.size(); i++)
00149                         tmp.setVal(i, img.getVal(i).red());
00150     tmp *= 256;
00151 
00152     img = tmp;
00153 
00154                 ofs->writeRGB(img, "output", FrameInfo("output", SRC_POS));
00155                 usleep(10000);
00156         }
00157 
00158         manager.stop();
00159         exit(0);
00160 
00161 }
00162 
00163 
Generated on Sun May 8 08:41:09 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3