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

SimilarityTableSetRank.h

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

Generated on Fri Mar 19 09:31:54 2010 for ImpalaSrc by  doxygen 1.5.1