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

KeyframeResultBar.h

Go to the documentation of this file.
00001 #ifndef Impala_Visualization_GUI_KeyframeResultBar_h
00002 #define Impala_Visualization_GUI_KeyframeResultBar_h
00003 
00004 #include "OglGui/Window.h"
00005 #include "Visualization/ImageSet.h"
00006 #include "Core/Trec/KeyframeResult.h"
00007 #include "Core/ImageSet/ImageSet.h"
00008 
00009 namespace Impala {
00010 namespace Visualization {
00011 namespace GUI {
00012 
00013 using namespace OglGui;
00014 
00015 class KeyframeResultBarListener
00016 {
00017 public:
00018     virtual void
00019     KeyframeSelectedEvent(String name, int keyframe)
00020     {
00021     }
00022 };
00023 
00024 
00025 class KeyframeResultBar :   public OglGui::Window,
00026                             public Visualization::ImagesListener
00027 {
00028 public:
00029     typedef std::list<Core::Trec::KeyframeResult>   KeyframeResultList;
00030     typedef Core::VideoSet::Keyframes               Keyframes;
00031 
00032     KeyframeResultBar(OglGui::Window *parent, int w, int h, String name,
00033                       KeyframeResultList results, Keyframes* keyframes,
00034                       Core::ImageSet::ImageSet* imSet, int thumbW, int thumbH,
00035                       double viewscale) :
00036         OglGui::Window(parent, w, h)
00037     {
00038         Init(w, h, name, results, keyframes, imSet, thumbW, thumbH, viewscale);
00039     }
00040 
00041     virtual void ImageSelectionEvent(Visualization::ImagesWindow *src,
00042                                      int imIndex, void* listenerData)
00043     {
00044         ILOG_DEBUG("ImSelEvent: selected rank=" << imIndex << " keyframe=" <<
00045                    GetImageKeyframeID(imIndex));
00046         if (!mBarListener) return;
00047         mBarListener->KeyframeSelectedEvent(mName, GetImageKeyframeID(imIndex));
00048     }
00049 
00050     void SetListener(KeyframeResultBarListener *listener)
00051     {
00052         mBarListener = listener;
00053     }
00054 
00055     String NiceName()
00056     {
00057         if (mName == "visual_vissem")
00058             return "Weibull";
00059         if (mName == "visual_vissemgabor")
00060             return "Gabor";
00061         if (mName == "visual_fusionvissemgabor")
00062             return "Weibull/Gabor fusion";
00063         if (mName == "visual_labhistogram")
00064             return "LAB color histogram";
00065         return mName;
00066     }
00067 
00068 protected:
00069     // add a simple plot of similarity scores for first n ranked similars
00070     void DoRankPlot(int wndW, int wndH)
00071     {
00072         int plotW   = mKeyResults.size() * 2;
00073         int plotH   = 16;
00074 
00075         OglGui::Window* simPlotWin = new Window(this,wndW-plotW-4, wndH-plotH-3,
00076                                                 plotW, plotH, true);
00077         simPlotWin->SetBackground(oglLIGHTGREEN);
00078         simPlotWin->ConnectTo(this, R2R|T2T|B2T);
00079 
00080         OGLWND *oglWnd = simPlotWin->GetOGLWND();
00081         mSimPlotView = new Visualization::View(oglWnd, 0, 0, plotW, plotH, 1.0,
00082                                                false, false, true, NULL);
00083         KeyframeResultList::reverse_iterator lastResult = mKeyResults.rbegin();
00084         // RvB: Next line caused crash
00085         // lastResult++; // SK: Shouldn't need this, but MSVC++ appears to do...
00086         double maxScore = lastResult->score;
00087 
00088         static Core::Array::Element::Vec3Int32 colorCanvas(40, 40, 40);
00089         static Core::Array::Element::Vec3Int32 colorPlot(255, 255, 0);
00090 
00091         Core::Array::Array2dVec3UInt8* im =
00092             new Core::Array::Array2dVec3UInt8(plotW, plotH, 0, 0);
00093 
00094         int xCoord = 0;
00095         KeyframeResultList::iterator res = mKeyResults.begin();
00096         while (res != mKeyResults.end())
00097         {
00098             int valueToPlot = (int)((res->score / maxScore) * (plotH-1.0)+0.5);
00099             for (int yCoord = 0; yCoord < plotH; yCoord++)
00100             {
00101                 Core::Array::Element::Vec3Int32& pixel =
00102                     (plotH-1-yCoord == valueToPlot ? colorPlot : colorCanvas);
00103                 im->SetValue(pixel, xCoord, yCoord);
00104                 im->SetValue(pixel, xCoord + 1, yCoord);
00105             }
00106             xCoord += 2;
00107             res++;
00108         }
00109         mSimPlotView->UpdateImage(im, "Direct");
00110         // RvB: 2-2-2009 I think this needs deleting
00111         delete im;
00112     }
00113 
00114     void Init(int wndW, int wndH, String name, KeyframeResultList results,
00115               Keyframes *keyframes, Core::ImageSet::ImageSet* imSet,
00116               int thumbW, int thumbH, double viewscale)
00117     {
00118         mName           = name;
00119         mKeyResults     = results;
00120         mKeyframes      = keyframes;
00121         mBarListener    = NULL;
00122         mPreviewImages  = NULL;
00123         mSimPlotView    = NULL;
00124 
00125         SetRoundness(4,4,4,4);
00126         SetBorderType(4);
00127         SetBorderFillShaded(2);
00128 
00129         StaticText *t = new StaticText(this,2,wndH-17,wndW-100,17,NiceName());
00130         t->SetAlign(oglLeftAlign, oglCenterAlign);
00131         t->ConnectTo(this, L2L|T2T|B2T);
00132 
00133         // images:
00134         if (results.size() == 0)
00135             return;
00136 
00137         int nrImOnRow   = (int)(wndW      / ((double)thumbW * viewscale));
00138         int nrRows      = (int)((wndH-18) / ((double)thumbH * viewscale));
00139         
00140         if (nrRows == 0) nrRows = 1;
00141 
00142         Window *wnd = new Window(this, 3, 2, wndW-6, wndH-19);
00143 
00144         mPreviewImages = new Visualization::ImageSet(wnd, 1, 1, thumbW, thumbH,
00145                                                     viewscale,nrImOnRow,nrRows);
00146         mPreviewImages->ActivateInfoBox(false);
00147         mPreviewImages->SetImagesListener(this, 0);
00148         // RvB: Added because views inside seem to be corrupt
00149         // and cause crash when doing standard viewSys.view2d stuff
00150         mPreviewImages->SetDisableOGLViewKeys( true );
00151         mPreviewImages->SetDisableOGLViewMouse( true );
00152 
00153         int i=0;
00154         KeyframeResultList::iterator shot;
00155         for (shot = results.begin(); shot != results.end(); shot++)
00156         {
00157             int frameID = shot->keyframeid;
00158             if (frameID >= 0)
00159                 mPreviewImages->AddImage(imSet->GetImage(frameID), "Direct",
00160                                          "", true);
00161             if (++i >= nrImOnRow * nrRows)
00162                 break;
00163         }
00164         DoRankPlot(wndW, wndH);
00165     }
00166 
00167     virtual int GetImageKeyframeID(int rank)
00168     {
00169         int foundrank = 0;
00170         KeyframeResultList::iterator shot;
00171         for (shot = mKeyResults.begin(); shot != mKeyResults.end(); shot++)
00172         {
00173             int frameID = shot->keyframeid;
00174             if (frameID >= 0)
00175             {
00176                 if (rank == foundrank)
00177                     return frameID;
00178                 foundrank ++;
00179             }
00180         }
00181         return -1;
00182     }
00183 
00184     String                      mName;
00185     Visualization::ImageSet*    mPreviewImages;
00186     KeyframeResultList          mKeyResults;
00187     Keyframes*                  mKeyframes;
00188     KeyframeResultBarListener*  mBarListener;
00189     Visualization::View*        mSimPlotView;
00190     
00191 ILOG_VAR_DEC;
00192 };
00193 
00194 ILOG_VAR_INIT(KeyframeResultBar, Impala.Visualization.GUI);
00195 
00196 } // namespace GUI
00197 } // namespace Visualization
00198 } // namespace Impala
00199 #endif

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