LineGrouping.H

Go to the documentation of this file.
00001 /*!@file SceneUnderstanding/LineGrouping.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/LineGrouping.H $
00035 // $Id: LineGrouping.H 14179 2010-10-28 19:49:24Z lior $
00036 //
00037 
00038 #ifndef LineGrouping_H_DEFINED
00039 #define LineGrouping_H_DEFINED
00040 
00041 #include "Image/OpenCVUtil.H" //Need to be first to avoid type def conf
00042 #include "Util/Types.H"
00043 #include "Image/Image.H"
00044 #include "Image/ImageSet.H"
00045 #include "Image/Pixels.H"
00046 #include "Image/Layout.H"
00047 #include "plugins/SceneUnderstanding/V2.H"
00048 #include "Simulation/SimEvents.H"
00049 #include "Simulation/SimModule.H"
00050 #include "GUI/ViewPort3D.H"
00051 #include "Learn/HMM.H"
00052 
00053 #include <vector>
00054 #include <string>
00055 #include <map>
00056 #include <queue>
00057 
00058 class SimEventLineGroupingPrior;
00059 
00060 
00061 class LineGrouping : public SimModule
00062 {
00063 public:
00064 
00065   struct LinesGroup
00066   {
00067     std::vector<V2::LineSegment> lines;
00068   };
00069 
00070   struct LineInfo
00071   {
00072     uint idx;
00073     double cost;
00074 
00075     LineInfo(uint i) :
00076       idx(i), cost(0)
00077     {
00078     }
00079 
00080     LineInfo(uint i, double c) :
00081       idx(i), cost(c)
00082     {
00083     }
00084 
00085   };
00086 
00087   struct LineInfoCmp
00088   {
00089     bool operator()(const LineInfo& l1, const LineInfo& l2)
00090     {
00091       return l1.cost > l2.cost;
00092     }
00093   };
00094 
00095   LineGrouping(OptionManager& mgr, const std::string& descrName = "LineGrouping",
00096       const std::string& tagName = "LineGrouping");
00097 
00098   //! Destructor
00099   ~LineGrouping();
00100 
00101   void evolve(SimEventQueue& q);
00102 
00103   Layout<PixRGB<byte> > getDebugImage(SimEventQueue& q);
00104 
00105   std::vector<V2::LineSegment>  getAndRemoveLinesNearLoc(Image<std::vector<uint> >& linesIndices,
00106       const Point2D<int> loc, const int radius);
00107 
00108   //! Get lines that are local (within radius) and have not been used
00109   std::vector<LineInfo>  getLocalLines(const Point2D<int> loc, const int radius, 
00110       std::vector<uint>& lineColour,
00111       const Image<std::vector<uint> >& linesIndices);
00112   
00113  
00114   void setTopDownCost(std::vector<LineInfo>& newLines,const std::vector<LineInfo>& contour);
00115   
00116 
00117 protected:
00118   //! Callback for when a new ganglion output is ready
00119   SIMCALLBACK_DECLARE(LineGrouping, SimEventV2Output);
00120 
00121   //! Callback for every time we should save our outputs
00122   SIMCALLBACK_DECLARE(LineGrouping, SimEventSaveOutput);
00123 
00124   ////! Callback for every time we have a user event
00125   SIMCALLBACK_DECLARE(LineGrouping, SimEventUserInput);
00126 
00127   //! Should we show our debug info
00128   OModelParam<bool> itsShowDebug;
00129 
00130 
00131 private:
00132   std::vector<V2::LineSegment> itsLines;
00133   std::vector<LinesGroup> itsLineGroups;
00134   HMM<uint> itsHMM;
00135 
00136   Dims itsInputDims;
00137   
00138 };
00139 
00140 /* ############################### V2 sim events ######################## */
00141 /*
00142 class SimEventLineGroupingOutput : public SimEvent
00143 {
00144 public:
00145   SimEventLineGroupingOutput(SimModule* src,
00146       std::vector<LineGrouping::SurfaceState>& surfaces) :
00147     SimEvent(src), itsLineGroups(surfaces)
00148   {}
00149 
00150   virtual ~SimEventLineGroupingOutput(){}
00151   std::vector<LineGrouping::SurfaceState> getSurfaces() { return itsSurfaces; }
00152 
00153 private:
00154   const std::vector<LineGrouping::SurfaceState>& itsSurfaces;
00155 };
00156 */
00157 
00158 
00159 
00160 // ######################################################################
00161 /* So things look consistent in everyone's emacs... */
00162 /* Local Variables: */
00163 /* indent-tabs-mode: nil */
00164 /* End: */
00165 
00166 #endif //
Generated on Sun May 8 08:41:09 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3