00001 #ifdef VCL_NEEDS_PRAGMA_INTERFACE 00002 #pragma implementation 00003 #endif 00004 //: 00005 // \file 00006 // \brief A base class for cameras/virtual cameras 00007 // \author Louise Butcher 00008 00009 #include "mvl2_video_reader.h" 00010 #include <vcl_cstdlib.h> // for vcl_getenv() 00011 #include <vcl_algorithm.h> // for vcl_find() 00012 #include <vcl_fstream.h> 00013 00014 mvl2_video_reader::mvl2_video_reader() 00015 { 00016 } 00017 00018 mvl2_video_reader::~mvl2_video_reader() 00019 { 00020 if (is_initialized()) uninitialize(); 00021 } 00022 00023 vcl_string mvl2_video_reader::is_a() const 00024 { 00025 return vcl_string("mvl2_video_reader"); 00026 } 00027 00028 vcl_vector<vcl_string> mvl2_video_reader::load_configs(vcl_string filename) 00029 { 00030 config_names_.clear(); 00031 config_sizes_.clear(); 00032 config_strings_.clear(); 00033 config_filenames_.clear(); 00034 00035 vcl_string config_name("Default"); 00036 vcl_pair<int,int> config_size(320,240); 00037 vcl_string config_string(""); 00038 vcl_string config_filename(""); 00039 00040 config_names_.push_back(config_name); 00041 config_sizes_.push_back(config_size); 00042 config_strings_.push_back(config_string); 00043 config_filenames_.push_back(config_filename); 00044 00045 vcl_ifstream* config_file=new vcl_ifstream(filename.c_str()); 00046 if (!(*config_file)) 00047 { 00048 const char* val; 00049 if ((val=vcl_getenv("VIDL2RC"))==0) 00050 { 00051 vcl_cerr << "VIDL2RC environment variable not defined.\n" 00052 << "Cannot find configuration file for video input.\n"; 00053 return config_names_; 00054 } 00055 config_file=new vcl_ifstream(val); 00056 if (!(*config_file)) 00057 { 00058 vcl_cerr << "Cannot find configuration file for video input.\n"; 00059 return config_names_; 00060 } 00061 } 00062 00063 while (!config_file->eof()) 00064 { 00065 config_name=vcl_string(""); 00066 00067 *config_file >> config_name >> config_size.first >> config_size.second; 00068 *config_file >> config_string >> config_filename; 00069 00070 if (config_name!=vcl_string("")) 00071 { 00072 config_names_.push_back(config_name); 00073 config_sizes_.push_back(config_size); 00074 config_strings_.push_back(config_string); 00075 config_filenames_.push_back(config_filename); 00076 } 00077 } 00078 00079 return config_names_; 00080 } 00081 00082 void mvl2_video_reader::display_configs() 00083 { 00084 vcl_cout << vcl_endl 00085 << "Video configurations :\n" 00086 << "======================\n"; 00087 for (unsigned int i=0; i<config_names_.size(); ++i) 00088 { 00089 vcl_cout << "Configuration " << i<< vcl_endl 00090 << "----------------\n" 00091 << "name = " << config_names_[i] << vcl_endl 00092 << "size = " << config_sizes_[i].first << 'x' 00093 << config_sizes_[i].second << vcl_endl 00094 << "options = " << config_strings_[i] << vcl_endl 00095 << "filename = " << config_filenames_[i] << vcl_endl 00096 << vcl_endl; 00097 } 00098 } 00099 00100 bool mvl2_video_reader::use_config(vcl_string configname) 00101 { 00102 vcl_size_t position=vcl_find(config_names_.begin(), config_names_.end(), configname) - config_names_.begin(); 00103 if (position<config_names_.size()) 00104 { 00105 return initialize(config_sizes_[position].first, 00106 config_sizes_[position].second, 00107 config_strings_[position],config_filenames_[position]); 00108 } 00109 else 00110 return false; 00111 } 00112 00113 int mvl2_video_reader::length() 00114 { 00115 return -1; 00116 }