00001 /*!@file BPnnet/KnowledgeBase.H Header file for knowledge base */ 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: Philip Williams <plw@usc.edu> 00034 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/BPnnet/KnowledgeBase.H $ 00035 // $Id: KnowledgeBase.H 9308 2008-02-22 19:04:41Z rjpeters $ 00036 // 00037 00038 #ifndef KNOWLEDGEBASE_H_DEFINED 00039 #define KNOWLEDGEBASE_H_DEFINED 00040 00041 #include "BPnnet/SimpleVisualObject.H" 00042 00043 #include <cstring> 00044 #include <vector> 00045 00046 //! this class holds a knowledge base 00047 class KnowledgeBase { 00048 public: 00049 //! Constructor 00050 KnowledgeBase(); 00051 00052 //! Destructor 00053 ~KnowledgeBase(); 00054 00055 //! load from disk 00056 bool load(const char *fname); 00057 00058 //! save to disk 00059 bool save(const char *fname) const; 00060 00061 //! Add new object to knowledge base. True on success. 00062 bool addSimpleVisualObject(SimpleVisualObject& o); 00063 00064 //! Find visual object from KB that has corresponding name 00065 /*! returns true on success */ 00066 inline bool findSimpleVisualObject(const char *name, SimpleVisualObject& o) const; 00067 00068 //! Find visual object indexed by "index" in the kb array 00069 /*! returns true on success */ 00070 inline bool findSimpleVisualObject(const int index, SimpleVisualObject& o) const; 00071 00072 //! Return visual object from KB that has corresponding name 00073 /*! or -1 of object not found */ 00074 inline int findSimpleVisualObjectIndex(const char *name) const; 00075 00076 //! get visual object at given index: 00077 inline SimpleVisualObject getSimpleVisualObject(const int index) const; 00078 00079 //! Return number of visual objects held in this knowledge base 00080 inline int getSize() const; 00081 00082 private: 00083 std::vector<SimpleVisualObject> vokb; 00084 }; 00085 00086 // ###################################################################### 00087 // ########## INLINED METHODS: 00088 // ###################################################################### 00089 00090 inline bool KnowledgeBase::findSimpleVisualObject(const char *name, 00091 SimpleVisualObject& o) const 00092 { 00093 int index = findSimpleVisualObjectIndex(name); 00094 if (index == -1) { o = SimpleVisualObject("<UNKNOWN>"); return false; } 00095 else { o = vokb[index]; return true; } 00096 } 00097 00098 // ###################################################################### 00099 inline bool KnowledgeBase::findSimpleVisualObject(const int index, 00100 SimpleVisualObject& o) const 00101 { 00102 if (index < 0 || index >= getSize()) 00103 { o = SimpleVisualObject("<UNKNOWN>"); return false; } 00104 else { o = vokb[index]; return true; } 00105 } 00106 00107 // ###################################################################### 00108 inline int KnowledgeBase::findSimpleVisualObjectIndex(const char *name) const 00109 { 00110 int n = getSize(); 00111 for (int i = 0; i < n; i ++) 00112 if (strcmp(name, vokb[i].getName()) == 0) return i; 00113 return -1; 00114 } 00115 00116 // ###################################################################### 00117 inline SimpleVisualObject KnowledgeBase::getSimpleVisualObject(const int index) const 00118 { 00119 if (index < 0 || index >= getSize()) return SimpleVisualObject("<UNKNOWN>"); 00120 else return vokb[index]; 00121 } 00122 00123 // ###################################################################### 00124 inline int KnowledgeBase::getSize() const 00125 { return (int)(vokb.size()); } 00126 00127 #endif 00128 00129 // ###################################################################### 00130 /* So things look consistent in everyone's emacs... */ 00131 /* Local Variables: */ 00132 /* indent-tabs-mode: nil */ 00133 /* End: */