LoPointMatrix.H

00001 /**
00002    \file  Robots/LoBot/misc/LoPointMatrix.H
00003    \brief A matrix for storing points and then computing an average point
00004    list.
00005 
00006    When we conduct an experiment to gauge lobot's performance, we collect
00007    several different lists of points: one to record the robot's
00008    trajectory from start to finish, another to record the locations where
00009    the robot's emergency stop behaviour was activated, another for the
00010    locations where the LGMD avoidance algorithm averted the robot away
00011    from an approaching obstacle; so on and so forth.
00012 
00013    Each experiment will produce point lists of different sizes. To
00014    compute the robot's average case behaviour, we will have to
00015    "normalize" these lists so that they all contain the same number of
00016    elements as some reference experiment. After we have discarded extra
00017    points or added missing points w.r.t. the reference experiment, we can
00018    find point correspondences across experiments and, finally, average
00019    these transformed lists to get the desired result.
00020 
00021    This file defines a class that is used to store the intermediate
00022    "normalized" point lists in a matrix. The columns of this matrix
00023    correspond to the individual experiments. The rows store corresponding
00024    points across experiments. For example, if we have 25 experiments in a
00025    dataset and the reference experiment is found to have 300 points in
00026    its trajectory point list, then this point matrix will have 25 columns
00027    and 300 rows.
00028 */
00029 
00030 // //////////////////////////////////////////////////////////////////// //
00031 // The iLab Neuromorphic Vision C++ Toolkit - Copyright (C) 2000-2005   //
00032 // by the University of Southern California (USC) and the iLab at USC.  //
00033 // See http://iLab.usc.edu for information about this project.          //
00034 // //////////////////////////////////////////////////////////////////// //
00035 // Major portions of the iLab Neuromorphic Vision Toolkit are protected //
00036 // under the U.S. patent ``Computation of Intrinsic Perceptual Saliency //
00037 // in Visual Environments, and Applications'' by Christof Koch and      //
00038 // Laurent Itti, California Institute of Technology, 2001 (patent       //
00039 // pending; application number 09/912,225 filed July 23, 2001; see      //
00040 // http://pair.uspto.gov/cgi-bin/final/home.pl for current status).     //
00041 // //////////////////////////////////////////////////////////////////// //
00042 // This file is part of the iLab Neuromorphic Vision C++ Toolkit.       //
00043 //                                                                      //
00044 // The iLab Neuromorphic Vision C++ Toolkit is free software; you can   //
00045 // redistribute it and/or modify it under the terms of the GNU General  //
00046 // Public License as published by the Free Software Foundation; either  //
00047 // version 2 of the License, or (at your option) any later version.     //
00048 //                                                                      //
00049 // The iLab Neuromorphic Vision C++ Toolkit is distributed in the hope  //
00050 // that it will be useful, but WITHOUT ANY WARRANTY; without even the   //
00051 // implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      //
00052 // PURPOSE.  See the GNU General Public License for more details.       //
00053 //                                                                      //
00054 // You should have received a copy of the GNU General Public License    //
00055 // along with the iLab Neuromorphic Vision C++ Toolkit; if not, write   //
00056 // to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,   //
00057 // Boston, MA 02111-1307 USA.                                           //
00058 // //////////////////////////////////////////////////////////////////// //
00059 //
00060 // Primary maintainer for this file: mviswana usc edu
00061 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/Robots/LoBot/metlog/LoPointMatrix.H $
00062 // $Id: LoPointMatrix.H 13934 2010-09-14 23:17:01Z mviswana $
00063 //
00064 
00065 #ifndef LOBOT_POINT_MATRIX_DOT_H
00066 #define LOBOT_POINT_MATRIX_DOT_H
00067 
00068 //------------------------------ HEADERS --------------------------------
00069 
00070 // lobot headers
00071 #include "Robots/LoBot/metlog/LoPointTypes.H"
00072 #include "Robots/LoBot/thread/LoMutex.H"
00073 
00074 // Boost headers
00075 #include <boost/numeric/ublas/matrix.hpp>
00076 
00077 // Standard C++ headers
00078 
00079 //----------------------------- NAMESPACE -------------------------------
00080 
00081 namespace lobot {
00082 
00083 //------------------------- CLASS DEFINITION ----------------------------
00084 
00085 // Forward declarations
00086 class PointList ;
00087 
00088 /**
00089    \class lobot::PointMatrix
00090    \brief A thread-safe container for storing "normalized" point lists.
00091 
00092    When we conduct an experiment to gauge lobot's performance, we collect
00093    several different lists of points: one to record the robot's
00094    trajectory from start to finish, another to record the locations where
00095    the robot's emergency stop behaviour was activated, another for the
00096    locations where the LGMD avoidance algorithm averted the robot away
00097    from an approaching obstacle; so on and so forth.
00098 
00099    Each experiment will produce point lists of different sizes. To
00100    compute the robot's average case behaviour, we will have to
00101    "normalize" these lists so that they all contain the same number of
00102    elements as some reference experiment. After we have discarded extra
00103    points or added missing points w.r.t. the reference experiment, we can
00104    find point correspondences across experiments and, finally, average
00105    these transformed lists to get the desired result.
00106 
00107    This class stores the intermediate "normalized" point lists in a
00108    matrix. The columns of this matrix correspond to the individual
00109    experiments. The rows store corresponding points across experiments.
00110    For example, if we have 25 experiments in a dataset and the reference
00111    experiment is found to have 300 points in its trajectory point list,
00112    then this point matrix will have 25 columns and 300 rows.
00113 
00114    To find the point correspondences between each experiment's point
00115    lists and that of the reference experiment, we find the nearest point
00116    to each point in the reference experiment. The resulting list of
00117    points is stored as a column vector in the point matrix.
00118 
00119    The correspondences for one experiment are completely independent
00120    of the correspondences for another. Therefore, we can parallelize the
00121    correspondence finding procedure by launching multiple threads to
00122    handle the different experiments.
00123 
00124    Consequently, this class implements a thread-safe API for adding
00125    column vectors. The main thread should instantiate this class and then
00126    pass its address to each of the correspondence finding threads.
00127 */
00128 class PointMatrix {
00129    // Prevent copy and assignment
00130    PointMatrix(const PointMatrix&) ;
00131    PointMatrix& operator=(const PointMatrix&) ;
00132 
00133    /// This class's raison d'etre: to store a bunch of points in a
00134    /// matrix.
00135    //@{
00136    typedef boost::numeric::ublas::matrix<mPoint> Matrix ;
00137    Matrix m_matrix ;
00138    //@}
00139 
00140    /// This data member keeps track of the column index into which new
00141    /// point lists should be copied.
00142    unsigned int m_next_col ;
00143 
00144    /// When a correspondence finder thread is done processing one
00145    /// experiment, it will add the resulting "normalized" point list to
00146    /// an instance of this class. Since multiple correspondence finder
00147    /// threads can use this object, we need a mutex to ensure that they
00148    /// don't step on each others' toes.
00149    Mutex m_mutex ;
00150 
00151 public:
00152    /// Initalization: creates a point matrix of the specified size.
00153    PointMatrix(int rows, int cols) ;
00154 
00155    /// This method adds the supplied point list to the point matrix by
00156    /// copying the point list to one of its columns. Since this method is
00157    /// called by the correspondence finder threads, it ensures
00158    /// thread-safety.
00159    ///
00160    /// WARNING: Attempting to add more point lists, i.e., column vectors,
00161    /// to the matrix than the number of columns (dataset size) will
00162    /// result in a lobot::misc_error(LOGIC_ERROR).
00163    void add(const PointList&) ;
00164 
00165    /// Computes the component-wise average of the matrix's column
00166    /// vectors.
00167    PointList average() const ;
00168 } ;
00169 
00170 //-----------------------------------------------------------------------
00171 
00172 } // end of namespace encapsulating this file's definitions
00173 
00174 #endif
00175 
00176 /* So things look consistent in everyone's emacs... */
00177 /* Local Variables: */
00178 /* indent-tabs-mode: nil */
00179 /* End: */
Generated on Sun May 8 08:41:31 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3