core/vul/vul_sequence_filename_map.h
Go to the documentation of this file.
00001 // This is core/vul/vul_sequence_filename_map.h
00002 #ifndef vul_sequence_filename_map_h_
00003 #define vul_sequence_filename_map_h_
00004 #ifdef VCL_NEEDS_PRAGMA_INTERFACE
00005 #pragma interface
00006 #endif
00007 //:
00008 // \file
00009 // \brief Contains class for mapping sequence frame indices to filenames
00010 // \author David Capel, Oxford RRG
00011 // \date   15 April 2000
00012 //
00013 // \verbatim
00014 // Modifications
00015 // PDA (Manchester) 21/03/2001: Tidied up the documentation
00016 // \endverbatim
00017 
00018 #include <vcl_string.h>
00019 #include <vcl_iosfwd.h>
00020 #include <vcl_vector.h>
00021 
00022 
00023 //: Maps sequence frame indices to filenames
00024 // vul_sequence_filename_map maps sequence frame indices to filenames. It
00025 // also performs some disk probing functions to discover the image extension,
00026 // directories and sequence template if not specified by the user.
00027 //
00028 // The template can have any of the following forms :
00029 //   "pgm/img.%03d.pgm,0:5:100", "pgm/img.####.pgm", "img.###.pgm",
00030 // "img.###,5:1:20", "img.%02d,:5:" (you get the idea..) If the image
00031 // directory and/or filename extension are not specified they
00032 // are automagically determined by probing the current directory for likely
00033 // candidates.
00034 //
00035 // The vector of indices specifies the mapping from sequence frame-index to
00036 // filename-index.  If not specified, the image directory is probed to
00037 // determine the sequence start/end frames.
00038 class vul_sequence_filename_map
00039 {
00040  public:
00041   vul_sequence_filename_map ();
00042   vul_sequence_filename_map (vcl_string const & seq_template,
00043                              vcl_vector<int> const & indices);
00044   vul_sequence_filename_map (vcl_string const & seq_template,
00045                              int start, int end, int step = 1);
00046   vul_sequence_filename_map (vcl_string const & seq_template,
00047                              int step = 1);
00048   ~vul_sequence_filename_map ();
00049 
00050   //: returns frame name with no extension, e.g. "img.003", "img.003.004"
00051   vcl_string name(int frame);
00052   vcl_string pair_name(int i, int j);
00053   vcl_string triplet_name(int i, int j, int k);
00054 
00055   vcl_string image_name(int frame)
00056   { return image_dir_ + name(frame) + image_extension_; }
00057 
00058   //: returns the image directory e.g. "pgm/"
00059   vcl_string get_image_dir() const { return image_dir_; }
00060 
00061   //: returns the image extension e.g. ".pgm"
00062   vcl_string get_image_extension() const { return image_extension_; }
00063 
00064   //: returns the base name e.h. "img."
00065   vcl_string get_base_name() const { return basename_; }
00066 
00067   //: returns the actually on-disk index corresponding to frame N
00068   int get_real_index(int frame) const { return indices_[frame]; }
00069   vcl_vector<int> const& get_real_indices() const { return indices_; }
00070 
00071   //: returns the frame number corresp. to on-disk index N, or -1 if out-of-range
00072   int get_mapped_index(int real) const;
00073 
00074   int get_nviews() const { return int(indices_.size()); }
00075 
00076 
00077   //: pretty print
00078   vcl_ostream& print(vcl_ostream& s) const;
00079 
00080  protected:
00081   bool filter_dirent(char const* name, vcl_string const& extension);
00082   int extract_index(char const* name);
00083 
00084   vcl_string seq_template_;
00085   vcl_vector<int> indices_;
00086   vcl_string basename_;
00087   vcl_string index_format_;
00088   vcl_string image_dir_;
00089   vcl_string image_extension_;
00090   int start_;
00091   int step_;
00092   int end_;
00093 
00094   void parse();
00095 };
00096 
00097 vcl_ostream& operator<<(vcl_ostream &os, const vul_sequence_filename_map& s);
00098 
00099 #endif // vul_sequence_filename_map_h_