00001 #ifndef Impala_Visualization_SearchJudgeGui_h
00002 #define Impala_Visualization_SearchJudgeGui_h
00003
00004 #include "OglGui/StringSelector.h"
00005 #include "OglGui/TextArea.h"
00006 #include "OglGui/Strut.h"
00007 #include "OglGui/Button.h"
00008 #include "Visualization/ImageStrip.h"
00009 #include "Core/VideoSet/PlayShot.h"
00010 #include "Core/VideoSet/Segmentation.h"
00011 #include "Core/VideoSet/Keyframes.h"
00012 #include "Core/VideoSet/TableShots.h"
00013 #include "Core/Trec/TrecTopic.h"
00014 #include "Core/Trec/SearchJudge.h"
00015 #include "Core/Trec/SearchResult.h"
00016 #include "Core/Trec/Thread.h"
00017
00018 namespace Impala {
00019 namespace Visualization {
00020
00021 class SearchJudgeGui : public Window,
00022 public OglGui::StringListener,
00023 public OglGui::ButtonListener
00024 {
00025 public:
00026
00027 SearchJudgeGui(OglGui::Window* parent, int wndWidth, int wndHeight,
00028 int nrImOnRow, int imWidth, int imHeight, double viewScale,
00029 std::string resultName1, std::string resultName2,
00030 Core::Trec::SearchJudge* judge,
00031 Core::Trec::TrecTopic* trecTopic,
00032 Core::VideoSet::Segmentation* shots,
00033 Core::VideoSet::Keyframes* keyframes,
00034 Core::ImageSet::ImageSet* imageSet) :
00035 Window(parent, wndWidth, wndHeight, true)
00036 {
00037 mJudge = judge;
00038 mTrecTopic = trecTopic;
00039 mShots = shots;
00040 mKeyframes = keyframes;
00041 mImageSet = imageSet;
00042
00043 int line = 20;
00044 mInfoText = new OglGui::TextArea(this, wndWidth-20, 1*line, "info");
00045 mInfoText->SetBorderType(0);
00046 mImagesStrip = new ImageStrip(this, imWidth, imHeight, viewScale,
00047 nrImOnRow);
00048 mImagesStrip->ActivateInfoBox(false);
00049 OglGui::Button* but = new OglGui::Button(this, 100, 22, "play");
00050 but->SetButtonListener(this, 0);
00051
00052 OglGui::Strut* strut = new OglGui::Strut(this, 4000, 1);
00053 OglGui::TextArea* tArea;
00054 tArea = new OglGui::TextArea(this, 100, 1*line, resultName1);
00055 tArea->SetBorderType(0);
00056 mStringSelector1 = new OglGui::StringSelector(this,wndWidth/2,12*line);
00057 mStringSelector1->SetStringListener(this, 1);
00058 mApText1 = new OglGui::TextArea(this, 100, 1*line, "ap of result1");
00059
00060 if (resultName2 == std::string(""))
00061 return;
00062
00063 strut = new OglGui::Strut(this, 4000, 1);
00064 tArea = new OglGui::TextArea(this, 100, 1*line, resultName2);
00065 tArea->SetBorderType(0);
00066 mStringSelector2 = new OglGui::StringSelector(this,wndWidth/2,12*line);
00067 mStringSelector2->SetStringListener(this, 2);
00068 mApText2 = new OglGui::TextArea(this, 100, 1*line, "ap of result2");
00069 }
00070
00071 void DoJudgement(Core::VideoSet::TableShots* result1,
00072 Core::Trec::Thread* result2)
00073 {
00074 int i;
00075 double ap;
00076 std::string topic = mTrecTopic->GetCurTopicNum();
00077 int nrRelevant = mJudge->GetNrRelevant(topic);
00078 int nrJudged = mJudge->GetNrJudged(topic);
00079 std::string info = std::string("Topic ") + topic;
00080 info += std::string(", nr relevant = ") + MakeString(nrRelevant);
00081 info += std::string(", nr judged = ") + MakeString(nrJudged);
00082 mInfoText->SetText(info);
00083 SetJudgeShot(-1, -1);
00084
00085
00086 std::vector<std::string> sNames;
00087 int lastShot = -1;
00088 for (i=0 ; i<result1->Size() ; i++)
00089 {
00090 std::string shot = mShots->GetName(result1->Get1(i));
00091 sNames.push_back(shot);
00092 }
00093 mSearchResult1.Load(topic, sNames);
00094 mSearchResult1.Judge(mJudge);
00095 ap = mSearchResult1.GetAveragePrecision();
00096 mApText1->SetText(std::string("AP = ") + MakeString(ap));
00097 mStringSelector1->RemoveStrings();
00098 for (i=0 ; i<mSearchResult1.NrElements() ; i++)
00099 mStringSelector1->AddString(mSearchResult1.Describe(i));
00100
00101 if (result2 == 0)
00102 return;
00103
00104
00105 sNames.clear();
00106 lastShot = -1;
00107 int nr = result2->GetLength();
00108 if (nr > 1000)
00109 nr = 1000;
00110 for (i=0 ; i<nr ; i++)
00111 {
00112 std::string shot = mShots->GetName(result2->GetShot(i));
00113 sNames.push_back(shot);
00114 }
00115 mSearchResult2.Load(topic, sNames);
00116 mSearchResult2.Judge(mJudge);
00117 ap = mSearchResult2.GetAveragePrecision();
00118 mApText2->SetText(std::string("AP = ") + MakeString(ap));
00119 mStringSelector2->RemoveStrings();
00120 for (i=0 ; i<mSearchResult2.NrElements() ; i++)
00121 mStringSelector2->AddString(mSearchResult2.Describe(i));
00122 }
00123
00124 void SetJudgeShot(int listId, int idx)
00125 {
00126 mImagesStrip->RemoveImages();
00127 mCurrentShot = -1;
00128 if (idx < 0)
00129 return;
00130 std::string shotName;
00131 if (listId == 1)
00132 {
00133 mStringSelector1->SetCurrentString(idx);
00134 shotName = mSearchResult1.GetShot(idx);
00135 }
00136 else
00137 {
00138 mStringSelector2->SetCurrentString(idx);
00139 shotName = mSearchResult2.GetShot(idx);
00140 }
00141 mCurrentShot = mShots->GetShotId(shotName);
00142 int vidId = mShots->GetVideoId(mCurrentShot);
00143 int nrKey = mKeyframes->GetNrKeyframesShot(mCurrentShot);
00144 int firstKey = mKeyframes->GetFirstKeyframeShot(mCurrentShot);
00145 for (int i=0 ; i<nrKey ; i++)
00146 mImagesStrip->AddImage(firstKey + i, mImageSet);
00147 }
00148
00149 virtual void StringSelectionEvent(OglGui::StringSelector* src, int strIndex,
00150 void* listenerData)
00151 {
00152 int listId = (int)(long long)listenerData;
00153 SetJudgeShot(listId, strIndex);
00154 }
00155
00156 virtual void
00157 ButtonSelectionEvent(OglGui::Button* src, void* listenerData)
00158 {
00159 if (mCurrentShot == -1)
00160 return;
00161 Core::VideoSet::PlayShot(mShots, mCurrentShot);
00162 }
00163
00164 private:
00165
00166 int mCurrentShot;
00167
00168 Core::Trec::SearchJudge* mJudge;
00169 Core::Trec::TrecTopic* mTrecTopic;
00170 Core::Trec::SearchResult mSearchResult1;
00171 Core::Trec::SearchResult mSearchResult2;
00172 Core::VideoSet::Segmentation* mShots;
00173 Core::VideoSet::Keyframes* mKeyframes;
00174 Core::ImageSet::ImageSet* mImageSet;
00175
00176 OglGui::TextArea* mInfoText;
00177 OglGui::StringSelector* mStringSelector1;
00178 OglGui::StringSelector* mStringSelector2;
00179 OglGui::TextArea* mApText1;
00180 OglGui::TextArea* mApText2;
00181
00182 Visualization::ImageStrip* mImagesStrip;
00183 };
00184
00185 }
00186 }
00187
00188 #endif