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

RgbDataSrcFactory.h

Go to the documentation of this file.
00001 #ifndef Impala_Core_Stream_RgbDataSrcFactory_h
00002 #define Impala_Core_Stream_RgbDataSrcFactory_h
00003 
00004 #include "Persistency/ImageArchiveRepository.h"
00005 #include "Persistency/RgbDataSrcLocator.h"
00006 #include "Basis/FileName.h"
00007 #include "Util/Database.h"
00008 #include "Core/Stream/RgbDataSrc.h"
00009 #include "Core/Stream/RgbDataSrcWindow.h"
00010 
00011 #ifdef DX_USED
00012 #include "Core/Stream/RgbDataSrcDX.h"
00013 #include "Core/Stream/RgbDataSrcAVI.h"
00014 #include "Core/Stream/RgbDataSrcCam.h"
00015 #endif
00016 
00017 //#include "Core/Stream/RgbDataSrcBmp.h"
00018 //#include "Core/Stream/RgbDataSrcJpg.h"
00019 //#include "Core/Stream/RgbDataSrcPng.h"
00020 
00021 #ifdef MPEG2_USED
00022 #include "Core/Stream/RgbDataSrcMpeg2.h"
00023 #endif
00024 
00025 //#include "Core/Stream/RgbDataSrcAloi.h"
00026 //#include "Core/Stream/RgbDataSrcPngList.h"
00027 
00028 #ifdef AVC_USED
00029 #include "Core/Stream/RgbDataSrcLavc.h"
00030 #endif
00031 #include "Core/Stream/RgbDataSrcInfo.h"
00032 #include "Core/Stream/RgbDataSrcRaw.h"
00033 
00034 namespace Impala
00035 {
00036 namespace Core
00037 {
00038 namespace Stream
00039 {
00040 
00041 
00042 class RgbDataSrcFactory
00043 {
00044 public:
00045     typedef Persistency::RgbDataSrcLocator RgbDataSrcLocator;
00046 
00047     static const int SRC_DX            = 1;
00048     static const int SRC_AVI           = 2;
00049     static const int SRC_CAM           = 3;
00050 
00051     //static const int SRC_BMP         = 4;
00052     //static const int SRC_JPG         = 5;
00053     //static const int SRC_PNG         = 6;
00054 
00055     static const int SRC_MPEG2         = 7;
00056     static const int SRC_MPEG2ES       = 8;
00057 
00058     //static const int SRC_ALOI        = 9;
00059     //static const int SRC_PNGLIST     = 10;
00060 
00061     static const int SRC_LAVC          = 11;
00062     static const int SRC_LAVC_NOCHECK  = 12;
00063     static const int SRC_LAVC_SCANONLY = 13;
00064     static const int SRC_LAVC_READIDX  = 14;
00065     static const int SRC_LAVC_WITHIDX  = 15;
00066     static const int SRC_LAVC_WRITEIDX = 16;
00067     static const int SRC_LAVC_ADHOCIDX = 17;
00068 
00069     static const int SRC_INFO          = 18;
00070     static const int SRC_INDEX         = 19;
00071     static const int SRC_RAW           = 20;
00072     
00073 
00074     static RgbDataSrcFactory&
00075     Instance()
00076     {
00077         static RgbDataSrcFactory theFactory;
00078         return theFactory;
00079     }
00080 
00081 #ifndef REPOSITORY_USED // Here comes the deprecated stuff
00082     RgbDataSrc*
00083     Construct(CString srcName, CString option,
00084               Util::Database* db = &Util::Database::GetInstance())
00085     {
00086 #else // REPOSITORY_USED
00087     RgbDataSrc*
00088     Construct(const RgbDataSrcLocator& loc, CString option)
00089     {
00090         String srcName = loc.GetName();
00091 #endif // REPOSITORY_USED
00092         int src = SuggestSrc(srcName);
00093         if (!option.empty())
00094         {
00095             if (option == "dx")
00096                 src = SRC_DX;
00097             else if (option == "avi")
00098                 src = SRC_AVI;
00099             else if (option == "mpeg2")
00100                 src = SRC_MPEG2;
00101             else if (option == "mpeg2es")
00102                 src = SRC_MPEG2ES;
00103 
00104             else if (option == "lavc")
00105                 src = SRC_LAVC; // use default setting 
00106             else if (option == "lavcnoidx") // deprecated
00107             {
00108                 ILOG_WARN("Value 'lavcnoidx' for option --src is deprecated;" <<
00109                     " you should choose from 'lavcnocheck' and 'lavcscanonly';" <<
00110                     " 'lavcnoidx' is handled as 'lavcnocheck'");
00111                 src = SRC_LAVC_NOCHECK;
00112             }
00113             else if (option == "lavcnocheck")
00114                 src = SRC_LAVC_NOCHECK;
00115             else if (option == "lavcscanonly")
00116                 src = SRC_LAVC_SCANONLY;
00117             else if (option == "lavcreadidx")
00118                 src = SRC_LAVC_READIDX;
00119             else if (option == "lavcwithidx")
00120                 src = SRC_LAVC_WITHIDX;
00121             else if (option == "lavcwriteidx")
00122                 src = SRC_LAVC_WRITEIDX;
00123             else if (option == "lavcadhocidx")
00124                 src = SRC_LAVC_ADHOCIDX;
00125 
00126             else if (option == "info")
00127                 src = SRC_INFO;
00128             else if (option == "index")
00129                 src = SRC_INDEX;
00130             else if (option == "raw")
00131                 src = SRC_RAW;
00132 
00133             else
00134             {
00135                 ILOG_ERROR("Unknown option value: --src " << option);
00136                 return 0;
00137             }
00138         }
00139 #ifndef REPOSITORY_USED // Here comes the deprecated stuff
00140         return Construct(src, srcName, db);
00141 #else // REPOSITORY_USED
00142         return Construct(src, loc);
00143 #endif // REPOSITORY_USED
00144     }
00145 
00146     int
00147     SuggestSrc(CString srcName)
00148     {
00149         int src = SRC_AVI;
00150         if (srcName.compare(0, 6, "camera") == 0)
00151             src = SRC_CAM;
00152         String ext = FileNameExt(srcName, true);
00153 
00154 #ifdef MPEG2_USED
00155         if (ext == "mpg")
00156             src = SRC_MPEG2;
00157         if (ext == "mpeg")
00158             src = SRC_MPEG2;
00159 #endif
00160 
00161 #ifdef DX_USED
00162         if (ext == "mpg")
00163             src = SRC_DX;
00164         if (ext == "mpeg")
00165             src = SRC_DX;
00166 #endif
00167 
00168 #ifdef AVC_USED
00169         if (ext == "mpg")
00170             src = SRC_LAVC;
00171         if (ext == "mpeg")
00172             src = SRC_LAVC;
00173         if (ext == "asf")
00174             src = SRC_LAVC;
00175 #endif
00176 
00177         if (ext == "info")
00178             src = SRC_INFO;
00179         if (ext == "raw")
00180             src = SRC_RAW;
00181 
00182         //if (ext == "bmp")
00183         //    src = SRC_BMP;
00184         //if (ext == "jpg")
00185         //    src = SRC_JPG;
00186         //if (ext == "png")
00187         //    src = SRC_PNG;
00188         //if (ext == "pnglist")
00189         //    src = SRC_PNGLIST;
00190 
00191 #ifdef unix
00192 #ifdef MPEG2_USED
00193         src = SRC_MPEG2;
00194 #endif
00195 #ifdef AVC_USED
00196         src = SRC_LAVC;
00197 #endif
00198 #endif
00199         return src;
00200     }
00201 
00202 #ifndef REPOSITORY_USED // Here comes the deprecated stuff
00203     RgbDataSrc*
00204     Construct(int src, CString srcName, Util::Database* db = 0)
00205     {
00206 #else // REPOSITORY_USED
00207     RgbDataSrc*
00208     Construct(int src, const RgbDataSrcLocator& loc)
00209     {
00210         String srcName = loc.GetName();
00211 #endif // REPOSITORY_USED
00212         ILOG_INFO("Construct: srcName=" << srcName);
00213 #ifdef DX_USED
00214         if (src == SRC_DX)
00215             return new RgbDataSrcDX(src, srcName);
00216         if (src == SRC_AVI)
00217             return new RgbDataSrcAVI(src, srcName);
00218         if (src == SRC_CAM)
00219             return new RgbDataSrcCam(src, srcName);
00220 #endif
00221 
00222         //if (src == SRC_BMP)
00223         //    return new RgbDataSrcBmp(src, srcName);
00224         //if (src == SRC_JPG)
00225         //    return new RgbDataSrcJpg(src, srcName);
00226         //if (src == SRC_PNG)
00227         //    return new RgbDataSrcPng(src, srcName);
00228 
00229 #ifdef MPEG2_USED
00230         if (src == SRC_MPEG2)
00231             return new RgbDataSrcMpeg2(src, srcName);
00232         if (src == SRC_MPEG2ES)
00233             return new RgbDataSrcMpeg2(src, srcName, true);
00234 #endif
00235 
00236         //if (src == SRC_ALOI)
00237         //    return new RgbDataSrcAloi(src, srcName);
00238         //if (src == SRC_PNGLIST)
00239         //    return new RgbDataSrcPngList(src, srcName);
00240 
00241 #ifdef AVC_USED
00242 #ifndef REPOSITORY_USED // Here comes the deprecated stuff
00243         if (src == SRC_LAVC) 
00244             return new RgbDataSrcLavc(src, srcName, db, READIDX); // default 
00245 
00246         if (src == SRC_LAVC_NOCHECK)
00247             return new RgbDataSrcLavc(src, srcName, db, NOCHECK);
00248 
00249         if (src == SRC_LAVC_SCANONLY)
00250             return new RgbDataSrcLavc(src, srcName, db, SCANONLY);
00251 
00252         if (src == SRC_LAVC_READIDX)
00253             return new RgbDataSrcLavc(src, srcName, db, READIDX);
00254 
00255         if (src == SRC_LAVC_WITHIDX)
00256             return new RgbDataSrcLavc(src, srcName, db, WITHIDX);
00257 
00258         if (src == SRC_LAVC_WRITEIDX)
00259             return new RgbDataSrcLavc(src, srcName, db, WRITEIDX);
00260 
00261         if (src == SRC_LAVC_ADHOCIDX)
00262             return new RgbDataSrcLavc(src, srcName, db, ADHOCIDX);
00263 #else // REPOSITORY_USED
00264         if (src == SRC_LAVC) 
00265             return new RgbDataSrcLavc(src, loc, READIDX); // default 
00266 
00267         if (src == SRC_LAVC_NOCHECK)
00268             return new RgbDataSrcLavc(src, loc, NOCHECK);
00269 
00270         if (src == SRC_LAVC_SCANONLY)
00271             return new RgbDataSrcLavc(src, loc, SCANONLY);
00272 
00273         if (src == SRC_LAVC_READIDX)
00274             return new RgbDataSrcLavc(src, loc, READIDX);
00275 
00276         if (src == SRC_LAVC_WITHIDX)
00277             return new RgbDataSrcLavc(src, loc, WITHIDX);
00278 
00279         if (src == SRC_LAVC_WRITEIDX)
00280             return new RgbDataSrcLavc(src, loc, WRITEIDX);
00281 
00282         if (src == SRC_LAVC_ADHOCIDX)
00283             return new RgbDataSrcLavc(src, loc, ADHOCIDX);
00284 #endif // REPOSITORY_USED
00285 #endif
00286 
00288         //if (src == SRC_INFO)
00289         //    return new RgbDataSrcInfo(src, srcName, db);
00290         //if (src == SRC_INDEX)
00291         //    return new RgbDataSrcInfo(src, srcName, db);
00292 
00293 #ifndef REPOSITORY_USED // Here comes the deprecated stuff
00294         if (src == SRC_RAW)
00295             return new RgbDataSrcRaw(srcName);
00296 #else // REPOSITORY_USED
00297         if (src == SRC_RAW)
00298         {
00299             Persistency::ImageArchiveLocator arLoc(loc, loc.GetName());
00300             Array::ImageArchive* archive =
00301                 Persistency::ImageArchiveRepository().Get(arLoc);
00302             return new RgbDataSrcRaw(src, loc.GetName(), archive);
00303         }
00304 #endif // REPOSITORY_USED
00305 
00306         ILOG_ERROR("Construction failed");
00307         return 0;
00308     }
00309 
00310 #ifndef REPOSITORY_USED // Here comes the deprecated stuff
00311     RgbDataSrc*
00312     ConstructWindow(CString srcName, CString srcOption, CString windowOption,
00313                     Util::Database* db)
00314     {
00315         RgbDataSrc* slave = Construct(srcName, srcOption, db);
00316 #else // REPOSITORY_USED
00317     RgbDataSrc*
00318     ConstructWindow(const RgbDataSrcLocator& loc, CString srcOption,
00319                     CString windowOption)
00320     {
00321         RgbDataSrc* slave = Construct(loc, srcOption);
00322 #endif // REPOSITORY_USED
00323         if (windowOption.empty())
00324             return slave;
00325 
00326         StringList sList(windowOption, ';');
00327         if (sList.size() < 3)
00328         {
00329             ILOG_ERROR("src window needs at least 3 arguments");
00330             return slave;
00331         }
00332 
00333         StringListCI it = sList.begin();
00334         String sizeType = *it++; // should be just "size"
00335         int wSize = atol(*it++);
00336         String prepType = *it++;
00337         if (prepType == "copyreal")
00338         {
00339             WindowPrepCopyToVec3Real64* prep = new WindowPrepCopyToVec3Real64();
00340             typedef RgbDataSrcWindow<WindowPrepCopyToVec3Real64> WindowType;
00341             WindowType* win = new WindowType(slave, wSize, prep, true, true);
00342             return win;
00343         }
00344         if (prepType == "rgb2ooo")
00345         {
00346             WindowPrepRgb2Ooo* prep = new WindowPrepRgb2Ooo();
00347             typedef RgbDataSrcWindow<WindowPrepRgb2Ooo> WindowType;
00348             WindowType* win = new WindowType(slave, wSize, prep, true, true);
00349             return win;
00350         }
00351         if (prepType == "gauss")
00352         {
00353             if (sList.size() != 7)
00354             {
00355                 ILOG_ERROR("gauss prep window needs 4 arguments");
00356                 return slave;
00357             }
00358             double sigma = atof(*it++);
00359             int orderDerivx = atol(*it++);
00360             int orderDerivy = atol(*it++);
00361             double truncation = atof(*it++);
00362             WindowPrepGaussDerivative* prep =
00363                 new WindowPrepGaussDerivative(sigma, orderDerivx, orderDerivy,
00364                                               truncation);
00365             typedef RgbDataSrcWindow<WindowPrepGaussDerivative> WindowType;
00366             WindowType* win = new WindowType(slave, wSize, prep, true, true);
00367             return win;
00368         }
00369         ILOG_ERROR("Unknown window prep type " << prepType << "!");
00370         return slave;
00371     }
00372 
00373 private:
00374 
00375     RgbDataSrcFactory()
00376     {
00377     }
00378 
00379     RgbDataSrcFactory(const RgbDataSrcFactory&)
00380     {
00381     }
00382 
00383     RgbDataSrcFactory&
00384     operator=(const RgbDataSrcFactory&);
00385 
00386     ILOG_VAR_DECL;
00387 };
00388 
00389 ILOG_VAR_INIT(RgbDataSrcFactory, Impala.Core.Stream);
00390 
00391 } // namespace Stream
00392 } // namespace Core
00393 } // namespace Impala
00394 
00395 #endif

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