00001
00002 #ifndef MediaTable_h
00003 #define MediaTable_h
00004
00005 typedef unsigned int uint;
00006
00007 #define MEDIATABLE_USING_IMAGEDIR
00008 #define MEDIATABLE_USING_CSV
00009 #define MEDIATABLE_USING_COMBINEDVIEWS
00010
00011 #define USE_CURL
00012
00013 #define USE_BOOST_THREADPOOL
00014
00015
00016
00017
00018
00019 #ifdef MEDIATABLE_BASIC
00020 #define MEDIATABLE_USING_CSV
00021 #undef MEDIATABLE_USING_IMAGEDIR
00022 #undef MEDIATABLE_USING_COMBINEDVIEWS
00023 #undef MEDIATABLE_USING_FLICKR
00024 #endif
00025
00026 #ifdef MEDIATABLE_VIDEOLYMPICS
00027 #undef MEDIATABLE_USING_CSV
00028 #undef MEDIATABLE_USING_IMAGEDIR
00029 #undef MEDIATABLE_USING_COMBINEDVIEWS
00030 #undef MEDIATABLE_USING_FLICKR
00031 #define MEDIATABLE_USING_TREC
00032 #undef USE_CURL
00033 #define BOOST_THREADPOOL_SIZE 1
00034 #endif
00035
00036 #ifdef RICHARD
00037
00038 #define MEDIATABLE_USING_TREC
00039 #undef MEDIATABLE_BASIC
00040 #undef MEDIATABLE_USING_CSV
00041 #undef MEDIATABLE_USING_COMBINEDVIEWS
00042 #undef MEDIATABLE_USING_FLICKR
00043 #undef USE_BOOST_THREAD
00044 #undef USE_BOOST_THREADPOOL
00045 #define BOOST_THREADPOOL_SIZE 8
00046 #undef OGL_USING_GLUT
00047 #endif
00048
00049 #include "Basis/CmdOptions.h"
00050
00051 #include "OglGui/OglLib.cpp"
00052 #include "OglGui/Tabs.h"
00053
00054 #include "Modules/ModuleStore.h"
00055
00056 #include "Modules/TableDataSourceModule.h"
00057 #include "Modules/VisualizationModule.h"
00058 #include "OglGui/Button.h"
00059 #include "OglGui/TitledWindow.h"
00060 #include "OglGui/GroupBox.h"
00061 #include "OglGui/DropDownStringSelector.h"
00062
00063 #ifdef MEDIATABLE_USING_IMAGEDIR
00064 #include "Modules/ImageDirModule.h"
00065 #endif
00066 #ifdef MEDIATABLE_USING_CSV
00067 #include "Modules/CSVModule.h"
00068 #endif
00069 #ifdef MEDIATABLE_USING_FLICKR
00070 #include "Modules/FlickrModule.h"
00071 #endif
00072 #ifdef MEDIATABLE_USING_COMBINEDVIEWS
00073 #include "Modules/CombinedViewsModule.h"
00074 #endif
00075 #ifdef MEDIATABLE_USING_TREC
00076 #include "TableDataSourceTrec.h"
00077 #endif
00078
00079 #ifndef MEDIATABLE_VIDEOLYMPICS
00080 #include "Modules/BarPlotModule.h"
00081 #include "Modules/TimeLineModule.h"
00082 #endif
00083
00084 #include "Modules/ViewerPointCloudModule.h"
00085
00086
00087
00088
00089 #include "Modules/RandomImageModule.h"
00090
00091 #include "TableDataStore.h"
00092
00093 #include "GridWindow.h"
00094 #include "SelectionCollection.h"
00095 #include "TableWindow.h"
00096 #include "TableControlBarWindow.h"
00097 #include "TableOverviewWindow.h"
00098
00099 #include "ImageLoader.h"
00100 #include "OglImageCacheStore.h"
00101
00102 namespace Impala {
00103 namespace Application {
00104 namespace MediaTable {
00105
00106 class MediaTable: public OglGui::Window, public OglGui::ButtonListener,
00107 public OglGui::StringListener, public TableDataStoreListener,
00108 public OglGui::CloseWindowListener, public OglGui::GetOglImageByIdInterface,
00109 public VisualizationModuleListener, public TableDataSourceModuleListener,
00110 public OglGui::TabsListener
00111 {
00112 typedef OglGui::Window Window;
00113 typedef OglGui::TitledWindow TitledWindow;
00114 typedef OglGui::GroupBox GroupBox;
00115 typedef OglGui::Button Button;
00116 typedef OglGui::Tabs Tabs;
00117 typedef OglGui::StringSelector StringSelector;
00118
00119 public:
00120 MediaTable(int w, int h) : Window(0, 0, w, h)
00121 {
00122 Impala::CmdOptions& options = Impala::CmdOptions::GetInstance();
00123
00124 ILOG_STARTACTION("building GUI", ILOG_LEVEL_INFO);
00125 Init(w,h);
00126 ILOG_ENDACTION("building GUI");
00127
00128 GetOGLWND()->topTitle = "MediaTable";
00129 }
00130
00131 void Go()
00132 {
00133 Start();
00134 OglEventLoop();
00135 }
00136
00137 virtual void KeyboardFunc(int c, int state)
00138 {
00139 if (mTable->GetVisible())
00140 mTable->KeyboardFunc(c, state);
00141 if (mGrid->GetVisible())
00142 mGrid->KeyboardFunc(c, state);
00143
00144 Window::KeyboardFunc(c, state);
00145 }
00146
00147 void Init(int w, int h)
00148 {
00149
00150 Impala::CmdOptions& options = Impala::CmdOptions::GetInstance();
00151
00152
00153 ULONG bgCol = oglGUI_BG;
00154 String bgStr = options.GetString("wndBg");
00155 if (!bgStr.empty())
00156 bgCol = OglColorStr(bgStr.c_str());
00157 SetBackground(bgCol);
00158
00159 TableDataSource *src = 0;
00160
00161 #ifdef MEDIATABLE_BASIC
00162 ILOG_INFO("loading data.csv...");
00163 src = new TableDataSourceCSV("data.csv");
00164 if(!src->GetTotalRows())
00165 {
00166 ILOG_ERROR("data.csv could not be opened");
00167 exit(0);
00168 }
00169 ILOG_INFO("..done. " << src->GetTotalRows() << " rows loaded.");
00170 #else
00171 #ifdef MEDIATABLE_USING_SQLITE
00172 if (options.GetString("database") != "")
00173 src = new TableDataSourceSqliteDb(options.GetString("database"));
00174 #endif
00175 #ifdef MEDIATABLE_USING_IMAGEDIR
00176 if (options.GetString("directory") != "")
00177 src = new TableDataSourceImageDir(options.GetString("directory"));
00178 #endif
00179 #ifdef MEDIATABLE_USING_TREC
00180 if (options.GetBool("trec"))
00181 src = new TableDataSourceTrec();
00182 #endif
00183
00184 #ifdef MEDIATABLE_USING_CSV
00185 if (options.GetString("csv") != "" && !src)
00186 src = new TableDataSourceCSV(options.GetString("csv"));
00187 if (options.GetString("csv") != "" && src)
00188 {
00189 TableDataSource *src1 = src;
00190 TableDataSource *src2 = new TableDataSourceCSV(options.GetString("csv"));
00191 TableDataView *view1 = new TableDataView(src1);
00192 TableDataView *view2 = new TableDataView(src2);
00193
00194 TableDataSourceCombinedViews *csrc = new TableDataSourceCombinedViews();
00195 csrc->AddTableDataView(view1, "filename");
00196 csrc->AddTableDataView(view2, "filename");
00197 src = csrc;
00198 }
00199 #endif
00200
00201 #ifdef MEDIATABLE_USING_FLICKR
00202 if(!src)
00203 src = new TableDataSourceFlickrPhotoList();
00204 #endif
00205 if (!src)
00206 {
00207 ILOG_ERROR("Please start with either -a <db>, -d <directory> " <<
00208 "or --trec --ini <inifile>");
00209 return;
00210 }
00211 #endif
00212
00213 TableDataStore *store = TableDataStore::GetInstance();
00214 store->AddTableDataSource("Default", src);
00215 TableDataView *view = store->GetTableDataView("Default", "Default");
00216
00217 mImageLoader = new ImageLoader(this);
00218
00219 int csize = options.GetInt("imageCacheSize");
00220 csize = (csize > 100) ? csize : 100;
00221 OglImageCacheStore::Initialize(csize);
00222
00223 if (options.GetBool("preload"))
00224 {
00225 std::string column = "";
00226 std::vector<TableColumn*>::iterator it;
00227 std::vector<TableColumn*> columns;
00228 columns = view->GetColumns(true, true);
00229 for(it = columns.begin(); it != columns.end(); it++)
00230 {
00231 if((*it)->GetType() && TableDataSource::TYPE_FLAG_IMAGE)
00232 {
00233 column = (*it)->GetName();
00234 break;
00235 }
00236 }
00237 if(column != "")
00238 {
00239 int maxPreload = csize;
00240 if(view->GetTotalRows() < maxPreload)
00241 maxPreload = view->GetTotalRows();
00242 ILOG_INFO("Pre-filling cache with " << maxPreload << " images.");
00243 for(int i = 0; i < maxPreload; i++)
00244 {
00245 if(i%100 == 0 && i != 0)
00246 {
00247 ILOG_DEBUG("Preloading images until " << i << " of " << maxPreload);
00248 mImageLoader->WaitUntilDone();
00249 }
00250 long long id = view->GetSortedQuid(column, i);
00251 OGLIMAGE* im = mImageLoader->GetOglImageById(id);
00252 OglImageCacheStore::GetInstance()->Add(im, id);
00253 }
00254 mImageLoader->WaitUntilDone();
00255 }
00256 }
00257
00258 int btnH = 32;
00259 int botH = 124;
00260 int centerH = h - 10 - btnH - botH;
00261
00262 #ifdef MEDIATABLE_USING_MULTIPLE_VIEWS
00263 #ifdef IMAGEDIRMODULE_H
00264 ModuleStore::GetInstance()->Register(new ImageDirModule());
00265 #endif
00266 #ifdef CSVMODULE_H
00267 ModuleStore::GetInstance()->Register(new CSVModule());
00268 #endif
00269 #ifdef FLICKRMODULE_H
00270 ModuleStore::GetInstance()->Register(new FlickrModule());
00271 #endif
00272 #ifdef COMBINEDVIEWSMODULE_H
00273 ModuleStore::GetInstance()->Register(new CombinedViewsModule());
00274 #endif
00275 #endif
00276
00277 VisualizationModule* m;
00278 #ifdef BARPLOTMODULE_H_
00279 m = new BarPlotModule();
00280 m->SetGetOglImageByIdInterface(mImageLoader);
00281 ModuleStore::GetInstance()->Register(m);
00282 #endif
00283 #ifdef MAPMODULE_H_
00284 m = new MapModule();
00285 m->SetGetOglImageByIdInterface(mImageLoader);
00286 ModuleStore::GetInstance()->Register(m);
00287 #endif
00288 #ifdef GRAPHMODULE_H_
00289 m = new GraphModule();
00290 m->SetGetOglImageByIdInterface(mImageLoader);
00291 ModuleStore::GetInstance()->Register(m);
00292 #endif
00293 #ifdef VIEWERPOINTCLOUDMODULE_H_
00294 m = new ViewerPointCloudModule();
00295 m->SetGetOglImageByIdInterface(mImageLoader);
00296 ModuleStore::GetInstance()->Register(m);
00297 #endif
00298 #ifdef TIMELINEMODULE_H_
00299 m = new TimeLineModule();
00300 m->SetGetOglImageByIdInterface(mImageLoader);
00301 ModuleStore::GetInstance()->Register(m);
00302 #endif
00303 #ifdef RANDOMIMAGEMODULE_H_
00304 m = new RandomImageModule();
00305 m->SetGetOglImageByIdInterface(mImageLoader);
00306 ModuleStore::GetInstance()->Register(m);
00307 #endif
00308
00309 ModuleStore::GetInstance()->RegisterListener(static_cast<VisualizationModuleListener*>(this));
00310 ModuleStore::GetInstance()->RegisterListener(static_cast<TableDataSourceModuleListener*>(this));
00311
00312 ModuleStore::ModuleMapType vModules =
00313 ModuleStore::GetInstance()->GetModulesOfType("VisualizationModule");
00314 ILOG_DEBUG("VisualizationModules = " << vModules.size());
00315
00316 ModuleStore::ModuleMapType::iterator it;
00317 for (it=vModules.begin() ; it != vModules.end(); it++ )
00318 {
00319 ILOG_DEBUG("VisualizationModule:" << (*it).first << " => " <<
00320 (*it).second);
00321 }
00322
00323 mTabs = new OglGui::Tabs(this, 5, 5+botH, w-60, centerH+btnH, 120);
00324 mTabs->ConnectTo(this);
00325
00326 OglGui::Window* wnd = mTabs->CreateTab("Table");
00327 TableWindow *table =
00328 new TableWindow(wnd, view, 0, 0, wnd->W(), wnd->H()-btnH);
00329 table->ConnectTo(wnd);
00330
00331 TableControlBarWindow *buttonbar =
00332 new TableControlBarWindow(wnd, table, 0, table->H(), wnd->W(), btnH);
00333 buttonbar->ConnectTo(wnd, OglGui::TOLEFTRIGHT | OglGui::TOTOP);
00334 buttonbar->SetVisible(true);
00335
00336 wnd = mTabs->CreateTab("Grid");
00337 GridWindow *grid = new GridWindow(wnd, view, 0, 0, wnd->W(), wnd->H());
00338 grid->ConnectTo(wnd);
00339 grid->SetGridSize(75, 75);
00340
00341 if(ModuleStore::GetInstance()->CountModulesOfType("VisualizationModule") ||
00342 ModuleStore::GetInstance()->CountModulesOfType("TableDataSourceModule"))
00343 {
00344 Window* tabBar = mTabs->TabBar();
00345 Button* but = new Button(tabBar, tabBar->W()-45, -2, 35, 26, "+");
00346 but->SetRoundness(200, 200, 2, 2);
00347 but->SetButtonListener(this);
00348 but->ConnectTo(tabBar, OglGui::TORIGHT);
00349 }
00350
00351 mTabs->SetActiveTab(0);
00352 mTabs->SetTabsListener(this);
00353
00354 mOverview =
00355 new TableOverviewWindow(this, view, w-55, 5+botH, 50, centerH);
00356 mOverview->ConnectTo(this, OglGui::TORIGHT|OglGui::TOTOPBOTTOM);
00357 mOverview->SetHeaderHeight(40);
00358
00359 SelectionCollection *selcol =
00360 new SelectionCollection(this,view,5,5,w-10,botH);
00361 selcol->ScaleChildren();
00362 selcol->SetAllowScaling(false);
00363 selcol->ConnectTo(this, OglGui::TOLEFTRIGHT | OglGui::TOBOTTOM);
00364
00365
00366
00367 mOverlayWindow = new Window(this, 0, 0, w, h);
00368 mOverlayWindow->ConnectTo(this);
00369 oglSys.SetNoMouseInput(mOverlayWindow->GetOGLWND(), 1);
00370
00371 grid->SetListenTableUpdates(false);
00372 table->SetListenTableUpdates(true);
00373 mOverview->SetListenTableUpdates(true);
00374
00375
00376 table->AddColumnsFromDataSource();
00377 grid->AddColumnsFromDataSource();
00378
00379 table->SetGetOglImageByIdInterface(mImageLoader);
00380 grid->SetGetOglImageByIdInterface(mImageLoader);
00381
00382
00383
00384 table->SetZoomViewTargetWindow(mOverlayWindow, true);
00385 grid->SetZoomViewTargetWindow(mOverlayWindow, true);
00386
00387 mTable = table;
00388 mGrid = grid;
00389
00390
00391 view->DoUpdateSelectionEvent();
00392
00393 #ifdef MEDIATABLE_USING_MULTIPLE_VIEWS
00394 DoTableDataStoreWindow(this, w-160+5, h-btnH+3, 150, centerH+btnH+8);
00395 #endif
00396
00397
00398 }
00399
00400 virtual OGLIMAGE* GetOglImageById(long long quid)
00401 {
00402 return Visualization::RgbOglImage::OglImage
00403 (TableDataStore::GetInstance()->GetImageDataByQuid(quid));
00404 }
00405
00406 #ifdef MEDIATABLE_USING_MULTIPLE_VIEWS
00407 void DoTableDataStoreWindow(OglGui::Window* parent, int x, int y, int w, int h) {
00408 mTableDataStoreWindow = new OglGui::DropDownStringSelector(parent, x, y, w, "TableDataStore", w, h);
00409 mTableDataStoreWindow->ConnectTo(parent, OglGui::TORIGHT|OglGui::TOTOPBOTTOM);
00410 mTableDataStoreWindow->StrSelector()->ConnectTo(parent, OglGui::TORIGHT|OglGui::TOTOPBOTTOM);
00411 mTableDataStoreWindow->StrSelector()->SetBackground(parent->GetBackground());
00412 mTableDataStoreWindow->StrSelector()->SetStringListener(this);
00413 mTableDataStoreWindow->StrSelector()->AddString("TableDataStore is empty.");
00414
00415 TableDataStore::GetInstance()->AddTableDataStoreListener(this);
00416 TableDataStore::GetInstance()->DoUpdateTableDataStoreEvent();
00417 }
00418
00419 void StringSelectionEvent(StringSelector *src, int strIndex, void* listenerData) {
00420 ILOG_INFO("StringSelection: " << src->GetString(strIndex));
00421 }
00422
00423 void UpdateTableDataStoreEvent() {
00424 mTableDataStoreWindow->StrSelector()->RemoveStrings();
00425 std::map<std::string, std::vector<std::string> > contents;
00426 contents = TableDataStore::GetInstance()->GetContents();
00427 for(std::map<std::string, std::vector<std::string> >::iterator it = contents.begin(); it != contents.end(); it++) {
00428 for(std::vector<std::string>::iterator itv = it->second.begin(); itv != it->second.end(); itv++) {
00429 mTableDataStoreWindow->StrSelector()->AddString(it->first + ":" + *itv);
00430 }
00431 if(!it->second.size())
00432 mTableDataStoreWindow->StrSelector()->AddString(it->first + ":Default");
00433 }
00434 }
00435 #endif
00436
00437 Window* GetConfigWindow()
00438 {
00439 mConfigWindow = new TitledWindow(mOverlayWindow, W()/2-260, H()/2-160,
00440 520, 320, "Add new tab",
00441 TitledWindow::BtnClose);
00442 mConfigWindow->SetBackground(this->GetBackground());
00443 mConfigWindow->SetRoundness(0, 0, 0 ,0);
00444 mConfigWindow->SetCloseWindowListener(this, 0);
00445 new OglGui::Strut(mConfigWindow, mConfigWindow->W(), 24);
00446
00447 int h = mConfigWindow->H();
00448 GroupBox* grp;
00449 ModuleStore::ModuleMapType::iterator it;
00450
00451 #ifdef MEDIATABLE_USING_MULTIPLE_VIEWS
00452 h -= 160;
00453 grp = new GroupBox(mConfigWindow, mConfigWindow->W()-4, 160,
00454 "Data Sources:");
00455 new OglGui::Strut(grp, grp->W(), 16);
00456
00457 ModuleStore::ModuleMapType tModules =
00458 ModuleStore::GetInstance()->GetModulesOfType("TableDataSourceModule");
00459
00460 for (it=tModules.begin() ; it != tModules.end(); it++ )
00461 static_cast<TableDataSourceModule*>
00462 ((*it).second)->ContributeToConfigurationWindow(mOverlayWindow, grp);
00463
00464 grp->RepositionViewports();
00465 grp->ScaleChildren();
00466 #endif
00467
00468 grp = new GroupBox(mConfigWindow, mConfigWindow->W()-4, h,
00469 "Visualizations:");
00470 new OglGui::Strut(grp, grp->W(), 16);
00471
00472 ModuleStore::ModuleMapType vModules =
00473 ModuleStore::GetInstance()->GetModulesOfType("VisualizationModule");
00474
00475 for (it=vModules.begin() ; it != vModules.end(); it++ )
00476 static_cast<VisualizationModule*>
00477 ((*it).second)->ContributeToConfigurationWindow(mOverlayWindow, grp);
00478
00479 grp->RepositionViewports();
00480 grp->ScaleChildren();
00481
00482 mConfigWindow->RepositionViewports();
00483 mConfigWindow->ScaleChildren();
00484
00485 mOverlayWindow->SetBackground(0xCC000000);
00486 oglSys.SetNoMouseInput(mOverlayWindow->GetOGLWND(),0);
00487
00488 #ifdef MEDIATABLE_VIDEOLYMPICS
00489 if(ModuleStore::GetInstance()->CountModulesOfType("VisualizationModule") == 1 &&
00490 ModuleStore::GetInstance()->CountModulesOfType("TableDataSourceModule") == 0)
00491 {
00492 VisualizationModule *vm =
00493 static_cast<VisualizationModule*> ((*vModules.begin()).second);
00494 vm->DrawConfigWindow();
00495 vm->ClearConfigWindowValues();
00496 vm->ModuleSelected();
00497 }
00498 #endif
00499
00500 return mOverlayWindow;
00501 }
00502
00503 void ReleaseConfigWindow()
00504 {
00505 mOverlayWindow->SetBackground(0);
00506 oglSys.SetNoMouseInput(mOverlayWindow->GetOGLWND(),1);
00507 }
00508
00509 private:
00510 void ButtonSelectionEvent(Button *src, void *userData)
00511 {
00512 if(src->GetLabel() == "+")
00513 {
00514 GetConfigWindow();
00515 return;
00516 }
00517 }
00518
00519 void
00520 TabSelectionEvent(Tabs *src, int tabNr, void* data)
00521 {
00522 switch (tabNr)
00523 {
00524 case 0:
00525 ILOG_USER("User switched to TABLE visualization");
00526 mOverview->SetHeaderHeight(40);
00527 mGrid->SetListenTableUpdates(false);
00528 mGrid->SetShowPreview(false);
00529 mTable->SetListenTableUpdates(true);
00530 mTable->GetTableDataView()->DoUpdateNumberOfRowsEvent();
00531 mTable->GetTableDataView()->DoUpdateScrollFromSourceEvent();
00532 break;
00533 case 1:
00534 ILOG_USER("User switched to GRID visualization");
00535 mOverview->SetHeaderHeight(0);
00536 mGrid->SetListenTableUpdates(true);
00537 mTable->SetShowPreview(false);
00538 mTable->SetListenTableUpdates(false);
00539 mGrid->GetTableDataView()->DoUpdateNumberOfRowsEvent();
00540 mGrid->GetTableDataView()->DoUpdateScrollFromSourceEvent();
00541 break;
00542 default:
00543 ILOG_USER("User switched to visualization at tab " << MakeString(src->GetActiveTab()));
00544 mOverview->SetHeaderHeight(40);
00545 mGrid->SetListenTableUpdates(false);
00546 mTable->SetListenTableUpdates(false);
00547 mGrid->SetShowPreview(false);
00548 mTable->SetShowPreview(false);
00549 break;
00550 }
00551 }
00552
00553 bool OnCloseWindow(Window *src, void* userData)
00554 {
00555 ReleaseConfigWindow();
00556 return true;
00557 }
00558
00559 static void ActivateLastTab(Tabs* tabs)
00560 {
00561 uint maxTabId = 0;
00562 if(tabs->GetActiveTab() == 0)
00563 tabs->ActivateNextTab();
00564 for(; tabs->GetActiveTab() != 0; tabs->ActivateNextTab())
00565 maxTabId = tabs->GetActiveTab();
00566 tabs->SetActiveTab(maxTabId);
00567 }
00568
00569 void HandleNewWindow(VisualizationModule* module)
00570 {
00571 mGrid->SetListenTableUpdates(false);
00572 mTable->SetListenTableUpdates(false);
00573 Window* wnd = mTabs->CreateTab(module->GetNewWindowName());
00574 module->NewWindow(wnd);
00575 ActivateLastTab(mTabs);
00576 }
00577
00578 void HandleNewTableDataSource(TableDataSourceModule* module)
00579 {
00580 module->NewTableDataSource();
00581 }
00582
00583 ImageLoader* mImageLoader;
00584
00585 TableWindow* mTable;
00586 GridWindow* mGrid;
00587 TableOverviewWindow* mOverview;
00588 Window* mOverlayWindow;
00589 TitledWindow* mConfigWindow;
00590 OglGui::Tabs* mTabs;
00591 OglGui::DropDownStringSelector* mTableDataStoreWindow;
00592
00593 ILOG_VAR_DEC;
00594 };
00595
00596 ILOG_VAR_INIT(MediaTable, MediaTable);
00597
00598 }
00599 }
00600 }
00601
00602 #endif // MediaTable_h