00001
00002 #ifndef Impala_Visualization_SimilarityTableSetRank_h
00003 #define Impala_Visualization_SimilarityTableSetRank_h
00004
00005 #include "Persistency/AnnotationTableRepository.h"
00006 #include "Core/Table/Select.h"
00007 #include "Core/Table/SelectQuids.h"
00008 #include "Core/Table/Copy.h"
00009 #include "Core/Table/AveragePrecision.h"
00010 #include "Core/Table/RemoveRow.h"
00011
00012 #include "Core/ImageSet/IxsDocument.h"
00013 #include "Core/VideoSet/SegmentationDocument.h"
00014
00015 #include "Core/VideoSet/PlayShot.h"
00016 #include "OglGui/StringSelector.h"
00017 #include "OglGui/StringListener.h"
00018 #include "OglGui/TextArea.h"
00019 #include "OglGui/CheckBox.h"
00020
00021
00022 #include "OglGui/StaticText.h"
00023 #include "OglGui/Button.h"
00024 #include "OglGui/Strut.h"
00025 #include "OglGui/TextEdit.h"
00026
00027 #include "Visualization/ImageSet.h"
00028 #include "Visualization/ImageSetIdxGridScroller.h"
00029 #include "Visualization/AppControlDoc.h"
00030 #include "Visualization/Plot/Plot.h"
00031 #include "Visualization/Plot/Line.h"
00032 #include "Visualization/Plot/Points.h"
00033 #include "Visualization/Plot/PlotNeedle.h"
00034 #include "Visualization/PunsOnlyControl.h"
00035 #include "Visualization/ShowNextFromControl.h"
00036
00037 namespace Impala {
00038 namespace Visualization {
00039
00040 class SimilarityTableSetRank : public Window,
00041 public AppControlDoc,
00042 public Core::Database::DataDocumentListener,
00043 public Plot::PlottableMouseListener,
00044 public ImageSetIdxGridListener,
00045 public ImagesListener,
00046 public PunsOnlyControlListener,
00047 public ShowNextFromControlListener,
00048 public OglGui::StringListener,
00049 public OglGui::CheckBoxListener,
00050 public OglGui::WindowListener,
00051 public OglGui::ButtonListener
00052 {
00053
00054 static const int SET_POSITIVE = 100;
00055 static const int SET_NEGATIVE = 101;
00056 static const int SET_SKIP = 102;
00057 static const int DELETE_CORR = 103;
00058 static const int SAVE_CORR = 104;
00059
00060 public:
00061 typedef Core::Table::QuidTable QuidTable;
00062 typedef Core::Table::SimilarityTableSet SimilarityTableSet;
00063 typedef SimilarityTableSet::RankTableType RankTableType;
00064 typedef SimilarityTableSet::SimTableType SimTableType;
00065 typedef Core::Table::AnnotationTable AnnotationTable;
00066 typedef Core::Database::DataDocument DataDocument;
00067 typedef Core::VideoSet::SegmentationDocument SegmentationDocument;
00068 typedef Core::ImageSet::IxsDocument IxsDocument;
00069
00070 SimilarityTableSetRank(OglGui::Window* parent, int wndWidth, int wndHeight,
00071 int nrImOnRow, int thumbWidth, int thumbHeight,
00072 double viewScale, SegmentationDocument* segDoc,
00073 SimilarityTableSet* simSet, bool showPlotLine,
00074 String annoSet, bool showPlotPoint, int controlId) :
00075 Window(parent, wndWidth, wndHeight, true),
00076 AppControlDoc(controlId, segDoc)
00077 {
00078 mIxsDoc = 0;
00079 mSegDoc = segDoc;
00080 mDataDoc = segDoc;
00081 Init(wndWidth, wndHeight, nrImOnRow, thumbWidth, thumbHeight, viewScale,
00082 simSet, showPlotLine, annoSet, showPlotPoint);
00083 }
00084
00085 SimilarityTableSetRank(OglGui::Window* parent, int wndWidth, int wndHeight,
00086 int nrImOnRow, int thumbWidth, int thumbHeight,
00087 double viewScale, IxsDocument* ixsDoc,
00088 SimilarityTableSet* simSet, bool showPlotLine,
00089 String annoSet, bool showPlotPoint, int controlId) :
00090 Window(parent, wndWidth, wndHeight, true),
00091 AppControlDoc(controlId, ixsDoc)
00092 {
00093 mSegDoc = 0;
00094 mIxsDoc = ixsDoc;
00095 mDataDoc = ixsDoc;
00096
00097 Init(wndWidth, wndHeight, nrImOnRow, thumbWidth, thumbHeight, viewScale,
00098 simSet, showPlotLine, annoSet, showPlotPoint);
00099 }
00100
00101 void Init(int wndWidth, int wndHeight, int nrImOnRow, int thumbWidth,
00102 int thumbHeight, double viewScale, SimilarityTableSet* simSet,
00103 bool showPlotLine, String annoSet, bool showPlotPoint)
00104 {
00105 CmdOptions& options = CmdOptions::GetInstance();
00106
00107 mSimSet = simSet;
00108 mAnnoSet = annoSet;
00109 mCorrectionSet = options.GetString("conceptCorrections");
00110 mImagesSet = 0;
00111 mImSetIdxGrid = 0;
00112 mIdxGridTotalTxt = 0;;
00113
00114 mShowNextFrom = 0;
00115 mCurConcept = -1;
00116 mAnno = 0;
00117 mAnnoConcept = -2;
00118 mCorrections = 0;
00119 mQualifiedRanking = new AnnotationTable();
00120 mSelectedRanking = new AnnotationTable();
00121 mStartIm = 0;
00122 mLineSize1 = -1;
00123 mLineData1 = 0;
00124 mLineSize2 = -1;
00125 mLineData2 = 0;
00126 mPoints = 0;
00127 mFloatWnd = 0;
00128 mViewWidth = thumbWidth * viewScale + 0.5;
00129
00130 mOptionBits = -1;
00131 mCurFileId = -1;
00132 mImageSelected = -1;
00133
00134 mNrToShow = options.GetInt("annoNrToShow", 200);
00135 int truthNrToShow = options.GetInt("annoNrToShowConceptsTruth",-1);
00136 int simNrToShow = options.GetInt("annoNrToShowConceptsSim",-1);
00137 int conNrToShow = options.GetInt("annoNrToShowConcepts",-1);
00138 if (showPlotPoint && truthNrToShow!=-1)
00139 mNrToShow = truthNrToShow;
00140 else if (showPlotLine && simNrToShow!=-1)
00141 mNrToShow = simNrToShow;
00142 else if (conNrToShow != -1)
00143 mNrToShow = conNrToShow;
00144
00145 mKeyframes = mSegDoc ? mSegDoc->GetKeyframes() : 0;
00146 mKeyframeSet =
00147 mSegDoc ? mSegDoc->GetImSetKeyframes(true) : mIxsDoc->GetImageSet();
00148 AddDocListener(this);
00149
00150 mStringSelector = new OglGui::StringSelector(this, wndWidth, 60);
00151 mStringSelector->SetStringListener(this, 0);
00152 int heightUsed = 60;
00153
00154 mPlotLine1 = 0;
00155 mPlotLine2 = 0;
00156 if (showPlotLine)
00157 {
00158 mPlotLine1 = new Plot::Plot(this, wndWidth, 180);
00159 heightUsed += 180;
00160 mLine1 = new Visualization::Plot::Line(0);
00161 mPlotLine1->Add(mLine1);
00162 mPlotLine1->AutoScale();
00163 mPlotLine1->SetDrawAxes(true);
00164
00165 mPlotLine2 = new Visualization::Plot::Plot(this, wndWidth, 180);
00166 heightUsed += 180;
00167 mLine2 = new Visualization::Plot::Line(0);
00168 mLine2->SetPlottableMouseListener(this,mPlotLine2);
00169 mPlotLine2->Add(mLine2);
00170 mPlotLine2->AutoScale();
00171 mPlotLine2->SetDrawAxes(true);
00172 mNeedle2 = new Plot::PlotNeedle(0,1500,0,1,0);
00173
00174 mNeedle2->SetColor(1,(165./255),0);
00175 mPlotLine2->Add(mNeedle2);
00176 }
00177
00178 mPlotPoints = 0;
00179 if (showPlotPoint)
00180 {
00181 int h = mSegDoc ? 430 : 215;
00182 mPlotPoints = new Plot::Plot(this, wndWidth, h);
00183 heightUsed += h;
00184 mPoints = new Plot::Points();
00185 mPoints->SetPlottableMouseListener(this,mPlotPoints);
00186 mPoints->HighLightColor(0xffffa500);
00187 mPlotPoints->Add(mPoints);
00188
00189 mPlotPoints->SetDrawAxes(true);
00190 }
00191
00192 String info = (mSimSet) ? mSimSet->GetDescription() : "no sims";
00193 mInfoText = new OglGui::TextArea(this, wndWidth/2 - 5, 20, info);
00194 mInfoText->SetBorderType(0);
00195 mVideoCheckBox = new OglGui::CheckBox(this, 100, 20, "OneVideo", false);
00196 mVideoCheckBox->SetCheckBoxListener(this, 0);
00197
00198 mVideoText = new OglGui::TextArea(this, wndWidth/2 - 110, 20, "empty");
00199 mVideoText->SetBorderType(0);
00200 heightUsed += 20;
00201
00202 mRkfCheckBox = new OglGui::CheckBox(this, 110, 20, "Only RKF", false);
00203 mRkfCheckBox->SetCheckBoxListener(this, 0);
00204 if (!mSegDoc)
00205 {
00206 mVideoCheckBox->SetVisible(false);
00207 mVideoText->SetVisible(false);
00208 mRkfCheckBox->SetVisible(false);
00209 }
00210
00211 mPunsOnly = new PunsOnlyControl(this, 334, 20, 13);
00212 mPunsOnly->SetListener(this);
00213
00214 if (!mCorrectionSet.empty())
00215 {
00216 OglGui::Button* but;
00217 but = new OglGui::Button(this, 120, 22, "SetPositive");
00218 but->SetButtonListener(this, SET_POSITIVE);
00219 but = new OglGui::Button(this, 120, 22, "SetNegative");
00220 but->SetButtonListener(this, SET_NEGATIVE);
00221 but = new OglGui::Button(this, 120, 22, "SetSkip");
00222 but->SetButtonListener(this, SET_SKIP);
00223 but = new OglGui::Button(this, 120, 22, "DeleteCorrection");
00224 but->SetButtonListener(this, DELETE_CORR);
00225 but = new OglGui::Button(this, 120, 22, "SaveCorrections");
00226 but->SetButtonListener(this, SAVE_CORR);
00227 }
00228
00229 heightUsed += 30;
00230
00231 if (!options.GetBool("conceptIdxGrid",true))
00232 {
00233 mShowNextFrom = new ShowNextFromControl(this, 350, 20, mNrToShow);
00234 mShowNextFrom->SetListener(this);
00235 new OglGui::Strut(this,200,1);
00236
00237 int nrRow = (wndHeight - heightUsed) / (thumbHeight + 6);
00238 mImagesSet = new ImageSet(this, thumbWidth, thumbHeight, viewScale,
00239 nrImOnRow, nrRow);
00240 mImagesSet->ActivateInfoBox(false);
00241 mImagesSet->SetImagesListener(this, 0);
00242 }
00243 else
00244 {
00245 mIdxGridTotalTxt = new OglGui::StaticText(this, 160, 20, "Total:");
00246 mIdxGridTotalTxt->SetAlign(oglLeftAlign);
00247 mImSetIdxGridScroller =
00248 new ImageSetIdxGridScroller(this,2,2,wndWidth-4,
00249 wndHeight-heightUsed-14,nrImOnRow);
00250 mNrToShow = 1000000;
00251 mImSetIdxGrid = mImSetIdxGridScroller->ImSetIdxGrid();
00252 mImSetIdxGrid->SetImageSetIdxGridListener(this);
00253
00254 mImSetIdxGrid->ShowDims(false);
00255 oglSys.SetSelectColor(mImSetIdxGrid->GetOGLWND(),0xffffa500);
00256 }
00257
00258 if (mPlotPoints || mPlotLine2)
00259 {
00260 mFloatWnd = new ImagesWindow(this,0,0,200,200);
00261 mFloatWnd->SetViewSize(200,200);
00262 }
00263
00264 std::vector<String> names;
00265 if (mSimSet)
00266 names = mSimSet->GetNames();
00267 for (int i=0 ; i<names.size() ; i++)
00268 {
00269 mStringSelector->AddString(names[i]);
00270 mDataDoc->AddConcept(names[i]);
00271 }
00272 mDataDoc->SetConcept(0);
00273 }
00274
00275 void CheckCurrentActual()
00276 {
00277 mCurConcept = mDataDoc->GetConceptIdx();
00278 if (mCurConcept != mStringSelector->GetCurrentStringIdx())
00279 mStringSelector->SetCurrentString(mCurConcept, true);
00280 mCurFileId = mDataDoc->CurFileId();
00281 String vidName;
00282 if (mCurFileId != -1)
00283 vidName = mDataDoc->GetDataSet()->GetFile(mCurFileId);
00284 mVideoText->SetText(vidName);
00285 }
00286
00287 void ClearImages()
00288 {
00289 mImageSelected = -1;
00290 if (mImagesSet)
00291 {
00292 mImagesSet->RemoveImages();
00293 mImagesSet->SetFirstVisY(0, true);
00294 mImagesSet->SetImageSelected(-1);
00295 }
00296 if (mImSetIdxGrid)
00297 mImSetIdxGrid->Clear();
00298 }
00299
00300 void HandleUpdate(bool doUpdateAnno)
00301 {
00302 Timer timer(1);
00303 ILOG_INFO("============================= start");
00304 ILOG_INFO("1 : " << timer.SplitTime() << " = " << timer.SplitTimeStr());
00305 if (doUpdateAnno)
00306 UpdateAnno();
00307 ILOG_INFO("2 : " << timer.SplitTime() << " = " << timer.SplitTimeStr());
00308 UpdateRanking();
00309 ILOG_INFO("3 : " << timer.SplitTime() << " = " << timer.SplitTimeStr());
00310 int nrPlot = mSelectedRanking->Size();
00311 int nrIm = Min(nrPlot, mNrToShow);
00312 int nrOk = 0;
00313 UpdateLineSize(Min(nrPlot, 1000));
00314 SimTableType* simTable = mSimSet->GetSimTable(mCurConcept);
00315 for (int i=0 ; i<nrPlot ; i++)
00316 {
00317 Quid quid = mSelectedRanking->Get1(i);
00318 if (i>=mStartIm && i<mStartIm+mNrToShow)
00319 {
00320 int imSetId = FindImSetId(quid);
00321 if (imSetId == -1)
00322 {
00323 ILOG_ERROR("Unable to find keyframe for " << QuidObj(quid));
00324 }
00325 else
00326 {
00327 if (mImagesSet)
00328 mImagesSet->AddImage(imSetId, mKeyframeSet);
00329 if (mImSetIdxGrid)
00330 mImSetIdxGrid->AddImageSetIdx(mKeyframeSet,imSetId);
00331 }
00332 }
00333 if (mPlotLine1 && i < mLineSize2)
00334 {
00335 int idx = mSimSet->FindQuid(quid);
00336 if ((idx >= 0) && (idx < mSimSet->TableSize()))
00337 mLineData2[i] = simTable->Get1(idx);
00338 else
00339 mLineData2[i] = 0;
00340 if (i<mLineSize1)
00341 mLineData1[i] = mLineData2[i];
00342 }
00343 if (mPlotPoints && mAnno)
00344 {
00345 int x = i%200;
00346 int y = -(i/200);
00347 if (mSelectedRanking->IsPositive(i))
00348 {
00349 mPoints->AddPoint(x, y, 0, 0, 1, 0, 3, false);
00350 nrOk++;
00351 }
00352 else if (mSelectedRanking->IsNegative(i))
00353 mPoints->AddPoint(x, y, 0, 1, 0, 0, 3, false);
00354 else if (mSelectedRanking->IsSkip(i))
00355 mPoints->AddPoint(x, y, 0, 1, 1, 0, 3, false);
00356 else
00357 mPoints->AddPoint(x, y, 0, 0.5, 0.5, 0.5, 3, false);
00358 }
00359 }
00360 if (mImSetIdxGrid)
00361 mImSetIdxGrid->UpdateLayout(true);
00362
00363 ILOG_INFO("4 : " << timer.SplitTime() << " = " << timer.SplitTimeStr());
00364 UpdateLinePlot();
00365 ILOG_INFO("5 : " << timer.SplitTime() << " = " << timer.SplitTimeStr());
00366 UpdatePointPlot();
00367 ILOG_INFO("Skipping judgement for efficiency reasons");
00368
00369
00370
00371
00372
00373
00374
00375
00376
00377
00378
00379
00380
00381
00382
00383
00384
00385
00386 ILOG_INFO("D : " << timer.SplitTime() << " = " << timer.SplitTimeStr());
00387 SetCurrent(mStartIm);
00388 }
00389
00390 virtual void
00391 HandleNewFile()
00392 {
00393 CheckCurrentActual();
00394 if (mAnnoConcept == mCurConcept && mOptionBits == OptionBits() &&
00395 !((mOptionBits&1) && mCurFileId != mDataDoc->CurFileId()))
00396 {
00397 HandleImageSelection(mImageSelected);
00398 return;
00399 }
00400 mOptionBits = OptionBits();
00401 ClearImages();
00402 if (mPlotPoints)
00403 mPoints->Clear();
00404 if ((mSegDoc && !mKeyframes) || !(mKeyframeSet && mSimSet))
00405 return;
00406 HandleUpdate(true);
00407 if (!mPlotPoints)
00408 HandleImageSelection(mImageSelected);
00409 }
00410
00411 int ShowImageInfo(int rankIdx)
00412 {
00413 Quid quid = mSelectedRanking->Get1(rankIdx);
00414 int imSetId = FindImSetId(quid);
00415 SimTableType* simTable = mSimSet->GetSimTable(mCurConcept);
00416 String truth;
00417 if (mAnno)
00418 {
00419 truth = " " + mAnno->GetQualificationString(quid) + " ";
00420 }
00421 if (mCorrections)
00422 {
00423 truth += "corr: " + mCorrections->GetQualificationString(quid) + " ";
00424 }
00425 int idx = mSimSet->FindQuid(quid);
00426 mInfoText->SetText("rank = " + MakeString(rankIdx) +
00427 ", sim = " + MakeString(simTable->Get1(idx))
00428 + " " + truth + mSimSet->GetDescription());
00429 return imSetId;
00430 }
00431
00432 void ShowFloatWnd(Plot::Plot* plot, int idx, double x, double y)
00433 {
00434 if (!mFloatWnd)
00435 return;
00436 ShowImageInfo(idx);
00437 if (mFloatIdx != idx)
00438 {
00439 mFloatWnd->RemoveImages();
00440 Quid quid = mSelectedRanking->Get1(idx);
00441 int imSetId = FindImSetId(quid);
00442 mFloatWnd->AddImage(imSetId,mKeyframeSet);
00443 mFloatIdx = idx;
00444 }
00445 double wX, wY;
00446 plot->Window2Pixel(x,y,wX,wY);
00447 mFloatWnd->SetDimensions(plot->X()+wX+8,
00448 plot->Y()+wY-200,RETAIN,RETAIN);
00449 mFloatWnd->SetVisible(true);
00450 }
00451
00452 void MakePointVisible(int idx)
00453 {
00454 if (!mPlotPoints || idx < 0 || idx >= mPoints->Size())
00455 return;
00456
00457 double px = mPoints->PointX(idx);
00458 double py = mPoints->PointY(idx);
00459 if (mPlotPoints->IsVisible(px,py))
00460 return;
00461 double wX, wY;
00462 mPlotPoints->Window2Pixel(px,py,wX,wY);
00463 if (wX < 0)
00464 wX = 20;
00465 if (wX > mPlotPoints->W())
00466 wX = mPlotPoints->W()-20;
00467 if (wY < 0)
00468 wY = 20;
00469 if (wY > mPlotPoints->H())
00470 wY = mPlotPoints->H()-20;
00471 mPlotPoints->MakeVisibleAtPix(px,py,wX,wY);
00472 }
00473
00474 void HandleImageSelection(int rankIdx)
00475 {
00476 if (rankIdx < 0)
00477 return;
00478 int keyfr = ShowImageInfo(rankIdx);
00479 if (mSegDoc)
00480 mSegDoc->GotoKeyfr(keyfr);
00481 if (mIxsDoc)
00482 mIxsDoc->CursorToFile(keyfr);
00483 SetCurrent(rankIdx);
00484 }
00485
00486 void HandlePlotIdxSelected(int idx)
00487 {
00488 if (idx < 0 || idx >= mSelectedRanking->Size())
00489 return;
00490 if (mImagesSet)
00491 {
00492 if (idx < mStartIm || idx >= mStartIm + mNrToShow)
00493 mShowNextFrom->StartVal(idx);
00494 int nrCol = mImagesSet->W() / (mViewWidth+3);
00495 mImagesSet->SetFirstVisY((idx - mStartIm)/nrCol, true);
00496 }
00497 if (mImSetIdxGrid)
00498 mImSetIdxGrid->SetFirstVisRow(idx);
00499 HandleImageSelection(idx);
00500 }
00501
00502 virtual void
00503 StringSelectionEvent(OglGui::StringSelector* src, int strIndex,
00504 void* listenerData)
00505 {
00506 mDataDoc->SetConcept(strIndex);
00507 if (mShowNextFrom)
00508 mShowNextFrom->StartVal(0);
00509 else
00510 HandleNewFile();
00511 }
00512
00513 virtual void PunsOnlyChanged(PunsOnlyControl *src, void* userData)
00514 {
00515 if (mShowNextFrom)
00516 mShowNextFrom->StartVal(0);
00517 else
00518 HandleNewFile();
00519 }
00520
00521 virtual void
00522 ShowNextFromChanged(ShowNextFromControl *src, void* userData)
00523 {
00524 mOptionBits = -1;
00525 HandleNewFile();
00526 }
00527
00528 virtual void
00529 CheckBoxEvent(OglGui::CheckBox *src, bool checked, void* userData)
00530 {
00531 if (mShowNextFrom)
00532 mShowNextFrom->StartVal(0);
00533 else
00534 HandleNewFile();
00535 }
00536
00537 virtual void
00538 ButtonSelectionEvent(OglGui::Button* src, void* vData)
00539 {
00540 int listenerData = (long long) vData;
00541 HandleCorrection(listenerData);
00542 }
00543
00544 virtual void
00545 ImageSelectionEvent(ImagesWindow* src, int imIndex, void* listenerData)
00546 {
00547 HandleImageSelection(imIndex+mStartIm);
00548 }
00549
00550 virtual void
00551 ImageSelectionEvent(ImageSetIdxGrid* src, int imIndex, void* listenerData)
00552 {
00553 HandleImageSelection(imIndex);
00554 }
00555
00556 virtual void
00557 HandleNewKey(int c, int state)
00558 {
00559 ILOG_DEBUG("HandleNewKey: " << c);
00560 if (c == 'P' && mSegDoc)
00561 {
00562 if (mSegDoc->HasCurShot())
00563 Core::VideoSet::PlayShot(mSegDoc->GetSegmentation(),
00564 mSegDoc->CurShot());
00565 }
00566 if (c == '1')
00567 HandleCorrection(SET_POSITIVE);
00568 if (c == '2')
00569 HandleCorrection(SET_NEGATIVE);
00570 if (c == '3')
00571 HandleCorrection(SET_SKIP);
00572 if (c == '4')
00573 HandleCorrection(DELETE_CORR);
00574 if (c == '5')
00575 HandleCorrection(SAVE_CORR);
00576 }
00577
00578 virtual void
00579 OnMouse(Plot::Plottable *src, double x, double y, int msg, int but,
00580 int state, void *userData)
00581 {
00582 if (mFloatWnd)
00583 mFloatWnd->SetVisible(false);
00584
00585 if (state & (oglShift | oglControl))
00586 return;
00587
00588 Plot::Plot* plot=0;
00589 int idx;
00590 bool validIdx = false;
00591
00592 if (mPlotPoints && (mPlotPoints == (Plot::Plot*)userData))
00593 {
00594 plot = mPlotPoints;
00595 idx = ((int)(x+.5)) % 200 - 200 * ((int)(y-0.5));
00596 validIdx = x>=-0.5 && x <= 200.5 &&
00597 idx >= 0 && idx < mSelectedRanking->Size();
00598 }
00599 if (mPlotLine2 && (mPlotLine2 == (Plot::Plot*)userData))
00600 {
00601 plot = mPlotLine2;
00602 idx = x;
00603 validIdx = idx >= 0 && idx < mSelectedRanking->Size();
00604 }
00605 if (msg == oglMouseUp)
00606 {
00607 if (but==oglLeftButton && !(state&oglRightButton) && validIdx)
00608 HandlePlotIdxSelected(idx);
00609 else
00610 HandleImageSelection(mImageSelected);
00611 }
00612 else if (validIdx && (state & (oglRightButton | oglLeftButton)))
00613 ShowFloatWnd(plot,idx,x,y);
00614 if (validIdx && (state & oglAlt))
00615 HandlePlotIdxSelected(idx);
00616 }
00617
00618 private:
00619
00620 int
00621 FindImSetId(Quid quid)
00622 {
00623 if (mSegDoc && QuidClass(quid) == QUID_CLASS_FRAME)
00624 {
00625 return mKeyframes->GetFrameId(quid);
00626 }
00627 if (mSegDoc && QuidClass(quid) == QUID_CLASS_SHOT)
00628 {
00629 int shotId = mSegDoc->GetSegmentation()->GetShotId(quid);
00630 return mKeyframes->GetShotRKF(shotId);
00631 }
00632 if (mIxsDoc && QuidClass(quid) == QUID_CLASS_IMAGE)
00633 {
00634 Core::ImageSet::ImageSet* imSet = mIxsDoc->GetImageSet();
00635 return (int) (imSet ? (quid & QUID_ID_MASK) : -1);
00636 }
00637
00638 return -1;
00639 }
00640
00641 void
00642 HandleCorrection(int code)
00643 {
00644 if (mCorrections == 0)
00645 {
00646 ILOG_ERROR("No corrections");
00647 return;
00648 }
00649 if (code == SAVE_CORR)
00650 {
00651 SaveCorrections();
00652 return;
00653 }
00654 if (mImageSelected == -1)
00655 {
00656 ILOG_ERROR("No image selected");
00657 return;
00658 }
00659 Quid quid = mSelectedRanking->Get1(mImageSelected);
00660 int cIndex = mCorrections->GetIndex(quid);
00661 int rIndex = mQualifiedRanking->GetIndex(quid);
00662 if (rIndex == mQualifiedRanking->Size())
00663 {
00664 ILOG_ERROR("HandleCorrection: Logic error");
00665 }
00666 if (code == DELETE_CORR)
00667 {
00668 if (cIndex == mCorrections->Size())
00669 {
00670 ILOG_ERROR("HandleCorrection: cannot find correction");
00671 }
00672 else
00673 {
00674 Core::Table::RemoveRow(mCorrections, cIndex);
00675 mQualifiedRanking->Set2(rIndex, mAnno->GetQualification(quid));
00676 }
00677 }
00678 else if (cIndex == mCorrections->Size())
00679 {
00680 if (code == SET_POSITIVE)
00681 {
00682 mCorrections->AddPositive(quid);
00683 mQualifiedRanking->SetPositive(rIndex);
00684 }
00685 else if (code == SET_NEGATIVE)
00686 {
00687 mCorrections->AddNegative(quid);
00688 mQualifiedRanking->SetNegative(rIndex);
00689 }
00690 else
00691 {
00692 mCorrections->AddSkip(quid);
00693 mQualifiedRanking->SetSkip(rIndex);
00694 }
00695 }
00696 else
00697 {
00698 if (code == SET_POSITIVE)
00699 {
00700 mCorrections->SetPositive(cIndex);
00701 mQualifiedRanking->SetPositive(rIndex);
00702 }
00703 else if (code == SET_NEGATIVE)
00704 {
00705 mCorrections->SetNegative(cIndex);
00706 mQualifiedRanking->SetNegative(rIndex);
00707 }
00708 else
00709 {
00710 mCorrections->SetSkip(cIndex);
00711 mQualifiedRanking->SetSkip(rIndex);
00712 }
00713 }
00714
00715 int curImage = mImageSelected;
00716 ClearImages();
00717 if (mPlotPoints)
00718 mPoints->Clear();
00719 HandleUpdate(false);
00720 HandlePlotIdxSelected(curImage);
00721 }
00722
00723 void
00724 SaveCorrections()
00725 {
00726 Core::Database::RawDataSet* dataSet = mDataDoc->GetDataSet();
00727 int qClass = mSimSet->GetQuidClass();
00728 typedef Persistency::AnnotationTableLocator Loc;
00729 String concept = mCorrections->GetLabel();
00730 Loc cLoc(dataSet->GetLocator(), qClass, mCorrectionSet, concept);
00731 ILOG_INFO("Saving corrections for " << concept);
00732 Persistency::AnnotationTableRepository().Replace(cLoc, mCorrections);
00733 }
00734
00735 void
00736 UpdateAnno()
00737 {
00738 if (mAnnoSet.empty())
00739 {
00740 Core::Table::Copy(mQualifiedRanking,
00741 mSimSet->GetRankTable(mCurConcept));
00742 return;
00743 }
00744 if (mAnnoConcept == mCurConcept)
00745 return;
00746
00747 if (mAnno)
00748 {
00749 delete mAnno;
00750 mAnno = 0;
00751 }
00752 if (mCorrections)
00753 {
00754 SaveCorrections();
00755 delete mCorrections;
00756 mCorrections = 0;
00757 }
00758
00759 Core::Database::RawDataSet* dataSet = mDataDoc->GetDataSet();
00760 int qClass = mSimSet->GetQuidClass();
00761 typedef Persistency::AnnotationTableLocator Loc;
00762 String concept = mDataDoc->GetConcept();
00763 Loc aLoc(dataSet->GetLocator(), qClass, mAnnoSet, concept);
00764 if (! Persistency::AnnotationTableRepository().Exists(aLoc))
00765 {
00766 ILOG_ERROR("No annations for " << concept);
00767 mAnnoConcept = -2;
00768 Core::Table::Copy(mQualifiedRanking,
00769 mSimSet->GetRankTable(mCurConcept));
00770 return;
00771 }
00772 mAnno = Persistency::AnnotationTableRepository().Get(aLoc);
00773
00774 if (!mCorrectionSet.empty())
00775 {
00776 aLoc.SetConceptSet(mCorrectionSet);
00777 if (Persistency::AnnotationTableRepository().Exists(aLoc))
00778 {
00779 ILOG_INFO("Loading corrections for " << concept);
00780 mCorrections = Persistency::AnnotationTableRepository().Get(aLoc);
00781 }
00782 else
00783 {
00784 ILOG_INFO("No existing corrections for " << concept);
00785 mCorrections = new AnnotationTable(concept, 0);
00786 }
00787 }
00788
00789 mAnnoConcept = mCurConcept;
00790 Core::Table::Copy(mQualifiedRanking, mSimSet->GetRankTable(mCurConcept));
00791 for (int i=0 ; i<mQualifiedRanking->Size() ; i++)
00792 {
00793 Quid quid = mQualifiedRanking->Get1(i);
00794 mQualifiedRanking->Set2(i, mAnno->GetQualification(quid));
00795 if (mCorrections)
00796 {
00797 int index = mCorrections->GetIndex(quid);
00798 if (index != mCorrections->Size())
00799 mQualifiedRanking->Set2(i, mCorrections->Get2(index));
00800 }
00801 }
00802 }
00803
00804 int OptionBits()
00805 {
00806 int bits = 0;
00807 if (mVideoCheckBox->GetSelected())
00808 bits |= 1;
00809 if (mPunsOnly->PositiveCheckBox()->GetSelected())
00810 bits |= 2;
00811 if (mPunsOnly->NegativeCheckBox()->GetSelected())
00812 bits |= 4;
00813 if (mPunsOnly->SkipCheckBox()->GetSelected())
00814 bits |= 8;
00815 if (mRkfCheckBox->GetSelected())
00816 bits |= 16;
00817 return bits;
00818 }
00819
00820 void
00821 UpdateRanking()
00822 {
00823 using Core::Table::CriterionQuidObjectEquals;
00824 using Core::Table::CriterionElement2Equals;
00825 Core::Table::Copy(mSelectedRanking, mQualifiedRanking);
00826 if (mSegDoc && mVideoCheckBox->GetSelected())
00827 {
00828 CriterionQuidObjectEquals<AnnotationTable> crit(mDataDoc->CurFileId());
00829 Core::Table::Select(mSelectedRanking, mSelectedRanking, crit, true);
00830 }
00831 if (mPunsOnly->PositiveCheckBox()->GetSelected())
00832 {
00833 CriterionElement2Equals<AnnotationTable> crit(1.0);
00834 Core::Table::Select(mSelectedRanking, mSelectedRanking, crit, true);
00835 }
00836 if (mPunsOnly->NegativeCheckBox()->GetSelected())
00837 {
00838 CriterionElement2Equals<AnnotationTable> crit(-1.0);
00839 Core::Table::Select(mSelectedRanking, mSelectedRanking, crit, true);
00840 }
00841 if (mPunsOnly->SkipCheckBox()->GetSelected())
00842 {
00843 CriterionElement2Equals<AnnotationTable> crit(0.0);
00844 Core::Table::Select(mSelectedRanking, mSelectedRanking, crit, true);
00845 }
00846 if (mSegDoc && mRkfCheckBox->GetSelected())
00847 {
00848 bool* filter = new bool[mSelectedRanking->Size()];
00849 for (int i=0 ; i<mSelectedRanking->Size() ; i++)
00850 {
00851 Quid q = mSelectedRanking->Get1(i);
00852 int keyId = mKeyframes->GetFrameId(q);
00853 filter[i] = mKeyframes->IsRKF(keyId);
00854 }
00855 Core::Table::Select(mSelectedRanking, mSelectedRanking, filter, true);
00856 delete filter;
00857 }
00858 int nrIm = mSelectedRanking->Size();
00859 if (mImagesSet)
00860 {
00861 mShowNextFrom->MaxVal(nrIm);
00862 mStartIm = mShowNextFrom->StartVal();
00863 mNrToShow = mShowNextFrom->NrToShow();
00864 }
00865 if (mIdxGridTotalTxt)
00866 mIdxGridTotalTxt->SetText("Total: " + MakeString(nrIm));
00867 }
00868
00869 void
00870 UpdateLineSize(int nrCandidates)
00871 {
00872 if (!mPlotLine1)
00873 return;
00874 mLineSize1 = Min(50, nrCandidates);
00875 mLineSize2 = Min(1000, nrCandidates);
00876 if (mLineData1)
00877 delete mLineData1;
00878 if (mLineData2)
00879 delete mLineData2;
00880 mLineData1 = new double[mLineSize1];
00881 mLineData2 = new double[mLineSize2];
00882 }
00883
00884 void
00885 UpdateLinePlot()
00886 {
00887 if (!mPlotLine1)
00888 return;
00889
00890 mLine1->SetData(mLineData1, mLineSize1);
00891 mLine1->SetDomain(0, mLineSize1);
00892 if (mLineSize1 > 1)
00893 mPlotLine1->AutoScale();
00894
00895 mLine2->SetData(mLineData2, mLineSize2);
00896 mLine2->SetDomain(0, mLineSize2);
00897 mLine2->UpdateDimensionsY();
00898 double minY, maxY;
00899 mLine2->GetDimensionsY(minY,maxY);
00900 mNeedle2->SetDimensionsY(minY,maxY);
00901 if (mLineSize2 > 1)
00902 mPlotLine2->AutoScale();
00903 }
00904
00905 void
00906 UpdatePointPlot()
00907 {
00908 if (!mPlotPoints)
00909 return;
00910
00911 mPoints->UpdateDimensions();
00912 mPlotPoints->SetCenter(100, mSegDoc ? -40 : -12.5, 0);
00913 mPlotPoints->SetRange(200, mSegDoc ? 80 : 25, 0);
00914 }
00915
00916 void SetCurrent(int idx)
00917 {
00918 mImageSelected = idx;
00919 if (mImagesSet)
00920 mImagesSet->SetImageSelected(mImageSelected-mStartIm);
00921 if (mImSetIdxGrid)
00922 mImSetIdxGrid->SetSelected(mImageSelected);
00923 if (mPlotPoints)
00924 {
00925 mPoints->HighLightPoint(idx);
00926 MakePointVisible(idx);
00927 }
00928 if (mPlotLine2)
00929 mNeedle2->MoveTo(idx);
00930 }
00931
00932 DataDocument* mDataDoc;
00933 SegmentationDocument* mSegDoc;
00934 IxsDocument* mIxsDoc;
00935
00936 SimilarityTableSet* mSimSet;
00937 String mAnnoSet;
00938 String mCorrectionSet;
00939 int mCurConcept;
00940 AnnotationTable* mAnno;
00941 int mAnnoConcept;
00942 AnnotationTable* mCorrections;
00943 AnnotationTable* mQualifiedRanking;
00944
00945 AnnotationTable* mSelectedRanking;
00946 Core::VideoSet::Keyframes* mKeyframes;
00947 Core::ImageSet::ImageSet* mKeyframeSet;
00948
00949 int mLineSize1;
00950 int mLineSize2;
00951 double* mLineData1;
00952 double* mLineData2;
00953 Visualization::Plot::Line* mLine1;
00954 Visualization::Plot::Line* mLine2;
00955 Plot::PlotNeedle* mNeedle2;
00956
00957 Visualization::Plot::Plot* mPlotLine1;
00958 Visualization::Plot::Plot* mPlotLine2;
00959 Plot::Points* mPoints;
00960 Plot::Plot* mPlotPoints;
00961
00962 ImagesWindow* mFloatWnd;
00963 int mFloatIdx;
00964
00965 OglGui::StringSelector* mStringSelector;
00966 OglGui::TextArea* mInfoText;
00967 OglGui::CheckBox* mVideoCheckBox;
00968 OglGui::CheckBox* mRkfCheckBox;
00969 OglGui::TextArea* mVideoText;
00970
00971 PunsOnlyControl* mPunsOnly;
00972 ShowNextFromControl* mShowNextFrom;
00973
00974 ImageSetIdxGridScroller* mImSetIdxGridScroller;
00975 ImageSetIdxGrid* mImSetIdxGrid;
00976 OglGui::StaticText* mIdxGridTotalTxt;
00977
00978 ImageSet* mImagesSet;
00979 int mImageSelected;
00980 int mStartIm;
00981 int mNrToShow;
00982 int mViewWidth;
00983
00984 int mOptionBits;
00985 int mCurFileId;
00986
00987 ILOG_VAR_DEC;
00988 };
00989
00990 ILOG_VAR_INIT(SimilarityTableSetRank, Visualization);
00991
00992
00993 }
00994 }
00995
00996 #endif