00001 #ifndef Impala_Visualization_ThreadSetGui_h
00002 #define Impala_Visualization_ThreadSetGui_h
00003
00004 #include "Core/Trec/ThreadSet.h"
00005 #include "Core/VideoSet/SegmentationDocument.h"
00006 #include "OglGui/StringSelector.h"
00007 #include "OglGui/TextArea.h"
00008 #include "OglGui/Strut.h"
00009 #include "OglGui/Button.h"
00010 #include "Visualization/ImageSet.h"
00011
00012 namespace Impala {
00013 namespace Visualization {
00014
00015 class ThreadSetGui : public Window,
00016 public ImagesListener,
00017 public OglGui::StringListener,
00018 public OglGui::ButtonListener
00019 {
00020 static const int IM_SET = 1;
00021 static const int IM_CURRENT = 2;
00022 static const int BUT_PREV = 1;
00023 static const int BUT_NEXT = 2;
00024
00025 public:
00026 typedef Core::VideoSet::SegmentationDocument SegmentationDocument;
00027
00028 ThreadSetGui(OglGui::Window* parent, int wndWidth, int wndHeight,
00029 int nrImOnRow, int imWidth, int imHeight, double viewScale,
00030 Core::Trec::ThreadSet* threadSet, SegmentationDocument* segDoc,
00031 int controlId) :
00032 Window(parent, wndWidth, wndHeight, true)
00033 {
00034 mThreadSet = threadSet;
00035 mSegDoc = segDoc;
00036 mCurThread = 0;
00037 SetControlId(controlId);
00038
00039 int line = 20;
00040 mThreadNameList = new OglGui::StringSelector(this, wndWidth - 20,
00041 6*line);
00042 mThreadNameList->SetStringListener(this, 0);
00043
00044 UpdateThreadList();
00045
00046 mTextArea = new OglGui::TextArea(this, wndWidth - 20, 3*line, "");
00047
00048 mImageSet = new ImageSet(this, imWidth, imHeight, viewScale,
00049 nrImOnRow, 5);
00050 mImageSet->SetImagesListener(this, IM_SET);
00051 mImageSet->ActivateInfoBox(false);
00052
00053 mCurShotWnd = new ImagesWindow(this, wndWidth/4, wndHeight/4);
00054 mCurShotWnd->SetImagesListener(this, IM_CURRENT);
00055 mCurShotWnd->ActivateInfoBox(false);
00056
00057 OglGui::Button* but;
00058 but = new OglGui::Button(this, 60, 22, "Prev");
00059 but->SetRepeatMode(true);
00060 but->SetButtonListener(this, BUT_PREV);
00061 but = new OglGui::Button(this, 60, 22, "Next");
00062 but->SetRepeatMode(true);
00063 but->SetButtonListener(this, BUT_NEXT);
00064 }
00065
00066 virtual void StringSelectionEvent(OglGui::StringSelector* src, int strIndex,
00067 void* listenerData)
00068 {
00069 ShowThread(strIndex);
00070 }
00071
00072 virtual void ButtonSelectionEvent(OglGui::Button* src, void* vData)
00073 {
00074 int curPos = mCurThread->GetShotPosition(mSegDoc->CurShot());
00075 if (curPos == -1)
00076 return;
00077 int listenerData = (int)(long long) vData;
00078 switch (listenerData)
00079 {
00080 case BUT_PREV:
00081 ThreadStep(curPos - 1);
00082 break;
00083 case BUT_NEXT:
00084 ThreadStep(curPos + 1);
00085 break;
00086 }
00087 }
00088
00089 virtual void
00090 ImageSelectionEvent(ImagesWindow* src, int imIndex, void* listenerData)
00091 {
00092 if (listenerData == (void*) IM_SET)
00093 ThreadStep(imIndex);
00094 }
00095
00096 void ShowThread(int idx)
00097 {
00098 mThreadNameList->SetCurrentString(idx);
00099 mCurThread = mThreadSet->GetThread(idx);
00100 int curShot = mSegDoc->CurShot();
00101 mCurThread->SetOrigin(curShot);
00102 mTextArea->SetText(mCurThread->GetName());
00103
00104 mImageSet->RemoveImages();
00105 mCurShotWnd->RemoveImages();
00106 if (curShot == -1)
00107 return;
00108
00109 mCurShotWnd->AddImage(mThreadSet->GetImageByShotID(curShot), "Direct",
00110 mThreadSet->GetShotName(curShot), true);
00111 bool useArchive = mThreadSet->GetImageSetThumbnails()->GetUseArchive();
00112 int maxNrIm = useArchive ? 300 : 100;
00113 int nrIm = Min(mCurThread->GetLength(), maxNrIm);
00114 int firstShot = mCurThread->GetFirstShot();
00115 for (int i=0 ; i<nrIm ; i++)
00116 {
00117 int shot = mCurThread->GetShotAt(firstShot, i);
00118 if (shot == -1)
00119 break;
00120 mImageSet->AddImage(mThreadSet->GetImageByShotID(shot), "Direct",
00121 mThreadSet->GetShotName(shot), true);
00122 }
00123 mImageSet->SetFirstVisY(0, true);
00124 }
00125
00126 void ThreadStep(int position)
00127 {
00128 if (!mCurThread || (!mSegDoc->HasCurShot()))
00129 return;
00130 int firstShot = mCurThread->GetFirstShot();
00131 int newShot = mCurThread->GetShotAt(firstShot, position);
00132 if (newShot == -1)
00133 return;
00134 mCurShotWnd->RemoveImages();
00135 mSegDoc->GotoShot(newShot);
00136 int curShot = mSegDoc->CurShot();
00137 mCurShotWnd->AddImage(mThreadSet->GetImageByShotID(curShot), "Direct",
00138 mThreadSet->GetShotName(curShot), true);
00139 }
00140
00141 void UpdateThreadList()
00142 {
00143 mThreadNameList->RemoveStrings();
00144 for (int i=0 ; i<mThreadSet->GetNrThreads() ; i++)
00145 mThreadNameList->AddString(mThreadSet->GetThread(i)->GetName());
00146 }
00147
00148 virtual void HandleActivate()
00149 {
00150 UpdateThreadList();
00151 ShowThread(0);
00152 }
00153
00154 private:
00155
00156 Core::Trec::ThreadSet* mThreadSet;
00157 Core::Trec::Thread* mCurThread;
00158 SegmentationDocument* mSegDoc;
00159
00160 OglGui::StringSelector* mThreadNameList;
00161 OglGui::TextArea* mTextArea;
00162 ImageSet* mImageSet;
00163 ImagesWindow* mCurShotWnd;
00164
00165 };
00166
00167 }
00168 }
00169
00170 #endif