Geons3D.H

Go to the documentation of this file.
00001 /*!@file SceneUnderstanding/Geons3D.H  */
00002 
00003 // //////////////////////////////////////////////////////////////////// //
00004 // The iLab Neuromorphic Vision C++ Toolkit - Copyright (C) 2000-2005   //
00005 // by the 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: Lior Elazary <elazary@usc.edu>
00034 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/plugins/SceneUnderstanding/Geons3D.H $
00035 // $Id: Geons3D.H 13875 2010-09-03 00:54:58Z lior $
00036 //
00037 
00038 #ifndef Geons3D_H_DEFINED
00039 #define Geons3D_H_DEFINED
00040 
00041 #include "plugins/SceneUnderstanding/TwoHalfDSketch.H"
00042 #include "Image/Image.H"
00043 #include "Image/ImageSet.H"
00044 #include "Image/Pixels.H"
00045 #include "Image/Layout.H"
00046 #include "Transport/World3DInput.H"
00047 #include "plugins/SceneUnderstanding/LGN.H"
00048 #include "plugins/SceneUnderstanding/SMap.H"
00049 #include "Simulation/SimEvents.H"
00050 #include "Simulation/SimModule.H"
00051 #include "FeatureMatching/GeometricHashing.H"
00052 #include "FeatureMatching/GHough.H"
00053 #include "GUI/ViewPort3D.H"
00054 #include "GUI/SuperQuadric.H"
00055 
00056 #include "Util/CpuTimer.H"
00057 #include "Util/JobServer.H"
00058 #include "Util/JobWithSemaphore.H"
00059 #include "Util/WorkThreadServer.H"
00060 
00061 #include <fcntl.h>
00062 #include <vector>
00063 #include <string>
00064 #include <map>
00065 
00066 class SimEventGeons3DPrior;
00067 
00068 class Geons3D : public SimModule
00069 {
00070 public:
00071 
00072   struct GeonState
00073   {
00074     Point3D<float> pos;
00075     Point3D<float> rot;
00076     PixRGB<byte> color;
00077     SuperQuadric superQuadric;
00078     double prob;
00079   };
00080 
00081   Geons3D(OptionManager& mgr, const std::string& descrName = "Geons3D",
00082       const std::string& tagName = "Geons3D");
00083 
00084   //! Destructor
00085   ~Geons3D();
00086 
00087   void evolve(SimEventQueue& q);
00088 
00089   std::vector<GeonState> proposeGeons(Rectangle& attenLoc);
00090 
00091   void  calcGeonLikelihood(GeonState& geon);
00092   double  calcGeonEdgeLikelihood(GeonState& geon, Image<float>& edges, Image<float>& surface);
00093   double  calcGeonSurfaceLikelihood(GeonState& geon, Image<float>& edges, Image<float>& surface);
00094 
00095 
00096   //! Get the probability from a model and data
00097   double getEdgeProb(Image<float>& mag, Image<float>& modelOri, Image<float>& modelMag);
00098 
00099   //! Get the probability of the surface
00100   double getSurfaceProb(Image<float>& data, Image<float>& model);
00101   
00102 
00103   //! Test the liklihood function
00104   void testLikelihood();
00105 
00106 
00107   Image<PixRGB<byte> > getGeonImage(GeonState& geon);
00108   
00109   void drawGeon(const GeonState& geon);
00110   void renderScene(const GeonState& geon, std::vector<ViewPort3D::Line>& lines, Image<PixRGB<byte> >& frame);
00111 
00112   Layout<PixRGB<byte> > getDebugImage(SimEventQueue& q);
00113 
00114 protected:
00115 
00116   //! Callback for when a new ganglion output is ready
00117   SIMCALLBACK_DECLARE(Geons3D, SimEventTwoHalfDSketchOutput);
00118 
00119   //! Callback for every time we should save our outputs
00120   SIMCALLBACK_DECLARE(Geons3D, SimEventSaveOutput);
00121 
00122   //! Callback for every time we have a user event
00123   SIMCALLBACK_DECLARE(Geons3D, SimEventUserInput);
00124 
00125   //! Callback for every time we have a prior input
00126   SIMCALLBACK_DECLARE(Geons3D, SimEventGeons3DPrior);
00127 
00128   //! Should we show our debug info
00129   OModelParam<bool> itsShowDebug;
00130 
00131 
00132 private:
00133   ViewPort3D *itsViewPort;
00134   ImageSet<float>  itsLGNInput;
00135   Image<float> itsEdges;
00136   Image<float> itsLinesMag;
00137   Image<float> itsLinesOri;
00138   Image<float> itsEdgesDT;
00139   ImageSet<float> itsOriEdgesDT;
00140   Image<float> itsTableDepth;
00141   Image<byte> itsSMap;
00142   rutz::shared_ptr<World3DInput::ObjectsData> itsObjectsData;
00143   std::vector<TwoHalfDSketch::SurfaceState> itsSurfaces;
00144   std::vector<GeonState> itsGeonsState;
00145   std::vector<GeonState> itsProposals;
00146   Point3D<double> itsGlobalRotation;
00147   Point3D<double> itsGlobalPos;
00148   Image<PixRGB<byte> > itsCurrentFrame;
00149   GeometricHashing itsGHash;
00150   GHough itsGHough;
00151   GHough itsGHough2;
00152   bool itsLearn;
00153 
00154   double itsTotalProb;
00155 
00156   float itsTrainingThreshold;
00157 
00158   rutz::shared_ptr<WorkThreadServer> itsThreadServer;
00159   
00160 
00161 };
00162 
00163 /* ############################### Geons3D sim events ######################## */
00164 class SimEventGeons3DOutput : public SimEvent
00165 {
00166 public:
00167   SimEventGeons3DOutput(SimModule* src,
00168       std::vector<Geons3D::GeonState>& geons, double prob) :
00169     SimEvent(src), itsGeons(geons), itsProb(prob)
00170   {}
00171 
00172   virtual ~SimEventGeons3DOutput(){}
00173   std::vector<Geons3D::GeonState> getGeons() { return itsGeons; }
00174   double getProb() { return itsProb; }
00175 
00176 private:
00177   const std::vector<Geons3D::GeonState>& itsGeons;
00178   double itsProb;
00179 };
00180 
00181 /* ############################### Objects sim events ######################## */
00182 class SimEventGeons3DPrior : public SimEvent
00183 {
00184 public:
00185   SimEventGeons3DPrior(SimModule* src,
00186       std::vector<Geons3D::GeonState>& geons,
00187       Point3D<double>& pos, Point3D<double>& rotation) :
00188     SimEvent(src), itsGeons(geons),
00189     itsPos(pos), itsRotation(rotation)
00190   {}
00191 
00192   virtual ~SimEventGeons3DPrior(){}
00193   std::vector<Geons3D::GeonState> getGeons() { return itsGeons; }
00194   Point3D<double> getRotation() { return itsRotation; }
00195   Point3D<double> getPos() { return itsPos; }
00196 
00197 private:
00198   const std::vector<Geons3D::GeonState>& itsGeons;
00199   Point3D<double> itsPos;
00200   Point3D<double> itsRotation;
00201 };
00202 
00203 // ######################################################################
00204 /* So things look consistent in everyone's emacs... */
00205 /* Local Variables: */
00206 /* indent-tabs-mode: nil */
00207 /* End: */
00208 
00209 #endif //
Generated on Sun May 8 08:05:31 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3