libeblearntools
/home/rex/ebltrunk/tools/libeblearntools/include/camera_directory.h
00001 /***************************************************************************
00002  *   Copyright (C) 2010 by Pierre Sermanet   *
00003  *   pierre.sermanet@gmail.com   *
00004  *   All rights reserved.
00005  *
00006  * Redistribution and use in source and binary forms, with or without
00007  * modification, are permitted provided that the following conditions are met:
00008  *     * Redistributions of source code must retain the above copyright
00009  *       notice, this list of conditions and the following disclaimer.
00010  *     * Redistributions in binary form must reproduce the above copyright
00011  *       notice, this list of conditions and the following disclaimer in the
00012  *       documentation and/or other materials provided with the distribution.
00013  *     * Redistribution under a license not approved by the Open Source 
00014  *       Initiative (http://www.opensource.org) must display the 
00015  *       following acknowledgement in all advertising material:
00016  *        This product includes software developed at the Courant
00017  *        Institute of Mathematical Sciences (http://cims.nyu.edu).
00018  *     * The names of the authors may not be used to endorse or promote products
00019  *       derived from this software without specific prior written permission.
00020  *
00021  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED 
00022  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00023  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00024  * DISCLAIMED. IN NO EVENT SHALL ThE AUTHORS BE LIABLE FOR ANY
00025  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
00026  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00027  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
00028  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00029  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00030  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00031  ***************************************************************************/
00032 
00033 #ifndef CAMERA_DIRECTORY_H_
00034 #define CAMERA_DIRECTORY_H_
00035 
00036 #include "camera.h"
00037 #include "tools_utils.h"
00038 
00039 #ifdef __BOOST__
00040 #define BOOST_FILESYSTEM_VERSION 2
00041 #include "boost/filesystem.hpp"
00042 #include "boost/regex.hpp"
00043 using namespace boost::filesystem;
00044 using namespace boost;
00045 #endif
00046 
00047 using namespace std;
00048 
00049 namespace ebl {
00050 
00054   template <typename Tdata> class camera_directory : public camera<Tdata> {
00055   public:
00056     // constructors/allocation /////////////////////////////////////////////////
00057 
00071     camera_directory(const char *directory, int height_ = -1, int width_ = -1,
00072                      bool randomize = false, uint npasses = 1,
00073                      std::ostream &out = std::cout,
00074                      std::ostream &err = std::cerr,
00075                      const char *file_pattern = IMAGE_PATTERN_MAT,
00076                      const list<string> *files = NULL);
00088     camera_directory(int height_ = -1, int width_ = -1,
00089                      bool randomize = false, uint npasses = 1,
00090                      std::ostream &out = std::cout,
00091                      std::ostream &err = std::cerr,
00092                      const char *file_pattern = IMAGE_PATTERN_MAT);
00094     bool read_directory(const char *directory);    
00096     virtual ~camera_directory();
00097 
00098     // frame grabbing //////////////////////////////////////////////////////////
00099 
00101     virtual idx<Tdata> grab();
00103     virtual string grab_filename();
00107     virtual void next();
00109     virtual void previous();
00111     virtual bool empty();
00113     virtual void skip(uint n);
00115     virtual string frame_name();
00117     virtual string frame_fullname();
00120     virtual string get_subdir();
00122     virtual int remaining();
00125     virtual int size();
00126 
00127     // members /////////////////////////////////////////////////////////////////
00128   protected:
00129     using camera<Tdata>::frame; 
00130     using camera<Tdata>::frame_id_;     
00131     using camera<Tdata>::frame_name_;   
00132     using camera<Tdata>::out;   
00133     using camera<Tdata>::err;   
00134     files_list          *fl;    
00135     files_list::iterator fli;   
00136     string               indir; 
00137     string               fdir;  
00138     string               fname; 
00139     string               subdir;
00140     ostringstream        oss;   
00141     uint                 flsize;        
00142     bool                 randomize; 
00143     uint                 npasses; 
00144     const char          *file_pattern; 
00145   };
00146 
00147 } // end namespace ebl
00148 
00149 #include "camera_directory.hpp"
00150 
00151 
00152 #endif /* CAMERA_DIRECTORY_H_ */