test-viewport.C

Go to the documentation of this file.
00001 /*!@file AppMedia/test-viewport.C test the opengl viewport */
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-viewport.C $
00033 // $Id: test-viewport.C 12962 2010-03-06 02:13:53Z irock $
00034 
00035 
00036 #include "GUI/ViewPort.H"
00037 #include "Util/log.H"
00038 #include "Util/WorkThreadServer.H"
00039 #include "Util/JobWithSemaphore.H"
00040 #include "Component/ModelManager.H"
00041 #include "Raster/GenericFrame.H"
00042 #include "Image/Layout.H"
00043 #include "Image/MatrixOps.H"
00044 #include "Media/FrameSeries.H"
00045 #include "Transport/FrameInfo.H"
00046 #include <stdlib.h>
00047 #include <math.h>
00048 
00049 double pos[3];
00050 double side[3];
00051 double R[12];
00052 
00053 Image<PixRGB<byte> > frame;
00054 
00055 namespace
00056 {
00057   class ViewPortLoop : public JobWithSemaphore
00058   {
00059     public:
00060       ViewPortLoop()
00061         :
00062           itsPriority(1),
00063           itsJobType("controllerLoop")
00064     {}
00065 
00066       virtual ~ViewPortLoop() {}
00067 
00068       virtual void run()
00069       {
00070         double cameraParam[3][4] = {
00071           {350.475735, 0, 158.250000, 0},
00072           {0.000000, -363.047091, 118.250000, 0.000000},
00073           {0.000000, 0.000000, 1.000000, 0.00000}};
00074 
00075         ViewPort vp("ViewPort", "ground.ppm", "", false, false,
00076             320, 240, cameraParam);
00077         vp.setTextures(false);
00078         vp.setDrawWorld(false);
00079         vp.setWireframe(false);
00080         vp.setZoom(0.85);
00081 
00082         //Set the camera
00083         double cam_xyz[3] = {10.569220,-210,140.959999};
00084         double cam_hpr[3] = {102.500000,-26.500000,-5.500000};
00085         vp.dsSetViewpoint (cam_xyz, cam_hpr);
00086 
00087 
00088         //ViewPort::DSObject object = vp.load3DSObject("./etc/spaceship.3ds", "./etc/textures/spaceshiptexture.ppm");
00089         //object.scale = 0.01;
00090 
00091         while(1)
00092         {
00093           double cameraParam[16]  = {
00094             0.995441, 0.044209, -0.084521, 0.000000, 0.095269, -0.504408, 0.858193, 0.000000,
00095             -0.004694, -0.862333, -0.506320, 0.000000, -6.439873, 11.187120, 197.639489, 1.000000};
00096 
00097           vp.initFrame(cameraParam);
00098           vp.dsDrawSphere(pos,R,1.3f);
00099           //vp.dsSetTexture (ViewPort::WOOD);
00100           vp.dsSetColor (1,1,0.0);
00101 
00102           vp.dsSetColor (0.5,0.5,0.5);
00103           vp.dsDrawBox(pos,R,side);
00104           //vp.dsSetTexture (ViewPort::OTHER, &objectTexture);
00105           //vp.dsDraw3DSObject(pos, R, object);
00106 
00107           vp.updateFrame();
00108 
00109           frame = flipVertic(vp.getFrame());
00110 
00111         }
00112       }
00113 
00114       virtual const char* jobType() const
00115       { return itsJobType.c_str(); }
00116 
00117       virtual int priority() const
00118       { return itsPriority; }
00119 
00120     private:
00121       const int itsPriority;
00122       const std::string itsJobType;
00123   };
00124 }
00125 
00126 int main(int argc, char *argv[]){
00127 
00128   ModelManager manager("Test Viewport");
00129 
00130   nub::ref<OutputFrameSeries> ofs(new OutputFrameSeries(manager));
00131   manager.addSubComponent(ofs);
00132 
00133   // Parse command-line:
00134   if (manager.parseCommandLine(argc, argv, "", 0, 0) == false) return(1);
00135   // let's get all our ModelComponent instances started:
00136         manager.start();
00137 
00138 
00139   pos[0] = 0;
00140   pos[1] = 0;
00141   pos[2] = 5;
00142   R[0] = 1; R[1] = 0; R[2] = 0;
00143   R[4] = 0;  R[5] = 1; R[6] = 0;
00144   R[8] = 0; R[9] = 0; R[10] = 1;
00145 
00146   side[0] = 30; side[1] = 30; side[2] = 30;
00147 
00148 
00149   rutz::shared_ptr<WorkThreadServer> itsThreadServer;
00150   itsThreadServer.reset(new WorkThreadServer("ViewPort",1)); //start a single worker thread
00151   itsThreadServer->setFlushBeforeStopping(false);
00152   rutz::shared_ptr<ViewPortLoop> j(new ViewPortLoop());
00153   itsThreadServer->enqueueJob(j);
00154 
00155 
00156   frame = Image<PixRGB<byte> >(255, 255, ZEROS);
00157         int run=1;
00158         while(run){
00159     ofs->writeRGB(frame, "viewport", FrameInfo("ViewPort", SRC_POS));
00160     usleep(1000);
00161          }
00162 
00163   exit(0);
00164 
00165 }
00166 
00167 
Generated on Sun May 8 08:40:08 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3