00001 /*!@file Beobot/Environment.H all the information describing 00002 an environment */ 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: Christian Siagian <siagian@usc.edu> 00034 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/Beobot/Environment.H $ 00035 // $Id: Environment.H 12962 2010-03-06 02:13:53Z irock $ 00036 // 00037 00038 // ###################################################################### 00039 /* Environment class has all the information describing an environment 00040 it connects the map and the landmarks 00041 */ 00042 00043 #ifndef BEOBOT_ENVIRONMENT_H_DEFINED 00044 #define BEOBOT_ENVIRONMENT_H_DEFINED 00045 00046 #include "Beobot/LandmarkDB.H" 00047 #include "Beobot/TopologicalMap.H" 00048 #include "Neuro/gistParams.H" 00049 #include "Gist/FFN.H" 00050 #include "Gist/trainUtils.H" 00051 #include "SIFT/Histogram.H" 00052 00053 //! Environment class 00054 class Environment 00055 { 00056 public: 00057 00058 // ###################################################################### 00059 /*! @name Constructors, assignment, and Destructors */ 00060 //@{ 00061 00062 //! Constructor: generate a blank environment if file does not exist 00063 Environment(std::string envFName = std::string("")); 00064 00065 //! return true if environment has no segments 00066 bool isBlank(); 00067 00068 //! load the .env file 00069 bool load(std::string fName); 00070 00071 //! save the main environment to a file 00072 bool save(std::string fName, std::string envPrefix); 00073 00074 //! save the main and the just build environment 00075 bool save(std::string fName, std::string tfName, std::string envPrefix); 00076 00077 //! Destructor 00078 ~Environment(); 00079 00080 //! set the window to view results 00081 inline void setWindow(rutz::shared_ptr<XWinManaged> win); 00082 00083 //! reset the number of segments in the environment 00084 void resetNumSegment(uint nSegment); 00085 00086 //! set the current 00087 void setCurrentSegment(uint currSegNum); 00088 00089 //@} 00090 00091 // ###################################################################### 00092 //! @name Access functions 00093 //@{ 00094 00095 //! get the number of segments 00096 inline uint getNumSegment(); 00097 00098 //! get the segment histogram 00099 inline rutz::shared_ptr<Histogram> getSegmentHistogram(); 00100 00101 //! get the topological map 00102 inline rutz::shared_ptr<TopologicalMap> getTopologicalMap(); 00103 00104 //! get the visual landmark database 00105 inline rutz::shared_ptr<LandmarkDB> getLandmarkDB(); 00106 00107 //! get Point2D<int> location of the (segnum, ltrav) descriptor 00108 inline Point2D<int> getLocation(uint cseg, float ltrav); 00109 00110 //! get Point2D<int> location (in float) of the (segnum, ltrav) descriptor 00111 inline void getLocationFloat(uint cseg, float ltrav, float &x, float &y); 00112 00113 //@} 00114 00115 // ###################################################################### 00116 //! @name Compute functions 00117 //@{ 00118 00119 //! classify segment number from the input gist 00120 rutz::shared_ptr<Histogram> classifySegNum(Image<double> cgist); 00121 00122 //! initialize a new landmarkDB to be build 00123 void build 00124 (std::vector<rutz::shared_ptr<VisualObject> > &inputVO, 00125 std::vector<Point2D<int> > &objOffset, uint fNum, 00126 rutz::shared_ptr<VisualObject> scene); 00127 00128 //! build the landmarkDB from the current run 00129 //! keep calling this every frame 00130 void startBuild(); 00131 00132 //! finish building the landmarkDB - has all the ending procedure 00133 void finishBuild(std::string prefix, std::string path, uint rframe); 00134 00135 //@} 00136 00137 private: 00138 00139 //! setup the segment recognizer 00140 void setupSegmentRecognizer(std::string segmentRecFName); 00141 00142 //! save a landmarkDB to a file 00143 bool save(rutz::shared_ptr<LandmarkDB> landmarkDB, 00144 std::string fName, std::string envPrefix); 00145 00146 //! fuse stored landmarks DB and just obtained DB when finished with a run 00147 rutz::shared_ptr<LandmarkDB> combineLandmarkDBs 00148 ( rutz::shared_ptr<LandmarkDB> lmks1, 00149 rutz::shared_ptr<LandmarkDB> lmks2); 00150 00151 //! the landmarkDB to store all the visual objects 00152 //! along the paths (edges) 00153 rutz::shared_ptr<LandmarkDB> itsLandmarkDB; 00154 00155 //! the topological map for localization 00156 rutz::shared_ptr<TopologicalMap> itsTopologicalMap; 00157 00158 //! segment recognizer: a feed-forward network 00159 rutz::shared_ptr<FeedForwardNetwork> itsSegmentRecognizer; 00160 FFNtrainInfo itsSegRecInfo; 00161 Image<double> itsPcaIcaMatrix; 00162 00163 //! the current segment prediction 00164 rutz::shared_ptr<Histogram> itsSegmentHistogram; 00165 uint itsCurrentSegment; 00166 00167 //! the display window to show results 00168 rutz::shared_ptr<XWinManaged> itsWin; 00169 00170 //! the current landmarkDB being built 00171 rutz::shared_ptr<LandmarkDB> itsTempLandmarkDB; 00172 }; 00173 00174 // ###################################################################### 00175 // Implementation for Environment inline functions 00176 // ###################################################################### 00177 00178 inline rutz::shared_ptr<Histogram> Environment::getSegmentHistogram() 00179 { 00180 return itsSegmentHistogram; 00181 } 00182 00183 inline uint Environment::getNumSegment() 00184 { 00185 return itsSegmentHistogram->getSize(); 00186 } 00187 00188 inline rutz::shared_ptr<TopologicalMap> Environment::getTopologicalMap() 00189 { 00190 return itsTopologicalMap; 00191 } 00192 00193 inline rutz::shared_ptr<LandmarkDB> Environment::getLandmarkDB() 00194 { 00195 return itsLandmarkDB; 00196 } 00197 00198 inline void Environment::setWindow(rutz::shared_ptr<XWinManaged> win) 00199 { 00200 itsWin = win; 00201 itsLandmarkDB->setWindow(win); 00202 } 00203 00204 inline Point2D<int> Environment::getLocation(uint cseg, float ltrav) 00205 { 00206 return itsTopologicalMap->getLocation(cseg, ltrav); 00207 } 00208 00209 inline void Environment::getLocationFloat 00210 (uint cseg, float ltrav, float &x, float &y) 00211 { 00212 itsTopologicalMap->getLocationFloat(cseg, ltrav, x, y); 00213 } 00214 00215 #endif 00216 00217 // ###################################################################### 00218 /* So things look consistent in everyone's emacs... */ 00219 /* Local Variables: */ 00220 /* indent-tabs-mode: nil */ 00221 /* End: */