MediaScript.C

Go to the documentation of this file.
00001 /*!@file Script/MediaScript.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/MediaScript.C $
00035 // $Id: MediaScript.C 11876 2009-10-22 15:53:06Z icore $
00036 //
00037 
00038 #ifndef SCRIPT_MEDIASCRIPT_C_DEFINED
00039 #define SCRIPT_MEDIASCRIPT_C_DEFINED
00040 
00041 #include "Script/MediaScript.H"
00042 
00043 #include "Component/OptionManager.H"
00044 #include "Image/Image.H"
00045 #include "Image/Pixels.H"
00046 #include "Media/FrameSeries.H"
00047 #include "Media/SimFrameSeries.H"
00048 #include "Script/ImageScript.H" // for tcl conversions
00049 #include "Script/ModelScript.H" // for registerComponentCreator()
00050 #include "rutz/error.h"
00051 #include "rutz/sfmt.h"
00052 #include "tcl/list.h"
00053 #include "tcl/objpkg.h"
00054 #include "tcl/pkg.h"
00055 #include "tcl/stdconversions.h"
00056 
00057 using nub::soft_ref;
00058 
00059 namespace
00060 {
00061   tcl::list ifsDims(soft_ref<InputFrameSeries> ifs)
00062   {
00063     Dims d = ifs->peekDims();
00064     tcl::list result;
00065     result.append(d.w());
00066     result.append(d.h());
00067     return result;
00068   }
00069 
00070   Image< PixRGB<byte> > ifsReadRGB(soft_ref<InputFrameSeries> ifs)
00071   { return ifs->readRGB(); }
00072 
00073   Image<byte> ifsReadGray(soft_ref<InputFrameSeries> ifs)
00074   { return ifs->readGray(); }
00075 
00076   void ofsWriteRGB(soft_ref<OutputFrameSeries> ofs,
00077                    const Image< PixRGB<byte> >& image,
00078                    const char* stem)
00079   { ofs->writeRGB(image, stem); }
00080 
00081   void ofsWriteGray(soft_ref<OutputFrameSeries> ofs,
00082                     const Image<byte>& image,
00083                     const char* stem)
00084   { ofs->writeGray(image, stem); }
00085 
00086   void ofsWriteFloat(soft_ref<OutputFrameSeries> ofs,
00087                      const Image<float>& image,
00088                      const char* stem)
00089   { ofs->writeFloat(image, FLOAT_NORM_0_255, stem); }
00090 }
00091 
00092 tcl::obj tcl::aux_convert_from(const FrameState s)
00093 {
00094   switch (s)
00095     {
00096     case FRAME_SAME:     return tcl::convert_from("SAME");
00097     case FRAME_NEXT:     return tcl::convert_from("NEXT");
00098     case FRAME_FINAL:    return tcl::convert_from("FINAL");
00099     case FRAME_COMPLETE: return tcl::convert_from("COMPLETE");
00100     }
00101 
00102   // else...
00103   throw rutz::error(rutz::sfmt("unknown FrameState '%d'", int(s)),
00104                     SRC_POS);
00105 
00106   /* can't happen */ return tcl::obj();
00107 }
00108 
00109 FrameState tcl::aux_convert_to(Tcl_Obj* obj, FrameState*)
00110 {
00111   const rutz::fstring f = tcl::aux_convert_to(obj, (rutz::fstring*)0);
00112 
00113   if      (f == "SAME")     return FRAME_SAME;
00114   else if (f == "NEXT")     return FRAME_NEXT;
00115   else if (f == "FINAL")    return FRAME_FINAL;
00116   else if (f == "COMPLETE") return FRAME_COMPLETE;
00117 
00118   // else...
00119   throw rutz::error(rutz::sfmt("unknown FrameSeries:State '%s'",
00120                                f.c_str()), SRC_POS);
00121 
00122   /* can't happen */ return FrameState(0);
00123 }
00124 
00125 tcl::obj tcl::aux_convert_from(SimTime t)
00126 {
00127   return tcl::convert_from(t.nsecs());
00128 }
00129 
00130 SimTime tcl::aux_convert_to(Tcl_Obj* obj, SimTime*)
00131 {
00132   return SimTime::NSECS(tcl::aux_convert_to(obj, (int64*)0));
00133 }
00134 
00135 extern "C"
00136 int Frameseries_Init(Tcl_Interp* interp)
00137 {
00138   GVX_PKG_CREATE(pkg, interp, "FrameSeries", "4.$Revision: 1$");
00139   pkg->inherit_pkg("Modelcomponent");
00140   tcl::def_basic_type_cmds<ModelComponent>(pkg, SRC_POS);
00141 
00142   GVX_PKG_RETURN(pkg);
00143 }
00144 
00145 extern "C"
00146 int Inputframeseries_Init(Tcl_Interp* interp)
00147 {
00148   GVX_PKG_CREATE(pkg, interp, "InputFrameSeries", "4.$Revision: 1$");
00149   pkg->inherit_pkg("Frameseries");
00150   tcl::def_basic_type_cmds<InputFrameSeries>(pkg, SRC_POS);
00151 
00152   registerComponentCreator<InputFrameSeries>();
00153 
00154   pkg->def("update", "stime", &InputFrameSeries::update, SRC_POS);
00155   pkg->def("updateNext", "objref", &InputFrameSeries::updateNext, SRC_POS);
00156   pkg->def("shouldWait", "objref", &InputFrameSeries::shouldWait, SRC_POS);
00157 
00158   pkg->def("dims", "objref", &ifsDims, SRC_POS);
00159   pkg->def("readRGB", "objref", &ifsReadRGB, SRC_POS);
00160   pkg->def("readGray", "objref", &ifsReadGray, SRC_POS);
00161 
00162   GVX_PKG_RETURN(pkg);
00163 }
00164 
00165 extern "C"
00166 int Outputframeseries_Init(Tcl_Interp* interp)
00167 {
00168   GVX_PKG_CREATE(pkg, interp, "OutputFrameSeries", "4.$Revision: 1$");
00169   pkg->inherit_pkg("Frameseries");
00170   tcl::def_basic_type_cmds<OutputFrameSeries>(pkg, SRC_POS);
00171 
00172   registerComponentCreator<OutputFrameSeries>();
00173 
00174   pkg->def("update", "stime new_event", &OutputFrameSeries::update, SRC_POS);
00175   pkg->def("updateNext", "objref", &OutputFrameSeries::updateNext, SRC_POS);
00176   pkg->def("shouldWait", "objref", &OutputFrameSeries::shouldWait, SRC_POS);
00177 
00178   pkg->def("writeRGB", "ofs img stem", &ofsWriteRGB, SRC_POS);
00179   pkg->def("writeGray", "ofs img stem", &ofsWriteGray, SRC_POS);
00180   pkg->def("writeFloat", "ofs img stem", &ofsWriteFloat, SRC_POS);
00181 
00182   GVX_PKG_RETURN(pkg);
00183 }
00184 
00185 extern "C"
00186 int Siminputframeseries_Init(Tcl_Interp* interp)
00187 {
00188   GVX_PKG_CREATE(pkg, interp, "SimInputFrameSeries", "4.$Revision: 1$");
00189   pkg->inherit_pkg("Simmodule");
00190   tcl::def_basic_type_cmds<SimInputFrameSeries>(pkg, SRC_POS);
00191 
00192   registerComponentCreator<SimInputFrameSeries>();
00193 
00194   GVX_PKG_RETURN(pkg);
00195 }
00196 
00197 extern "C"
00198 int Simoutputframeseries_Init(Tcl_Interp* interp)
00199 {
00200   GVX_PKG_CREATE(pkg, interp, "SimOutputFrameSeries", "4.$Revision: 1$");
00201   pkg->inherit_pkg("Simmodule");
00202   tcl::def_basic_type_cmds<SimOutputFrameSeries>(pkg, SRC_POS);
00203 
00204   registerComponentCreator<SimOutputFrameSeries>();
00205 
00206   GVX_PKG_RETURN(pkg);
00207 }
00208 
00209 // ######################################################################
00210 /* So things look consistent in everyone's emacs... */
00211 /* Local Variables: */
00212 /* indent-tabs-mode: nil */
00213 /* End: */
00214 
00215 #endif // SCRIPT_MEDIASCRIPT_C_DEFINED
Generated on Sun May 8 08:42:13 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3