LoPointList.H

00001 /**
00002    \file  Robots/LoBot/misc/LoPointList.H
00003    \brief A class for storing a list of points.
00004 
00005    When we conduct an experiment to gauge lobot's performance, we collect
00006    several different lists of points: one to record the robot's
00007    trajectory from start to finish, another to record the locations where
00008    the robot's emergency stop behaviour was activated, another for the
00009    locations where the LGMD avoidance algorithm averted the robot away
00010    from an approaching obstacle; so on and so forth.
00011 
00012    This file defines a class that is used to store the above-mentioned
00013    point lists.
00014 */
00015 
00016 // //////////////////////////////////////////////////////////////////// //
00017 // The iLab Neuromorphic Vision C++ Toolkit - Copyright (C) 2000-2005   //
00018 // by the University of Southern California (USC) and the iLab at USC.  //
00019 // See http://iLab.usc.edu for information about this project.          //
00020 // //////////////////////////////////////////////////////////////////// //
00021 // Major portions of the iLab Neuromorphic Vision Toolkit are protected //
00022 // under the U.S. patent ``Computation of Intrinsic Perceptual Saliency //
00023 // in Visual Environments, and Applications'' by Christof Koch and      //
00024 // Laurent Itti, California Institute of Technology, 2001 (patent       //
00025 // pending; application number 09/912,225 filed July 23, 2001; see      //
00026 // http://pair.uspto.gov/cgi-bin/final/home.pl for current status).     //
00027 // //////////////////////////////////////////////////////////////////// //
00028 // This file is part of the iLab Neuromorphic Vision C++ Toolkit.       //
00029 //                                                                      //
00030 // The iLab Neuromorphic Vision C++ Toolkit is free software; you can   //
00031 // redistribute it and/or modify it under the terms of the GNU General  //
00032 // Public License as published by the Free Software Foundation; either  //
00033 // version 2 of the License, or (at your option) any later version.     //
00034 //                                                                      //
00035 // The iLab Neuromorphic Vision C++ Toolkit is distributed in the hope  //
00036 // that it will be useful, but WITHOUT ANY WARRANTY; without even the   //
00037 // implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      //
00038 // PURPOSE.  See the GNU General Public License for more details.       //
00039 //                                                                      //
00040 // You should have received a copy of the GNU General Public License    //
00041 // along with the iLab Neuromorphic Vision C++ Toolkit; if not, write   //
00042 // to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,   //
00043 // Boston, MA 02111-1307 USA.                                           //
00044 // //////////////////////////////////////////////////////////////////// //
00045 //
00046 // Primary maintainer for this file: mviswana usc edu
00047 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/Robots/LoBot/metlog/LoPointList.H $
00048 // $Id: LoPointList.H 13967 2010-09-18 08:00:07Z mviswana $
00049 //
00050 
00051 #ifndef LOBOT_POINT_LIST_DOT_H
00052 #define LOBOT_POINT_LIST_DOT_H
00053 
00054 //------------------------------ HEADERS --------------------------------
00055 
00056 // lobot headers
00057 #include "Robots/LoBot/metlog/LoPointTypes.H"
00058 
00059 // Standard C++ headers
00060 #include <vector>
00061 
00062 //----------------------------- NAMESPACE -------------------------------
00063 
00064 namespace lobot {
00065 
00066 //------------------------- CLASS DEFINITION ----------------------------
00067 
00068 /**
00069    \class lobot::PointList
00070    \brief A container for storing lists of points.
00071 
00072    This class provides a convenient API for storing a list of points and
00073    performing some useful operations such as finding correspondences
00074    between two point lists. Additionally, though it is named PointList,
00075    it, in fact, behaves like a set, i.e., each point appears only once in
00076    the list. Thus, attempts to add duplicate points will be silently
00077    ignored.
00078 */
00079 class PointList {
00080    /// This class's raison d'etre: to store a bunch of points.
00081    //@{
00082    typedef std::vector<mPoint> List ;
00083    List m_list ;
00084    //@}
00085 
00086 public:
00087    /// Initalization: creates a point list with enough memory to
00088    /// initially store the specified number of points. If this memory
00089    /// fills up, not to worry, extra memory will be automagically
00090    /// acquired.
00091    PointList(int n = 0) ;
00092 
00093    /// This method adds a point to the point list. If the point already
00094    /// appears in the list, it will not be added a second time. Thus,
00095    /// this point list actually is a point set.
00096    void add(int x, int y) ;
00097 
00098    /// This operator appends the given point list to this one.
00099    PointList& operator+=(const PointList&) ;
00100 
00101    /// This method returns the number of points stored in this point
00102    /// list.
00103    int size() const {return m_list.size() ;}
00104 
00105    /// This method checks if the point list has anything in it or not.
00106    bool empty() const {return m_list.empty() ;}
00107 
00108    /// These types are defined for STL compatibility and to allow this
00109    /// class to be used directly in STL algorithms.
00110    //@{
00111    typedef List::const_reference const_reference ;
00112    typedef List::const_iterator iterator ;
00113    //@}
00114 
00115    /// These functions allow clients to walk through the point list using
00116    /// STL algorithms.
00117    //@{
00118    iterator begin() const {return m_list.begin() ;}
00119    iterator end()   const {return m_list.end()   ;}
00120    //@}
00121 
00122    /// This function deletes all the entries in the point list.
00123    void clear() {m_list.clear() ;}
00124 
00125    /// For each point in this point list, find the closest point in the
00126    /// given point list P and return the resulting point list.
00127    ///
00128    /// NOTE: If either this point list or the other point list is empty,
00129    /// this function will throw a lobot::misc_error with LOGIC_ERROR as
00130    /// the code.
00131    PointList find_correspondences(const PointList& P) const ;
00132 } ;
00133 
00134 //-----------------------------------------------------------------------
00135 
00136 } // end of namespace encapsulating this file's definitions
00137 
00138 #endif
00139 
00140 /* So things look consistent in everyone's emacs... */
00141 /* Local Variables: */
00142 /* indent-tabs-mode: nil */
00143 /* End: */
Generated on Sun May 8 08:05:55 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3