Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

Graph.H

Go to the documentation of this file.
00001 /*!@file Beobot/Graph.H basic graph class can be both directed
00002   and undirected */
00003 
00004 // //////////////////////////////////////////////////////////////////// //
00005 // The iLab Neuromorphic Vision C++ Toolkit - Copyright (C) 2001 by the //
00006 // University of Southern California (USC) and the iLab at USC.         //
00007 // See http://iLab.usc.edu for information about this project.          //
00008 // //////////////////////////////////////////////////////////////////// //
00009 // Major portions of the iLab Neuromorphic Vision Toolkit are protected //
00010 // under the U.S. patent ``Computation of Intrinsic Perceptual Saliency //
00011 // in Visual Environments, and Applications'' by Christof Koch and      //
00012 // Laurent Itti, California Institute of Technology, 2001 (patent       //
00013 // pending; application number 09/912,225 filed July 23, 2001; see      //
00014 // http://pair.uspto.gov/cgi-bin/final/home.pl for current status).     //
00015 // //////////////////////////////////////////////////////////////////// //
00016 // This file is part of the iLab Neuromorphic Vision C++ Toolkit.       //
00017 //                                                                      //
00018 // The iLab Neuromorphic Vision C++ Toolkit is free software; you can   //
00019 // redistribute it and/or modify it under the terms of the GNU General  //
00020 // Public License as published by the Free Software Foundation; either  //
00021 // version 2 of the License, or (at your option) any later version.     //
00022 //                                                                      //
00023 // The iLab Neuromorphic Vision C++ Toolkit is distributed in the hope  //
00024 // that it will be useful, but WITHOUT ANY WARRANTY; without even the   //
00025 // implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      //
00026 // PURPOSE.  See the GNU General Public License for more details.       //
00027 //                                                                      //
00028 // You should have received a copy of the GNU General Public License    //
00029 // along with the iLab Neuromorphic Vision C++ Toolkit; if not, write   //
00030 // to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,   //
00031 // Boston, MA 02111-1307 USA.                                           //
00032 // //////////////////////////////////////////////////////////////////// //
00033 //
00034 // Primary maintainer for this file: Christian Siagian <siagian@usc.edu>
00035 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/Beobot/Graph.H $
00036 // $Id $
00037 //
00038 
00039 #ifndef BEOBOT_GRAPH_H_DEFINED
00040 #define BEOBOT_GRAPH_H_DEFINED
00041 
00042 #include "Beobot/Node.H"
00043 #include "Beobot/Edge.H"
00044 #include "Image/Image.H"
00045 
00046 //! basic graph class
00047 //! has all the access functions and shortest path
00048 //! no input/output file function because usually the file
00049 //! has to be filled with extra information
00050 class Graph
00051 {
00052 public:
00053   // ######################################################################
00054   //! @name Constructor, assigment and destructor
00055   //@{
00056 
00057   //! Constructor: generate a blank graph
00058   Graph();
00059 
00060   //! Constructor: generate a graph with edges
00061   Graph(std::vector<rutz::shared_ptr<Node> > nodes,
00062         std::vector<rutz::shared_ptr<Edge> > edges);
00063 
00064   //! Destructor
00065   ~Graph();
00066 
00067   //! add edges and nodes
00068   void addNode(rutz::shared_ptr<Node>);
00069   void addEdge(rutz::shared_ptr<Edge>);
00070 
00071   //@}
00072 
00073   // ######################################################################
00074   //! @name Access functions
00075   //@{
00076 
00077   //! get node and edge size
00078   inline uint getNumNode();
00079   inline uint getNumEdge();
00080 
00081   //! get node or edge of the passed in index
00082   inline rutz::shared_ptr<Node> getNode(uint index);
00083   inline rutz::shared_ptr<Edge> getEdge(uint index);
00084 
00085   //@}
00086 
00087   // ######################################################################
00088   //! @name Compute functions
00089   //@{
00090 
00091   //! compute the adjecency list
00092   void computeAdjecencyList();
00093 
00094   //! compute all the shortcuts for shortest-distance related operations
00095   void computeDistances();
00096 
00097   //! get the shortest distance from A to B
00098   //! using Dijkstra shortest-path algorithm
00099   float getDistance(uint a, uint b);
00100 
00101   //! get the maximum distance of any 2 points in the map
00102   //! return -1.0F if the graph is unconnected
00103   float getMaxDistance();
00104 
00105   //! get edge where the point is at
00106   rutz::shared_ptr<Edge> getEdge();
00107 
00108   //!
00109   //std::vector<rutz::shared_ptr<Node> > > getNodes();
00110   //std::vector<rutz::shared_ptr<Edge> > > getEdges();
00111 
00112   //!
00113   //std::vector<rutz::shared_ptr<Node> > getpath( node a, node b);
00114 
00115   //@}
00116 
00117 private:
00118 
00119   //! all the nodes and edge information
00120   std::vector<rutz::shared_ptr<Node> > itsNodes;
00121   std::vector<rutz::shared_ptr<Edge> > itsEdges;
00122 
00123   std::vector<std::vector<uint> > itsAdjecencyList;
00124   std::vector<std::vector<float> > itsAdjecencyCostList;
00125 
00126   //! all the distances (pre-computed if 'computeDistances' is called)
00127   Image<float> itsDistanceMatrix;
00128   bool itsDistanceMatrixComputed;
00129 };
00130 
00131 // ######################################################################
00132 // Implementation for Node inline functions
00133 // ######################################################################
00134 
00135 inline uint Graph::getNumNode()
00136 {
00137   return itsNodes.size();
00138 }
00139 
00140 inline uint Graph::getNumEdge()
00141 {
00142   return itsEdges.size();
00143 }
00144 
00145 inline rutz::shared_ptr<Node> Graph::getNode(uint index)
00146 {
00147   ASSERT(index < itsNodes.size());
00148   return itsNodes[index];
00149 }
00150 
00151 inline rutz::shared_ptr<Edge> Graph::getEdge(uint index)
00152 {
00153   ASSERT(index < itsEdges.size());
00154   return itsEdges[index];
00155 }
00156 
00157 #endif
00158 
00159 // ######################################################################
00160 /* So things look consistent in everyone's emacs... */
00161 /* Local Variables: */
00162 /* indent-tabs-mode: nil */
00163 /* End: */

Generated on Mon Nov 23 15:45:16 2009 for iLab Neuromorphic Vision Toolkit by  doxygen 1.4.4