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

ShotResultPreviewBar.h

Go to the documentation of this file.
00001 #ifndef Impala_Visualization_GUI_ShotResultPreviewBar_h
00002 #define Impala_Visualization_GUI_ShotResultPreviewBar_h
00003 
00004 #include "PreviewBar.h"
00005 
00006 #include "Core/Trec/ShotResult.h"
00007 #include "Core/Trec/KeyframeResult.h"
00008 
00009 #include "Core/ImageSet/ImageSet.h"
00010 #include "Core/VideoSet/Segmentation.h"
00011 
00012 namespace Impala {
00013 namespace Visualization {
00014 namespace GUI {
00015 
00016 //using namespace OglGui;
00017 
00018 class ShotResultPreviewBar : public PreviewBar
00019 {
00020 public:
00021     typedef Core::Trec::ShotResult              ShotResult;
00022     typedef Core::Trec::KeyframeResult          KeyframeResult;
00023     typedef std::list<ShotResult>               ShotResultList;
00024     typedef std::list<KeyframeResult>           KeyframeResultList;
00025     typedef Core::VideoSet::Segmentation        Segmentation;
00026     typedef Core::VideoSet::Keyframes           Keyframes;
00027     typedef Core::ImageSet::ImageSet            CoreImageSet;
00028 
00029     ShotResultPreviewBar(OglGui::Window* parent, int w, int h, String query,
00030                          ShotResultList results, Segmentation* shots,
00031                          Keyframes* keyframes, CoreImageSet* imSet,
00032                          bool selected, int thumbW, int thumbH,
00033                          double viewscale) :
00034         PreviewBar(parent, w, h, query, 1.0, selected)
00035     {
00036         Init(results, shots, keyframes, imSet, thumbW, thumbH, viewscale);
00037     }
00038 
00039     ShotResultPreviewBar(Window *parent, int w, int h, String query,
00040                          KeyframeResultList results, Segmentation* shots,
00041                          Keyframes* keyframes, CoreImageSet* imSet,
00042                          bool selected, int thumbW, int thumbH,
00043                          double viewscale) :
00044         PreviewBar(parent, w, h, query, 1.0, selected)
00045     {
00046         Init(results, shots, keyframes, imSet, thumbW, thumbH, viewscale);
00047     }
00048 
00049 
00050     ShotResultList GetShots()
00051     {
00052         return mShotResults;
00053     }
00054 
00055 private:
00056     void GeneralInit(int type, int nrIm, int space, Segmentation* shots,
00057                      Keyframes *keyframes, int thumbW, int thumbH,
00058                      double viewscale)
00059     {
00060         SetType(type);
00061 
00062         mPreviewImages  = NULL;
00063         mShots          = shots;
00064         mKeyframes      = keyframes;
00065         mNrImOnRow      = 10; // Dummy default
00066 
00067         // images:
00068         if (nrIm == 0)
00069             return;
00070 
00071         if (H() < thumbH) // adjusting scale to fit
00072             viewscale = (H()-2.0) / thumbH;
00073 
00074         mNrImOnRow = (W()-(space+4)) / (thumbW * viewscale) + 1;
00075 
00076         Window *wnd = new OglGui::Window(this, space, 0, W()-(space+4), H());
00077         if (debug)
00078             std::cout << " Preview: " << mName << ": " << thumbW << "x" <<
00079                          thumbH << "@" << viewscale << ", nr " <<
00080                          mNrImOnRow << std::endl;
00081 
00082         mPreviewImages = new Visualization::ImageSet(wnd, thumbW, thumbH,
00083                                                      viewscale,mNrImOnRow,1,0);
00084         mPreviewImages->ActivateInfoBox(false);
00085         mPreviewImages->SetImagesListener(this, 0);
00086     }
00087 
00088     void Init(ShotResultList results, Segmentation* shots, Keyframes *keyframes,
00089               CoreImageSet* imSet, int thumbW, int thumbH, double viewscale)
00090     {
00091         GeneralInit(10, results.size(), 170, shots, keyframes,
00092                     thumbW, thumbH, viewscale);
00093 
00094         mShotResults = results;
00095 
00096         // images:
00097         if (!mPreviewImages)
00098             return;
00099 
00100         int i=0;
00101         ShotResultList::iterator shot;
00102         for (shot = results.begin(); shot != results.end(); shot++)
00103         {
00104             if (debug)
00105                 std::cout << shot->shotid << " (rank=" << shot->rank
00106                           << " score=" << shot->score << "): ";
00107 
00108             int shotID = shot->shotid; //shots->GetShotId(shot->shotname);
00109             if (shotID >= 0)
00110             {
00111                 int frameID = keyframes->GetShotRKF(shotID);
00112                 if (frameID >= 0)
00113                 {
00114                     if (debug)
00115                         std::cout << "rkf = " << shotID << " frame = "
00116                                   << frameID << std::endl;
00117                     std::ostringstream m;
00118                     m << shot->rank << " " << shot->score << " " << frameID;
00119                     mPreviewImages->AddImage(imSet->GetImage(frameID), "Direct",
00120                                              m.str(), true);
00121                     if (++i >= mNrImOnRow)
00122                         break;
00123                 }
00124             }
00125         }
00126     }
00127 
00128     void Init(KeyframeResultList results, Segmentation* shots,
00129               Keyframes *keyframes, CoreImageSet* imSet, int thumbW, int thumbH,
00130               double viewscale)
00131     {
00132         GeneralInit(11, results.size(), 120, shots, keyframes,
00133                     thumbW, thumbH, viewscale);
00134 
00135         mKeyResults = results;
00136 
00137         if (!mPreviewImages)
00138             return;
00139 
00140         int i=0;
00141         KeyframeResultList::iterator shot;
00142         for (shot = results.begin(); shot != results.end(); shot++)
00143         {
00144             if (debug)
00145                 std::cout << shot->keyframeid << " (rank=" << shot->rank
00146                           << " score=" << shot->score << "): ";
00147 
00148             int frameID = shot->keyframeid;
00149             if (frameID >= 0)
00150             {
00151                 std::ostringstream m;
00152                 m << shot->rank << " " << shot->score;
00153                 mPreviewImages->AddImage(imSet->GetImage(frameID), "Direct",
00154                                          m.str(), true);
00155                 if (++i >= mNrImOnRow)
00156                     break;
00157             }
00158         }
00159     }
00160 
00161     virtual int
00162     GetImageKeyframeID(int rank)
00163     {
00164         // ugly loop-implementation to allow for missing images:
00165         int foundrank = 0;
00166 
00167         if (mShotResults.size() > 0)
00168         {
00169             ShotResultList::iterator shot;
00170             for (shot=mShotResults.begin(); shot!=mShotResults.end(); shot++)
00171             {
00172                 int shotID = shot->shotid;
00173                 if (shotID >= 0)
00174                 {
00175                     if (rank == foundrank)
00176                     {
00177                         // we found our match:
00178                         int frameID = mKeyframes->GetShotRKF(shotID);
00179                         if (debug)
00180                             std::cout << "FOUND shot " << shotID
00181                                       << " translates into " << frameID
00182                                       << std::endl;
00183     
00184                         return frameID;
00185                     }
00186                     foundrank ++;
00187                 }
00188             }
00189         }
00190         else
00191         {
00192             KeyframeResultList::iterator shot;
00193             for (shot = mKeyResults.begin(); shot != mKeyResults.end(); shot++)
00194             {
00195                 int frameID = shot->keyframeid;
00196                 if (frameID >= 0)
00197                 {
00198                     if (rank == foundrank)
00199                     {
00200                         // we found our match:
00201                         std::cout << "FOUND shot " << frameID << std::endl;
00202                         return frameID;
00203                     }
00204                     foundrank ++;
00205                 }
00206             }
00207         }
00208         return -1;
00209     }
00210 
00211     // allow for select/deselect in this GUI component
00212 
00213     int                 mNrImOnRow;
00214     ShotResultList      mShotResults;
00215     KeyframeResultList  mKeyResults;
00216     Segmentation*       mShots;
00217     Keyframes*          mKeyframes;
00218 };
00219 
00220 } // GUI
00221 } // Visualization
00222 } // Impala
00223 
00224 #endif

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