vul_sequence_filename_map.h
Go to the documentation of this file.
1 // This is core/vul/vul_sequence_filename_map.h
2 #ifndef vul_sequence_filename_map_h_
3 #define vul_sequence_filename_map_h_
4 //:
5 // \file
6 // \brief Contains class for mapping sequence frame indices to filenames
7 // \author David Capel, Oxford RRG
8 // \date 15 April 2000
9 //
10 // \verbatim
11 // Modifications
12 // PDA (Manchester) 21/03/2001: Tidied up the documentation
13 // \endverbatim
14 
15 #include <string>
16 #include <iosfwd>
17 #include <vector>
18 #ifdef _MSC_VER
19 # include <vcl_msvc_warnings.h>
20 #endif
21 
22 
23 //: Maps sequence frame indices to filenames
24 // vul_sequence_filename_map maps sequence frame indices to filenames. It
25 // also performs some disk probing functions to discover the image extension,
26 // directories and sequence template if not specified by the user.
27 //
28 // The template can have any of the following forms :
29 // "pgm/img.%03d.pgm,0:5:100", "pgm/img.####.pgm", "img.###.pgm",
30 // "img.###,5:1:20", "img.%02d,:5:" (you get the idea..) If the image
31 // directory and/or filename extension are not specified they
32 // are automagically determined by probing the current directory for likely
33 // candidates.
34 //
35 // The vector of indices specifies the mapping from sequence frame-index to
36 // filename-index. If not specified, the image directory is probed to
37 // determine the sequence start/end frames.
39 {
40  public:
42  vul_sequence_filename_map (std::string seq_template,
43  std::vector<int> indices);
44  vul_sequence_filename_map (std::string seq_template,
45  int start, int end, int step = 1);
46  vul_sequence_filename_map (std::string seq_template,
47  int step = 1);
49 
50  //: returns frame name with no extension, e.g. "img.003", "img.003.004"
51  std::string name(int frame);
52  std::string pair_name(int i, int j);
53  std::string triplet_name(int i, int j, int k);
54 
55  std::string image_name(int frame)
56  { return image_dir_ + name(frame) + image_extension_; }
57 
58  //: returns the image directory e.g. "pgm/"
59  std::string get_image_dir() const { return image_dir_; }
60 
61  //: returns the image extension e.g. ".pgm"
62  std::string get_image_extension() const { return image_extension_; }
63 
64  //: returns the base name e.h. "img."
65  std::string get_base_name() const { return basename_; }
66 
67  //: returns the actually on-disk index corresponding to frame N
68  int get_real_index(int frame) const { return indices_[frame]; }
69  std::vector<int> const& get_real_indices() const { return indices_; }
70 
71  //: returns the frame number corresp. to on-disk index N, or -1 if out-of-range
72  int get_mapped_index(int real) const;
73 
74  int get_nviews() const { return int(indices_.size()); }
75 
76 
77  //: pretty print
78  std::ostream& print(std::ostream& s) const;
79 
80  protected:
81  bool filter_dirent(char const* name, std::string const& extension);
82  int extract_index(char const* name);
83 
84  std::string seq_template_;
85  std::vector<int> indices_;
86  std::string basename_;
87  std::string index_format_;
88  std::string image_dir_;
89  std::string image_extension_;
90  int start_;
91  int step_;
92  int end_;
93 
94  void parse();
95 };
96 
97 std::ostream& operator<<(std::ostream &os, const vul_sequence_filename_map& s);
98 
99 #endif // vul_sequence_filename_map_h_
std::ostream & print(std::ostream &s) const
pretty print.
std::string get_base_name() const
returns the base name e.h. "img.".
int get_real_index(int frame) const
returns the actually on-disk index corresponding to frame N.
std::string get_image_extension() const
returns the image extension e.g. ".pgm".
char const * extension
std::vector< int > const & get_real_indices() const
std::string get_image_dir() const
returns the image directory e.g. "pgm/".
int get_mapped_index(int real) const
returns the frame number corresp. to on-disk index N, or -1 if out-of-range.
std::string image_name(int frame)
std::string name(int frame)
returns frame name with no extension, e.g. "img.003", "img.003.004".
std::string triplet_name(int i, int j, int k)
bool filter_dirent(char const *name, std::string const &extension)
Maps sequence frame indices to filenames.
std::string pair_name(int i, int j)
std::ostream & operator<<(std::ostream &os, const vul_sequence_filename_map &s)