00001 // This is brl/bbas/vidl2/vidl2_image_list_istream.h 00002 #ifndef vidl2_image_list_istream_h_ 00003 #define vidl2_image_list_istream_h_ 00004 #ifdef VCL_NEEDS_PRAGMA_INTERFACE 00005 #pragma interface 00006 #endif 00007 //: 00008 // \file 00009 // \brief A video input stream from a list of images on disk 00010 // 00011 // \author Matt Leotta 00012 // \date 19 Dec 2005 00013 00014 #include "vidl2_istream.h" 00015 #include <vcl_vector.h> 00016 #include <vcl_string.h> 00017 00018 00019 //: A video input stream from a list of images on disk 00020 // This istream will try to open and validate (but not read image data from) 00021 // every file in a list of file paths. The paths to valid image files 00022 // are maintained, but only one image is opened at a time. Keeping a list of 00023 // open file descriptors (via vil_image_resource_sptr) was found to be problematic. 00024 // The number of simultaneously open files is limited on many platforms. 00025 // The paths are tested for validity at the "open" stage rather than the "stream" 00026 // stage so that we have random access to the frames (i.e. the stream is seekable). 00027 class vidl2_image_list_istream 00028 : public vidl2_istream 00029 { 00030 public: 00031 //: Constructor - default 00032 vidl2_image_list_istream(); 00033 00034 //: Constructor - from a file glob string 00035 vidl2_image_list_istream(const vcl_string& glob); 00036 00037 //: Constructor - from a vector of file paths 00038 vidl2_image_list_istream(const vcl_vector<vcl_string>& paths); 00039 00040 //: Destructor 00041 virtual ~vidl2_image_list_istream() { close(); } 00042 00043 00044 //: Open a new stream using a file glob (see vul_file_iterator) 00045 // \note files are loaded in alphanumeric order by path name 00046 virtual bool open(const vcl_string& glob); 00047 00048 //: Open a new stream using a vector of file paths 00049 // \note all files are tested and only valid image files are retained 00050 virtual bool open(const vcl_vector<vcl_string>& paths); 00051 00052 //: Close the stream 00053 virtual void close(); 00054 00055 00056 //: Return true if the stream is open for reading 00057 virtual bool is_open() const { return !image_paths_.empty(); } 00058 00059 //: Return true if the stream is in a valid state 00060 virtual bool is_valid() const { return is_open() && 00061 index_ < image_paths_.size(); } 00062 00063 //: Return true if the stream support seeking 00064 virtual bool is_seekable() const { return true; } 00065 00066 //: Return the current frame number 00067 virtual unsigned int frame_number() const { return index_; } 00068 00069 00070 //: Advance to the next frame (but do not open the next image) 00071 virtual bool advance(); 00072 00073 //: Read the next frame from the stream 00074 virtual vidl2_frame_sptr read_frame(); 00075 00076 //: Return the current frame in the stream 00077 virtual vidl2_frame_sptr current_frame(); 00078 00079 //: Seek to the given frame number (but do not load the image) 00080 // \returns true if successful 00081 virtual bool seek_frame(unsigned int frame_number); 00082 00083 private: 00084 //: The vector of images 00085 vcl_vector<vcl_string> image_paths_; 00086 00087 //: The current index 00088 unsigned int index_; 00089 00090 //: The current frame (cached) 00091 vidl2_frame_sptr current_frame_; 00092 }; 00093 00094 #endif // vidl2_image_list_istream_h_
1.4.4