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

ScreenBrowser.h

Go to the documentation of this file.
00001 /***********************************************************************************
00002  *
00003  * Application: Investigator's Dashboard (MultimediaN project 6)
00004  * 
00005  * Screen: Browser
00006  *
00007  * Primary author(s): Ork
00008  *                  : 
00009  *                  : 
00010  ***********************************************************************************/
00011 
00012 #ifndef Impala_Application_IDash_ScreenBrowser_h
00013 #define Impala_Application_IDash_ScreenBrowser_h
00014 
00015 
00016 #include "ScreenBase.h"
00017 
00018 #include "OglGui/SixButtonCross.h"
00019 
00020 #include "OglGui/Tabs.h"
00021 #include "OglGui/CheckBox.h"
00022 #include "OglGui/CheckBoxListener.h"
00023 #include "OglGui/Button.h"
00024 #include "OglGui/Strut.h"
00025 #include "OglGui/GroupBox.h"
00026 #include "OglGui/Strut.h"
00027 #include "OglGui/ButtonListener.h"
00028 #include "OglGui/RadioGroup.h"
00029 #include "OglGui/OglLib.cpp"
00030 
00031 #include "Visualization/RotorBrowser/RotorBrowserGUI.h"
00032 #include "Visualization/GUI/ShotDetailSidebar.h"
00033 
00034 #include "ScreenReconstruction.h"
00035 #include "DossierListener.h"
00036 
00037 namespace Impala {
00038 namespace Application {
00039 namespace IDash {
00040 
00041 //using namespace Visualization;
00042 #ifndef VisRotorBrowser
00043 #define VisRotorBrowser  Visualization::RotorBrowser
00044 #endif
00045 
00046 class ScreenBrowser : public ScreenBase,
00047                       public VisRotorBrowser::RotorBrowserListener,
00048                       public OglGui::CheckBoxListener,
00049                       public OglGui::RadioGroupListener,
00050                       public Visualization::GUI::ShotDetailSidebarListener,
00051                       public ReconstructionListener
00052 {
00053 
00054 public:
00055     typedef OglGui::Window                              Window;
00056     typedef OglGui::Strut                               Strut;
00057     typedef OglGui::Button                              Button;
00058     typedef OglGui::CheckBox                            CheckBox;
00059     typedef OglGui::StaticText                          StaticText;
00060     typedef OglGui::RadioGroup                          RadioGroup;
00061 
00062     typedef Visualization::AppController                AppController;
00063 
00064     typedef VisRotorBrowser::RotorBrowserContext        RotorBrowserContext;
00065 
00066     const static int MODE_CROSSBROWSER  = VisRotorBrowser::RotorBrowser::
00067                                           MODE_CROSSBROWSER;
00068     //const static int MODE_FORKBROWSER   = Visualization::RotorBrowser::
00069 //
00070     ScreenBrowser(int width, int height, bool enableQueryPane) :
00071         ScreenBase(width, height) 
00072     {
00073         InitScreen(enableQueryPane);
00074     }
00075 
00076     ScreenBrowser(OglGui::Window *parent, int width, int height, bool enableQueryPane) :
00077         ScreenBase(parent, width, height)
00078     {
00079         InitScreen(enableQueryPane);
00080     }
00081 
00082     ScreenBrowser(OglGui::Window *parent, bool enableQueryPane) :
00083         ScreenBase(parent)
00084     {
00085         InitScreen(enableQueryPane);
00086     }
00087 
00088 
00089     // rotorbrowser listener:
00090     virtual void
00091     ContextMoveEvent(OglGui::Window* src, int direction, int position)
00092     {
00093         ILOG_DEBUG("ContextMoveEvent: direction=" << direction << " position=" << position);
00094         mShotDetails->Update();
00095     }
00096 
00097     virtual void
00098     ContextChangeEvent(OglGui::Window* src, RotorBrowserContext *newcontext)
00099     {
00100         ILOG_DEBUG("ContextChangeEvent: newcontext=" << newcontext->GetName());
00101     }
00102 
00103     virtual void
00104     BookmarkEvent(OglGui::Window* src, int shotid, bool isbookmarked)
00105     {
00106         ILOG_DEBUG("ScreenBrowser::BookmarkEvent(" << shotid << ", " << isbookmarked << ")");
00107         mAppControlDoc->AllHandleBookmarkEvent(shotid, isbookmarked);
00108         if (isbookmarked)
00109             mAppControlDoc->AllHandleAddedBookmark();
00110         else
00111             mAppControlDoc->AllHandleRemovedBookmark();
00112     }
00113 
00114 
00115     // support for queries from external query window:
00116     virtual void
00117     DoInitialQuery()
00118     {
00119         ILOG_SYSTEM("DoInitialQuery: showing all movies");
00120         ButtonSelectionEvent(0, (void*) BTN_SHOWALLMOVIES);
00121     }
00122 
00123     virtual void
00124     DoConceptQuery(std::list<std::string> queryconcepts)
00125     {
00126         ILOG_SYSTEM("DoConceptQuery: " << queryconcepts.size() << " concepts in query.");
00127         mQueryComponents = queryconcepts;
00128         DoQuery();
00129     }
00130 
00131     // code to handle listeners
00132 
00133     void AddDossierListener(DossierListener *l)
00134     {
00135         mListeners.push_back(l);
00136     }
00137 private:
00138 
00139     void
00140     InitScreen(bool enableQueryPane)
00141     {
00142         ILOG_DEBUG("constructing screen Browser");
00143         mEnableQueryPane = enableQueryPane;
00144 
00145         int queryheight = 100;
00146         int controlsheight = 50;
00147         //int sidewidth = Engine()->ImWidth() + 12;
00148         int sidewidth = Engine()->ImWidth() + 40;
00149 
00150         // QUERY PANE:
00151 #ifdef AS_TODS_BROWSER
00152         mEnableQueryPane = false;
00153 #endif
00154 
00155         if (mEnableQueryPane)
00156         {
00157             mQueryPane = new Window(this, 2, WndHeight() - queryheight - 2, WndWidth() - 2*2, queryheight);
00158             DoQueryPane(mQueryPane);
00159             //mQueryPane->ConnectTo(this, T2T|B2T|R2R|L2L);
00160             mQueryPane->ConnectTo(this, OglGui::TOTOP|OglGui::TOLEFTRIGHT);
00161         } else {
00162             mQueryPane = 0;
00163             queryheight = 0;
00164         }
00165 
00166         int middlePanesHeight = WndHeight() - controlsheight - queryheight - (queryheight > 0 ? 4*2 : 3*2);
00167 
00168         // BROWSER PANE:
00169         mBrowserPane = new Window(this, 2, controlsheight + 2*2, WndWidth() - sidewidth - 3*2, middlePanesHeight);
00170 
00171         SetAsBox(mBrowserPane);
00172 
00173         bool enableMinimap = CmdOptions::GetInstance().GetBool("enableMinimap");
00174 
00175         mRotorBrowserGUI = new Visualization::RotorBrowser::RotorBrowserGUI(
00176                      mBrowserPane, mBrowserPane->WndWidth(), mBrowserPane->WndHeight(),
00177                      Engine()->ThreadSet(), Engine()->SegmentationDocument(), 
00178                      Engine()->ImWidth(), Engine()->ImHeight(), Engine()->ImScale(), 
00179                      GetAppControlID(), false, enableMinimap);
00180         //mRotorBrowserGUI->SetVisible(false);
00181 
00182         mRotorBrowserGUI->ScaleChildren();
00183         mRotorBrowserGUI->ConnectTo(mBrowserPane);
00184         mRotorBrowserGUI->AddRotorBrowserListener(this);
00185         AppController::Instance().AddControl(mRotorBrowserGUI);
00186         mBrowserPane->ConnectTo(this);
00187 
00188         mRotorBrowserGUI->SetShowMinimap(false);
00189 
00190         // SHOT DETAIL SIDE PANE:
00191 
00192         mDetailPane = new Window(this, WndWidth() - sidewidth - 2, controlsheight + 2*2, sidewidth, middlePanesHeight);
00193         SetAsBox(mDetailPane);
00194         
00195         mShotDetails = new Visualization::GUI::ShotDetailSidebar(
00196                      mDetailPane, 0, 0, mDetailPane->WndWidth(), mDetailPane->WndHeight(),
00197                      Engine()->ImWidth(), Engine()->ImHeight(),
00198                      Engine()->ThreadSet(), Engine()->SegmentationDocument());
00199         mShotDetails->ConnectTo(mDetailPane);
00200         mShotDetails->SetListener(this);
00201 
00202 // RvB Comment mShotDetails->SetShowSimilarity(false);
00203         mShotDetails->SetShowSimilarity(true);
00204 
00205         //mDetailPane->ConnectTo(this, L2R|R2R|T2T|B2B);
00206         mDetailPane->ConnectTo(this, OglGui::TORIGHT|OglGui::TOTOPBOTTOM);
00207 //        mAppControlDoc->AddDocListener(mShotDetails);
00208 //        oglSys.SetAlwaysDraw(mShotDetails->GetOGLWND(), 1); // TODO: hack.
00209 
00210         // CONTROL BAR PANE:
00211         mControlPane = new Window(this, 2, 2, WndWidth() - 4, controlsheight);
00212         DoControlsPane(mControlPane);
00213         mControlPane->ConnectTo(this, OglGui::TOLEFTRIGHT|OglGui::TOBOTTOM);
00214 OglGui::SixButtonCross* sixBtnCross = new OglGui::SixButtonCross(this,2,controlsheight+4,200,200);
00215 sixBtnCross->SetTexts("Last","First","Left","Right","Up","Down");
00216 for (int i=0 ; i<6 ; i++)
00217     sixBtnCross->Btn(i)->SetButtonListener(this, (void*)(BTN_CROSS + i));
00218 //        RepositionViewports();
00219 //        ScaleChildren();
00220 
00221     }
00222 
00223 
00224     void AddTog(Window *w, char *text, std::string mapping)
00225     {
00226         OglGui::Window *v = new OglGui::Window(w, 80, 80);
00227         v->SetBorderType(4);
00228         v->SetRoundness(3,3,3,3);
00229         v->SetBorderFillShaded(1);
00230         std::string imname = "icons/unknown.png";
00231         if (mapping.find("CONCEPT:") == 0 ) { // query starts with CONCEPT:
00232             imname = "icons/" + mapping.substr(8) +".png";
00233         }
00234         ILOG_DEBUG(" reading image " << imname);
00235         OGLIMAGE *image = OGLReadPNG(imname.c_str(), false);
00236         if (image != NULL) {
00237             OglGui::View *icon = new OglGui::View(v->GetOGLWND(), image, 0, 0, 75, 75);
00238         }
00239         OglGui::CheckBox *c = new OglGui::CheckBox(v, 2, 2, 80, 24, text);
00240         c->SetBorderType(0);
00241         c->SetRoundness(16,16,16,16);
00242         c->SetBorderFillShaded(0);
00243         c->SetBackground(0xaabbbbbb);
00244         mToggleMap[mToggleLastID] = mapping;
00245         c->SetCheckBoxListener(this, mToggleLastID);
00246         mToggleLastID++;
00247     }
00248 
00249 
00250     void AddBtn(Window *w, char *text, int width=80, int userData=0)
00251     {
00252         OglGui::Button *b = new OglGui::Button(w, width, 32, text);
00253         b->SetButtonListener(this, userData);
00254     }
00255     
00256     
00257     void
00258     DoQueryPane(Window *w)
00259     {
00260         SetAsBox(w);
00261 
00262         mToggleLastID = 0;
00263 
00264         // add logo code here:
00265 //        CreateLogos(w, 0,-5);
00266 //        new OglGui::StaticText(w, 30, 20, 200, 24, "Here be logo's");
00267 
00268     
00269         OglGui::StaticText *txte = new OglGui::StaticText(w, w->WndWidth() - 388 - 180 - 180, w->WndHeight() - 24, 380, 24, "1. Select features you want to find:");
00270         txte->SetAlign(oglLeftAlign, oglCenterAlign);
00271         Window *tog = new Window(w, w->WndWidth() - 388 - 180 - 180, 4, 380, 76);
00272         tog->SetBorderType(1);
00273         tog->SetRoundness(10,10,10,10);
00274         tog->SetBorderFillShaded(1);
00275         tog->SetBorderBackground(0xff666666);
00276     
00277         OglGui::StaticText *txtf = new OglGui::StaticText(w, w->WndWidth() - 180 - 180, w->WndHeight() - 24, 170, 24, "2. Where:");
00278         txtf->SetAlign(oglLeftAlign, oglCenterAlign);
00279         RadioGroup *locality = new RadioGroup(w, w->WndWidth() - 180 - 180, 4, 170, 76);
00280         locality->SetButtonDimensions(160, 20);
00281         locality->Add("No preference", BEV_RAISED, true);
00282         locality->Add("Only indoor scenes", BEV_RAISED, true);
00283         locality->Add("Only outdoor scenes", BEV_RAISED, true);
00284         locality->SetRadioListener(this, RAD_LOCALITY);
00285 
00286         OglGui::StaticText *txt = new OglGui::StaticText(w, w->WndWidth() - 170, w->WndHeight() - 24, 160, 24, "3. Start exploring:");
00287         txt->SetAlign(oglLeftAlign, oglCenterAlign);
00288         OglGui::Button *b;
00289 
00290         b = new OglGui::Button(w, w->WndWidth() - 170, 48, 160, 32, "Show selection");
00291         b->SetButtonListener(this, BTN_SHOWSELECTION);
00292         
00293         b = new OglGui::Button(w, w->WndWidth() - 170, 4, 160, 32, "Show all videos");
00294         b->SetButtonListener(this, BTN_SHOWALLMOVIES);
00295 
00296 
00297         AddTog(tog, "person", "CONCEPT:Person");
00298         AddTog(tog, "face", "CONCEPT:Face");
00299         AddTog(tog, "waterbody", "CONCEPT:Waterscape_Waterfront");
00300         AddTog(tog, "Indoor scene", "CONCEPT:Office");
00301         AddTog(tog, "Outdoor scene", "CONCEPT:Outdoor");
00302 
00303         tog->RepositionViewports();
00304         tog->ScaleChildren();
00305         w->RepositionViewports();
00306         w->ScaleChildren();
00307     }
00308     
00309     void
00310     DoControlsPane(Window *w)
00311     {
00312         SetAsBox(w);
00313     
00314         new OglGui::Strut(w, 4000, 2);
00315         new OglGui::Strut(w, 16, 2);
00316     
00317         new OglGui::StaticText(w,40,32,"Result:");
00318         AddBtn(w, "<<",20, BTN_RFIRST);
00319         AddBtn(w, "<",20, BTN_RPREV);
00320         AddBtn(w, ">",20, BTN_RNEXT);
00321         AddBtn(w, ">>",20, BTN_RLAST);
00322     
00323         new OglGui::Strut(w, 16,2);
00324         new OglGui::StaticText(w,30,32,"Time:");
00325 //        AddBtn(w, "<<",20, BTN_TFIRST);
00326         AddBtn(w, "<",20, BTN_TPREV);
00327         AddBtn(w, ">",20, BTN_TNEXT);
00328 //        AddBtn(w, ">>",20, BTN_TLAST);
00329     
00330         new OglGui::Strut(w, 160,2);
00331         AddBtn(w, "All movies", 80, BTN_SHOWALLMOVIES);
00332         AddBtn(w, "Bookmark", 80, BTN_BOOKMARK);
00333         AddBtn(w, "Play video", 80, BTN_PLAYVIDEO);
00334 
00335         new OglGui::Strut(w, 20, 2);
00336         AddBtn(w, "toggle similarity", 100, BTN_SHOWSIMILARITY);
00337         AddBtn(w, "toggle minimap", 100, BTN_SHOWMINIMAP);
00338 
00339 //        AddBtn(w, "Region query", );
00340 //        AddBtn(w, "Go to 3D scene", 120, true);
00341 
00342         OglGui::Window *logo = CreateLogos(w, w->W() - 342, 0);
00343         logo->ConnectTo(w, OglGui::TORIGHT);
00344 
00345         w->RepositionViewports();
00346         w->ScaleChildren();
00347     }
00348 
00349     void PlayVideo(int videoID) {
00350         ILOG_DEBUG("sending PlayFileEvent(" << videoID <<")...");
00351         for (int i=0; i<mListeners.size();i++)
00352             mListeners[i]->PlayFileEvent(videoID);
00353     }
00354 
00355     // QUERY SUPPORT CODE:
00356     void
00357     DoQuery()
00358     {
00359         ILOG_SYSTEM("Performing IDASH query...");
00360         if (mQueryComponents.size() == 0) {
00361             ILOG_SYSTEM("Nothing selected. Showing all movies.");
00362             mRotorBrowserGUI->SetInitialQueryToMovies();
00363             mRotorBrowserGUI->ResetRanking();
00364             mRotorBrowserGUI->SetBrowseMode(MODE_CROSSBROWSER);
00365             return;
00366         }
00367         Engine()->PerformQuery(mQueryComponents);
00368         mRotorBrowserGUI->SetBrowseMode(MODE_CROSSBROWSER);
00369         mRotorBrowserGUI->ResetRanking();
00370     }
00371 
00372     void
00373     AddComponent(std::string qomponent)
00374     {
00375         std::list<std::string>::iterator i = 
00376         std::find(mQueryComponents.begin(), mQueryComponents.end(), qomponent);
00377         if (i == mQueryComponents.end()) {
00378             ILOG_DEBUG("Query - adding: " << qomponent);
00379             mQueryComponents.push_back(qomponent);
00380         }
00381     }
00382 
00383     void
00384     RemoveComponent(std::string qomponent)
00385     {
00386         std::list<std::string>::iterator i = 
00387         std::find(mQueryComponents.begin(), mQueryComponents.end(), qomponent);
00388         if (i != mQueryComponents.end()) {
00389             ILOG_DEBUG("Query - removing: " << qomponent);
00390             mQueryComponents.erase(i);
00391         }
00392     }
00393 
00394 
00395 
00396     // HANDLERS:
00397     virtual void
00398     ButtonSelectionEvent(Button *src, void* vData)
00399     {
00400         int userData = (int) (long long) vData;
00401         switch (userData) {
00402             case BTN_SHOWALLMOVIES:
00403                 ILOG_USER("BTN: show all movies");
00404                 mRotorBrowserGUI->SetInitialQueryToMovies();
00405                 mRotorBrowserGUI->ResetRanking();
00406                 mRotorBrowserGUI->SetBrowseMode(MODE_CROSSBROWSER);
00407                 break;
00408             case BTN_SHOWSELECTION:
00409                 ILOG_USER("BTN: show selection");
00410                 DoQuery();
00411                 break;
00412 
00413 
00414             case BTN_TFIRST:  break; //mRotorBrowserGUI->PressKey('q'); break;
00415 case BTN_CROSS+2:
00416             case BTN_TPREV:   mRotorBrowserGUI->PressKey('a'); break;
00417 case BTN_CROSS+3:
00418             case BTN_TNEXT:   mRotorBrowserGUI->PressKey('d'); break;
00419             case BTN_TLAST:   break; //mRotorBrowserGUI->PressKey('e'); break;
00420 case BTN_CROSS + 1:
00421             case BTN_RFIRST:  mRotorBrowserGUI->PressKey('q'); break;
00422 case BTN_CROSS + 5:
00423             case BTN_RPREV:   mRotorBrowserGUI->PressKey('s'); break;
00424 case BTN_CROSS + 4:
00425             case BTN_RNEXT:   mRotorBrowserGUI->PressKey('w'); break;
00426 case BTN_CROSS + 0:
00427             case BTN_RLAST:   mRotorBrowserGUI->PressKey('e'); break;
00428 
00429             case BTN_BOOKMARK: mRotorBrowserGUI->PressKey(' '); break;
00430 
00431             case BTN_PLAYVIDEO:
00432                 ILOG_USER("BTN: Play video");
00433                 {
00434                     int shot = mRotorBrowserGUI->GetCenterShot();
00435                     if (shot != -1) {
00436                         int videoID = Engine()->ThreadSet()->GetSegmentation()->GetVideoId(shot);
00437                         PlayVideo(videoID);
00438                     }
00439                 }
00440                 break;
00441 
00442             case BTN_SHOWSIMILARITY:
00443                 ILOG_USER("BTN: show similarity");
00444                 mShotDetails->SetShowSimilarity(!mShotDetails->GetShowSimilarity());
00445 // RvB: Direkt update
00446 mShotDetails->Update();
00447                 break;
00448 
00449             case BTN_SHOWMINIMAP:
00450                 ILOG_USER("BTN: show minimap");
00451                 mRotorBrowserGUI->SetShowMinimap(!mRotorBrowserGUI->GetShowMinimap());
00452                 break;
00453         }
00454 mRotorBrowserGUI->FocusToBrowser();
00455     }
00456 
00457     virtual void
00458     QueryVisualEvent(std::string visname, int keyframe)
00459     {
00460         ILOG_DEBUG("QueryVisualEvent for " << visname << " (keyframe " << keyframe << ")");
00461         Engine()->PerformVisualQuery(visname, keyframe);
00462         mRotorBrowserGUI->ResetCrossBrowser();
00463 //        mRotorBrowserGUI->SetBrowseMode(RotorBrowser::RotorBrowser::MODE_CROSSBROWSER);
00464         mRotorBrowserGUI->ResetRanking();
00465         mRotorBrowserGUI->FocusToBrowser();
00466         mShotDetails->Update();
00467     }
00468 
00469     virtual void
00470     QueryByRegionEvent(int keyframe, float x, float y, float w, float h)
00471     {
00472         ILOG_DEBUG("QueryByRegionEvent for " << keyframe);
00473         mRotorBrowserGUI->DoQueryByRegion(keyframe, x, y, w, h);
00474     }
00475 
00476     virtual void
00477     CheckBoxEvent(OglGui::CheckBox *src, bool isChecked, void* vData) {
00478         int userData = (int)(long long) vData;
00479         std::string qomponent = mToggleMap[userData];
00480 
00481         if (isChecked) {
00482             AddComponent(qomponent);
00483         } else {
00484             RemoveComponent(qomponent);
00485         }
00486     }
00487 
00488     virtual void
00489     OnRadioChange(RadioGroup *src, int button, void* data)
00490     {
00491         if (data == (void*)RAD_LOCALITY) {
00492             switch (button) {
00493             case 0: // no preference
00494                 RemoveComponent("CONCEPT:indoor");
00495                 RemoveComponent("CONCEPT:outdoor");
00496                 break;
00497             case 1: // indoor
00498                 AddComponent("CONCEPT:indoor");
00499                 RemoveComponent("CONCEPT:outdoor");
00500                 break;
00501             case 2: // outdoor
00502                 RemoveComponent("CONCEPT:indoor");
00503                 AddComponent("CONCEPT:outdoor");
00504                 break;
00505             }
00506         }
00507 
00508     }
00509 
00510     const static int RAD_LOCALITY = 1;
00511 
00512     static const int BTN_SHOWSELECTION = 1;
00513     static const int BTN_SHOWALLMOVIES = 2;
00514 
00515 const static int BTN_CROSS = 200;
00516 
00517     const static int BTN_TFIRST = 101;
00518     const static int BTN_TPREV = 102;
00519     const static int BTN_TNEXT = 103;
00520     const static int BTN_TLAST = 104;
00521     const static int BTN_RFIRST =105;
00522     const static int BTN_RPREV = 106;
00523     const static int BTN_RNEXT = 107;
00524     const static int BTN_RLAST = 108;
00525 
00526     const static int BTN_BOOKMARK =110;
00527     const static int BTN_PLAYVIDEO = 111;
00528     const static int BTN_SHOWSIMILARITY = 112;
00529     const static int BTN_SHOWMINIMAP = 113;
00530 
00531 
00532 private:
00533     Window *mQueryPane, *mBrowserPane, *mDetailPane, *mControlPane;
00534 
00535     Visualization::RotorBrowser::RotorBrowserGUI *mRotorBrowserGUI;
00536     Visualization::GUI::ShotDetailSidebar        *mShotDetails;
00537 
00538     bool                       mEnableQueryPane;
00539 
00540     // toggle-o-matic code:
00541     std::map<int, std::string> mToggleMap;
00542     int                        mToggleLastID;
00543     std::list<std::string>     mQueryComponents;
00544 
00545     std::vector<DossierListener*> mListeners;
00546 
00547     ILOG_VAR_DEC;
00548 };
00549 
00550 ILOG_VAR_INIT(ScreenBrowser, Application.IDash);
00551 
00552 }
00553 }
00554 }
00555 
00556 #endif

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