image_loader.h

Go to the documentation of this file.
00001 #ifndef MMVL_IMAGE_LOADER_HH_INCLUDED
00002 #define MMVL_IMAGE_LOADER_HH_INCLUDED
00003 
00004 #include <string>
00005 #include <iostream>
00006 #include <iomanip>
00007 #include <sstream>
00008 #include <fstream>
00009 #include <image.h>
00010 #include <image_fileinput.h>
00011 #include "mimasexception.h"
00012 
00013 namespace mimas{
00014   namespace hf{
00023     template<typename T>
00024     class image_loader{
00025     public:
00026       image<T> &image_IL;
00027       
00030       class set{
00031       public:
00032   std::string basename;
00033   int nb_images; 
00034   
00035   int image_nb;
00036   std::string extension;
00037   int size;
00038   int first_image_number;
00039   
00040   set(std::string basename, int size = 4, std::string extension = ".pgm",
00041       int first_image_number = 0, int nb_images = 0)
00042     :basename(basename), nb_images(nb_images), extension(extension),
00043      size(size),first_image_number(first_image_number){} 
00044       };
00045       
00046       //carefull, if it is not used as a policy you need to load the first image by
00047       //a call to next() which is not very satisfying in the sense that when
00048       //the class is instanciated it is not directly usable.
00049       image_loader(image<T> &image, set param)
00050         :image_IL(image), basename(param.basename), nb_images(param.nb_images),
00051   image_nb(param.first_image_number),extension(param.extension),size(param.size)
00052       {
00053   next(); //load the first image so the object is ready to use 
00054       }
00055 
00056       //"Normal" constructor
00057       image_loader(image<T> &image, std::string basename, int size, std::string extension, int first_image_number = 0, int nb_images = 0)
00058         :image_IL(image), basename(basename), nb_images(nb_images),
00059   image_nb(first_image_number),extension(extension),size(size)
00060       {
00061   next(); //load the first image so the object is ready to use 
00062       }
00063 
00064 
00065       //debug code
00066       std::string fileName(void)
00067       {
00068   std::ostringstream str;
00069   str << basename << std::setw( size ) << std::setfill( '0' ) <<  image_nb
00070       << extension;
00071 #ifndef NDEBUG
00072   std::cerr<< "File name is: " << str.str() <<std::endl; 
00073 #endif
00074   return str.str();
00075       }
00076 
00079       void next(void) throw(mimasexception)
00080       {
00081   //put an ending condition
00082   //if nb_images equal 0 we do not consider their is a maximal number of images.
00083   //An exception will be raised when the filename does not correspond to any file
00084   if(image_nb < nb_images || nb_images == 0)
00085     {
00086       std::ifstream cimage_file(fileName().c_str(), std::ios::binary );
00087       if (cimage_file.fail())
00088         MMERROR(false , mimasexception, ,
00089           "failed to open file");  
00090       cimage_file >> image_IL;
00091       image_nb++;
00092       return;
00093     }
00094   else
00095     MMERROR(false , mimasexception, ,
00096        "max number of image to read reached");
00097       }
00098 
00099     private:
00100 
00101       std::string basename;
00102       int nb_images; 
00103 
00104       int image_nb;
00105       std::string extension;
00106       int size;
00107     };
00108 
00109   }
00110 }
00111 
00112 #endif

[GNU/Linux] [Qt] [Mesa] [STL] [Lapack] [Boost] [Magick++] [Xalan-C and Xerces-C] [doxygen] [graphviz] [FFTW] [popt] [xine] [Gnuplot] [gnu-arch] [gcc] [gstreamer] [autoconf/automake/make] [freshmeat.net] [opensource.org] [sourceforge.net] [MMVL]
mimas 2.1 - Copyright Mon Oct 30 11:31:17 2006, Bala Amavasai, Stuart Meikle, Arul Selvan, Fabio Caparrelli, Jan Wedekind, Manuel Boissenin, ...