00001 #ifndef Impala_Persistency_ImageArchiveRepositoryInFile_h
00002 #define Impala_Persistency_ImageArchiveRepositoryInFile_h
00003
00004 #include "Persistency/RepositoryInFileSystem.h"
00005 #include "Core/Array/ImageArchiveFile.h"
00006 #include "Core/Array/ImageArchiveFileFset.h"
00007 #include "Persistency/ImageArchiveLocator.h"
00008 #include "Core/Array/ArrayListDelete.h"
00009
00010 namespace Impala
00011 {
00012 namespace Persistency
00013 {
00014
00015
00016 class ImageArchiveRepositoryInFile
00017 {
00018 public:
00019
00020 typedef Core::Array::ImageArchive ImageArchive;
00021 typedef Core::Array::Array2dScalarUInt8 Array2dScalarUInt8;
00022
00023 ImageArchiveRepositoryInFile()
00024 {
00025 }
00026
00027 ImageArchive*
00028 Get(const ImageArchiveLocator& 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 ImageArchive* res = 0;
00036 if (loc.GetIsFset())
00037 res = new Core::Array::ImageArchiveFileFset(file);
00038 else
00039 res = new Core::Array::ImageArchiveFile(file);
00040 return res;
00041 }
00042
00043 void
00044 Add(const ImageArchiveLocator& loc, ImageArchive* archive)
00045 {
00046 std::vector<Array2dScalarUInt8*> images;
00047 if (archive->GetImageDataList() != 0)
00048 {
00049 images = *(archive->GetImageDataList());
00050 }
00051 else
00052 {
00053 for (int i=0 ; i<archive->NrImages() ; i++)
00054 {
00055 size_t blockSize = 0;
00056 UInt8* data = archive->GetImageData(i, blockSize);
00057 Array2dScalarUInt8* im = new Array2dScalarUInt8(blockSize, 1, 0,
00058 0, data, false);
00059 images.push_back(im);
00060 }
00061 }
00062
00063 String dir = GetDir(loc);
00064 File file = RepFS().GetFile(loc, dir, loc.GetName(), true, false);
00065 WriteRawListVar(images, file, true, true);
00066 if (archive->GetImageDataList() == 0)
00067 Core::Array::ArrayListDelete(&images);
00068 }
00069
00070 private:
00071
00072 RepositoryInFileSystem&
00073 RepFS()
00074 {
00075 return RepositoryInFileSystem::GetInstance();
00076 }
00077
00078 String
00079 GetDir(const ImageArchiveLocator& loc)
00080 {
00081 String dir = loc.GetFramesString();
00082 dir = FileNameConcat(dir, loc.GetContainer());
00083 return dir;
00084 }
00085
00086 ILOG_VAR_DEC;
00087 };
00088
00089 ILOG_VAR_INIT(ImageArchiveRepositoryInFile, Impala.Persistency);
00090
00091 }
00092 }
00093
00094 #endif