MbariResultViewer.H

Go to the documentation of this file.
00001 /*!@file MBARI/MbariResultViewer.H class that manages the results viewing and
00002   saving for the MBARI programs */
00003 
00004 // //////////////////////////////////////////////////////////////////// //
00005 // The iLab Neuromorphic Vision C++ Toolkit - Copyright (C) 2000-2003   //
00006 // by the University of Southern California (USC) and the iLab at USC.  //
00007 // See http://iLab.usc.edu for information about this project.          //
00008 // //////////////////////////////////////////////////////////////////// //
00009 // Major portions of the iLab Neuromorphic Vision Toolkit are protected //
00010 // under the U.S. patent ``Computation of Intrinsic Perceptual Saliency //
00011 // in Visual Environments, and Applications'' by Christof Koch and      //
00012 // Laurent Itti, California Institute of Technology, 2001 (patent       //
00013 // pending; application number 09/912,225 filed July 23, 2001; see      //
00014 // http://pair.uspto.gov/cgi-bin/final/home.pl for current status).     //
00015 // //////////////////////////////////////////////////////////////////// //
00016 // This file is part of the iLab Neuromorphic Vision C++ Toolkit.       //
00017 //                                                                      //
00018 // The iLab Neuromorphic Vision C++ Toolkit is free software; you can   //
00019 // redistribute it and/or modify it under the terms of the GNU General  //
00020 // Public License as published by the Free Software Foundation; either  //
00021 // version 2 of the License, or (at your option) any later version.     //
00022 //                                                                      //
00023 // The iLab Neuromorphic Vision C++ Toolkit is distributed in the hope  //
00024 // that it will be useful, but WITHOUT ANY WARRANTY; without even the   //
00025 // implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      //
00026 // PURPOSE.  See the GNU General Public License for more details.       //
00027 //                                                                      //
00028 // You should have received a copy of the GNU General Public License    //
00029 // along with the iLab Neuromorphic Vision C++ Toolkit; if not, write   //
00030 // to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,   //
00031 // Boston, MA 02111-1307 USA.                                           //
00032 // //////////////////////////////////////////////////////////////////// //
00033 //
00034 // Primary maintainer for this file: Laurent Itti <itti@usc.edu>
00035 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/MBARI/MbariResultViewer.H $
00036 // $Id: MbariResultViewer.H 8160 2007-03-21 21:34:16Z rjpeters $
00037 //
00038 
00039 #ifndef MBARIRESULTVIEWER_H_DEFINED
00040 #define MBARIRESULTVIEWER_H_DEFINED
00041 
00042 #include "Component/ModelComponent.H"
00043 #include "Component/ModelParam.H"
00044 #include "Image/ArrayData.H"
00045 #include "Image/Pixels.H"
00046 #include "MBARI/BitObjectDrawModes.H"
00047 #include "Util/Types.H"
00048 #include "rutz/shared_ptr.h"
00049 #include <string>
00050 #include <vector>
00051 
00052 class VisualEvent;
00053 class VisualEventSet;
00054 class PropertyVectorSet;
00055 class OutputMbariFrameSeries;
00056 class ModelManager;
00057 class XWinManaged;
00058 template <class T> class Image;
00059 
00060 //! Command-line options for MbariResultViewer
00061 //@{
00062 extern const ModelOptionDef OPT_MRVsaveEvents;
00063 extern const ModelOptionDef OPT_MRVloadEvents;
00064 extern const ModelOptionDef OPT_MRVsaveProperties;
00065 extern const ModelOptionDef OPT_MRVloadProperties;
00066 extern const ModelOptionDef OPT_MRVsavePositions;
00067 extern const ModelOptionDef OPT_MRVmarkInteresting;
00068 extern const ModelOptionDef OPT_MRVopacity;
00069 extern const ModelOptionDef OPT_MRVmarkCandidate;
00070 extern const ModelOptionDef OPT_MRVmarkPrediction;
00071 extern const ModelOptionDef OPT_MRVmarkFOE;
00072 extern const ModelOptionDef OPT_MRVsaveResults;
00073 extern const ModelOptionDef OPT_MRVdisplayResults;
00074 extern const ModelOptionDef OPT_MRVsaveOutput;
00075 extern const ModelOptionDef OPT_MRVdisplayOutput;
00076 extern const ModelOptionDef OPT_MRVshowEventLabels;
00077 extern const ModelOptionDef OPT_MRVrescaleDisplay;
00078 extern const ModelOptionDef OPT_MRVsaveEventNums;
00079 extern const ModelOptionDef OPT_MRVsizeAvgCache;
00080 //@}
00081 
00082 //! Class to facilitate displaying and saving of intermediate results
00083 /*! This class provides command lne options to control the saving
00084   and displaying of intermediate results as well as output frames
00085   for MBARI programs */
00086 class MbariResultViewer : public ModelComponent
00087 {
00088 public:
00089   //! Constructor - give a ModelManager and an OutputMbariFrameSeries
00090   /*! If the OutputMbariFrameSeries is not yet registered in the manager,
00091     it will be registered here */
00092   MbariResultViewer(ModelManager& mgr, nub::soft_ref<OutputMbariFrameSeries> ofs);
00093 
00094   //! Destructor - destroy all the windows that may be present
00095   ~MbariResultViewer();
00096 
00097   //! implements ModelComponent::paramChanged
00098   /*! intercepts setting of MRVmarkXXX variables and sets drawing
00099     colors accordingly */
00100   virtual void paramChanged(ModelParamBase* const param,
00101                             const bool valueChanged,
00102                             ParamClient::ChangeStatus* status);
00103 
00104   //! destroy all the windows
00105   virtual void reset1();
00106 
00107   //! save and/or display intermediate result
00108   /*! whether the result image is saved and/or displayed is
00109     determined by the ModelParams
00110     @param img the image containing the intermediate result
00111     @param frameNum the frame number of the image
00112     @param resultName a string that defines the kind of interemediate
00113     result - this is appended to the filestem for the file name
00114     and/or window title
00115     @param resNum if there are several results of this type for each frame,
00116     the number of the result*/
00117   template <class T>
00118   void output(const Image<T>& img, const uint frameNum,
00119               const std::string& resultName, const int resNum = -1);
00120 
00121   //! display intermediate result
00122   /*!@param img the image containing the intermediate result
00123     @param frameNum the frame number of the image
00124     @param resultName a string that defines the kind of interemediate
00125     result - this is appended to the filestem for the file name
00126     and/or window title
00127     @param resNum if there are several results of this type for each frame,
00128     the number of the resul*/
00129   template <class T>
00130   void display(const Image<T>& img, const uint frameNum,
00131                const std::string& resultName, const int resNum = -1);
00132 
00133   //! save intermediate result
00134   /*!@param img the image containing the intermediate result
00135     @param frameNum the frame number of the image
00136     @param resultName a string that defines the kind of interemediate
00137     result - this is appended to the filestem for the file name
00138     and/or window title
00139     @param resNum if there are several results of this type for each frame,
00140     the number of the resul*/
00141   void save(const Image< PixRGB<byte> >& img, const uint frameNum,
00142             const std::string& resultName, const int resNum = -1);
00143 
00144   //! save intermediate result
00145   /*!@param img the image containing the intermediate result
00146     @param frameNum the frame number of the image
00147     @param resultName a string that defines the kind of interemediate
00148     result - this is appended to the filestem for the file name
00149     and/or window title
00150     @param resNum if there are several results of this type for each frame,
00151     the number of the resul*/
00152   void save(const Image<byte>& img, const uint frameNum,
00153             const std::string& resultName, const int resNum = -1);
00154 
00155   //! save intermediate result
00156   /*!@param img the image containing the intermediate result
00157     @param frameNum the frame number of the image
00158     @param resultName a string that defines the kind of interemediate
00159     result - this is appended to the filestem for the file name
00160     and/or window title
00161     @param resNum if there are several results of this type for each frame,
00162     the number of the resul*/
00163   void save(const Image<float>& img, const uint frameNum,
00164             const std::string& resultName, const int resNum = -1);
00165 
00166   //! save and possibly display an output frame
00167   /*!Depending on the ModelParams, interesting events, candidates
00168     for interesting events and skipped event locations are marked
00169     in the frame, the frame is displayed (if desired) and saved.
00170     @param resultImg the output image
00171     @param frameNum the frame number of the output image
00172     @param evts the event set to be used for drawing the events
00173     @param circleRadius the radius of the circles used for marking*/
00174   void outputResultFrame(const Image< PixRGB<byte> >& resultImg,
00175                          const std::string& frameStem,
00176                          const uint frameNum,
00177                          VisualEventSet& evts,
00178                          PropertyVectorSet& pvs,
00179                          const int circleRadius);
00180 
00181   //! check if the LoadEventsName is set
00182   bool isLoadEventsNameSet() const;
00183 
00184   //! load the VisualEventSet from the file LoadEventsName
00185   void loadVisualEventSet(VisualEventSet& ves) const;
00186 
00187   //! check if the LoadPropertiesName is set
00188   bool isLoadPropertiesNameSet() const;
00189 
00190   //! load the PropertyVector from the file LoadPropertiesName
00191   void loadProperties(PropertyVectorSet& pvs) const;
00192 
00193   //! check if the SaveEventsName is set
00194   bool isSaveEventsNameSet() const;
00195 
00196   //! save the VisualEventSet to the file SaveEventsName
00197   void saveVisualEventSet(const VisualEventSet& ves) const;
00198 
00199   //! check if the SavePropertiesName is set
00200   bool isSavePropertiesNameSet() const;
00201 
00202   //! save the PropertyVector to the file SavePropertiesName
00203   void saveProperties(const PropertyVectorSet& pvs) const;
00204 
00205   //! check if the SavePositionsName is set
00206   bool isSavePositionsNameSet() const;
00207 
00208   //! save the positions to the file SavePositionsName
00209   void savePositions(const VisualEventSet& ves) const;
00210 
00211   //! determine whether the frames actually need to be loaded
00212   bool needFrames() const;
00213 
00214   //! returns the size of the cache for running averages (from the command line)
00215   uint getAvgCacheSize() const;
00216 
00217   //! determine whether we have to save any event clips
00218   bool isSaveEventClip() const;
00219 
00220   //! return the number of event clips we have to save
00221   uint numSaveEventClips() const;
00222 
00223   //! returns the event number with idx to be saved as a clip
00224   uint getSaveEventClipNum(uint idx) const;
00225 
00226   //! save a cut-out piece of frame containing a single event
00227   void saveSingleEventFrame(const Image< PixRGB<byte> >& img,
00228                             int frameNum, const VisualEvent& event);
00229 
00230 protected:
00231 
00232   //! destroy windows and other internal variables
00233   void freeMem();
00234 
00235   //! get an internal reference number from a resultName
00236   /*! If this resultName is new, a new reference is created*/
00237   uint getNumFromString(const std::string& resultName);
00238 
00239   //! make a label text from the reference number and the frame number
00240   std::string getLabel(const uint num, const uint frameNum, const int resNum = -1);
00241 
00242   //! make the file stem for saving files
00243   std::string getFileStem(const std::string& resultName, const int resNum = -1);
00244 
00245   //! draw an image to a window, deal with creating and rescaling the window
00246   template <class T>
00247   XWinManaged* displayImage(const Image<T>& img,
00248                             XWinManaged* win,
00249                             const char* label);
00250 
00251   //! parse the SaveEventNumString and store the numbers in itsSaveEventNums
00252   void parseSaveEventNums(const std::string& value);
00253 
00254   OModelParam<bool> itsSaveResults;     //!<whether intermediate results are saved
00255   OModelParam<bool> itsDisplayResults;  //!<whether intermediate results are displayed
00256   OModelParam<BitObjectDrawMode> itsMarkInteresting; //!<the way interesting events are marked
00257   OModelParam<float> itsOpacity;        //!<opacity of shape or outline markings of events
00258   OModelParam<bool> itsMarkCandidate;   //!<whether candidates for int. events are marked
00259   OModelParam<bool> itsMarkPrediction;  //!<whether predictions of event locations are marked
00260   OModelParam<bool> itsMarkFOE;         //!<whether the focus of expansion is marked
00261   OModelParam<bool> itsSaveOutput;      //!<whether the output frames are saved
00262   OModelParam<bool> itsDisplayOutput;   //!<whether the output frames are displayed
00263   OModelParam<bool> itsShowEventLabels; //!<whether the event labels are written into output frames
00264 
00265   OModelParam<Dims> itsRescaleDisplay;  //!<rescale intermediate results to this scale for display
00266 
00267   OModelParam<uint> itsSizeAvgCache;     //!<the number of images used for running average
00268 
00269   OModelParam<std::string> itsSaveEventsName;
00270   OModelParam<std::string> itsLoadEventsName;
00271   OModelParam<std::string> itsSavePropertiesName;
00272   OModelParam<std::string> itsLoadPropertiesName;
00273   OModelParam<std::string> itsSavePositionsName;
00274 
00275   OModelParam<std::string> itsSaveEventNumString;
00276 
00277 private:
00278   std::vector<std::string> itsResultNames;
00279   std::vector<XWinManaged*> itsResultWindows;
00280   XWinManaged* resFrameWindow;
00281   nub::soft_ref<OutputMbariFrameSeries> itsOfs;
00282   PixRGB<byte> colInteresting, colCandidate, colPrediction, colFOE;
00283   std::vector<uint> itsSaveEventNums;
00284 };
00285 
00286 #endif
00287 
00288 // ######################################################################
00289 /* So things look consistent in everyone's emacs... */
00290 /* Local Variables: */
00291 /* indent-tabs-mode: nil */
00292 /* End: */
Generated on Sun May 8 08:05:20 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3