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

mainVideoExcel.cpp

Go to the documentation of this file.
00001 //345678901234567890123456789012345678901234567890123456789012345678901234567890
00002 #include "OglGui/OglLib.cpp"
00003 
00004 #include "Basis/CmdOptions.h"
00005 
00006 #include "GridWindow.h"
00007 #include "SelectionCollection.h"
00008 #include "ImageCache.h"
00009 #include "TableWindow.h"
00010 #include "TableControlBarWindow.h"
00011 #include "TableOverviewWindow.h"
00012 #include "TableDataSource.h"
00013 #include "TableDataSourceImageDir.h"
00014 
00015 //#define VE_USING_SQLITE
00016 #ifdef VE_USING_SQLITE
00017 #include "TableDataSourceSqliteDb.h"
00018 #endif
00019 
00020 #define VE_USING_TREC
00021 #ifdef VE_USING_TREC
00022 #include "TableDataSourceTrec.h"
00023 #endif
00024 
00025 namespace Impala {
00026 namespace Application {
00027 namespace VideoExcel {
00028 
00029 //using namespace OglGui; 
00030 
00031 class VideoExcel: public OglGui::Window
00032 {
00033     typedef OglGui::Window                      Window;
00034 
00035 public:
00036     VideoExcel(int w, int h) : Window(0, 0, w, h)
00037     {
00038         Impala::CmdOptions& options = Impala::CmdOptions::GetInstance();
00039 
00040         ILOG_STARTACTION("building GUI", ILOG_LEVEL_INFO);
00041         Init(w,h);
00042         ILOG_ENDACTION("building GUI");  
00043 
00044         GetOGLWND()->topTitle = "VideoExcel";
00045     }
00046 
00047     void Go()
00048     {
00049         Start();
00050         OglEventLoop();
00051     }
00052 
00053     virtual void KeyboardFunc(int c, int state)
00054     {
00055         if (mTable->GetVisible())
00056             mTable->KeyboardFunc(c, state);
00057         if (mGrid->GetVisible())
00058             mGrid->KeyboardFunc(c, state);
00059         Window::KeyboardFunc(c, state);
00060     }
00061 
00062     void Init(int w, int h)
00063     {
00064         /* quick parsing of options, to be redone later */
00065         Impala::CmdOptions& options = Impala::CmdOptions::GetInstance();
00066 
00067         //ULONG bgCol  = 0xffd2c799;
00068         ULONG bgCol  = oglGUI_BG;
00069         String bgStr = options.GetString("wndBg");
00070         if (!bgStr.empty())
00071             bgCol = OglColorStr(bgStr.c_str());
00072         SetBackground(bgCol);
00073 
00074         TableDataSource *src = 0;
00075 
00076 #ifdef VE_USING_SQLITE
00077         if (options.GetString("database") != "")
00078             src = new TableDataSourceSqliteDb(options.GetString("database"));
00079 #endif
00080         if (options.GetString("directory") != "")
00081             src = new TableDataSourceImageDir(options.GetString("directory"));
00082 #ifdef VE_USING_TREC
00083         if (options.GetBool("trec"))
00084             src = new TableDataSourceTrec();
00085 #endif
00086         if (!src)
00087         {
00088             ILOG_ERROR("Please start with either -a <db>, -d <directory> " <<
00089                        "or --trec --ini <inifile>");
00090             return;
00091         }
00092 
00093         int csize = options.GetInt("imageCacheSize");
00094         if (csize < 100) csize = 100;
00095         ImageCache::InitializeCache(src, csize);
00096 
00097         if (options.GetBool("preload"))
00098         {
00099             ILOG_INFO("Pre-filling cache with content...");
00100             ImageCache::GetInstance()->PreloadCache();
00101         }
00102 
00103         int btnH = 32;
00104         int botH = 140;
00105         int centerH = h - 10 - btnH - botH;
00106 
00107         GridWindow *grid = new GridWindow(this,src,5,5+botH,w-160,centerH);
00108         grid->ConnectTo(this);
00109 
00110         TableWindow *table = new TableWindow(this,src,5,5+botH,w-160,centerH);
00111         table->ConnectTo(this);
00112 
00113         TableOverviewWindow *overview =
00114             new TableOverviewWindow(this,src,w-155,5+botH,150,centerH);
00115         //overview->ConnectTo(this, L2R|R2R|T2T|B2B);
00116         overview->ConnectTo(this, OglGui::TORIGHT|OglGui::TOTOPBOTTOM);
00117 
00118         TableControlBarWindow *buttonbar =
00119             new TableControlBarWindow(this,table,grid,5,h-btnH-5,w-10,btnH);
00120         //buttonbar->ConnectTo(this, L2L|R2R|T2T|B2T);
00121         buttonbar->ConnectTo(this, OglGui::TOLEFTRIGHT | OglGui::TOTOP);
00122 
00123         SelectionCollection *selcol =
00124             new SelectionCollection(this,src,5,5,w-10,botH);
00125         //selcol->ConnectTo(this, L2L|R2R|T2B|B2B);
00126         selcol->ConnectTo(this, OglGui::TOLEFTRIGHT | OglGui::TOBOTTOM);
00127 
00128         // overlay window to show preview of table on top of everything else..
00129         // there must be a better way to do this though :)
00130         Window *overlay = new Window(this, 0, 0, w, h);
00131         overlay->ConnectTo(this);
00132         oglSys.SetNoMouseInput(overlay->GetOGLWND(),1);
00133 
00134         grid->SetListenTableUpdates(false);
00135         table->SetListenTableUpdates(true);
00136         overview->SetListenTableUpdates(true);
00137 
00138         // add default data columns for specified data source:
00139         table->AddColumnsFromDataSource();
00140         grid->AddColumnsFromDataSource();
00141 
00142         // for which column/cache should the table display larger images
00143         // OBS: (need to set here because there can be more than one images row)
00144         table->SetZoomViewTargetWindow(overlay, true);
00145         grid->SetZoomViewTargetWindow(overlay, true);
00146 
00147         table->SetVisible(true);
00148         grid->SetVisible(false);
00149 
00150 
00151         mTable = table;
00152         mGrid = grid;
00153 
00154 /*      Example of manually marking ranges:
00155         src->MarkRange(10, 20, 2);
00156         src->MarkRange(15, 25, 4);
00157         src->MarkRange(19, 28, 8);
00158 */
00159 
00160 /*
00161         Example of manually adding data columns:
00162 
00163         table->AddColumn(new TableColumn(table, src, "id", 40));
00164         TableColumn *p = new TableColumn(table, src, "picture", 100);
00165         p->SetDisplayMode(TableCell::DISPLAY_IMAGE);
00166         table->AddColumn(p);
00167 
00168         table->AddColumn(new TableColumn(table, src, "filename", 300));
00169         table->AddColumn(new TableColumn(table, src, "width", 80));
00170         table->AddColumn(new TableColumn(table, src, "height", 80));
00171 
00172         TableColumn *c = new TableColumn(table, src, "red", 20);
00173         c->SetDisplayMode(TableCell::DISPLAY_DOT, TableCell::GRADIENT_REDFADE);
00174         table->AddColumn(c);
00175 
00176         c = new TableColumn(table, src, "green", 20);
00177         c->SetDisplayMode(TableCell::DISPLAY_DOT,TableCell::GRADIENT_GREENFADE);
00178         table->AddColumn(c);
00179 
00180         c = new TableColumn(table, src, "blue", 20);
00181         c->SetDisplayMode(TableCell::DISPLAY_DOT, TableCell::GRADIENT_BLUEFADE);
00182         table->AddColumn(c);
00183 */
00184     }
00185 
00186 private:
00187 
00188     TableWindow *mTable;
00189     GridWindow *mGrid;
00190 
00191     ILOG_VAR_DEC;
00192 };
00193 
00194 int mainVideoExcel(int argc, char* argv[])
00195 {
00196     OglInit(&argc, &argv[0]);
00197 
00198     // configuration:
00199     Impala::CmdOptions& options = Impala::CmdOptions::GetInstance();
00200     options.Initialise(true, false, true);
00201     options.SetDefault("wndWidth", "1270");
00202     options.SetDefault("wndHeight", "975");
00203     options.AddOption(0, "imageCacheSize", "size of image cache", "800");
00204     options.AddOption('a',"database", "database file to use","");
00205     options.AddOption('d',"directory", "directory of images to use","");
00206     options.AddOption(0, "trec", "", "0");
00207     options.AddOption(0, "preload","", "0");
00208 
00209     if (! options.ParseArgs(argc, argv, "", 0))
00210         return 1;
00211 
00212     ILOG_VAR(VideoExcel.mainVideoExcel);
00213 
00214     ILOG_SYSTEM("LOADING......");
00215     int w = options.GetInt("wndWidth");
00216     int h = options.GetInt("wndHeight");
00217 
00218 
00219     Impala::Application::VideoExcel::VideoExcel *d =
00220         new Impala::Application::VideoExcel::VideoExcel(w,h);
00221     ILOG_SYSTEM("STARTING -----------------------------");
00222     d->Go();
00223     return 0;
00224 }
00225 
00226 ILOG_VAR_INIT(VideoExcel, VideoExcel);
00227 
00228 } // namespace VideoExcel
00229 } // namespace Application
00230 } // namespace Impala
00231 
00232 int main(int argc, char* argv[])
00233 {
00234     return Impala::Application::VideoExcel::mainVideoExcel(argc, argv);
00235 }
00236 

Generated on Fri Mar 19 09:30:40 2010 for ImpalaSrc by  doxygen 1.5.1