00001 /** 00002 \file Robots/LoBot/misc/LoDataset.C 00003 \brief This file defines the non-inline member functions of the 00004 lobot::Dataset class. 00005 */ 00006 00007 // //////////////////////////////////////////////////////////////////// // 00008 // The iLab Neuromorphic Vision C++ Toolkit - Copyright (C) 2000-2005 // 00009 // by the University of Southern California (USC) and the iLab at USC. // 00010 // See http://iLab.usc.edu for information about this project. // 00011 // //////////////////////////////////////////////////////////////////// // 00012 // Major portions of the iLab Neuromorphic Vision Toolkit are protected // 00013 // under the U.S. patent ``Computation of Intrinsic Perceptual Saliency // 00014 // in Visual Environments, and Applications'' by Christof Koch and // 00015 // Laurent Itti, California Institute of Technology, 2001 (patent // 00016 // pending; application number 09/912,225 filed July 23, 2001; see // 00017 // http://pair.uspto.gov/cgi-bin/final/home.pl for current status). // 00018 // //////////////////////////////////////////////////////////////////// // 00019 // This file is part of the iLab Neuromorphic Vision C++ Toolkit. // 00020 // // 00021 // The iLab Neuromorphic Vision C++ Toolkit is free software; you can // 00022 // redistribute it and/or modify it under the terms of the GNU General // 00023 // Public License as published by the Free Software Foundation; either // 00024 // version 2 of the License, or (at your option) any later version. // 00025 // // 00026 // The iLab Neuromorphic Vision C++ Toolkit is distributed in the hope // 00027 // that it will be useful, but WITHOUT ANY WARRANTY; without even the // 00028 // implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR // 00029 // PURPOSE. See the GNU General Public License for more details. // 00030 // // 00031 // You should have received a copy of the GNU General Public License // 00032 // along with the iLab Neuromorphic Vision C++ Toolkit; if not, write // 00033 // to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, // 00034 // Boston, MA 02111-1307 USA. // 00035 // //////////////////////////////////////////////////////////////////// // 00036 // 00037 // Primary maintainer for this file: mviswana usc edu 00038 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/Robots/LoBot/metlog/LoDataset.C $ 00039 // $Id: LoDataset.C 13934 2010-09-14 23:17:01Z mviswana $ 00040 // 00041 00042 //------------------------------ HEADERS -------------------------------- 00043 00044 // lobot headers 00045 #include "Robots/LoBot/metlog/LoDataset.H" 00046 #include "Robots/LoBot/metlog/LoExperiment.H" 00047 #include "Robots/LoBot/metlog/LoPointTypes.H" 00048 00049 #include "Robots/LoBot/misc/LoExcept.H" 00050 #include "Robots/LoBot/util/LoSTL.H" 00051 00052 // Standard C++ headers 00053 #include <algorithm> 00054 #include <functional> 00055 00056 //----------------------------- NAMESPACE ------------------------------- 00057 00058 namespace lobot { 00059 00060 //-------------------------- INITIALIZATION ----------------------------- 00061 00062 Dataset::Dataset() 00063 { 00064 m_list.reserve(25) ; // just a guess 00065 } 00066 00067 //---------------------------- LIST ACCESS ------------------------------ 00068 00069 void Dataset::add(Experiment* E) 00070 { 00071 AutoMutex M(m_mutex) ; 00072 m_list.push_back(E) ; 00073 } 00074 00075 // These comparison functions are used in conjunction with std::sort to 00076 // find the "reference experiment" in a dataset, i.e., the one that has 00077 // the median number of points in the point list of interest. 00078 static bool cmp_trajectory(const Experiment* a, const Experiment* b) 00079 { 00080 return a->trajectory_size() < b->trajectory_size() ; 00081 } 00082 00083 static bool cmp_emergency_stop(const Experiment* a, const Experiment* b) 00084 { 00085 return a->emergency_stop_size() < b->emergency_stop_size() ; 00086 } 00087 00088 static bool cmp_extricate(const Experiment* a, const Experiment* b) 00089 { 00090 return a->extricate_size() < b->extricate_size() ; 00091 } 00092 00093 static bool cmp_lgmd_extricate(const Experiment* a, const Experiment* b) 00094 { 00095 return a->lgmd_extricate_size() < b->lgmd_extricate_size() ; 00096 } 00097 00098 // Sort the experiment list in order to find the one with the median 00099 // number of points in one of the experiment's point lists. 00100 const Experiment* Dataset::find_refexp(PointListName L) const 00101 { 00102 if (m_list.empty()) 00103 throw misc_error(LOGIC_ERROR) ; 00104 00105 typedef bool (*CMP)(const Experiment*, const Experiment*) ; 00106 const CMP cmp[] = { 00107 cmp_trajectory, 00108 cmp_emergency_stop, 00109 cmp_extricate, 00110 cmp_lgmd_extricate, 00111 } ; 00112 00113 std::sort(m_list.begin(), m_list.end(), cmp[L]) ; 00114 return m_list[m_list.size()/2] ; 00115 } 00116 00117 // Thread-safe sequential access to the experiment list 00118 const Experiment* Dataset::next() const 00119 { 00120 AutoMutex M(m_mutex) ; 00121 if (m_next == m_list.end()) 00122 throw eol() ; 00123 return *m_next++ ; 00124 } 00125 00126 // Resetting sequential access to the beginning of the experiment list 00127 void Dataset::rewind() 00128 { 00129 if (m_list.empty()) 00130 throw misc_error(LOGIC_ERROR) ; 00131 m_next = m_list.begin() ; 00132 } 00133 00134 //----------------------------- CLEAN-UP -------------------------------- 00135 00136 Dataset::~Dataset() 00137 { 00138 purge_container(m_list) ; 00139 } 00140 00141 //--------------------------- DEBUG SUPPORT ----------------------------- 00142 00143 void Dataset::dump() const 00144 { 00145 std::for_each(m_list.begin(), m_list.end(), 00146 std::mem_fun(&Experiment::dump)) ; 00147 } 00148 00149 //----------------------------------------------------------------------- 00150 00151 } // end of namespace encapsulating this file's definitions 00152 00153 /* So things look consistent in everyone's emacs... */ 00154 /* Local Variables: */ 00155 /* indent-tabs-mode: nil */ 00156 /* End: */