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

Archive.h

Go to the documentation of this file.
00001 #ifndef Impala_Core_ImageSet_Archive_h
00002 #define Impala_Core_ImageSet_Archive_h
00003 
00004 #include "Core/ImageSet/Reporter.h"
00005 #include "Core/ImageSet/MakeImageSet.h"
00006 #include "Core/Array/MakeFromValue.h"
00007 #include "Core/Array/ArrayListDelete.h"
00008 #include "Core/Array/WriteRaw.h"
00009 #include "Core/Array/ImageArchiveMemory.h"
00010 
00011 namespace Impala
00012 {
00013 namespace Core
00014 {
00015 namespace ImageSet
00016 {
00017 
00018 
00019 class Archive : public Listener
00020 {
00021     typedef Array::Array2dScalarUInt8 ImType;
00022 public:
00023 
00024     Archive(Reporter* reporter, CmdOptions& options)
00025     {
00026         mReporter = reporter;
00027         mReporter->SetReportArray(false); // we will cause a "memory leak"
00028         mSplit = options.GetNrArg() > 2;
00029     }
00030 
00031     virtual
00032     ~Archive()
00033     {
00034         Array::ArrayListDelete(&mImList);
00035     }
00036 
00037     virtual void
00038     HandleNewFile(ImageSet* is, int fileId, Array::Array2dVec3UInt8* im)
00039     {
00040 #ifndef REPOSITORY_USED // Here comes the deprecated stuff
00041         String fileName = is->GetFilePathImageData(fileId, false, false);
00042         Util::Database* db = is->GetDatabase();
00043         Util::IOBuffer* ioBuf = db->GetIOBuffer(fileName, true, false, "", 0,
00044                                                 true);
00045         if (!ioBuf)
00046         {
00047             ILOG_ERROR("Unable to open file " << fileName);
00048             return;
00049         }
00050 #else // REPOSITORY_USED
00051         Persistency::ImageLocator loc(is->GetLocator(),
00052                                       is->GetContainerDirOfFile(fileId), 
00053                                       is->GetFile(fileId));
00054         Util::IOBuffer* ioBuf =
00055             Persistency::ImageRepositoryInFile().GetReadBuffer(loc);
00056 #endif // REPOSITORY_USED
00057 
00058         Int64 bufSize = ioBuf->Size();
00059         ImType* bufIm = Array::ArrayCreate<ImType>(bufSize, 1);
00060         Int64 nrRead = ioBuf->Read(bufIm->CPB(), ioBuf->Size());
00061 
00062         mImList.push_back(bufIm);
00063         delete ioBuf;
00064     }
00065 
00066     virtual void
00067     HandleDoneDir(ImageSet* is, int dirId)
00068     {
00069         if (!mSplit)
00070             return;
00071 #ifndef REPOSITORY_USED // Here comes the deprecated stuff
00072         int fileId = is->GetFirstFileId(dirId);
00073         String fName = is->GetFilePathImageArchive(fileId, "images.raw", true,
00074                                                    false);
00075         Array::WriteRawListVar(mImList, fName, is->GetDatabase(), true, true);
00076 #else // REPOSITORY_USED
00077         String container = is->GetContainerDir(dirId);
00078         Persistency::ImageArchiveLocator loc(is->GetLocator(), false,
00079                                              container, "images.raw", 0);
00080         Array::ImageArchiveMemory wrapper(&mImList);
00081         Persistency::ImageArchiveRepository().Add(loc, &wrapper);
00082 #endif // REPOSITORY_USED
00083         Array::ArrayListDelete(&mImList);
00084     }
00085 
00086     virtual void
00087     HandleDoneWalk(ImageSet* is)
00088     {
00089         if (mSplit)
00090             return;
00091 
00092 #ifndef REPOSITORY_USED // Here comes the deprecated stuff
00093         String arName = is->GetSetNameBase() + ".raw";
00094         String fName = is->GetFilePathImageArchive(arName, true, false);
00095         ILOG_INFO("writing archive [" << fName << "]");
00096         Array::WriteRawListVar(mImList, fName, is->GetDatabase(), true, true);
00097 #else // REPOSITORY_USED
00098         String arName = is->GetSetNameBase() + ".raw";
00099         Persistency::ImageArchiveLocator loc(is->GetLocator(), false,
00100                                              "", arName, 0);
00101         Array::ImageArchiveMemory wrapper(&mImList);
00102         Persistency::ImageArchiveRepository().Add(loc, &wrapper);
00103 #endif // REPOSITORY_USED
00104     }
00105 
00106 private:
00107 
00108     Reporter*            mReporter;
00109     bool                 mSplit;
00110     std::vector<ImType*> mImList;
00111 
00112     ILOG_VAR_DEC;
00113 };
00114 
00115 ILOG_VAR_INIT(Archive, Core.ImageSet);
00116 
00117 } // namespace ImageSet
00118 } // namespace Core
00119 } // namespace Impala
00120 
00121 #endif

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