//=============================== // // Implementation for image reader class // #include #include #include "Image.h" #include "ImageReader.h" // ------------------------------------ // Method to read a set of images from a set of files std::vector ImageReader::readImages( std::vector files ) { std::vector images; for( int ind=0; ind < files.size() ; ++ind ) { Image* newImage = this->readAnImage( files[ind] ) ; images.push_back( newImage ) ; } return images ; } //------------------------------------- // Method to read a single image from a single file Image* ImageReader::readAnImage( std::string file ) { // Open file std::ifstream ifile( file.c_str() ) ; if( ! ifile ) { std::cout << " Error - cannot read file specified "+file << std::endl; return NULL ; } // Read first number which is the date int date ; ifile >> date ; // Read second number which is the number of pixels int noPixels ; ifile >> noPixels ; // Read rest of file std::vector pixels ; int pixel ; for( int ind=0; ind < noPixels ; ++ind ) { ifile >> pixel ; pixels.push_back( pixel ); } Image* i = new Image( date, pixels ) ; return i ; }