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

Generated on Thu Jan 13 09:04:36 2011 for ImpalaSrc by  doxygen 1.5.1