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 typedef Core::Array::Array2dScalarUInt8 Array2dScalarUInt8;
00022
00023 ImageRepositoryInFile()
00024 {
00025 }
00026
00027 Array2dVec3UInt8*
00028 Get(const ImageLocator& loc)
00029 {
00030 String dir = GetDir(loc);
00031 File file = RepFS().GetFile(loc, dir, loc.GetName(), false, false);
00032 if (!file.Valid())
00033 return 0;
00034
00035 Array2dVec3UInt8* res = 0;
00036 Core::Array::ReadFile(res, file);
00037 return res;
00038 }
00039
00040 Array2dScalarUInt8*
00041 GetImageData(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 Util::IOBuffer* ioBuf = file.GetReadBuffer();
00049 Int64 bufSize = ioBuf->Size();
00050 Array2dScalarUInt8* bufIm =
00051 Core::Array::ArrayCreate<Array2dScalarUInt8>(bufSize, 1);
00052 Int64 nrRead = ioBuf->Read(bufIm->CPB(), bufSize);
00053 if (nrRead != bufSize)
00054 ILOG_ERROR("[GetImageData] Read failed");
00055 delete ioBuf;
00056 return bufIm;
00057 }
00058
00059 void
00060 Add(const ImageLocator& loc, Array2dVec3UInt8* image)
00061 {
00062 String dir = GetDir(loc);
00063 File file = RepFS().GetFile(loc, dir, loc.GetName(), true, false);
00064 Core::Array::WriteFile(image, file);
00065 }
00066
00067 private:
00068
00069 RepositoryInFileSystem&
00070 RepFS()
00071 {
00072 return RepositoryInFileSystem::GetInstance();
00073 }
00074
00075 String
00076 GetDir(const ImageLocator& loc)
00077 {
00078 String dir = "";
00079 if (FileNameExt(loc.GetDataSet()) == "txt")
00080 dir = "ImageData";
00081 dir = FileNameConcat(dir, loc.GetContainer());
00082 return dir;
00083 }
00084
00085 ILOG_VAR_DEC;
00086 };
00087
00088 ILOG_VAR_INIT(ImageRepositoryInFile, Impala.Persistency);
00089
00090 }
00091 }
00092
00093 #endif