00001 /*!@file Transport/FrameOstream.H */ 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/Transport/FrameOstream.H $ 00035 // $Id: FrameOstream.H 9547 2008-03-28 23:32:43Z rjpeters $ 00036 // 00037 00038 #ifndef FRAMEOSTREAM_H_DEFINED 00039 #define FRAMEOSTREAM_H_DEFINED 00040 00041 #include "Component/ModelComponent.H" 00042 #include "Image/Normalize.H" // for float normalization flags 00043 #include "Util/Types.H" // for byte 00044 00045 template <class T> class Image; 00046 template <class T> class Layout; 00047 template <class T> class PixRGB; 00048 00049 class FrameInfo; 00050 class GenericFrame; 00051 00052 //! Abstract interface class representing a destination for Image frames 00053 /*! Concrete classes might implement this interface so that the real 00054 final destination is either a series of bitmap files 00055 (e.g. RasterOutputSeries), or an mpeg-encoded movie stream 00056 (OutputMPEGStream), or an on-screen window (ImageDisplayStream), 00057 or a composite of destinations (OutputFrameSeries). 00058 00059 See also FrameIstream for the analogous input interface. */ 00060 class FrameOstream : public ModelComponent 00061 { 00062 public: 00063 //! Constructor 00064 FrameOstream(OptionManager& mgr, 00065 const std::string& descrName, 00066 const std::string& tagName); 00067 00068 //! Virtual destructor 00069 virtual ~FrameOstream(); 00070 00071 //! Configure the FrameOstream object in a type-dependent manner 00072 /*! The string is expected to be some piece of user input (e.g. from 00073 the command-line) specifying key information for the 00074 FrameOstream (e.g., the filename stem for a RasterOutputSeries). 00075 00076 The default implementation does nothing; derived classes can 00077 override if they need to receive such user input. 00078 */ 00079 virtual void setConfigInfo(const std::string& cfg); 00080 00081 //! Advise the FrameOstream object of the current frame number 00082 /*! NOTE: the default implementation does nothing -- it just ignores 00083 the frame number. This is allowed for subclasses, too, since for 00084 certain output formats (e.g., onscreen windows) it doesn't make 00085 any sense to specify a frame number. On the other hand, certain 00086 subclasses require a frame number to function properly (e.g., 00087 for writing a series of consecutively-numbered raster 00088 files). So, the bottom line is: clients of FrameOstream must be 00089 sure to call setFrameNumber(), but should make no assumptions 00090 about what it will actually do. 00091 00092 @return Whether the frame number was successfully set as 00093 requested. 00094 */ 00095 virtual bool setFrameNumber(int n); 00096 00097 //! Write a frame to the output destination 00098 /*! Destination could be a raster file, frame in an mpeg-encoded 00099 movie, an on-screen window, etc., depending on the concrete 00100 subclass. 00101 00102 @param image the image to be written, displayed, etc. 00103 00104 @param shortname a brief string (with no spaces) describing the 00105 image; it is expected that this shortname should be usable as 00106 part of a filename if the particular FrameOstream subclass 00107 involves writing files to disk 00108 00109 @param auxinfo extra optional information describing the image; 00110 FrameOstream subclasses make use of this information in a 00111 subclass-dependent manner, e.g. they could display this 00112 information in an onscreen window, or embed it into a comments 00113 in an image or movie file, etc. 00114 */ 00115 virtual void writeFrame(const GenericFrame& frame, 00116 const std::string& shortname, 00117 const FrameInfo& auxinfo = defaultInfo) = 0; 00118 00119 //! Write a frame to the output destination 00120 /*! Just calls writeFrame() with GenericFrame(image). 00121 00122 Derived classes must not override this function; instead they 00123 must implement writeFrame(). 00124 */ 00125 void writeRGB(const Image< PixRGB<byte> >& image, 00126 const std::string& shortname, 00127 const FrameInfo& auxinfo = defaultInfo); 00128 00129 //! Write a frame to the output destination 00130 /*! Just calls writeFrame() with GenericFrame(image). 00131 00132 Derived classes must not override this function; instead they 00133 must implement writeFrame(). 00134 */ 00135 void writeGray(const Image<byte>& image, 00136 const std::string& shortname, 00137 const FrameInfo& auxinfo = defaultInfo); 00138 00139 //! Write a frame to the output destination 00140 /*! Just calls writeFrame() with GenericFrame(image, flags). 00141 00142 Derived classes must not override this function; instead they 00143 must implement writeFrame(). 00144 */ 00145 void writeFloat(const Image<float>& image, 00146 const int flags, 00147 const std::string& shortname, 00148 const FrameInfo& auxinfo = defaultInfo); 00149 00150 //! Write an image layout to the output destination 00151 /*! This constructs a GenericFrame that retains the layout 00152 information and passes that to writeFrame(). Some subclasses may 00153 be able to handle a Layout in an optimized way, while others may 00154 simple call render() on it and handle it as an ordinary image. 00155 */ 00156 void writeRgbLayout(const Layout<PixRGB<byte> >& layout, 00157 const std::string& shortname, 00158 const FrameInfo& auxinfo = defaultInfo); 00159 00160 //! Write an image layout to the output destination 00161 /*! This constructs a GenericFrame that retains the layout 00162 information and passes that to writeFrame(). Some subclasses may 00163 be able to handle a Layout in an optimized way, while others may 00164 simple call render() on it and handle it as an ordinary image. 00165 */ 00166 void writeGrayLayout(const Layout<byte>& layout, 00167 const std::string& shortname, 00168 const FrameInfo& auxinfo = defaultInfo); 00169 00170 //! Check if we have no output destinations (e.g., user gave --out=none) 00171 /*! Clients can test isVoid() before they generate potentially 00172 expensive output images. This is just a performance optimization 00173 -- even if isVoid() is true, it's still safe to call writeRGB(), 00174 writeGray(), etc., but those calls will do nothing, and so any 00175 time spent computing the image will have been wasted. 00176 00177 The default implementation returns false; subclasses need 00178 override only if they want to (sometimes) return true. 00179 */ 00180 virtual bool isVoid() const; 00181 00182 //! Close off the underlying destination corresponding to shortname 00183 /*! The semantics of this operation are subclass-dependent, but the 00184 intention is for subclasses to follow these guidelines when 00185 implementing closeStream(): 00186 00187 - if the FrameOstream subclass deals with files, then the file 00188 corresponding to shortname should be closed, or if the 00189 FrameOstream deals with onscreen windows, then the 00190 corresponding window should be closed 00191 00192 - calling closeStream() for a particular shortname should not 00193 prevent a stream later being reopened for that shortname if 00194 writeFrame() is later called again with that shortname. 00195 00196 - calling closeStream() with a shortname for which there is no 00197 associated destination, or for a shortname which has already 00198 been closed, should not be an error but should just be 00199 silently ignored 00200 */ 00201 virtual void closeStream(const std::string& shortname) = 0; 00202 00203 //! Default FrameInfo object 00204 /*! The purpose of this object is so that the default value for the 00205 write functions can be 'defaultInfo' rather than 'FrameInfo()', 00206 since the former does not require #include 00207 "Transport/FrameInfo.H", while the latter does require it. */ 00208 static const FrameInfo defaultInfo; 00209 }; 00210 00211 // ###################################################################### 00212 /* So things look consistent in everyone's emacs... */ 00213 /* Local Variables: */ 00214 /* indent-tabs-mode: nil */ 00215 /* End: */ 00216 00217 #endif // FRAMEOSTREAM_H_DEFINED