00001 /*!@file Beobot/TopologicalMap.H topological map for localization */ 00002 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/TopologicalMap.H $ 00035 // $Id: TopologicalMap.H 12962 2010-03-06 02:13:53Z irock $ 00036 // 00037 00038 // ###################################################################### 00039 /*! Topological Map 00040 actually it's metric augmented topological map 00041 there are coordinates for the nodes in the map 00042 DIRECTED edges/segments connect the nodes 00043 00044 Also generate path: vector of segment numbers 00045 */ 00046 00047 #ifndef BEOBOT_TOPOLOGICALMAP_H_DEFINED 00048 #define BEOBOT_TOPOLOGICALMAP_H_DEFINED 00049 00050 #include "Beobot/Map.H" 00051 #include "Beobot/Graph.H" 00052 #include <vector> 00053 00054 #define TOPOMAP_MOVE_FORWARD -1 00055 #define TOPOMAP_TURN_AROUND -2 00056 00057 //! topological map using a list of landmarks 00058 class TopologicalMap : public Map 00059 { 00060 public: 00061 00062 // ###################################################################### 00063 /*! @name Constructors, assignment, and Destructors */ 00064 //@{ 00065 00066 //! Constructor: generate a blank map 00067 TopologicalMap(); 00068 00069 //! Constructor: retrieve the map from a file 00070 TopologicalMap(std::string fileName); 00071 00072 //! Destructor 00073 ~TopologicalMap(); 00074 00075 //! read a map from a file 00076 bool read(std::string fileName); 00077 00078 //! write a map to a file 00079 bool write(std::string fileName); 00080 00081 //@} 00082 00083 // ###################################################################### 00084 //! @name Access functions 00085 //@{ 00086 00087 //! get segment size 00088 inline uint getSegmentNum(); 00089 00090 //! get the map dimension 00091 inline Dims getMapDims(); 00092 00093 //! get the map scale in (ft/unit map) 00094 inline float getMapScale(); 00095 00096 //! get node - segment distance matrix 00097 inline Image<float> getNodeSegmentDistanceMatrix(); 00098 00099 //! get node or edge of the passed in index 00100 inline rutz::shared_ptr<Node> getNode(uint index); 00101 inline rutz::shared_ptr<Edge> getEdge(uint index); 00102 00103 //! get node and edge size 00104 inline uint getNumNode(); 00105 inline uint getNumEdge(); 00106 00107 //! get maximum node-to-node distance 00108 inline float getMaxDistance(); 00109 00110 //! get maximum node-to-segment distance 00111 float getNodeSegmentMaxDistance(); 00112 00113 //@} 00114 00115 // ###################################################################### 00116 /*! @name member functions */ 00117 //@{ 00118 00119 //! get the distance from the point to the segment 00120 //! also return the intersecting node 00121 float getSegmentDistance(uint sseg, float ltrav, uint dseg, 00122 uint &intIndex); 00123 00124 //! get the distance between two points 00125 float getDistance(uint asnum, float altrav, uint bsnum, float bltrav); 00126 00127 //! return a path from points 'a' to 'b' 00128 float getPath 00129 (uint asnum, float altrav, uint bsnum, float bltrav, 00130 std::vector<int> &moves); 00131 00132 //! get the length of the segment 00133 float getSegmentLength(uint index); 00134 00135 //! get Point2D<int> location of the (segnum, ltrav) descriptor 00136 Point2D<int> getLocation(uint cseg, float ltrav); 00137 00138 //! get Point2D<int> location (in float) of the (segnum, ltrav) descriptor 00139 void getLocationFloat(uint cseg, float ltrav, float &x, float &y); 00140 00141 //! get the edge in which the point (snum, ltrav) is at 00142 rutz::shared_ptr<Edge> getEdge(uint cseg, float ltrav, 00143 float &sdist, 00144 float &edist); 00145 00146 //! get the edge in which the point (snum, ltrav) is at 00147 rutz::shared_ptr<Edge> getEdge(uint cseg, float ltrav, 00148 float &sdist, 00149 float &edist, 00150 uint& eindex); 00151 00152 //! get the edge in which the point is at 00153 rutz::shared_ptr<Edge> getEdge(Point2D<int> loc, 00154 float &sdist, 00155 float &edist); 00156 00157 //! get the angle (in radians) between two edges 00158 //! they two edges do not have to have a common node 00159 //! angles are intuitive from the robot's perspective 00160 //! 0 degrees/radians means going straight, 00161 //! 180/-180 degrees or M_PI/-M_PI means turn around 00162 //! positive angle to the right, negative angle to the left 00163 float getAngle(rutz::shared_ptr<Edge> e1, rutz::shared_ptr<Edge> e2); 00164 00165 //! convert Point2D<int> location the segment number and length traveled 00166 void getLocation(Point2D<int>, uint &cseg, float <rav); 00167 00168 //! convert Point2D<int> location to segment number 00169 uint getSegmentLocation(Point2D<int> loc); 00170 00171 //! convert Point2D<int> location to segment length traveled 00172 float getSegmentLengthTraveled(Point2D<int> loc); 00173 00174 //! get the list of nodes in between the inputted interval 00175 //! two different versions of the results 00176 std::vector<rutz::shared_ptr<Node> > 00177 getNodesInInterval(uint index, float fltrav, float lltrav); 00178 std::vector<std::pair<uint,float> > 00179 getNodeLocationsInInterval(uint index, float fltrav, float lltrav); 00180 00181 //! returns an image representation of the map 00182 //! the w and h is the ideal size while keeping aspect ratio 00183 //! so most likely the image returned will be smaller in size 00184 Image<PixRGB<byte> > getMapImage(uint w, uint h); 00185 00186 //! ADD: modify the map 00187 00188 //@} 00189 00190 private: 00191 00192 //! compute all the shortcuts for shortest-distance related operations 00193 //! node-to-segment, and segment-to-segment 00194 void computeDistances(); 00195 00196 //! set all the segment lengths 00197 void setSegmentLength(); 00198 00199 rutz::shared_ptr<Graph> itsGraph; 00200 00201 //! the map size and scale in ft/unit 00202 int itsMapWidth; 00203 int itsMapHeight; 00204 float itsMapScale; 00205 00206 //! the list of segments in the map 00207 //! each segment is an ordered list of directed edges 00208 std::vector< std::vector<rutz::shared_ptr<Edge> > > itsSegmentList; 00209 std::vector< std::vector<uint> > itsSegmentEdgeIndexList; 00210 00211 //! store the segment lengths 00212 std::vector<float> itsSegmentLength; 00213 00214 //! the segment to segment distance matrix 00215 //! note that this is to the closest point in the segment 00216 Image<float> itsNodeSegmentDistanceMatrix; 00217 00218 //! segment labels for each edge 00219 //std::vector<int> segmentLabels; 00220 //std::vector<std::string> landmarkNames; 00221 }; 00222 00223 // ###################################################################### 00224 // Implementation for Topological Map inline functions 00225 // ###################################################################### 00226 inline uint TopologicalMap::getSegmentNum() 00227 { 00228 return itsSegmentList.size(); 00229 } 00230 00231 inline Dims TopologicalMap::getMapDims() 00232 { 00233 return Dims(itsMapWidth, itsMapHeight); 00234 } 00235 00236 inline float TopologicalMap::getMapScale() 00237 { 00238 return itsMapScale; 00239 } 00240 inline Image<float> TopologicalMap::getNodeSegmentDistanceMatrix() 00241 { 00242 return itsNodeSegmentDistanceMatrix; 00243 } 00244 00245 inline float TopologicalMap::getMaxDistance() 00246 { 00247 return itsGraph->getMaxUndirectedDistance(); 00248 } 00249 00250 inline uint TopologicalMap::getNumNode() 00251 { 00252 return itsGraph->getNumNode(); 00253 } 00254 00255 inline uint TopologicalMap::getNumEdge() 00256 { 00257 return itsGraph->getNumEdge(); 00258 } 00259 00260 inline rutz::shared_ptr<Node> TopologicalMap::getNode(uint index) 00261 { 00262 ASSERT(index < getNumNode()); 00263 return itsGraph->getNode(index); 00264 } 00265 00266 inline rutz::shared_ptr<Edge> TopologicalMap::getEdge(uint index) 00267 { 00268 ASSERT(index < getNumEdge()); 00269 return itsGraph->getEdge(index); 00270 } 00271 00272 #endif 00273 00274 // ###################################################################### 00275 /* So things look consistent in everyone's emacs... */ 00276 /* Local Variables: */ 00277 /* indent-tabs-mode: nil */ 00278 /* End: */