contrib/brl/vvid/vvid_vil_file_manager.h
Go to the documentation of this file.
00001 // This is brl/vvid/vvid_vil_file_manager.h
00002 #ifndef vvid_vil_file_manager_h_
00003 #define vvid_vil_file_manager_h_
00004 //-----------------------------------------------------------------------------
00005 //:
00006 // \file
00007 // \author J.L. Mundy
00008 // \brief A sample video file player
00009 //
00010 // \verbatim
00011 //  Modifications:
00012 //   J.L. Mundy October 05, 2002 Ported from jvid
00013 // \endverbatim
00014 //----------------------------------------------------------------------------
00015 #include <vcl_vector.h>
00016 // not used? #include <vcl_list.h>
00017 #include <vgui/vgui_grid_tableau.h>
00018 #include <vgui/vgui_wrapper_tableau.h>
00019 #include <vgui/vgui_image_tableau_sptr.h>
00020 #include <bgui/bgui_image_tableau_sptr.h>
00021 #include <vgui/vgui_rubberband_tableau_sptr.h>
00022 #include <vgui/vgui_range_map_params_sptr.h>
00023 #include <bgui/bgui_vsol2D_tableau_sptr.h>
00024 #include <vgui/vgui_easy2D_tableau_sptr.h>
00025 #include <bgui/bgui_picker_tableau_sptr.h>
00026 #include <bgui/bgui_bargraph_clipon_tableau_sptr.h>
00027 #include <vgui/vgui_viewer2D_tableau_sptr.h>
00028 #include <vgui/vgui_window.h>
00029 #include <vsol/vsol_polygon_2d_sptr.h>
00030 #include <vidl1/vidl1_movie_sptr.h>
00031 #include <vil/vil_image_resource.h>
00032 #include <vpro/vpro_vil_video_process_sptr.h>
00033 
00034 //: A singleton manager class for playing videos.
00035 // A vector of images with
00036 // enclosing image and easy2D tableaux is cached so that computed overlays
00037 // such as Harris corners can be played back quickly. The cache option can be
00038 // turned off if one is going to just play the video and not apply image
00039 // segmentation processing to the frames.
00040 //
00041 // A demo of overlaying points on the video is provide by ::easy2D_demo
00042 // to get rid of the points, reload the video
00043 //
00044 // It is planned to extend the class to handle multiple panes (grid locations)
00045 // so that different (or the same) videos can be playing simultaneously
00046 // in different zoom states as well as pause states. This extension will
00047 // the state variables to be changed to vectors as well as having multiple
00048 // caches.. etc.
00049 //
00050 // Known problems:
00051 //  - quiting while the video is paused can cause a seg fault since
00052 //    the movie gets deleted before the loop quits
00053 //  - There is a continuous gl error stream from vgui_adaptor. Something to
00054 //    do with "setting draw buffer to back"
00055 //
00056 
00057 class vvid_vil_file_manager : public vgui_wrapper_tableau
00058 {
00059  public:
00060   vvid_vil_file_manager();
00061   ~vvid_vil_file_manager();
00062   //: returns the unique instance of vvid_vil_file_manger
00063   static vvid_vil_file_manager *instance();
00064 
00065   //: height (in pixels) of the video frame
00066   unsigned get_height() const { return height_; }
00067 
00068   //: width (in pixels) of the video frame
00069   unsigned get_width() const { return width_; }
00070 
00071   //: quit the application
00072   void quit();
00073   //: load each frame of the video into a cached vector of overlays if caching is enabled
00074   void load_video_file();
00075 
00076   //: load a pyramid video as a set of tiff images
00077   void load_pyramid_video();
00078 
00079   //: loop through the frames and display
00080   void play_video();
00081 
00082   //: loop through the pyramid frames and display
00083   void play_pyramid();
00084 
00085   //: stop at the current frame
00086   void pause_video();
00087 
00088   //: stop playing and return to the first frame
00089   void stop_video();
00090 
00091   //: pops up a dialog to indicate what frame to start play
00092   void start_frame();
00093 
00094   //: pops up a dialog to indicate what frame to start play
00095   void end_frame();
00096 
00097   //: index to the next frame (must be paused)
00098   void next_frame();
00099 
00100   //: index to the previous frame (must be paused)
00101   void prev_frame();
00102 
00103   //: set the frame rate
00104   void set_speed();
00105 
00106   //: set the range map rate
00107   void set_range_params();
00108 
00109   //: create a box as a vsol_polygon
00110   void create_box();
00111 
00112   //: save a video of according to a specified roi
00113   void save_roi();
00114   //: get the window of this player
00115   vgui_window* get_window() { return win_; }
00116 
00117   //: set the window
00118   void set_window(vgui_window* win){win_=win;}
00119 
00120   //: tableau handle function
00121   virtual bool handle(const vgui_event&);
00122 
00123  protected:
00124   //utility functions
00125   void init();
00126   void un_cached_play();
00127   void pyramid_play();
00128  private:
00129   //flags
00130   bool cache_frames_;
00131   bool play_video_;
00132   bool pause_video_;
00133   bool next_frame_;
00134   bool prev_frame_;
00135   vgui_range_map_params_sptr rmps_;
00136   int window_;//frame trail time window
00137   int start_frame_; //frame to start play
00138   int end_frame_; //frame to start play
00139   float time_interval_;
00140   int display_frame_repeat_;//insert duplicate frames to slow playback
00141   unsigned width_;
00142   unsigned height_;
00143   unsigned x0_;
00144   unsigned y0_;
00145   unsigned xsize_;
00146   unsigned ysize_;
00147   vidl1_movie_sptr my_movie_;
00148   vcl_vector<vil_image_resource_sptr> pyramid_movie_;
00149   vgui_window* win_;
00150   vsol_polygon_2d_sptr box_;
00151   vcl_vector<vgui_easy2D_tableau_sptr> tabs_;
00152   vgui_viewer2D_tableau_sptr v2D0_;
00153   vgui_viewer2D_tableau_sptr v2D1_;
00154   vgui_easy2D_tableau_sptr easy0_;
00155   vgui_easy2D_tableau_sptr easy1_;
00156   bgui_image_tableau_sptr itab0_;
00157   vgui_rubberband_tableau_sptr rubber0_;
00158   bgui_picker_tableau_sptr picktab0_;
00159   vgui_image_tableau_sptr itab1_;
00160   vpro_vil_video_process_sptr video_process_;
00161   vgui_grid_tableau_sptr grid_;
00162   static vvid_vil_file_manager *instance_;
00163 };
00164 
00165 #endif // vvid_vil_file_manager_h_