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

VideoPlayerView.h

Go to the documentation of this file.
00001 #ifndef Impala_Application_SDash_VideoPlayerView_h
00002 #define Impala_Application_SDash_VideoPlayerView_h
00003 
00004 #include <vector>
00005 #include <ostream>
00006 #include <strstream>
00007 
00008 #include "Link/OGL/OGLWnd.h"
00009 #include "Link/OGL/OGLView2D.h"
00010 #include "Link/OGL/OGLGraphics.h"
00011 
00012 #include "Core/Geometry/Rectangle.h"
00013 #include "Core/Array/Arrays.h"
00014 #include "Core/Array/ReadJpg.h"
00015 
00016 #include "OglGui/View.h"
00017 #include "OglGui/WindowView2D.h"
00018 #include "OglGui/ViewStrip.h"
00019 
00020 #include "Application/sdash/RegionsOfInterestInfo.h"
00021 #include "Application/sdash/RoiLoader.h"
00022 
00023 namespace Impala {
00024 namespace Application {
00025 namespace SDash {
00026 
00027 class VideoPlayerView : public OglGui::View
00028 {
00029 
00030 public:
00031 
00032     typedef Core::Geometry::Rectangle Rectangle;
00033 
00034     // Give constructor extra arguments to pass your information in
00035     VideoPlayerView(OGLVIEW* oglView) 
00036         : OglGui::View(oglView), mColor(oglTrGREEN)
00037     {
00038         Init();
00039     }
00040 
00041     virtual ~VideoPlayerView() 
00042     {
00043         if (mRoiLoader != 0)
00044             delete mRoiLoader;
00045     }
00046 
00047     virtual void OnDrawView()
00048     {
00049         // Give possible already existing drawing behavior a chance
00050         // Example only. Not really necessary in our case
00051         //OglGui::View::OnDrawView();
00052 
00053         if (mShowFrameNr)
00054         {
00055             OGC dbOGC;
00056             OGCSave(&dbOGC);
00057             oglSys.PosColPrintf(mView2D->oglWnd, 4,4,oglRED, "fnr: %d", mFrameNr);
00058             OGCRestore(&dbOGC);
00059         }
00060 
00061         if (mRegionsOfInterest.empty())
00062             return;
00063 
00064         //glPushMatrix();
00065         OGC myOGC;
00066         OGCSave(&myOGC);
00067 
00068         viewSys.View2DNormTransform(mView2D);
00069 
00070         //SetFillColors(mColor,mColor,mColor,mColor,mColor);
00071         int bInfo[3];
00072         oglSys.StartBlend(bInfo);
00073 
00074         SetSolidLineColor(mColor);
00075         SetLineWidth(3);
00076         int nrOfRegions = mRegionsOfInterest.size();
00077         for (int i = 0; i < nrOfRegions; i++)
00078         {
00079             const RegionsOfInterestInfo::ScaledRegion& region = mRegionsOfInterest[i];
00080             DrawRectangle(region.left, region.top, region.width, region.height);
00081         }
00082 
00083         oglSys.EndBlend(bInfo);
00084 
00086         //viewSys.View2DTransform(mView2D);
00087         //float x = mX*mView2D->w, y = mY*mView2D->h;
00090         //oglSys.PosColPrintf(mView2D->oglWnd, x,y,oglRED,
00091         //                    "sDash", mX, mY); 
00092 
00093         OGCRestore(&myOGC);
00094         //glPopMatrix();
00095     }
00096 
00097     // Note: unlike the standard Window::OnMouseFunc the view OnMouse
00098     // uses float x, float y rather than ints.
00099     // This to also function for 3D viewers
00100     virtual void OnMouse(int msg, int btn, int state, float x, float y)
00101     {
00102         // Give possible already existing mouse behavior a chance
00103         // Example only. Not really necessary in our case
00104         //OglGui::View::OnMouse(msg,btn,state,x,y);
00105 
00106         if (mRegionsOfInterest.empty())
00107             return;
00108 
00109         // Normalize x,y since this example uses normalized rect coordinates
00110         float normX = x / mView2D->w;
00111         float normY = y / mView2D->h;
00112 
00113         int nrOfRegions = mRegionsOfInterest.size();
00114         for (int i = 0; i < nrOfRegions; i++)
00115         {
00116             const RegionsOfInterestInfo::ScaledRegion& region = mRegionsOfInterest[i];
00117             if (normX >= region.left && normX <= region.left + region.width
00118                 && normY >= region.top && normY <= region.top + region.height)
00119             {
00120                 mRoiNr = i;
00121 
00122                 OGLIMAGE* regionImage = mRoiLoader->Load(mVideoId, mFrameNr, mRoiNr);
00123                 mSubjectWindow->SetImage(regionImage);
00124                 // RvB: OGLIMAGES are refCounted. After mRoiLoader->Load refCount == 1.
00125                 // After mSubjectWindow->SetImage(regionImage); refCount == 2
00126                 // Since the SubjectWindow now has a hold on the image we now must release it
00127                 oglSys.ReleaseOglImage(regionImage);
00128 
00129                 // provide the subject image with roi info
00130                 RoiInfo* roiInfo = new RoiInfo();
00131                 roiInfo->videoId = mVideoId;
00132                 roiInfo->frameNr = mFrameNr;
00133                 roiInfo->roiNr = mRoiNr;
00134                 mSubjectWindow->GetOglView()->UserData1 = roiInfo;
00135 
00136                 return;
00137             }
00138         }
00139 
00140         // no roi clicked; clear the subject window?
00141     }
00142 
00143     void SubjectWindow(OglGui::WindowView2D* subjectWindow, const std::string& roiPath)
00144     {
00145         mSubjectWindow = subjectWindow;
00146         mRoiLoader = new RoiLoader(roiPath);
00147     }
00148 
00149     void Color(ULONG col)
00150     {
00151         mColor = col;
00152     }
00153 
00154     int GetVideoId() { return mVideoId; }
00155 
00156     int GetFrameNr() { return mFrameNr; }
00157 
00158     int GetRoiNr() { return mRoiNr; }
00159 
00160     void SetVideoId(int id) { mVideoId = id; }
00161 
00162     void SetFrameNr(int nr) { mFrameNr = nr; }
00163 
00164     void SetRoiNr(int nr) { mRoiNr = nr; }
00165 
00166     void SetRegionsOfInterest(const std::vector<RegionsOfInterestInfo::ScaledRegion>& regions)
00167     {
00168         mRegionsOfInterest = regions;
00169     }
00170 
00171     bool    mShowFrameNr;
00172 
00173 private:
00174 
00175     void Init()
00176     {
00177         mSubjectWindow = 0;
00178         mShowFrameNr = true;
00179         mVideoId = -1;
00180         mFrameNr = -1;
00181         mRoiNr = -1;
00182         mRoiLoader = 0;
00183     }
00184 
00185     OglGui::WindowView2D*       mSubjectWindow;
00186     RoiLoader* mRoiLoader;
00187 
00188     ULONG   mColor;
00189     float   mX, mY, mW, mH;
00190 
00191     int mVideoId;
00192     int mFrameNr;
00193     int mRoiNr;
00194     std::vector<RegionsOfInterestInfo::ScaledRegion> mRegionsOfInterest;
00195 
00196 }; //class VideoPlayerView
00197 
00198 
00199 /*
00201 //  NOTE:   You could also implement VideoPlayerView
00202 //  in a completely different way.
00203 //  If you do not like having the logic in the VideoPlayerView class
00204 //  you could work with an interface class, and implement the interface
00205 //  in a class of your own:
00206 //  This way the intelligence and actions would not be in the View class
00207 //  but at your side.
00208 //  I even think this alternative method is more natural.
00209 
00210     class InspectViewInterface
00211     {
00212         virtual void OnDrawView()
00213         virtual void OnMouse(int camId, float normX, float normY)
00214         ... Whatever you need
00215     };
00216 
00217     class SandersClass : public InspectViewInterface
00218     {
00219         // Whatever your class has to offer
00220         // ...
00221 
00223         // Implementation of InspectViewInterface
00224         virtual void OnDrawView(...)
00225         {
00226             // Do your logic
00227         }
00228         virtual void OnMouse(int camId, int frameNr, float normX, float normY)
00229         {
00230             // Do your logic
00231         }
00232         // ... Whatever you need
00233         // End of InspectViewInterface
00235     };
00236 
00237     class VideoPlayerView : OglGui::View
00238     {
00239     public:
00240         VideoPlayerView(OGLVIEW* oglView, InspectInterface inspectI) :
00241             OglGui::View(oglView)
00242         {
00243             mInspectI = inspectI;
00244         }
00245         virtual void OnDrawView()
00246         {
00247             OglGui::View::OnDrawView();
00248             mInspectI->OnDrawView(...);
00249         }
00250 
00251         virtual void OnMouse(int msg, int btn, int state, float x, float y)
00252         {
00253             OglGui::View::OnMouse(msg,btn,state,x,y);
00254             float normX = x / mView2D->w;
00255             float normY = y / mView2D->h;
00256             mInspectI->OnMouse(mCamId, mFrameNr, normX, normY);
00257         }
00258 
00259         int mCamId;     // Must be set by the steering class
00260         int mFrameNr;   // Must be set by the steering class
00261     };
00262 */
00263 
00264 }
00265 }
00266 }
00267 
00268 #endif
00269 
00270 

Generated on Fri Mar 19 09:30:39 2010 for ImpalaSrc by  doxygen 1.5.1