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

SimilarityPlotNeedleImage.h

Go to the documentation of this file.
00001 //345678901234567890123456789012345678901234567890123456789012345678901234567890
00002 // Author: Richard van Balen
00003 #ifndef Impala_Visualization_SimilarityPlotNeedleImage_h
00004 #define Impala_Visualization_SimilarityPlotNeedleImage_h
00005 
00006 #include "Core/VideoSet/SegmentationDocument.h"
00007 #include "OglGui/StringSelector.h"
00008 #include "OglGui/StringListener.h"
00009 #include "OglGui/StaticText.h"
00010 #include "OglGui/Slider.h"
00011 #include "Visualization/ImagesWindow.h"
00012 #include "Visualization/AppControlDoc.h"
00013 #include "Visualization/Plot/Plot.h"
00014 #include "Visualization/Plot/Points.h"
00015 #include "Visualization/Plot/PlotNeedle.h"
00016 
00017 namespace Impala {
00018 namespace Visualization {
00019 
00020 class SimilarityPlotNeedleImage : public Window,
00021                                   public AppControlDoc,
00022                                   public Core::Database::DataDocumentListener,
00023                                   public ImagesListener,
00024                                   public OglGui::StringListener,
00025                                   //public OglGui::SliderListener,
00026                                   public Visualization::Plot::PlotNeedleListener
00027 {
00028 public:
00029     typedef Core::VideoSet::SegmentationDocument    SegmentationDocument;
00030     typedef Core::Table::SimilarityTableSet         SimilarityTableSet;
00031     typedef SimilarityTableSet::RankTableType       RankTableType;
00032     typedef SimilarityTableSet::SimTableType        SimTableType;
00033     typedef Visualization::Plot::PlotNeedle         PlotNeedle;
00034     typedef OglGui::StringSelector                  StringSelector;
00035     typedef OglGui::StaticText                      StaticText;
00036     //typedef OglGui::Slider                          Slider;
00037 
00038     SimilarityPlotNeedleImage(OglGui::Window* parent,
00039                               int wndWidth, int wndHeight,
00040                               int thumbWidth, int thumbHeight,
00041                               SegmentationDocument* segDoc,
00042                               SimilarityTableSet* simSet, int controlId) :
00043         Window(parent, wndWidth, wndHeight, true),
00044         AppControlDoc(controlId, segDoc)
00045     {
00046         mSegDoc = segDoc;
00047         mSimSet = simSet;
00048         mCurKeyframe = -1;
00049         mCurFile = -1;
00050         mCurConcept = -1;
00051         mShowMaxSim = 1.0;
00052         mPointSize = 1;
00053         mKeyframes = mSegDoc->GetKeyframes();
00054         mKeyframeSet = mSegDoc->GetImSetKeyframes(true);
00055         AddDocListener(this);
00056 
00057         mStringSelector = new StringSelector(this, wndWidth, 120);
00058         std::vector<std::string> names = mSimSet->GetNames();
00059         for (int i=0 ; i<names.size() ; i++)
00060         {
00061             mStringSelector->AddString(names[i]);
00062             mSegDoc->AddConcept(names[i]);
00063         }
00064         mStringSelector->SetStringListener(this, 0);
00065 
00066         mPlotPoints = new Plot::Plot(this, wndWidth-10, 490);
00067         mPlotPoints->SetDrawAxes(true);
00068 
00069         mPlotNeedle = new PlotNeedle(0,100,0,5,-5);
00070         mPlotNeedle->SetRoundOffset(0.5); // To find frame nearest to needle
00071         mPlotNeedle->SetPlotNeedleListener(this, 0);
00072         mPlotPoints->Add(mPlotNeedle);
00073 
00074         mPoints = new Visualization::Plot::Points();
00075         mPlotPoints->Add(mPoints);
00076 
00077         mImageWnd = new ImagesWindow(this, thumbWidth, thumbHeight);
00078         mImageWnd->ActivateInfoBox(false);
00079         mImageWnd->SetImagesListener(this, 0);
00080 
00081         mInfoText = new StaticText(this, 200, 20, "");
00082         mInfoText->SetAlign(oglLeftAlign, oglCenterAlign);
00083 
00084         /*
00085         mMaxSimSlider = new Slider(this,400,50,0,1000,1000);
00086         mMaxSimSlider->SetShowValPerc(true);
00087         mMaxSimSlider->SetPrecisionIdx(3);
00088         mMaxSimSlider->SetSliderListener(this, 0);
00089         new StaticText(this, 100, 20, "Max sim to show", false);
00090         */
00091         mSegDoc->SetConcept(0);
00092     }
00093 
00094     void FillPoints()
00095     {
00096         double minY = 1000, maxY=-1000;
00097         mPoints->Clear();
00098         for (int i=0; i<mNrOfKeys; i++)
00099         {
00100             //double y = mSimTable->Get1(mStartKey+i);
00101             Quid quid = mKeyframes->GetQuidFrame(mStartKey+i);
00102             int rank = mSimSet->FindQuid(quid);
00103             double y = mSimTable->Get1(rank);
00104             if (y<minY) minY = y;
00105             if (y>maxY) maxY = y;
00106             if (y<=mShowMaxSim)
00107                 mPoints->AddPoint(i+1, y, 0, 0, 1, 0, mPointSize, false);
00108         }
00109         mPoints->SetDimensionsX(1, mNrOfKeys);
00110         mPoints->SetDimensionsY(minY, maxY);
00111 
00112         mPlotPoints->SetRange(mNrOfKeys,2*fabs(maxY-minY),0);
00113         mPlotPoints->SetCenter(mNrOfKeys/2,minY,0.5);
00114 
00115         mPlotNeedle->SetMinMaxX(1, mNrOfKeys);
00116 
00117         //mMaxSimSlider->SetMinMax(minY*1000,maxY*1000);
00118         //mMaxSimSlider->SetTickInterval(fabs(maxY-minY)*100);
00119     }
00120 
00121     virtual void
00122     HandleNewFile()
00123     {
00124         if (!(mSegDoc->HasCursor() && mKeyframes && mKeyframeSet))
00125         {
00126             mCurKeyframe = mCurFile = -1;
00127             mImageWnd->RemoveImages();
00128             return;
00129         }
00130 
00131         int fileId  = mSegDoc->CurFileId();
00132         int concept = mSegDoc->GetConceptIdx();
00133 
00134         if (concept != mStringSelector->GetCurrentStringIdx())
00135             mStringSelector->SetCurrentString(concept, true);
00136 
00137         mSimTable = mSimSet->GetSimTable(concept);
00138         mStartKey = mKeyframes->GetFirstKeyframeVideo(fileId);
00139         mNrOfKeys = mKeyframes->GetNrKeyframesVideo(fileId);
00140         mCurKeyframe = mStartKey;
00141 
00142         if (!(fileId == mCurFile && concept == mCurConcept))
00143         {
00144             FillPoints();
00145             mPlotPoints->SetUserPan(0,0);
00146             mPlotPoints->SetUserZoom(0.9,0.9);
00147         }
00148 
00149         mCurFile = fileId;
00150         mCurConcept = concept;
00151 
00152         mCurKeyframe = mSegDoc->CurKeyfr() - mStartKey;
00153         mPlotNeedle->MoveTo(mCurKeyframe+1);
00154         //int minV, maxV;
00155         //mMaxSimSlider->GetMinMax(minV, maxV);
00156         //mMaxSimSlider->SetValue(maxV);
00157         UpdateImage();
00158     }
00159 
00160 
00161     void UpdateImage()
00162     {
00163         if (mCurKeyframe == -1 || !mKeyframeSet)
00164             return;
00165 
00166         mImageWnd->RemoveImages();
00167         mImageWnd->AddImage(mCurKeyframe, mKeyframeSet);
00168 
00169         //double sim = mSimTable->Get1(mCurKeyframe);
00170         Quid quid = mKeyframes->GetQuidFrame(mCurKeyframe);
00171         int rank = mSimSet->FindQuid(quid);
00172         double sim = mSimTable->Get1(rank);
00173         mInfoText->SetText("sim = "+ MakeString(sim));
00174 
00175         UpdatePointPlot();
00176 //mSegDoc->GotoKeyfr(mCurKeyframe);
00177 //AllHandleNewCursor(Core::Database::LEVEL_FRAME, false);
00178     }
00179 
00180     virtual void
00181     StringSelectionEvent(StringSelector* src, int strIndex, void* listenerData)
00182     {
00183         mSegDoc->SetConcept(strIndex);
00184         HandleNewFile();
00185     }
00186 
00187     /*
00188     virtual void SliderChangedEvent(Slider *src, int userData)
00189     {
00190         mShowMaxSim = src->GetValue()/1000.0f;
00191         FillPoints();
00192     }
00193     */
00194 
00195     virtual void
00196     ImageSelectionEvent(ImagesWindow* src, int imIndex, void* listenerData)
00197     {
00198         /*
00199         RankTableType* rank = mSimSet->GetRankTable(mCurConcept);
00200         bool rankIsKeyframe = rank->Size() == mKeyframes->GetNrKeyframes();
00201         int rankId = rank->Get1(mCurKeyframe);
00202         int keyfr = (rankIsKeyframe) ? rankId : mKeyframes->GetShotRKF(rankId);
00203         int shot = mKeyframes->GetShotId(keyfr);
00204         mSegDoc->GotoKeyfr(keyfr);
00205         SimTableType* simTable = mSimSet->GetSimTable(mCurConcept);
00206         std::string truth;
00207         mInfoText->SetText("rank = " + MakeString(rankId) +
00208                            ", sim = " + MakeString(simTable->Get1(rankId))
00209                           );
00210         AllHandleNewCursor(Core::Database::LEVEL_SHOT, false);
00211         */
00212     }
00213 
00214     virtual void
00215     KeyEvent(OglGui::Window* src, int c, int state)
00216     {
00217         int oldKeyFr = mCurKeyframe;
00218 
00219         if (c=='p' || c=='P') {
00220             if ((mPointSize += (c=='P' ? 1 : -1)) < 1)
00221                 mPointSize = 1;
00222             FillPoints();
00223         }
00224         if (c==oglLEFT && --mCurKeyframe < 0)
00225             mCurKeyframe = 0;
00226         if (c==oglRIGHT && ++mCurKeyframe > mKeyframes->GetNrKeyframes())
00227             mCurKeyframe = mKeyframes->GetNrKeyframes()-1;
00228         if (oldKeyFr != mCurKeyframe)
00229             UpdateImage();
00230     }
00231 
00232     virtual void PlotNeedleChanged(PlotNeedle* src, double nX, void* userData)
00233     {
00234         if (mCurKeyframe == (int) (mStartKey+nX-1))
00235         {
00236             UpdatePointPlot();
00237             return;
00238         }
00239         mCurKeyframe = mStartKey + nX-1;
00240         if (mCurKeyframe < mStartKey)
00241             mCurKeyframe = mStartKey;
00242         if (mCurKeyframe > mStartKey+mNrOfKeys)
00243             mCurKeyframe = mStartKey+mNrOfKeys;
00244         UpdateImage();
00245     }
00246 
00247 
00248 private:
00249     void
00250     UpdatePointPlot()
00251     {
00252         if (!mPlotPoints)
00253             return;
00254 
00255         double nPos = mCurKeyframe-mStartKey+1;
00256         mPlotNeedle->MoveTo(nPos);
00257 
00258         // Lines below pan the plot to keep the needle in sight
00259         double panX, panY;
00260         double l,t,r,b;
00261         mPlotPoints->GetUserPan(panX, panY);
00262         mPlotPoints->GetRange(l,t,r,b);
00263         if (nPos > r || nPos < l)
00264             mPlotPoints->SetUserPan(panX - (nPos - (nPos>r ? r:l)), panY);
00265     }
00266 
00267     SegmentationDocument*         mSegDoc;
00268     SimilarityTableSet*           mSimSet;
00269     SimTableType*                 mSimTable;
00270     int                           mCurConcept;
00271     int                           mCurFile;
00272     int                           mStartKey;
00273     int                           mNrOfKeys;
00274     int                           mCurKeyframe;
00275     int                           mPointSize;
00276 
00277     double                        mShowMaxSim;
00278 
00279     Core::VideoSet::Keyframes*    mKeyframes;
00280     Core::ImageSet::ImageSet*     mKeyframeSet;
00281 
00282     StringSelector*               mStringSelector;
00283     StaticText*                   mInfoText;
00284     ImagesWindow*                 mImageWnd;
00285     //Slider*                       mMaxSimSlider;
00286 
00287     Visualization::Plot::Plot*    mPlotPoints;
00288     Visualization::Plot::Points*  mPoints;
00289     PlotNeedle*                   mPlotNeedle;
00290 
00291     ILOG_VAR_DEC;
00292 };
00293 
00294 ILOG_VAR_INIT(SimilarityPlotNeedleImage, Visualization);
00295 
00296 } // namespace Visualization
00297 } // namespace Impala
00298 
00299 #endif

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