Home || Architecture || Video Search || Visual Search || Scripts || Applications || Important Messages || OGL || Src

ImageRepositoryInFile.h

Go to the documentation of this file.
00001 #ifndef Impala_Persistency_ImageRepositoryInFile_h
00002 #define Impala_Persistency_ImageRepositoryInFile_h
00003 
00004 #include "Persistency/RepositoryInFileSystem.h"
00005 #include "Core/Array/Arrays.h"
00006 #include "Persistency/ImageLocator.h"
00007 #include "Core/Array/ReadFile.h"
00008 #include "Core/Array/WriteFile.h"
00009 
00010 namespace Impala
00011 {
00012 namespace Persistency
00013 {
00014 
00015 
00016 class ImageRepositoryInFile
00017 {
00018 public:
00019 
00020     typedef Core::Array::Array2dVec3UInt8 Array2dVec3UInt8;
00021 
00022     ImageRepositoryInFile()
00023     {
00024     }
00025 
00026     Array2dVec3UInt8*
00027     Get(const ImageLocator& loc)
00028     {
00029         String dir = GetDir(loc);
00030         File file = RepFS().GetFile(loc, dir, loc.GetName(), false, false);
00031         if (!file.Valid())
00032             return 0;
00033 
00034         Array2dVec3UInt8* res = 0;
00035         Core::Array::ReadFile(res, file);
00036         return res;
00037     }
00038 
00039     // Special case for jpg content of images
00040     Util::IOBuffer*
00041     GetReadBuffer(const ImageLocator& loc)
00042     {
00043         String dir = GetDir(loc);
00044         File file = RepFS().GetFile(loc, dir, loc.GetName(), false, false);
00045         if (!file.Valid())
00046             return 0;
00047 
00048         return file.GetReadBuffer();
00049     }
00050 
00051     void
00052     Add(const ImageLocator& loc, Array2dVec3UInt8* image)
00053     {
00054         String dir = GetDir(loc);
00055         File file = RepFS().GetFile(loc, dir, loc.GetName(), true, false);
00056         Core::Array::WriteFile(image, file);
00057     }
00058 
00059 private:
00060 
00061     RepositoryInFileSystem&
00062     RepFS()
00063     {
00064         return RepositoryInFileSystem::GetInstance();
00065     }
00066 
00067     String
00068     GetDir(const ImageLocator& loc)
00069     {
00070         String dir = "";
00071         if (FileNameExt(loc.GetDataSet()) == "txt")
00072             dir = "ImageData";
00073         dir = FileNameConcat(dir, loc.GetContainer());
00074         return dir;
00075     }
00076 
00077     ILOG_VAR_DEC;
00078 };
00079 
00080 ILOG_VAR_INIT(ImageRepositoryInFile, Impala.Persistency);
00081 
00082 } // namespace Persistency
00083 } // namespace Impala
00084 
00085 #endif

Generated on Fri Mar 19 09:31:43 2010 for ImpalaSrc by  doxygen 1.5.1