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

SegmentationDocumentGuiAnno.h

Go to the documentation of this file.
00001 //345678901234567890123456789012345678901234567890123456789012345678901234567890
00002 #ifndef Impala_Visualization_SegmentationDocumentGuiAnno_h
00003 #define Impala_Visualization_SegmentationDocumentGuiAnno_h
00004 
00005 //#include "OglGui/SplashScreenWoggel.h"
00006 
00007 #include "Persistency/Mpeg7DocRepository.h"
00008 #include "Persistency/SimilarityTableSetRepository.h"
00009 #include "Core/VideoSet/SegmentationDocument.h"
00010 #include "Core/VideoSet/Mpeg7DocWrite.h"
00011 #include "Core/Stream/RgbDataSrcFactory.h"
00012 #include "Core/Stream/RgbDataSrcRaw.h"
00013 #include "Core/Table/SimilarityTableSet.h"
00014 
00015 #include "Visualization/SimilarityTimeLineVideo.h"
00016 #include "Visualization/ImageStrip.h"
00017 #include "Visualization/ImageSet.h"
00018 #include "Visualization/DataDocumentGui.h"
00019 
00020 #include "OglGui/TextArea.h"
00021 #include "OglGui/Strut.h"
00022 #include "OglGui/Button.h"
00023 #include "OglGui/ValueScrollBar.h"
00024 #include "OglGui/UpDownNumber.h"
00025 
00026 namespace Impala {
00027 namespace Visualization {
00028 
00029 class SegmentationDocumentGuiAnno :
00030             public DataDocumentGui<Core::VideoSet::SegmentationDocument>,
00031             public ImagesListener,
00032             public OglGui::ViewListener,
00033             public OglGui::WindowListener,
00034             public OglGui::CheckBoxListener,
00035             public OglGui::ValueScrollBarListener,
00036             public OglGui::UpDownButtonListener,
00037             public OglGui::UpDownNumberListener
00038 {
00039     static const int BUT_POSITIVE               = 100;
00040     static const int BUT_SKIP                   = 101;
00041     static const int BUT_NEGATIVE               = 102;
00042     static const int BUT_SAVE                   = 103;
00043     static const int BUT_BACK                   = 104;
00044     static const int BUT_FORW                   = 105;
00045     static const int BUT_SHOT_POS               = 106;
00046     static const int BUT_SHOT_NEG               = 107;
00047     static const int BUT_LEFT_SHOT              = 108;
00048     static const int BUT_RIGHT_SHOT             = 109;
00049     static const int BUT_SYNC                   = 110;
00050     static const int VIEWSTRIP_PRE              = 111;
00051     static const int VIEWSTRIP_MIN              = 112;
00052     static const int VIEWSTRIP_MAX              = 113;
00053     static const int BUT_NAV_MODE               = 114;
00054     static const int BUT_NAV_BEGIN              = 115;
00055     static const int BUT_NAV_END                = 116;
00056     static const int BUT_RANK_ALL               = 117;
00057     static const int BUT_RANK_NOT_ANN           = 118;
00058 
00059     static const int UPDOWNBUT_POSITIVE         = 130;
00060     static const int UPDOWNBUT_SKIPPED          = 131;
00061     static const int UPDOWNBUT_NEGATIVE         = 132;
00062     static const int UPDOWNBUT_UNKNOWN          = 133;
00063 
00064     static const int CHBOX_RANK_MODE            = 203;
00065     static const int CHBOX_SHOW_THRESH_SHOTS    = 204;
00066     static const int CHBOX_SHOW_SEG_SHOTS       = 205;
00067     static const int CHBOX_PN_IN_VIDEO          = 206;
00068 
00069     static const int UNKNOWN_BIT                = 1;
00070     static const int POSITIVE_BIT               = 2;
00071     static const int SKIPPED_BIT                = 4;
00072     static const int NEGATIVE_BIT               = 8;
00073 
00074 public:
00075 
00076     typedef std::vector<UCHAR>                      VideoAnnotation;
00077     typedef std::vector<VideoAnnotation*>           VideoAnnotations;
00078 
00079     typedef Core::VideoSet::SegmentationDocument    SegmentationDocument;
00080     typedef Core::VideoSet::Segmentation            Segmentation;
00081     typedef Core::Array::Array2dVec3UInt8           Array2dVec3UInt8;
00082     typedef Core::VideoSet::Mpeg7Doc                Mpeg7Doc;
00083     typedef Core::Stream::RgbDataSrc                RgbDataSrc;
00084     typedef Core::Stream::RgbDataSrcRaw             RgbDataSrcRaw;
00085     typedef Core::Stream::RgbDataSrcFactory         RgbDataSrcFactory;
00086     typedef Core::Table::SimilarityTableSet         SimilarityTableSet;
00087 
00088     typedef Visualization::SimilarityTimeLineVideo  SimilarityTimeLineVideo;
00089 
00090     typedef SimilarityTableSet::SimTableType        SimTableType;
00091     typedef SimilarityTableSet::RankTableType       RankTableType;
00092 
00093     typedef OglGui::TitledWindow                    TitledWindow;
00094     typedef OglGui::Button                          Button;
00095     typedef OglGui::StaticText                      StaticText;
00096     typedef OglGui::TextArea                        TextArea;
00097     typedef OglGui::CheckBox                        CheckBox;
00098     typedef OglGui::UpDownButton                    UpDownButton;
00099     typedef OglGui::UpDownNumber                    UpDownNumber;
00100     typedef OglGui::ValueScrollBar                  ValueScrollBar;
00101     typedef OglGui::Strut                           Strut;
00102 
00103     struct AnnoHistory {
00104         int fileIdx;
00105         int frameIdx;
00106         int rankIdx;
00107     };
00108 
00109     SegmentationDocumentGuiAnno(OglGui::Window* parent, int wndWidth,
00110                   int wndHeight, SegmentationDocument* segDoc,
00111                   String conceptSet, int maxAnnoPerVideo,
00112                               int controlId) :
00113         DataDocumentGui<SegmentationDocument>(parent, wndWidth, wndHeight,
00114                                               segDoc, controlId, true,
00115                                               false, false, 2, 4, true,
00116                                               false)
00117     {
00118         Init(segDoc, conceptSet, maxAnnoPerVideo);
00119     }
00120 
00121     virtual void HandleActivate()
00122     {
00123         mNoAutoNextAnno = true;
00124         AppControlDoc::HandleActivate();
00125         mNoAutoNextAnno = false;
00126     }
00127     
00128     virtual void
00129     HandleNewFile()
00130     {
00131         DataDocumentGui<SegmentationDocument>::HandleNewFile();
00132         int oldCurFile = mCurFile;
00133         CheckLoadMpeg7();
00134 
00135         if (mAnnoSearching)
00136             return;
00137 
00138         // RvB ShotSimilarWnd: oldCurFile because CheckLoadMpeg7 sets curFile
00139         CheckNewVideo(oldCurFile);
00140         HandleNewShot();
00141         if (mRankingMode)
00142             CheckAnnoMax();
00143     }
00144 
00145     virtual void
00146     HandleNewShot()
00147     {
00148         if (mAnnoSearching)
00149             return;
00150         mImWnd->RemoveImages();
00151         mImShotWnd->RemoveImages();
00152         mCurShotFrames.clear();
00153 
00154         mFrameText->SetText("");
00155         if (!(mKeyframes && mKeyframeSet))
00156             return;
00157         int shot = mSegDoc->CurShot();
00158         if (shot == -1)
00159             return;
00160 
00161         // Line below conflicts with annotations
00162         // as annotations only work based on RKF keyframes
00163         // if ((mCurKey = mSegDoc->CurKeyfr())==-1)
00164             mCurKey = mKeyframes->GetShotRKF(shot);
00165         mImWnd->AddImage(mCurKey, mKeyframeSet);
00166 
00167         int frame = mKeyframes->GetFrameNr(mCurKey);
00168         int firstFrame = -1, lastFrame = -1;
00169                 int     idx = -1;
00170             if (mCurMpeg7)
00171             {
00172             idx = mCurMpeg7->FindShot(frame);
00173             if (idx != -1)
00174             {
00175                 firstFrame = mCurMpeg7->StartFrame(idx);
00176                 lastFrame  = mCurMpeg7->EndFrame(idx);
00177             }
00178             }
00179         if (firstFrame == lastFrame)
00180         {
00181             if ((shot = FindFrameShot(frame))==-1)
00182                 return;
00183             firstFrame = mShots[shot]+1;
00184             lastFrame  = mShots[shot+((shot<mShots.size()-1) ? 1 : 0)];
00185         }
00186         FillShotSample(firstFrame, lastFrame, frame);
00187         UpdateRelevance();
00188         if (mSimTLV)
00189         {
00190             if (mAllowSlidingChBox)
00191                 mFrameSliding = mAllowSlidingChBox->GetSelected();
00192             if (mFrameSliding)
00193                 mSimTLV->Player()->MoveToFrame(frame);
00194             else
00195                 mSimTLV->Player()->GotoFrame(frame);
00196         }
00197     }
00198 
00199     void FillShotSample(int firstFrame, int lastFrame, int curFrame)
00200     {
00201         if (firstFrame > curFrame)
00202             firstFrame = curFrame;
00203         if (lastFrame < curFrame)
00204             lastFrame = curFrame;
00205         if (firstFrame > lastFrame)
00206         {
00207             int tmp = lastFrame;
00208             lastFrame = firstFrame;
00209             firstFrame = tmp;
00210         }
00211         mImShotWnd->RemoveImages();
00212         mCurShotFrames.clear();
00213         if (mRgbDataSrc && firstFrame < lastFrame)
00214         {
00215             if (mShotValueSB)
00216             {
00217                 mShotValueSB->SetVisible(true);
00218                 mShotValueSB->SetMinMaxValue(firstFrame, lastFrame);
00219             }
00220 
00221             int nrShotFrames = lastFrame-firstFrame;
00222             if (nrShotFrames > 1)
00223             {
00224                 float step = (nrShotFrames<5)? 1.f : nrShotFrames/4.f;
00225                 for (float i=firstFrame; i<=lastFrame; i += step)
00226                     ToShotWindow(i,((int)i)==curFrame);
00227             }
00228         }
00229     }
00230 
00231     void ToShotWindow(int idx, bool isKeyFrame=false)
00232     {
00233         char buf[60];
00234         sprintf(buf,isKeyFrame?"%d (*)" : "%d", idx);
00235         Array2dVec3UInt8* arrIm = GetFrameArrIm(idx);
00236         mImShotWnd->AddImage(arrIm,"Direct",buf,true,false);
00237         mCurShotFrames.push_back(idx);
00238     }
00239 
00240 
00241     VideoAnnotations* GetVideoAnnotations()
00242     {
00243         return &mVideoAnnotations;
00244     }
00245 
00246 
00247     Array2dVec3UInt8* GetFrameArrIm(int frameNr)
00248     {
00249         if (!mRgbDataSrc)
00250             return 0;
00251 
00252         int imW = mRgbDataSrc->FrameWidth();
00253         int imH = mRgbDataSrc->FrameHeight();
00254             Array2dVec3UInt8* ar =
00255             new Array2dVec3UInt8(imW, imH, 0, 0, 0, false);
00256         mRgbDataSrc->GotoFrame(frameNr);
00257             memcpy( (void *) ar->CPB(0, 0), mRgbDataSrc->DataPtr(), imW*imH*3 );
00258         return ar;
00259     }
00260 
00261     virtual void
00262     HandleNewConcept()
00263     {
00264         mNrAnnotated = 0;
00265         mNrPositive = 0;
00266         mNrSkip = 0;
00267         mNrNegative = 0;
00268 
00269         CheckLoadVideoAnnotations();
00270         CheckLoadMpeg7();
00271         ConstructShotRanking(!mRankAll);
00272         HandleNewShot();
00273     }
00274 
00275     virtual void
00276     HandleLoadConcepts(String fileName, bool handleNew=true)
00277     {
00278         mConceptSet = fileName;
00279         if (mConceptSet.empty())
00280             return;
00281         mSegDoc->LoadConcepts(fileName);
00282         if (mSegDoc->HasConcepts())
00283         {
00284             mSegDoc->SetConcept(0);
00285             mConceptField->SetText(mSegDoc->GetConcept());
00286             if (handleNew)
00287                 HandleNewConcept();
00288         }
00289     }
00290 
00291     virtual void
00292     HandleSaveConcepts(String fileName)
00293     {
00294         mConceptSet = fileName;
00295         if (mConceptSet.empty())
00296             return;
00297         mSegDoc->SaveConcepts(fileName);
00298     }
00299 
00300     // Find shot of frame in thresholded shots
00301     int FindFrameShot(int frame)
00302     {
00303         int     i;
00304         for (i=0; i<mShots.size(); i++)
00305             if (mShots[i] >= frame)
00306                 return i==0 ? 0 : i-1;
00307         return -1;
00308     }
00309 
00310     // Find shot of frame in segmentation document shots
00311     int FindSegFrameShot(int frame)
00312     {
00313         Segmentation* seg       = mSegDoc->GetSegmentation();
00314         int           firstShot = seg->GetFirstShotVideo(mCurFile);
00315         int           lastShot  = firstShot+seg->GetNrShotsVideo(mCurFile);
00316         int               i;
00317 
00318         for (i=firstShot; i<lastShot; i++)
00319             if (seg->GetStart(i) > frame)
00320                 break;
00321         return i==firstShot ? i : i-1;
00322     }
00323 
00324     int FindAdjacentAnnoShot(int curFile, int bit, int shotIdx, bool next)
00325     {
00326         if (curFile == -1) return -1;
00327 
00328         Segmentation* seg         = mSegDoc->GetSegmentation();
00329         int           firstShot   = seg->GetFirstShotVideo(curFile);
00330         int           sz          = seg->GetNrShotsVideo(curFile);
00331         int           lastShot    = firstShot+sz;
00332         int           foundShotNr = -1;
00333 
00334         for (int i=firstShot; i<lastShot; i++)
00335         {
00336             int   kFrame   = mKeyframes->GetShotRKF(i);
00337             int   frame    = mKeyframes->GetFrameNr(kFrame);
00338             int   val      = (*mVideoAnnotations[curFile])[i-firstShot];
00339             bool  unknown  = (val == 0);
00340             bool  skipped  = (val == SKIPPED_BIT);
00341             bool  positive = (val == POSITIVE_BIT);
00342             bool  negative = (val == NEGATIVE_BIT);
00343             bool  passTest = ((bit==POSITIVE_BIT) && positive ||
00344                              (bit==NEGATIVE_BIT) && negative ||
00345                              (bit==SKIPPED_BIT)  && skipped  ||
00346                              (bit==UNKNOWN_BIT)  && unknown);
00347             if (passTest && next && i > shotIdx)
00348                 return i;
00349             if (i!=shotIdx && passTest && !next)
00350                 foundShotNr = i;
00351             if (!next && i>=shotIdx)
00352                 return foundShotNr;
00353         }
00354         return foundShotNr;
00355     }
00356 
00357     int FindAdjacentAnnoShot(int bit, int shotIdx, bool next)
00358     {
00359         return FindAdjacentAnnoShot(mCurFile,bit,shotIdx,next);
00360     }
00361 
00362     bool GoToAdjacentAnnoShot(int bit, int shotIdx, bool next)
00363     {
00364         int shot;
00365         if ((shot=FindAdjacentAnnoShot(bit,shotIdx,next))==-1)
00366             return false;
00367         mSegDoc->GotoShot(shot);
00368         AllHandleNewCursor(Core::Database::LEVEL_SHOT, false);
00369         return true;
00370     }
00371 
00372     int FindNextAnno(int bit, bool next, bool stayInVideo)
00373     {
00374         Segmentation* seg        = mSegDoc->GetSegmentation();
00375         int           nrVideos   = seg->GetNrVideos();
00376         int           curShot    = mSegDoc->CurShot();
00377         int           curFile    = mCurFile;
00378 curFile = mSegDoc->CurFileId();
00379         int           shot;
00380 
00381         if ((shot=FindAdjacentAnnoShot(curFile,bit,curShot,next))!=-1)
00382             return curFile * 100000 + shot;
00383         if (stayInVideo)
00384             return -1;
00385 
00386         if (next) while (++curFile < nrVideos)
00387         {
00388             int firstShot = seg->GetFirstShotVideo(curFile);
00389             if ((shot = FindAdjacentAnnoShot(curFile,bit,firstShot-1,true))!=-1)
00390                 return curFile * 100000 + shot;
00391         }
00392         else while(--curFile >= 0)
00393         {
00394             int firstShot = seg->GetFirstShotVideo(curFile);
00395             int lastShot = firstShot+seg->GetNrShotsVideo(curFile);
00396             if ((shot = FindAdjacentAnnoShot(curFile,bit,lastShot,false))!=-1)
00397                 return curFile * 100000 + shot;
00398         }
00399         return -1;
00400     }
00401 
00402     void GoToNextAnno(int bit, bool next, bool stayInVideo)
00403     {
00404         int res = FindNextAnno(bit,next,stayInVideo);
00405         if (res != -1)
00406         {
00407             AllHandleNewCursor(mSegDoc->CursorToFile(res/100000),false);
00408             mSegDoc->GotoShot(res%100000);
00409             AllHandleNewCursor(Core::Database::LEVEL_SHOT,false);
00410         }
00411     }
00412 
00413 
00414     void Synchronize(int kf=-1)
00415     {
00416         if (kf==-1) kf = 0;
00417         int frame = mSimTLV ? mSimTLV->Player()->FrameNr() : kf;
00418         int shot = FindSegFrameShot(frame);
00419         int kFrame = mKeyframes->GetShotRKF(shot);
00420         mSegDoc->GotoKeyfr(kFrame);
00421         AllHandleNewCursor(Core::Database::LEVEL_SHOT, false);
00422     }
00423 
00424     // Shot boundary editing
00425     void AdjustAnnoBoundary(int lData)
00426     {
00427         int frame = mSimTLV->Player()->FrameNr();
00428         int lFrame, rFrame;
00429         int kFrame = ((mCurKey!=-1) ? mKeyframes->GetFrameNr(mCurKey) : 0);
00430 
00431         mShotValueSB->GetMinMaxValue(lFrame, rFrame);
00432         if (lData==BUT_LEFT_SHOT)
00433             FillShotSample(frame, rFrame, kFrame);
00434         else
00435             FillShotSample(lFrame, frame, kFrame);
00436     }
00437 
00438     void SetRankingMode(bool mode)
00439     {
00440         mRankingMode = mSimSet ? mode : false;
00441         mNavModeBtn->SetText(mRankingMode ? "R" : "S");
00442         PrevNextAnnoControlFeedBack();
00443     }
00444 
00445     void GoToCurrentRank()
00446     {
00447         if (mRankedShots.size())
00448         {
00449             mSegDoc->GotoShot(mRankedShots[mCurRankShot]);
00450             AllHandleNewCursor(Core::Database::LEVEL_SHOT, false);
00451         }
00452     }
00453 
00454     void ToggleNavigationMode()
00455     {
00456         SetRankingMode(mNavModeBtn->GetText() == "S");
00457         if (mRankingMode)
00458             GoToCurrentRank();
00459     }
00460 
00461     void NavigateExtremes(bool toStart)
00462     {
00463         int shot = 0;
00464 
00465         if (mRankingMode && mRankedShots.size())
00466         {
00467             if ((mCurRankShot = toStart ? 0 : mRankedShots.size()-1)!=-1)
00468                 shot = mRankedShots[mCurRankShot];
00469         }
00470         else
00471         {
00472             Segmentation* seg = mSegDoc->GetSegmentation();
00473             shot =  seg->GetFirstShotVideo(mCurFile);
00474             if (!toStart)
00475                 shot += seg->GetNrShotsVideo(mCurFile)-1;
00476         }
00477         mSegDoc->GotoShot(shot);
00478         AllHandleNewCursor(Core::Database::LEVEL_SHOT, false);
00479     }
00480 
00482 // Event handling stuff
00483     virtual void
00484     ButtonSelectionEvent(Button* src, void* vData)
00485     {
00486         DataDocumentGui<SegmentationDocument>::ButtonSelectionEvent(src, vData);
00487         int lData = (int)((long long) vData);
00488         switch (lData)
00489         {
00490         case BUT_POSITIVE:
00491             DoAnno(1,false);
00492             break;
00493         case BUT_SKIP:
00494             DoAnno(0.5,false);
00495             break;
00496         case BUT_NEGATIVE:
00497             DoAnno(0,false);
00498             break;
00499         case BUT_SHOT_POS:
00500             DoAnno(1,true);
00501             break;
00502         case BUT_SHOT_NEG:
00503             DoAnno(0,true);
00504             break;
00505         case BUT_NAV_MODE:
00506             ToggleNavigationMode();
00507             break;
00508         case BUT_NAV_BEGIN:
00509         case BUT_NAV_END:
00510             NavigateExtremes(lData==BUT_NAV_BEGIN);
00511             break;
00512         case BUT_BACK:
00513             GoBack();
00514             break;
00515         case BUT_FORW:
00516             GoForw(true);
00517             break;
00518         case BUT_SAVE:
00519             CheckSaveMpeg7(false);
00520             break;
00521         case BUT_SYNC:
00522             Synchronize();
00523             break;
00524         case BUT_LEFT_SHOT:
00525         case BUT_RIGHT_SHOT:
00526             AdjustAnnoBoundary(lData);
00527             break;
00528         case VIEWSTRIP_PRE:
00529         case VIEWSTRIP_MIN:
00530         case VIEWSTRIP_MAX:
00531             mSimTLV->TimeLine()->ViewStripZoomToShowViews(lData-VIEWSTRIP_PRE);
00532         break;
00533         case BUT_RANK_ALL:
00534         case BUT_RANK_NOT_ANN:
00535             ConstructShotRanking(lData==BUT_RANK_NOT_ANN);
00536             SetRankingMode(true);
00537             if (mRankingMode)
00538                 GoToCurrentRank();
00539         break;
00540 /*
00541         case 1234:
00542             HandlePUNS();
00543         break;
00544 */
00545         } // end switch
00546         
00547     }
00548     virtual void
00549     HandleNewKey(int c, int state)
00550     {
00551         ILOG_DEBUG("HandleNewKey: " << c);
00552         if (CheckBinding("annoPositive",c,state))
00553             DoAnno(1,false);
00554         if (CheckBinding("annoSkip",c,state))
00555             DoAnno(0.5,false);
00556         if (CheckBinding("annoNegative",c,state))
00557             DoAnno(0,false);
00558         if (CheckBinding("annoShotPositive",c,state))
00559             DoAnno(1,true);
00560         if (CheckBinding("annoShotNegative",c,state))
00561             DoAnno(0,true);
00562         if (CheckBinding("annoBackward",c,state) || (mRankingMode && c==oglLEFT))
00563             GoBack();
00564         if (CheckBinding("annoForward",c,state) || (mRankingMode && c==oglRIGHT))
00565             GoForw(true);
00566         if (c == oglHOME || c == oglEND)
00567             NavigateExtremes(c==oglHOME);
00568         if (CheckBinding("annoTogglePlay",c,state) && mSimTLV)
00569         {
00570             if (mSimTLV->Player()->Playing())
00571                 mSimTLV->Player()->Stop();
00572             else
00573                 mSimTLV->Player()->Play();
00574         }
00575         if (c == 8 || c == 127)
00576         {
00577             if (mAnnoHistoryVSB)
00578                 mAnnoHistoryVSB->SBar()->ChangePos((state&oglControl)?1:-1);
00579             else
00580                 OnAnnoHistoryVSB(mAnnoHistoryPos + ((c==8) ? -1 : 1));
00581         }
00582     }
00583 
00584     void OnAnnoHistoryVSB(int value)
00585     {
00586         int sz = mAnnoHistory.size();
00587         if (value < 0 || value > sz || sz==0)
00588             return;
00589         bool goForward = (value == sz);
00590         mAnnoHistoryPos = value -= goForward ? 1 : 0;
00591         mDataDoc->CursorToFile(mAnnoHistory[value].fileIdx);
00592         AllHandleNewCursor(Core::Database::LEVEL_FILE, false);
00593         if (mSimTLV)
00594             mSimTLV->Player()->GotoFrame(mAnnoHistory[value].frameIdx);
00595         mCurRankShot = mAnnoHistory[value].rankIdx;
00596         Synchronize(mAnnoHistory[value].frameIdx);
00597         if (goForward)
00598             GoForw(false);
00599     }
00600 
00601     virtual void
00602     UpDownButtonSelectionEvent(UpDownButton *src, bool isUpBtn, void* userData)
00603     {
00604         int updownBut = (long long) userData;
00605         int bit = 0;
00606         if (updownBut == UPDOWNBUT_POSITIVE)
00607             bit = POSITIVE_BIT;
00608         else if (updownBut == UPDOWNBUT_SKIPPED)
00609             bit = SKIPPED_BIT;
00610         else if (updownBut == UPDOWNBUT_NEGATIVE)
00611             bit = NEGATIVE_BIT;
00612         else if (updownBut == UPDOWNBUT_UNKNOWN)
00613             bit = UNKNOWN_BIT;
00614         if (bit)
00615             GoToNextAnno(bit, isUpBtn, mPrevNextAnnoStayInVideo);
00616     }
00617 
00618     virtual void
00619     UpDownNumberChangedEvent(UpDownNumber *src, void* userData)
00620     {
00621         if (src == mStepUpDown)
00622             mStepSize = src->GetValue();
00623         if (src == mShotThresholdUDNr)
00624         {
00625             mShotThreshold = src->Value();
00626             ConstructShots(mShotThreshold);
00627             HandleNewShot(); // To recompute present values
00628         }
00629     }
00630 
00631     virtual void
00632     OnValueChanged(ValueScrollBar *src, int value, void* userData)
00633     {
00634         if (mSimTLV && src == mShotValueSB && !mShotValueSBAdjusting)
00635             mSimTLV->Player()->GotoFrame(value);
00636         if (src == mRankVSB && !mRankVSBAdjusting)
00637         {
00638             mCurRankShot = value;
00639             GoToCurrentRank();
00640         }
00641         if (src == mAnnoHistoryVSB && !mAnnoHistoryVSBAdjusting)
00642             OnAnnoHistoryVSB(value);
00643     }
00644 
00645     virtual void
00646     CheckBoxEvent(CheckBox *src, bool checked, void* vData)
00647     {
00648         int userData = (long long) vData;
00649 
00650         if (userData == CHBOX_RANK_MODE)
00651         {
00652             SetRankingMode(checked);
00653             GoToCurrentRank();
00654         }
00655         if (userData == CHBOX_SHOW_THRESH_SHOTS)
00656             mShowThreshShots = checked;
00657         if (userData == CHBOX_SHOW_SEG_SHOTS)
00658             mShowSegShots = checked;
00659         if (userData == CHBOX_PN_IN_VIDEO)
00660             mPrevNextAnnoStayInVideo = checked;
00661     }
00662 // End of event handling stuff
00664 
00666 // Feedback stuff
00667     void DrawFramesLine(SimilarityTimeLine* sTL, int f1,int f2, int w,
00668                         int y1, int y2, ULONG col)
00669     {
00670         if (!sTL)
00671             return;
00672         int fPix = sTL->Unit2Pixel(f1*40);
00673         int lPix = sTL->Unit2Pixel(f2*40);
00674         if (fPix == lPix && y1 == y2)
00675             lPix += 1;
00676         SetLineWidth(w);
00677         SetSolidLineColor(col);
00678         DrawLine(fPix, y1, lPix, y2);
00679         SetLineWidth(1);
00680     }
00681 
00682     void
00683     DisplayThreshShots(SimilarityTimeLine* sTL, int y, ULONG col1, ULONG col2)
00684     {
00685         if (!sTL)
00686             return;
00687         int fVisFr   = sTL->FirstVisibleFrame();
00688         int lVisFr   = sTL->LastVisibleFrame();
00689         int fVisShot = FindFrameShot(fVisFr);
00690         int lVisShot = FindFrameShot(lVisFr);
00691         for (int i = fVisShot; i<lVisShot+1 && i<mShots.size()-1; i++)
00692         {
00693             int fFrame = mShots[i]+1;
00694             int lFrame = mShots[i+1];
00695             DrawFramesLine(sTL,fFrame,lFrame,2,y,y,(i%2) ? col1 : col2);
00696         }
00697     }
00698 
00699     void
00700     DisplaySegShots(SimilarityTimeLine* sTL, int y, ULONG col1, ULONG col2)
00701     {
00702         Segmentation* seg = mSegDoc->GetSegmentation();
00703         if (!seg || !sTL)
00704             return;
00705 
00706         int fVisFr    = sTL->FirstVisibleFrame();
00707         int lVisFr    = sTL->LastVisibleFrame();
00708         int firstShot = seg->GetFirstShotVideo(mCurFile);
00709         int lastShot  = firstShot+seg->GetNrShotsVideo(mCurFile);
00710         int fVisShot  = FindSegFrameShot(fVisFr);
00711         int lVisShot  = FindSegFrameShot(lVisFr);
00712 
00713         for (int i = fVisShot; i<lVisShot+1 && i<lastShot; i++)
00714         {
00715             int fFrame = seg->GetStart(i);
00716             int lFrame = seg->GetEnd(i);
00717             DrawFramesLine(sTL,fFrame,lFrame,2,y,y,(i%2) ? col1 : col2);
00718         }
00719     }
00720 
00721     void
00722     DisplayShotRelevances(SimilarityTimeLine* sTL, int y)
00723     {
00724         Segmentation* seg = mSegDoc->GetSegmentation();
00725         if (!seg || !sTL || !mCurMpeg7)
00726             return;
00727 
00728         int fVisFr    = sTL->FirstVisibleFrame();
00729         int lVisFr    = sTL->LastVisibleFrame();
00730         int firstShot = seg->GetFirstShotVideo(mCurFile);
00731         int lastShot  = firstShot+seg->GetNrShotsVideo(mCurFile);
00732         int fVisShot  = FindSegFrameShot(fVisFr);
00733         int lVisShot  = FindSegFrameShot(lVisFr);
00734 
00735         for (int i = fVisShot; i<lVisShot+1 && i<lastShot-1; i++)
00736         {
00737             int fFrame = seg->GetStart(i);
00738             int idx = mCurMpeg7->FindShot(fFrame+1);
00739             DrawShotRelevance(sTL, idx, -1, y);
00740         }
00741     }
00742 
00743     void ShotControlFeedback(int fFrame, int lFrame, int kFrame)
00744     {
00745         if (!mSimTLV || !mShotValueSB)
00746             return;
00747         // Feedback for Shot Scrollbar
00748         int playFrame = mSimTLV->Player()->FrameNr();
00749         mShotValueSBAdjusting = true;
00750         mShotValueSB->SetValue(playFrame);
00751         mShotValueSBAdjusting = false;
00752         mShotValueSB->SBar()->ButDecr()
00753             ->SetBorderBackground((playFrame<fFrame) ? oglRED : 0);
00754         mShotValueSB->SBar()->ButIncr()
00755             ->SetBorderBackground((playFrame>lFrame) ? oglRED : 0);
00756         // Feedback for adjust shot boundaries
00757         if (!mNoShotEditing)
00758         {
00759             mShotLeftBtn ->SetState(((playFrame<kFrame) && mSimTLV) ? 1 : 0); 
00760             mShotRightBtn->SetState(((playFrame>kFrame) && mSimTLV) ? 1 : 0);
00761         }
00762     }
00763 
00764     // Feedback for ranking options and scrollbar
00765     void RankingControlFeedback()
00766     {
00767         if (mRankVSB)
00768         {
00769             if (mRankingMode)
00770             {
00771                 mRankVSBAdjusting = true;
00772                 mRankVSB->SetValue(mCurRankShot);
00773                 mRankVSBAdjusting = false;
00774             }
00775             mRankVSB->SBar()->SetState(mRankingMode ? 1 : 0);
00776             mRankVSB->ValText()->SetState(mRankingMode ? 1 : 0);
00777         }
00778         mRankChBox->SetState(mSimSet?1:0);
00779         mRankChBox->SetSelected(mRankingMode);
00780         mRankAllBtn->SetBorderBackground(mRankAll?oglTrLIGHTGREEN:0);
00781         mRankNotAnnoBtn->SetBorderBackground(mRankAll?0:oglTrLIGHTGREEN);
00782     }
00783 
00784     void HandleUpDownState(UpDownButton* udBtn, int state, bool doParent=false)
00785     {
00786         udBtn->UpButton()->SetState(state);
00787         udBtn->DownButton()->SetState(state);
00788         udBtn->SetState(state);
00789         if (doParent)
00790             udBtn->GetParent()->SetState(state);
00791     }
00792 
00793     void PrevNextAnnoControlFeedBack()
00794     {
00795         if (mNoPrevNextControl)
00796             return;
00797         int state = !mRankingMode;
00798         HandleUpDownState(mPositiveUDBtn,state,true);
00799         HandleUpDownState(mSkippedUDBtn,state,true);
00800         HandleUpDownState(mNegativeUDBtn,state,true);
00801         HandleUpDownState(mUnknownUDBtn,state,true);
00802     }
00803 
00804     void DrawShotRelevance(SimilarityTimeLine* sTL, int idx, int kFrame, int y)
00805     {
00806         if (idx == -1 || !mCurMpeg7)
00807             return;
00808         float relevance = mCurMpeg7->Relevance(idx);
00809         ULONG col = RelevanceColor(relevance);
00810         int fFrame = mCurMpeg7->StartFrame(idx);
00811         int lFrame = mCurMpeg7->EndFrame(idx);
00812         DrawFramesLine(sTL, fFrame, lFrame, 2, y, y, col);
00813         if (kFrame != -1)
00814             DrawFramesLine(sTL, kFrame, kFrame, 1, y, y-6, col);
00815     }
00816 
00817     // Called when the SimTimeLineVideo is displayed
00818     virtual void WindowDisplayEvent(OglGui::Window *src, void* userData)
00819     {
00820         SimilarityTimeLine* sTL = (SimilarityTimeLine*) src;
00821         int y                   = sTL->GetAxisY();
00822         int kFrame              = mKeyframes->GetFrameNr(mCurKey);
00823         int fFrame              = -1;
00824         int lFrame              = -1;
00825 
00826         // Draw line between shot boundaries
00827         if (!mCurShotFrames.empty())
00828         {
00829             fFrame = mCurShotFrames[0];
00830             lFrame = mCurShotFrames[mCurShotFrames.size()-1];
00831             DrawFramesLine(sTL, fFrame, lFrame, 2, y-18, y-18, 0xffffff00);
00832         }
00833 
00834         ShotControlFeedback(fFrame,lFrame,kFrame);
00835         if (mShowThreshShots)
00836             DisplayThreshShots(sTL, y-24,0xff808000, 0xffb0b000);
00837         if (mShowSegShots)
00838             DisplaySegShots(sTL,y-27,0xffb0b0ff,0xff8080ff);
00839         if (mCurMpeg7)
00840         {
00841                int idx = mCurMpeg7->FindShot(kFrame);
00842                DrawShotRelevance(sTL, idx, kFrame, y-20);
00843         }
00844     }
00845 
00846     virtual void DisplayFunc()
00847     {
00848         DataDocumentGui<Core::VideoSet::SegmentationDocument>::DisplayFunc();
00849 
00850         char buf[100];
00851         sprintf(buf, "NrAnno: %d Pos %d Skip %d Neg %d V(%d)", mNrAnnotated,
00852                 mNrPositive, mNrSkip, mNrNegative, mNrAnnoPerVideo);
00853         mNrAnnoTxt->SetText(buf);
00854         RankingControlFeedback();
00855     }
00856 // End of feedback stuff
00858 
00859 private:
00860 
00861     int Relevance2Bit(float rel)
00862     {
00863         if (rel < 0.01)
00864             return NEGATIVE_BIT;
00865         if (rel > 0.99)
00866             return POSITIVE_BIT;
00867         else
00868             return SKIPPED_BIT;
00869     }
00870 
00871     void RelevanceStats(double rel, int delta)
00872     {
00873         if (rel < 0.01)
00874             mNrNegative += delta;
00875         else if (rel > 0.99)
00876             mNrPositive += delta;
00877         else
00878             mNrSkip += delta;
00879     }
00880 
00881     void AnnoStats(int idx, double relevance)
00882     {
00883         if (idx == -1)
00884         {
00885             mNrAnnoPerVideo++;
00886             mNrAnnotated++;
00887         }
00888         RelevanceStats(relevance,1);
00889     }
00890 
00891     bool InAnnoHistory(AnnoHistory* aH)
00892     {
00893         for (int i=0; i<mAnnoHistory.size(); i++)
00894         {
00895             AnnoHistory *annoH = &mAnnoHistory[i];
00896             if (annoH->fileIdx == aH->fileIdx &&
00897                 annoH->frameIdx == aH->frameIdx &&
00898                 annoH->rankIdx == aH->rankIdx
00899                )
00900                 return true;
00901         }
00902         return false;
00903     }
00904 
00905     void ToAnnoHistory(int fileIdx, int frameIdx, int rankIdx)
00906     {
00907         AnnoHistory annoHist = {fileIdx, frameIdx, rankIdx};
00908         if (!InAnnoHistory(&annoHist))
00909         {
00910             mAnnoHistory.push_back(annoHist);
00911             mAnnoHistoryPos = mAnnoHistory.size();
00912             if (!mAnnoHistoryVSB)
00913                 return;
00914             mAnnoHistoryVSBAdjusting = true;
00915             mAnnoHistoryVSB->SetMinMaxValue(0,mAnnoHistoryPos);
00916             mAnnoHistoryVSB->SetValue(mAnnoHistoryPos);
00917             mAnnoHistoryVSBAdjusting = false;
00918         }
00919     }
00920 
00921     bool CheckAnnoMax()
00922     {
00923         Segmentation* seg       = mSegDoc->GetSegmentation();
00924         int           firstShot = seg->GetFirstShotVideo(mCurFile);
00925 
00926         bool annoMax = mNrAnnoPerVideo >= mMaxAnnoPerVideo ||
00927                        FindAdjacentAnnoShot(UNKNOWN_BIT,firstShot-1,true)==-1;
00928         if (annoMax && mRankingMode && !mNoAutoNextAnno)
00929         {
00930                         mCurFile;
00931                         if (!mSegDoc->GotoNextVideo())
00932                                 return true;
00933                         mCurFile;
00934                         //mCurFile = mSegDoc->CurFileId();
00935             int res = FindNextAnno(UNKNOWN_BIT, true, false);
00936             if (res != -1)
00937                 AllHandleNewCursor(mSegDoc->CursorToFile(res/100000),false);
00938         }
00939         return annoMax;
00940     }
00941 
00942     void DoAnno(double relevance, bool isShot)
00943     {
00944         if (!mSegDoc->HasCurShot() || !mCurMpeg7)
00945             return;
00946         String  name      = FileNameBase(mKeyframes->GetName(mCurKey));
00947         int     frameNr   = mKeyframes->GetFrameNr(mCurKey);
00948         bool    empty     = mCurShotFrames.empty();
00949         int     sz        = mCurShotFrames.size();
00950         int     shotStart = (empty||!isShot) ? frameNr : mCurShotFrames[0];
00951         int     shotEnd   = (empty||!isShot) ? frameNr : mCurShotFrames[sz-1];
00952 
00953         int oldIdx = mCurMpeg7->FindShot(frameNr);
00954         if (oldIdx!=-1)
00955             RelevanceStats(mCurMpeg7->Relevance(oldIdx),-1);
00956 
00957         char buf[80];
00958         sprintf(buf, "%s_frame%d_%d", name.c_str(),shotStart,shotEnd);
00959         int idx = mCurMpeg7->ReplaceAnnotationEx(mSegDoc->GetConcept(),
00960                                                  isShot?buf:name,
00961                                                  frameNr,shotStart,
00962                                                  shotEnd,relevance,1);
00963 
00964         Segmentation* seg = mSegDoc->GetSegmentation();
00965         int shot = FindSegFrameShot(frameNr) - seg->GetFirstShotVideo(mCurFile);
00966         (*mVideoAnnotations[mCurFile])[shot] = Relevance2Bit(relevance); 
00967 
00968         mCurMpeg7Changed = true;
00969         ToAnnoHistory(mCurFile, frameNr, mCurRankShot);
00970         AnnoStats(idx, relevance);
00971         UpdateRelevance();
00972         if (!CheckAnnoMax() || !mRankingMode)
00973             GoForw(false);
00974     }
00975 
00976     void
00977     GoBack()
00978     {
00979         if (mRankingMode)
00980         {
00981             if (!mRankedShots.size())
00982                 return;
00983             if ((mCurRankShot-=mStepSize) < 0)
00984                 mCurRankShot = 0;
00985             int newShot = mRankedShots[mCurRankShot];
00986             if (newShot != mSegDoc->CurShot())
00987             {
00988                 mSegDoc->GotoShot(newShot);
00989                 return AllHandleNewCursor(Core::Database::LEVEL_SHOT, false);
00990             }
00991         }
00992         else if (mSegDoc->GotoPrevShot(mStepSize))
00993             return AllHandleNewCursor(Core::Database::LEVEL_SHOT, false);
00994     }
00995 
00996     void
00997     GoForw(bool withinVideo)
00998     {
00999         if (mRankingMode)
01000         {
01001             int sz = mRankedShots.size();
01002             mCurRankShot += mStepSize;
01003             if (mCurRankShot > sz-1)
01004             {
01005                 mCurRankShot = sz ? sz-1 : 0;
01006                 if (!withinVideo && mSegDoc->GotoNextVideo())
01007                     return AllHandleNewCursor(Core::Database::LEVEL_FILE,false);
01008             }
01009             if (mCurRankShot >= 0 && mCurRankShot < sz)
01010             {
01011                 int newShot = mRankedShots[mCurRankShot];
01012                 if (newShot != mSegDoc->CurShot())
01013                 {
01014                     mSegDoc->GotoShot(newShot);
01015                     return AllHandleNewCursor(Core::Database::LEVEL_SHOT, false);
01016                 }
01017             }
01018             CheckSaveMpeg7(false);
01019             return;
01020         }
01021         if (mSegDoc->GotoNextShot(mStepSize))
01022             return AllHandleNewCursor(Core::Database::LEVEL_SHOT, false);
01023         if (withinVideo)
01024             return;
01025         if (mSegDoc->GotoNextVideo())
01026             return AllHandleNewCursor(Core::Database::LEVEL_FILE, false);
01027         CheckSaveMpeg7(false);
01028     }
01029 
01030     void
01031     UpdateRelevance()
01032     {
01033                 if (!mCurMpeg7)
01034                         return;
01035         int frame = mKeyframes->GetFrameNr(mCurKey);
01036         int idx = mCurMpeg7->FindShot(frame);
01037         mCurRelevance = (idx == -1) ? 0.5 : mCurMpeg7->Relevance(idx);
01038         String typeString;
01039         if (mCurRelevance < 0.01)
01040             typeString = "negative";
01041         else if (mCurRelevance > 0.99)
01042             typeString = "positive";
01043         else
01044             typeString = "skip";
01045          if (idx == -1)
01046              typeString = "unknown";
01047 
01048         bool isShot = false;
01049         if (idx != -1 && mCurShotFrames.size() != 0)
01050         {
01051             int fFrame = mCurMpeg7->StartFrame(idx);
01052             int lFrame = mCurMpeg7->EndFrame(idx);
01053             if (fFrame != lFrame)
01054                 isShot = true;
01055         }
01056         mShotText->SetTextColor(isShot?RelevanceColor(mCurRelevance):oglBLACK);
01057         mImShotWnd->SetBorderBackground(isShot?RelevanceColor(mCurRelevance):0);
01058         mFrameText->SetTextColor(RelevanceColor(mCurRelevance));
01059         mShotText->SetText("shot " + (isShot ? typeString : "unknown"));
01060         mFrameText->SetText(isShot ? "" : ("fr " + typeString));
01061     }
01062 
01063     ULONG RelevanceColor(float relevance)
01064     {
01065         if (relevance < 0.01)
01066             return oglTrRED;
01067         if (relevance > 0.99)
01068             return oglTrDARKGREEN;
01069         return oglBLACK;
01070     }
01071 
01072     void
01073     CheckLoadMpeg7()
01074     {
01075         if ((mCurFile == mSegDoc->CurFileId()) &&
01076             (mCurConcept == mSegDoc->GetConceptIdx()))
01077         {
01078             return;
01079         }
01080         CheckSaveMpeg7(true);
01081         mCurFile = mSegDoc->CurFileId();
01082         mCurConcept = mSegDoc->GetConceptIdx();
01083         if ((mCurFile == -1) || (mCurConcept == -1))
01084             return;
01085         String vidName = mVidSet->GetFile(mCurFile);
01086         String concept = mSegDoc->GetConcept();
01087         // ILOG_INFO("Loading " << concept << " for " << vidName);
01088         int fractions = 0;
01089         int frameRateNum = (mRgbDataSrc) ? mRgbDataSrc->FrameRateNum() : 0;
01090         int frameRateDen = (mRgbDataSrc) ? mRgbDataSrc->FrameRateDen() : 0;
01091         String container = mConceptSet + "/" + mVidSet->GetContainerFile(mCurFile);
01092         typedef Persistency::Mpeg7DocLocator MP7Loc;
01093         MP7Loc loc(mVidSet->GetLocator(), MP7Loc::MPEG7_ANNOTATION, container,
01094                    concept + ".xml");
01095         if (!Persistency::Mpeg7DocRepository().Exists(loc))
01096         {
01097             int nrFr = mSegDoc->GetSegmentation()->GetNrFramesVideo(mCurFile);
01098                         mConceptSet;
01099             mCurMpeg7 = new Mpeg7Doc(vidName, vidName, nrFr, fractions, false,
01100                                      mConceptSet, concept, frameRateNum,
01101                                      frameRateDen);
01102         }
01103         else
01104         {
01105             mCurMpeg7 = Persistency::Mpeg7DocRepository().Get(loc);
01106             mCurMpeg7->SetConceptSet(mConceptSet);
01107         }
01108     }
01109 
01110     void
01111     CheckSaveMpeg7(bool doDelete)
01112     {
01113         if (mCurMpeg7 && mCurMpeg7Changed)
01114         {
01115             ILOG_INFO("Saving " << mSegDoc->GetConcept(mCurConcept) << " for "
01116                       << mVidSet->GetFile(mCurFile));
01117             Core::VideoSet::Mpeg7DocWrite(mCurMpeg7, mSegDoc->GetVideoSet(),
01118                                           mCurFile);
01119             if (doDelete)
01120             {
01121                 delete mCurMpeg7;
01122                 mCurMpeg7 = 0;
01123             }
01124         }
01125         mCurMpeg7Changed = false;
01126     }
01127 
01128     void ClearVideoAnnotations()
01129     {
01130         for (int i = mVideoAnnotations.size()-1; i>=0; i--)
01131             delete mVideoAnnotations[i];
01132         mVideoAnnotations.clear();
01133     }
01134 
01135     void CheckLoadVideoAnnotations()
01136     {
01137         int oldCurFile      = mCurFile;
01138         int conceptIdx      = mSegDoc->GetConceptIdx();
01139 
01140         if (conceptIdx == -1 || conceptIdx == mCurConcept)
01141             return;
01142         ClearVideoAnnotations();
01143         Segmentation* seg = mSegDoc->GetSegmentation();
01144         int nrVideos = seg->GetNrVideos();
01145 
01146         ILOG_INFO("Reading Mpeg7 video annotations for concept "
01147                   + mSegDoc->GetConcept(conceptIdx));
01148         mSegDoc->CursorToDir(0);
01149         do {
01150             CheckLoadMpeg7();
01151             printf("Video annotation %d of %d   \r",mCurFile,nrVideos);
01152             int firstShot   = seg->GetFirstShotVideo(mCurFile);
01153             int sz          = seg->GetNrShotsVideo(mCurFile);
01154             int lastShot    = firstShot+sz;
01155             VideoAnnotation* vidAnno = new VideoAnnotation(sz);
01156             mVideoAnnotations.push_back(vidAnno);
01157             for (int i=firstShot; i<lastShot; i++)
01158             {
01159                 int   kFrame   = mKeyframes->GetShotRKF(i);
01160                 int   frame    = mKeyframes->GetFrameNr(kFrame);
01161                 int   idx      = mCurMpeg7->FindShot(frame);
01162                 bool  unknown  = (idx==-1);
01163                 float rel      = unknown ? 0.5 : mCurMpeg7->Relevance(idx);
01164                 bool  positive = rel > 0.99;
01165                 bool  negative = rel < 0.01;
01166                 bool  skipped  = !unknown && !positive && !negative;
01167                 if (skipped)
01168                     (*vidAnno)[i-firstShot] = SKIPPED_BIT;
01169                 if (positive)
01170                     (*vidAnno)[i-firstShot] = POSITIVE_BIT;
01171                 if (negative)
01172                     (*vidAnno)[i-firstShot] = NEGATIVE_BIT;
01173             }
01174         } while (mSegDoc->CursorNextFile());
01175         mCurFile = -1;
01176         AllHandleNewCursor(mSegDoc->CursorToFile(oldCurFile), false);
01177     }
01178 
01179     RgbDataSrc* GetCurrentVideo()
01180     {
01181         RgbDataSrc *rgbDataSrc =
01182             mSegDoc->GetVideoSet()->GetVideoInLowResolution(mCurFile, true);
01183         if (!rgbDataSrc)
01184             rgbDataSrc = mSegDoc->GetVideoSet()->GetVideo(mCurFile);
01185         return rgbDataSrc;
01186     }
01187 
01188     void CheckNewVideo(int oldCurFile)
01189     {
01190         if (mRgbDataSrc && oldCurFile == mSegDoc->CurFileId())
01191             return;
01192 
01193         mNrAnnoPerVideo = 0;
01194         mCurFile = mSegDoc->CurFileId();
01195 
01196         String videoName = mSegDoc->GetVideoSet()->GetFile(mCurFile);
01197 
01198         ConstructNewVideoSimSet();
01199 
01200         if (mRgbDataSrc)
01201             delete mRgbDataSrc;
01202 
01203         mRgbDataSrc = GetCurrentVideo();
01204 
01205         if (!mSimTLV && !mNoSimTLV && mShotSimSet)
01206             CreateSimTLV();
01207 
01208         if (mSimTLV && mShotSimSet)
01209         {
01210             RgbDataSrc *rgbDataSrc = GetCurrentVideo();
01211             mSimTLV->OpenVideo(rgbDataSrc, videoName);
01212             mSimTLV->TimeLine()->DocW(4*rgbDataSrc->LastFrame());
01213             mSimTLV->SetSimilarityTableSet(mShotSimSet);
01214 
01215             rgbDataSrc = GetCurrentVideo();
01216             mSimTLV->TimeLine()->ViewStripRgbDataSrc(rgbDataSrc);
01217             mSimTLV->TimeLine()->ViewStripShow(true);
01218         }
01219         ConstructShots(mShotThreshold);
01220         mCurRankShot = 0;
01221         if (mRankingMode && !mNoAutoNextAnno)
01222             GoToCurrentRank();
01223         else
01224             HandleNewShot();
01225     }
01226 
01227 #if OLD
01228     void CheckNewVideo(int oldCurFile)
01229     {
01230         if (mRgbDataSrc && oldCurFile == mSegDoc->CurFileId())
01231             return;
01232 
01233         mNrAnnoPerVideo = 0;
01234         mCurFile = mSegDoc->CurFileId();
01235 
01236         ConstructNewVideoSimSet();
01237 
01238         if (mRgbDataSrc)
01239             delete mRgbDataSrc;
01240         mRgbDataSrc = 0;
01241 
01242         Core::Database::RawDataSet* dataSet = mSegDoc->GetDataSet();
01243 #ifndef REPOSITORY_USED // Here comes the deprecated stuff
01244         String videoName =
01245             dataSet->GetFilePathVideoData(mCurFile,false,false);
01246         String rawName =
01247             dataSet->GetFilePathFrames(mCurFile,"images_jpg.raw",false,false);
01248         mRgbDataSrc = OpenRgbDataSrc(rawName, videoName);
01249 #else // REPOSITORY_USED
01250         ILOG_ERROR("Todo : CheckNewVideo");
01251         String videoName = mSegDoc->GetVideoSet()->GetFile(mCurFile);;
01252         String rawName;
01253 #endif // REPOSITORY_USED
01254 
01255         if (!mSimTLV && !mNoSimTLV && mShotSimSet)
01256             CreateSimTLV();
01257 
01258         if (mSimTLV && mShotSimSet)
01259         {
01260 #ifndef REPOSITORY_USED
01261             RgbDataSrc *rgbDataSrc = OpenRgbDataSrc(rawName, videoName);
01262 #else
01263             RgbDataSrc *rgbDataSrc = mSegDoc->GetVideoSet()->
01264                 GetVideoInLowResolution(mCurFile);
01265             if (!rgbDataSrc)
01266                 rgbDataSrc = mSegDoc->GetVideoSet()->GetVideo(mCurFile);
01267 #endif
01268             mSimTLV->OpenVideo(rgbDataSrc, videoName);
01269             mSimTLV->TimeLine()->DocW(4*rgbDataSrc->LastFrame());
01270             mSimTLV->SetSimilarityTableSet(mShotSimSet);
01271 #ifndef REPOSITORY_USED
01272             rgbDataSrc = OpenRgbDataSrc(rawName, videoName);
01273 #else
01274             rgbDataSrc = mSegDoc->GetVideoSet()->GetVideoInLowResolution(mCurFile);
01275             if (!rgbDataSrc)
01276                 rgbDataSrc = mSegDoc->GetVideoSet()->GetVideo(mCurFile);
01277 #endif
01278             mSimTLV->TimeLine()->ViewStripRgbDataSrc(rgbDataSrc);
01279             mSimTLV->TimeLine()->ViewStripShow(true);
01280         }
01281         ConstructShots(mShotThreshold);
01282         mCurRankShot = 0;
01283         if (mRankingMode && !mNoAutoNextAnno)
01284             GoToCurrentRank();
01285         else
01286             HandleNewShot();
01287     }
01288 
01289     RgbDataSrc* OpenRgbDataSrc(String rawName, String videoName)
01290     {
01291         RgbDataSrc *rgbDataSrc = 0;
01292 #ifndef REPOSITORY_USED // Here comes the deprecated stuff
01293         if (!rawName.empty())
01294             rgbDataSrc = new RgbDataSrcRaw(rawName);
01295         else if (!videoName.empty())
01296         {
01297             RgbDataSrcFactory& f = RgbDataSrcFactory::Instance();
01298             rgbDataSrc = f.Construct(RgbDataSrcFactory::SRC_LAVC_WITHIDX,
01299                                      videoName, mVidSet->GetDatabase());
01300         }
01301 #else // REPOSITORY_USED
01302         ILOG_ERROR("Todo : OpenRgbDataSrc");
01303 #endif // REPOSITORY_USED
01304 
01305         if (!rgbDataSrc || !rgbDataSrc->Valid())
01306         {
01307             ILOG_ERROR("Opening RgbDataSrc failed");
01308             if (rgbDataSrc)
01309                 delete rgbDataSrc;
01310             return 0;
01311             }
01312         return rgbDataSrc;
01313     }
01314 #endif OLD
01315 
01316     void ConstructShots(float threshold)
01317     {
01318         mShots.clear();
01319         mShots.push_back(-1);
01320         SimTableType* simTable  = mShotSimSet->GetSimTable(0);
01321         int sz = simTable->Size();
01322         for (int i=0; i<sz; i++)
01323         {
01324             if (simTable->Get1(i) > threshold)
01325                 mShots.push_back(i);
01326         }
01327         if (mShots[mShots.size()-1] != sz-1)
01328             mShots.push_back(sz-1);
01329     }
01330 
01331     void CreateSimTLV()
01332     {
01333         OglGui::TitledWindow*
01334             tWnd = new TitledWindow(this,2,0,W()-4,396,"TimeLineVideo");
01335         mSimTLV = new SimilarityTimeLineVideo(tWnd->ContentPane(),0,0,
01336                                               W()-10,364, mShotSimSet,15);
01337         mSimTLV->TimeLine()->SetWindowListener(this);
01338         mSimTLV->TimeLine()->ShowClassify(false);
01339         mSimTLV->TimeLine()->SetSimColor(0,0xffffff00);
01340         mSimTLV->TimeLine()->CurrentViewOnTop(2);
01341         mSimTLV->TimeLine()->ViewStripMinViewWidth(12);
01342         mSimTLV->ScaleChildren();
01343         tWnd->ContentPane()->ScaleChildren();
01344 
01345         StaticText* TBar = mSimTLV->TitledTimeLine()->TitleText();
01346         new Strut(TBar,160,1);
01347         // Synchronize with nearest shot
01348         mSyncBtn = new Button(TBar, 50, 21, "Sync", 4, true);
01349         mSyncBtn->SetButtonListener(this, BUT_SYNC);
01350         // Frame Sliding Animation
01351         mAllowSlidingChBox =
01352             new CheckBox( TBar, 70, 21, "Sliding", true, 4);
01353         if (!mNoViewStripControl)
01354         {
01355             // ViewStrip Options
01356             StaticText* vStripTxt =
01357                 new StaticText(TBar,160,21,"ViewStrip",false,true);
01358             vStripTxt->SetBorderType(BEV_ETCHED);
01359             InBoxButton(vStripTxt,62,32,"Pre",VIEWSTRIP_PRE);
01360             InBoxButton(vStripTxt,94,32,"Min",VIEWSTRIP_MIN);
01361             InBoxButton(vStripTxt,126,32,"Max",VIEWSTRIP_MAX);
01362         }
01363         new Strut(TBar,10,1);
01364         RectCheckBox(TBar,150,21,"Show Seg Shots",
01365                      CHBOX_SHOW_SEG_SHOTS); 
01366         RectCheckBox(TBar,160,21,"Show Thresh Shots",
01367                      CHBOX_SHOW_THRESH_SHOTS);
01368     }
01369 
01370     void ConstructNewVideoSimSet()
01371     {
01372         Core::Database::RawDataSet* dataSet = mSegDoc->GetDataSet();
01373 #ifndef REPOSITORY_USED // Here comes the deprecated stuff
01374         Util::Database* db = dataSet->GetDatabase();
01375 
01376         String simNames =
01377             dataSet->GetFilePathSimilarityData("Frames", "streamConcepts.txt",
01378                                                "no_model", "direct", mCurFile,
01379                                                "names.txt", false, false);
01380         if (mShotSimSet)
01381             delete mShotSimSet;
01382         mShotSimSet = SimilarityTableSet::MakeFromFile(simNames, db);
01383 
01384         // Obtain ranking similarities. Artificial randomizing access in mRankingMode
01385         simNames = dataSet->GetFilePathSimilarityData
01386             ("Keyframes",mRankSet,mRankModel,mRankFeature,mCurFile,
01387              "names.txt",false,false);
01388         if (mSimSet)
01389             delete mSimSet;
01390         mSimSet = 0;
01391         if (!simNames.empty())
01392             mSimSet = SimilarityTableSet::MakeFromFile(simNames, db);
01393 #else // REPOSITORY_USED
01394         typedef Persistency::SimilarityTableSetLocator SimLoc;
01395         SimLoc loc(dataSet->GetLocator(), false, "Frames", "streamConcepts.txt",
01396                    "no_model", "direct", dataSet->GetContainerFile(mCurFile));
01397         if (mShotSimSet)
01398             delete mShotSimSet;
01399         mShotSimSet = Persistency::SimilarityTableSetRepository().Get(loc);
01400 
01401         // Obtain ranking similarities. Artificial randomizing access in mRankingMode
01402         loc = SimLoc(dataSet->GetLocator(), false, "Keyframes", mRankSet,
01403                      mRankModel, mRankFeature,
01404                      dataSet->GetContainerFile(mCurFile));
01405         if (mSimSet)
01406             delete mSimSet;
01407         mSimSet = 0;
01408         mSimSet = Persistency::SimilarityTableSetRepository().Get(loc);
01409 #endif // REPOSITORY_USED
01410         ConstructShotRanking(!mRankAll);
01411     }
01412 
01413     int FindRankedShot(int shot)
01414     {
01415         int sz = mRankedShots.size();
01416         for (int i=0; i<sz; i++)
01417             if (mRankedShots[i] == shot)
01418                 return i;
01419         return -1;
01420     }
01421 
01422     bool PassTest(int filter, bool unKnown, bool pos, bool neg, bool skip)
01423     {
01424         if ( ((filter & UNKNOWN_BIT)  && unKnown) ||
01425              ((filter & POSITIVE_BIT) && pos)     ||
01426              ((filter & NEGATIVE_BIT) && neg)     ||
01427              ((filter & SKIPPED_BIT)  && skip)
01428            )
01429             return true;
01430         return false;
01431     }
01432 
01433     bool ToRankedShots(RankTableType* rankTable, int i, int filter)
01434     {
01435         int frame    = QuidId(rankTable->Get1(i));
01436         int shot     = FindSegFrameShot(frame);
01437         int firstKey = mKeyframes->GetFirstKeyframeShot(shot);
01438         int lastKey  = firstKey + mKeyframes->GetNrKeyframesShot(shot);
01439         int keyfr    = mKeyframes->GetFrameId(frame, firstKey, lastKey);
01440         if (keyfr==-1 || !mKeyframes->IsRKF(keyfr))
01441             return false;
01442 
01443         int firstFrame = -1, lastFrame = -1;
01444         int idx = mCurMpeg7->FindShot(frame);
01445         /* RvB: Not used
01446         if (idx != -1)
01447         {
01448             firstFrame = mCurMpeg7->StartFrame(idx);
01449             lastFrame = mCurMpeg7->EndFrame(idx);
01450         }
01451         */
01452         bool unKnown = (idx == -1);
01453         float relevance = unKnown ? 0.5 : mCurMpeg7->Relevance(idx);
01454         bool positive = relevance > 0.99;
01455         bool negative = relevance < 0.01;
01456         bool skipped = !unKnown && !positive && !negative;
01457         if (PassTest(filter,unKnown,positive,negative,skipped))
01458         {
01459             if (FindRankedShot(shot) == -1){
01460                 mRankedShots.push_back(shot);
01461                 return true;
01462             }
01463         }
01464         return false;
01465     }
01466 
01467     void ConstructShotRanking(bool exclAnnotatedMode)
01468     {
01469         mRankedShots.clear();
01470         mCurRankShot = 0;
01471         mRankAll = !exclAnnotatedMode;
01472 
01473         if (!mSimSet)
01474             return;
01475 
01476         int tableNr = (mSimSet->NrTables()==1) ? 0 : mCurConcept;
01477         RankTableType* rankTable = mSimSet->GetRankTable(tableNr);
01478 
01479         int nShots = 0;
01480         int sz = mSimSet->TableSize();
01481         for (int i=0; i<sz; i++)
01482         {
01483             int filter = exclAnnotatedMode ? UNKNOWN_BIT :
01484                          UNKNOWN_BIT|POSITIVE_BIT|NEGATIVE_BIT|SKIPPED_BIT;
01485             if (ToRankedShots(rankTable, i, filter))
01486                 nShots++;
01487         }
01488         if (mRankVSB)
01489             mRankVSB->SetMinMaxValue(0,nShots-1);
01490     }
01491 
01492     void HandleConceptsFromFile()
01493     {
01494         mConceptFileField->SetText(mConceptSet);
01495         HandleLoadConcepts(mConceptSet, false);
01496 
01497         CmdOptions& options = CmdOptions::GetInstance();
01498         String conceptStr = options.GetString("concept");
01499         if (!conceptStr.empty())
01500         {
01501             for (int i=0 ; i<mDataDoc->NrConcepts() ; i++)
01502             {
01503                 if (conceptStr == mDataDoc->GetConcept(i))
01504                 {
01505                     mDataDoc->SetConcept(i);
01506                     mConceptField->SetText(mDataDoc->GetConcept());
01507                     mConceptField->ResetCaret();
01508                     break;
01509                 }
01510             }
01511         }
01512         if (mDataDoc->GetConceptIdx() != -1)
01513             HandleNewConcept();
01514     }
01515 
01516     Button* KbButton(char* str, int w, int h, String keyStr, int userData)
01517     {
01518         char buf[40];
01519         sprintf(buf, "%s (%s)", str, mKeyBindings[keyStr].c_str());
01520 
01521         Button* but = new Button(this,w,h,buf,4,true);
01522         but->SetButtonListener(this,userData);
01523         return but;
01524     }
01525 
01526     UpDownButton*
01527     PrevNextAnnoShot(OglGui::Window* parent, strconst str, int userData)
01528     {
01529         StaticText* txt = new StaticText(parent,50,24,str);
01530         txt->SetAlign(oglLeftAlign);
01531         UpDownButton* upDownBtn = new UpDownButton(txt,15,2,36,22,true,2);
01532         upDownBtn->SetUpDownButtonListener(this, userData);
01533         upDownBtn->SetBorderType(0);
01534         upDownBtn->SetRepeatMode(false); // Op duration disturbes repeatmode
01535         return upDownBtn;
01536     }
01537 
01538     Button*
01539     InBoxButton(OglGui::Window* parent, int x, int w, strconst str, int lData)
01540     {
01541         Button *btn
01542             = new Button(parent,x,2,w,parent->H()-4,str,BEV_ETCHED,true);
01543         btn->SetButtonListener(this,lData);
01544         btn->ScaleTo(parent);
01545         btn->SetAllowScaling(false);
01546         return btn;
01547     }
01548 
01549     CheckBox*
01550     RectCheckBox(OglGui::Window* parent, int w, int h,String str,int lData)
01551     {
01552         int pW = parent->W();
01553         int pH = parent->H();
01554         CheckBox* cb = new CheckBox(parent,w,h,str,false,1);
01555         cb->SetCheckBoxListener(this,lData);
01556         cb->SetBoxFrameType(4);
01557         cb->SetRoundedCheck(false);
01558         return cb;
01559     }
01560 
01561     void GuiNavigation()
01562     {
01563         Button* but;
01564                 char    buf[40];
01565 
01566         OglGui::Window* navWnd = new OglGui::Window(this,270,24);
01567         // Navigation mode
01568         mNavModeBtn = new Button(navWnd,0,0,18,24,"R",4,true);
01569         mNavModeBtn->SetButtonListener(this,BUT_NAV_MODE);
01570         // To Start [HOME]
01571         but = new Button(navWnd,20,0,14, 24,"[",4,true);
01572         but->SetButtonListener(this,BUT_NAV_BEGIN);
01573         // Backward
01574                 sprintf(buf,"Backward (%s)", mKeyBindings["annoBackward"].c_str());
01575         but = new Button(navWnd,34,0,94,24,buf,4,true);
01576         but->SetButtonListener(this, BUT_BACK);
01577         but->SetRepeatMode(true);
01578         // StepSize
01579         mStepUpDown = new OglGui::UpDownNumber(navWnd,128,0,34,24,1,12,false,0);
01580         mStepUpDown->SetUpDownNumberListener(this);
01581         mStepUpDown->SetBorderType(BEV_ETCHED);
01582         mStepUpDown->SetRange(1,999);
01583         // Forward
01584                 sprintf(buf,"Forward (%s)", mKeyBindings["annoForward"].c_str());
01585         but = new Button(navWnd,162,0,94,24,buf,4,true);
01586         but->SetButtonListener(this, BUT_FORW);
01587         but->SetRepeatMode(true);
01588         // To End [END]
01589         but = new Button(navWnd,256,0,14,24,"]",4,true);
01590         but->SetButtonListener(this,BUT_NAV_END);
01591     }
01592 
01593     void GuiVideoShotControl()
01594     {
01595         if (mNoSimTLV || mNoShotControl)
01596             return;
01597 
01598         // Adjust left boundary
01599         if (!mNoShotEditing)
01600         {
01601             mShotLeftBtn = new Button(this,12,24,"|",4,true);
01602             mShotLeftBtn->SetButtonListener(this, BUT_LEFT_SHOT);
01603         }
01604         // Scroll over shot
01605         mShotValueSB = new ValueScrollBar(this,160,24,0,100,50,2);
01606         mShotValueSB->SetValueScrollBarListener(this);
01607         // Adjust right boundary
01608         if (!mNoShotEditing)
01609         {
01610             mShotRightBtn = new Button(this,12,24,"|",4,true);
01611             mShotRightBtn->SetButtonListener(this, BUT_RIGHT_SHOT);
01612         }
01613         if (!mNoShotThreshold)
01614         {
01615             // Dynamic shot threshold
01616             StaticText* sTxt = new StaticText(this, 70, 24, "thr:");
01617             sTxt->SetAlign(oglLeftAlign);
01618             mShotThresholdUDNr =
01619                 new UpDownNumber(sTxt,22,0,48,24,0.2f,12,false,0);
01620             mShotThresholdUDNr->SetUpDownNumberListener(this);
01621             mShotThresholdUDNr->SetIncrement(0.01f);
01622             mShotThresholdUDNr->SetBorderType(4);
01623             mShotThresholdUDNr->SetRange(0.1f,0.6f);
01624         }
01625     }
01626 
01627     void GuiRankingControl()
01628     {
01629         int sz = mNoRankSlider ? 160 : 290;
01630         OglGui::Window* rankWnd = new OglGui::Window(this,sz,24);
01631         // Rank mode
01632         mRankChBox = new CheckBox(rankWnd,0,0,130,24,"Rank",false,4);
01633         mRankChBox->SetCheckBoxListener(this, CHBOX_RANK_MODE);
01634         // Rank all shots including annotated ones
01635         mRankAllBtn = InBoxButton(mRankChBox,60,32,"All",BUT_RANK_ALL);
01636         // Rank only shots without annotation
01637         mRankNotAnnoBtn = InBoxButton(mRankChBox,92,36,"!Ann",BUT_RANK_NOT_ANN);
01638         if (!mNoRankSlider)        // Ranking scrollbar
01639         {        
01640             mRankVSB = new ValueScrollBar(rankWnd,130,0,160,24,0,100,0);
01641             mRankVSB->SetValueScrollBarListener(this);
01642         }
01643     }
01644 
01645     void GuiAnnotationControl()
01646     {
01647         Button* but;
01648         but = new Button(this, 140, 24, "Save Annotation",4,true);
01649         but->SetButtonListener(this, BUT_SAVE);
01650 
01651         new Strut(this, 4000, 1);
01652         KbButton("Positive",110,24,"annoPositive",BUT_POSITIVE);
01653         KbButton("Skip",110,24,"annoSkip",BUT_SKIP);
01654         KbButton("Negative",110,24,"annoNegative",BUT_NEGATIVE);
01655         new Strut(this, 100, 1); // Cause newline
01656 
01657         new Strut(this, 16, 1);
01658         KbButton("Shot Positive",160,24,"annoShotPositive",BUT_SHOT_POS);
01659         KbButton("Shot Negative",160,24,"annoShotNegative",BUT_SHOT_NEG);
01660     }
01661 
01662     void GuiAnnoHistoryControl()
01663     {
01664         mAnnoHistoryVSB = 0;
01665         mAnnoHistoryPos = 0;
01666         if (mNoAnnoHistoryControl)
01667             return;
01668         StaticText* txt = new StaticText(this,210,24,"AnnoHistory:");
01669         txt->SetAlign(oglLeftAlign);
01670         mAnnoHistoryVSB = new ValueScrollBar(txt,90,0,120,24,0,1,0);
01671         mAnnoHistoryVSB->SetValueScrollBarListener(this);
01672     }
01673 
01674     void GuiPrevNextAnnotatedControl()
01675     {
01676         if (mNoPrevNextControl)
01677             return;
01678         // PrevNextAnno P|S|N|U  (Pos|Neg|Skip|unknown)
01679         OglGui::Window* prevNextWnd = new OglGui::Window(this,340,24);
01680         prevNextWnd->SetBorderType(BEV_ETCHED);
01681         mPNInVideoCB
01682             = new CheckBox(prevNextWnd,108,22,"StayInVideo",true,0);
01683         mPNInVideoCB->SetCheckBoxListener(this, CHBOX_PN_IN_VIDEO);
01684         mPositiveUDBtn = PrevNextAnnoShot(prevNextWnd,"P", UPDOWNBUT_POSITIVE);
01685         mSkippedUDBtn  = PrevNextAnnoShot(prevNextWnd,"S", UPDOWNBUT_SKIPPED);
01686         mNegativeUDBtn = PrevNextAnnoShot(prevNextWnd,"N", UPDOWNBUT_NEGATIVE);
01687         mUnknownUDBtn  = PrevNextAnnoShot(prevNextWnd,"U", UPDOWNBUT_UNKNOWN);
01688         PrevNextAnnoControlFeedBack();
01689     }
01690 
01691     void InitGUI()
01692     {
01693         GuiName("AnnoControl");
01694         mNrAnnoTxt =  new StaticText(this,340,22,"NrAnno: ");
01695 
01696         mImWnd = new ImagesWindow(this, 360, 290, true);
01697         mImWnd->SetViewSize(352,280);
01698 
01699         mImShotWnd = new ImagesWindow(this, W()-380, 290, true);
01700         mImShotWnd->SetBorderType(BEV_ETCHED);
01701         mImShotWnd->SetViewSize(176,140);
01702 
01703         GuiNavigation();
01704 
01705         // Relevance texts
01706         mFrameText  = new TextArea(this, 100, 24, "<empty>",false);
01707         mShotText   = new TextArea(this, 100, 24, "<empty>",false);
01708 
01709         new Strut(this,1,1);
01710         GuiVideoShotControl();
01711         new Strut(this,15,1);
01712         GuiRankingControl();
01713         new Strut(this, 20, 1);
01714         GuiAnnotationControl();
01715         GuiAnnoHistoryControl();
01716         GuiPrevNextAnnotatedControl();
01717         //Button* btn = new Button(this,60,24,"PUNS");
01718         //btn->SetButtonListener(this,1234);
01719         HandleConceptsFromFile();
01720     }
01721 
01722     void ReadKeyBindings()
01723     {
01724         InitKeyBinding("annoForward","0");
01725         InitKeyBinding("annoBackward", "9");
01726         InitKeyBinding("annoPositive", "1");
01727         InitKeyBinding("annoSkip", "2");
01728         InitKeyBinding("annoNegative", "3");
01729         InitKeyBinding("annoShotPositive", "6");
01730         InitKeyBinding("annoShotNegative", "7");
01731         InitKeyBinding("annoTogglePlay", " ");
01732     }
01733 
01734     void HandleCmdOptions()
01735     {
01736         CmdOptions& options = CmdOptions::GetInstance();
01737         mConceptFeature = options.GetString("conceptFeature");
01738         mConceptModel = options.GetString("conceptModel");
01739         mRankSet = options.GetString("rankSet");
01740         mRankFeature = options.GetString("rankFeature");
01741         mRankModel = options.GetString("rankModel");
01742         mFrameSliding = options.GetBool("annoFrameSliding",false);
01743         mNoSimTLV = options.GetBool("annoNoTimeLineVideo", false);
01744         mNoShotControl = options.GetBool("annoNoShotControl", false);
01745         mNoShotEditing = options.GetBool("annoNoShotEditing", false);
01746         mNoShotThreshold = options.GetBool("annoNoShotThreshold", false);
01747         mNoRankSlider = options.GetBool("annoNoRankSlider", false);
01748         mNoAnnoHistoryControl = options.GetBool("annoNoHistoryControl", false);
01749         mNoPrevNextControl = options.GetBool("annoNoPrevNextControl", false);
01750         mNoViewStripControl = options.GetBool("annoNoViewStripControl",false);
01751         //mWoggelOnLoadAnnotations = options.GetBool("annoWoggelOnLoadAnnotations",false);
01752     }
01753 
01754     void
01755     InitVars(SegmentationDocument* segDoc, String conceptSet, int annoPerVideo)
01756     {
01757         mSegDoc                 = segDoc;
01758         mConceptSet             = conceptSet;
01759         mMaxAnnoPerVideo        = annoPerVideo;
01760 
01761         mVidSet                 = mSegDoc->GetVideoSet();
01762         mKeyframes              = mSegDoc->GetKeyframes();
01763         mKeyframeSet            = mSegDoc->GetImSetKeyframes(false);
01764 
01765         if (!mKeyframeSet)
01766             mKeyframeSet        = mSegDoc->GetImSetKeyframes(true);
01767 
01768         mNrAnnoPerVideo         = 0;
01769         mNrAnnotated            = 0;
01770         mNrPositive             = 0;
01771         mNrSkip                 = 0;
01772         mNrNegative             = 0;
01773         mStepSize               = 1;
01774 
01775         mCurFile                = -1;
01776         mCurConcept             = -1;
01777         mCurMpeg7               = 0;
01778         mCurKey                 = 0;
01779 
01780         mRgbDataSrc             = 0;
01781         mShotSimSet             = 0;
01782         mSimSet                 = 0;
01783         mSimTLV                 = 0;
01784 
01785         mCurRankShot            = 0;
01786         mRankingMode            = true;
01787         mRankAll                = false;
01788         mRankFilterBits         = UNKNOWN_BIT;
01789 
01790         mShotThreshold          = 0.2f;
01791         mShotValueSB            = 0;
01792         mAnnoSearchRecursLevel  = 0;
01793 
01794         //mTitledPUNS             = 0;
01795 
01796         mRankVSB                = 0;
01797         mRankVSBAdjusting       = false;
01798         mAnnoHistoryVSBAdjusting = false;
01799         mPrevNextAnnoStayInVideo = true;
01800         mAnnoSearching          = false;
01801         mShowSegShots           = false;
01802         mShowThreshShots        = false;
01803         mCurMpeg7Changed        = false;
01804         mNoAutoNextAnno         = false;
01805     }
01806 
01807 
01808     void
01809     Init(SegmentationDocument* segDoc, String conceptSet, int maxAnnoPerVideo)
01810     {
01811         HandleCmdOptions();
01812         ReadKeyBindings();
01813         InitVars(segDoc,conceptSet,maxAnnoPerVideo);
01814         mNoAutoNextAnno = true;
01815         InitGUI();
01816         AllHandleNewCursor(segDoc->CursorToDir(0),false);
01817         mNoAutoNextAnno = false;
01818     }
01819 
01820     VideoAnnotations                mVideoAnnotations;
01821     std::vector<AnnoHistory>        mAnnoHistory;
01822     std::vector<int>                mShots;
01823     std::vector<int>                mCurShotFrames;
01824     std::vector<int>                mRankedShots;
01825 
01826     SegmentationDocument*           mSegDoc;
01827     Core::VideoSet::VideoSet*       mVidSet;
01828     Core::VideoSet::Keyframes*      mKeyframes;
01829     Core::ImageSet::ImageSet*       mKeyframeSet;
01830     Core::VideoSet::Mpeg7Doc*       mCurMpeg7;
01831     SimilarityTableSet*             mShotSimSet; // ShotBoundaries
01832     SimilarityTableSet*             mSimSet;     // Concept similarities+ranking
01833     RgbDataSrc*                     mRgbDataSrc;
01834 
01835     ImagesWindow*                   mImWnd;
01836     ImagesWindow*                   mImShotWnd;
01837     StaticText*                     mNrAnnoTxt;
01838     TextArea*                       mFrameText;
01839     TextArea*                       mShotText;
01840     CheckBox*                       mAllowSlidingChBox;
01841     CheckBox*                       mPNInVideoCB;
01842     CheckBox*                       mRankChBox;
01843 
01844     SimilarityTimeLineVideo*        mSimTLV;
01845     ValueScrollBar*                 mRankVSB;
01846     ValueScrollBar*                 mShotValueSB;
01847     ValueScrollBar*                 mAnnoHistoryVSB;
01848     UpDownNumber*                   mStepUpDown;
01849     UpDownNumber*                   mShotThresholdUDNr;
01850     UpDownButton*                   mPositiveUDBtn;
01851     UpDownButton*                   mNegativeUDBtn;
01852     UpDownButton*                   mSkippedUDBtn;
01853     UpDownButton*                   mUnknownUDBtn;
01854 
01855     Button*                         mNavModeBtn;
01856     Button*                         mRankAllBtn;
01857     Button*                         mRankNotAnnoBtn;
01858     Button*                         mShotLeftBtn;
01859     Button*                         mShotRightBtn;
01860     Button*                         mSyncBtn;
01861 
01862     String                          mRankSet;
01863     String                          mRankFeature;
01864     String                          mRankModel;
01865     String                          mConceptModel;
01866     String                          mConceptFeature;
01867     String                          mConceptSet;
01868 
01869     double                     mCurRelevance;
01870     float                      mShotThreshold;
01871 
01872     int                        mCurFile;
01873     int                        mCurConcept;
01874     int                        mCurKey;
01875     int                        mCurRankShot;
01876     int                        mMaxAnnoPerVideo;
01877     int                        mStepSize;
01878     int                        mNrAnnoPerVideo;
01879     int                        mNrAnnotated;
01880     int                        mNrPositive;
01881     int                        mNrSkip;
01882     int                        mNrNegative;
01883     int                        mAnnoSearchRecursLevel;
01884     int                        mRankFilterBits;
01885     int                        mAnnoHistoryPos;
01886 
01887     bool                       mRankAll;
01888     bool                       mShotValueSBAdjusting;
01889     bool                       mRankVSBAdjusting;
01890     bool                       mAnnoHistoryVSBAdjusting;
01891 
01892     bool                       mNoSimTLV;
01893     bool                       mNoShotControl;
01894     bool                       mNoShotEditing;
01895     bool                       mNoShotThreshold;
01896     bool                       mNoRankSlider;
01897     bool                       mNoAnnoHistoryControl;
01898     bool                       mNoPrevNextControl;
01899     bool                       mNoViewStripControl;
01900     //bool                       mWoggelOnLoadAnnotations;
01901 
01902     bool                       mRankingMode;
01903     bool                       mShowSegShots;
01904     bool                       mShowThreshShots;
01905     bool                       mPrevNextAnnoStayInVideo;
01906     bool                       mAnnoSearching;
01907     bool                       mNextAnnoFound;
01908     bool                       mCurMpeg7Changed;
01909     bool                       mFrameSliding;
01910     bool                       mNoAutoNextAnno;
01911 
01912     ILOG_VAR_DEC;
01913 };
01914 
01915 ILOG_VAR_INIT(SegmentationDocumentGuiAnno, Visualization);
01916 
01917 } // namespace Visualization
01918 } // namespace Impala
01919 
01920 #endif

Generated on Thu Jan 13 09:05:21 2011 for ImpalaSrc by  doxygen 1.5.1