00001 /*!@file Script/ModelScript.C */ 00002 00003 // //////////////////////////////////////////////////////////////////// // 00004 // The iLab Neuromorphic Vision C++ Toolkit - Copyright (C) 2000-2005 // 00005 // by the 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: Rob Peters <rjpeters at usc dot edu> 00034 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/Script/ModelScript.C $ 00035 // $Id: ModelScript.C 11876 2009-10-22 15:53:06Z icore $ 00036 // 00037 00038 #ifndef SCRIPT_MODELSCRIPT_C_DEFINED 00039 #define SCRIPT_MODELSCRIPT_C_DEFINED 00040 00041 #include "Script/ModelScript.H" 00042 00043 #include "tcl/stdconversions.h" 00044 00045 #include "Component/ModelManager.H" 00046 #include "Neuro/StdBrain.H" 00047 #include "Util/log.H" 00048 #include "tcl/list.h" 00049 #include "tcl/objpkg.h" 00050 #include "tcl/pkg.h" 00051 00052 #include <sstream> 00053 #include <string> 00054 #include <tcl.h> 00055 00056 namespace 00057 { 00058 nub::soft_ref<ModelManager> theManager; 00059 00060 nub::soft_ref<StdBrain> makeStdBrain() 00061 { 00062 return nub::soft_ref<StdBrain>(new StdBrain(*theManager)); 00063 } 00064 00065 void setMPString(nub::soft_ref<ModelComponent> comp, 00066 const std::string& name, 00067 const std::string& value) 00068 { 00069 comp->setModelParamString(name, value); 00070 } 00071 00072 std::string getMPString(nub::soft_ref<ModelComponent> comp, 00073 const std::string& name) 00074 { 00075 return comp->getModelParamString(name); 00076 } 00077 00078 std::string printout(nub::soft_ref<ModelComponent> comp) 00079 { 00080 std::ostringstream strm; 00081 comp->printout(strm); 00082 return strm.str(); 00083 } 00084 00085 bool mmParse(nub::soft_ref<ModelManager> mm, 00086 tcl::list argv, const char* usage, 00087 int minarg, int maxarg) 00088 { 00089 const char* args[argv.length()]; 00090 00091 for (uint i = 0; i < argv.length(); ++i) 00092 args[i] = argv.get<const char*>(i); 00093 00094 return mm->parseCommandLine(argv.length(), args, usage, 00095 minarg, maxarg); 00096 } 00097 00098 tcl::list mmExtraArgs(nub::soft_ref<ModelManager> mm) 00099 { 00100 tcl::list result; 00101 for (uint i = 0; i < mm->numExtraArgs(); ++i) 00102 result.append(mm->getExtraArg(i)); 00103 return result; 00104 } 00105 00106 int evolveMaster(nub::ref<SimEventQueue> seq) 00107 { 00108 const SimStatus status = seq->evolve(); 00109 return status == SIM_BREAK; 00110 } 00111 } 00112 00113 OptionManager& getManager() 00114 { 00115 return *theManager; 00116 } 00117 00118 extern "C" 00119 int Modelcomponent_Init(Tcl_Interp* interp) 00120 { 00121 GVX_PKG_CREATE(pkg, interp, "Modelcomponent", "4.$Revision: 1$"); 00122 pkg->inherit_pkg("Obj"); 00123 tcl::def_basic_type_cmds<ModelComponent>(pkg, SRC_POS); 00124 00125 pkg->def("start", "objref", 00126 &ModelComponent::start, SRC_POS); 00127 pkg->def("stop", "objref", 00128 &ModelComponent::stop, SRC_POS); 00129 pkg->def("started", "objref", 00130 &ModelComponent::started, SRC_POS); 00131 pkg->def("descriptiveName", "objref", 00132 &ModelComponent::descriptiveName, SRC_POS); 00133 pkg->def("tagName", "objref", 00134 &ModelComponent::tagName, SRC_POS); 00135 pkg->def("tagName", "objref newname", 00136 &ModelComponent::setTagName, SRC_POS); 00137 pkg->def("addSubComponent", "objref subcomp propgrealm", 00138 &ModelComponent::addSubComponent, SRC_POS); 00139 pkg->def("removeSubComponentByIndex", "objref index", 00140 (void (ModelComponent::*)(uint)) 00141 &ModelComponent::setTagName, SRC_POS); 00142 pkg->def("removeSubComponentByName", "objref tagname ", 00143 (void (ModelComponent::*)(const std::string&)) 00144 &ModelComponent::setTagName, SRC_POS); 00145 pkg->def("removeAllSubComponents", "objref", 00146 &ModelComponent::removeAllSubComponents, SRC_POS); 00147 pkg->def("numSubComp", "objref", 00148 &ModelComponent::numSubComp, SRC_POS); 00149 pkg->def("subCompByIndex", "objref index", 00150 (nub::ref<ModelComponent> (ModelComponent::*)(uint) const) 00151 &ModelComponent::subComponent, SRC_POS); 00152 pkg->def("subCompByName", "objref tagname flags", 00153 (nub::ref<ModelComponent> (ModelComponent::*)(const std::string&, int) const) 00154 &ModelComponent::subComponent, SRC_POS); 00155 pkg->def("hasSubComponent", "objref tagname flags", 00156 (bool (ModelComponent::*)(const std::string&, int) const) 00157 &ModelComponent::hasSubComponent, SRC_POS); 00158 pkg->def("printout", "objref", 00159 &printout, SRC_POS); 00160 pkg->def("reset", "objref do_recurse", 00161 &ModelComponent::reset, SRC_POS); 00162 00163 pkg->def("param", "objref paramname", 00164 &getMPString, SRC_POS); 00165 00166 pkg->def("param", "objref paramname paramvalue", 00167 &setMPString, SRC_POS); 00168 00169 GVX_PKG_RETURN(pkg); 00170 } 00171 00172 extern "C" 00173 int Modelmanager_Init(Tcl_Interp* interp) 00174 { 00175 GVX_PKG_CREATE(pkg, interp, "ModelManager", "4.$Revision: 1$"); 00176 pkg->inherit_pkg("Modelcomponent"); 00177 tcl::def_basic_type_cmds<ModelManager>(pkg, SRC_POS); 00178 00179 theManager.reset(new ModelManager("iLab Neuromorphic Vision Toolkit")); 00180 00181 registerComponentCreator<StdBrain>(); 00182 00183 pkg->def("parseCommandLine", "objref argv usage minarg maxarg", 00184 &mmParse, SRC_POS); 00185 00186 pkg->def("extraArgs", "objref", &mmExtraArgs, SRC_POS); 00187 00188 GVX_PKG_RETURN(pkg); 00189 } 00190 00191 extern "C" 00192 int Simmodule_Init(Tcl_Interp* interp) 00193 { 00194 GVX_PKG_CREATE(pkg, interp, "SimModule", "4.$Revision: 1$"); 00195 pkg->inherit_pkg("Modelcomponent"); 00196 tcl::def_basic_type_cmds<SimModule>(pkg, SRC_POS); 00197 00198 GVX_PKG_RETURN(pkg); 00199 } 00200 00201 extern "C" 00202 int Simeventqueue_Init(Tcl_Interp* interp) 00203 { 00204 GVX_PKG_CREATE(pkg, interp, "SimEventQueue", "4.$Revision: 1$"); 00205 pkg->inherit_pkg("Modelcomponent"); 00206 tcl::def_basic_type_cmds<SimEventQueue>(pkg, SRC_POS); 00207 00208 registerComponentCreator<SimEventQueue>(); 00209 00210 pkg->def("evolveMaster", "objref", &evolveMaster, SRC_POS); 00211 00212 //pkg->def("now", "objref", &SimEventQueue::now, SRC_POS); 00213 00214 GVX_PKG_RETURN(pkg); 00215 } 00216 00217 // ###################################################################### 00218 /* So things look consistent in everyone's emacs... */ 00219 /* Local Variables: */ 00220 /* indent-tabs-mode: nil */ 00221 /* End: */ 00222 00223 #endif // SCRIPT_MODELSCRIPT_C_DEFINED