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

SurveillanceMap.h

Go to the documentation of this file.
00001 /*******************************************************************************
00002  *
00003  * Application: Surveillance Dashboard (MultimediaN project 6)
00004  *
00005  * Primary author(s): Richard van Balen
00006  *                  : 
00007  *                  : 
00008  ******************************************************************************/
00009 /*
00010 12345678901234567890123456789012345678901234567890123456789012345678901234567890
00011 */
00012 
00013 #ifndef Impala_Application_SDash_SurveillanceMap_h
00014 #define Impala_Application_SDash_SurveillanceMap_h
00015 
00016 #include <vector>
00017 #include <string>
00018 #include <ostream>
00019 #include <strstream>
00020 
00021 #ifndef Impala_Application_SDash_SurveillanceMapListener_h
00022 #include "Application/sdash/SurveillanceMapListener.h"
00023 #endif
00024 
00025 #ifndef OglGui_Button_h
00026 #include "OglGui/Button.h"
00027 #endif
00028 
00029 #ifndef OglGui_WindowView2D
00030 #include "OglGui/WindowView2D.h"
00031 #endif
00032 
00033 #ifndef OglGui_StaticText_h
00034 #include "OglGui/StaticText.h"
00035 #endif
00036 
00037 #include "Link/OGL/OGLGraphics.h"
00038 
00039 namespace Impala {
00040 namespace Application {
00041 namespace SDash {
00042 
00043 // Sander: In deze class kun je het tekenen van een track implementeren
00044 // Ik wil het ook wel doen. Je zegt het maar.
00045 class SurveillanceMap : public OglGui::WindowView2D,
00046                         public OglGui::ButtonListener,
00047                         public OglGui::WindowListener
00048 {
00049 typedef OglGui::WindowView2D     WindowView2D;
00050 typedef OglGui::ButtonListener   ButtonListener;
00051 typedef OglGui::Window           Window;
00052 typedef OglGui::Button           Button;
00053 typedef OglGui::StaticText       StaticText;
00054 
00055 public:
00056 
00057     SurveillanceMap(int x,int y,int w,int h, OGLIMAGE* im=0) :
00058         WindowView2D(x, y, w, h, im)
00059         {
00060                 Init(w, h);
00061         }
00062 
00063     SurveillanceMap(Window *parent, int w, int h, OGLIMAGE* im=0) :
00064         WindowView2D(parent, w, h, im)
00065         {
00066                 Init(w, h);
00067         }
00068 
00069     SurveillanceMap(Window *parent,int x,int y,int w,int h, OGLIMAGE* im=0) :
00070         WindowView2D(parent, x, y, w, h, im)
00071         {
00072                 Init(w, h);
00073         }
00074 
00075     void SetSurveillanceMapListener(SurveillanceMapListener* li, void* userData=0)
00076     {
00077         mListener = li;
00078         mListenerData = userData;
00079     }
00080 
00081     /*
00082     virtual void ButtonSelectionEvent(Button *src, int userData)
00083     {
00084         for (int i=0; i<mButtons.size(); i++)
00085             mButtons[i]->SetBackground(mButtons[i]==src ? oglRED : 0);
00086         mCurrent = GetButtonId(src);
00087         if (mListener != 0)
00088             mListener->ButtonSelectionEvent(this, mCurrent, mListenerData);
00089     }
00090     */
00091     virtual void ButtonSelectionEvent(Button *src, void* userData)
00092     {
00093         int mCurrent = GetButtonId(src);
00094         SetSelectedButton(mCurrent);
00095         if (mListener != 0)
00096             mListener->ButtonSelectionEvent(this, mCurrent, mListenerData);
00097     }
00098 
00099     // Reacts on mouse enter and leave of the buttons
00100     virtual void
00101     WindowMouseEvent(Window *src, int msg, int but, int state,
00102                      int x, int y, void* userData )
00103     {
00104         if (mShowTrack)
00105             return;
00106         int id = GetButtonId((Button*)src);
00107         if (msg == oglMouseEnter)
00108             mStreetLabels[id]->SetVisible(true);
00109         if (msg == oglMouseLeave)
00110             mStreetLabels[id]->SetVisible(false);
00111     }
00112 
00113     Button* CreateButton(int x, int y, strconst title)
00114     {
00115         Button* btn = new Button(this, x-12, y-12, 24, 24, title);
00116 
00117         btn->SetBorderType(-1);
00118         btn->SetBorderBackground(oglBLUE);
00119         btn->SetForeground(oglWHITE);
00120         btn->SetTextShadowed(false);
00121         btn->SetDoStateFeedback(false);
00122         btn->SetButtonListener(this);
00123         btn->SetWindowListener(this);
00124 
00125         int index = mButtons.size();
00126         int labelPos = mLabelPositions[index];
00127         int xL, yL;
00128         int wL = 200;
00129         int hL = 20;
00130 
00131         if (labelPos == 0)
00132         {
00133             xL = x + 8;
00134             yL = y + 8;
00135         }
00136         else if (labelPos == 1)
00137         {
00138             xL = x + 8;
00139             yL = y - hL - 8;
00140         }
00141         else if (labelPos == 2)
00142         {
00143             xL = x - wL - 8;
00144             yL = y - hL - 8;
00145         }
00146         else 
00147         {
00148             xL = x - wL - 8;
00149             yL = y + 8;
00150         }
00151 
00152         StaticText* label = new StaticText(this, xL, yL, wL, hL, "-", false);
00153         label->SetBorderType(BEV_RIDGE);
00154         label->SetBorderBackground(0x80ff002f);
00155         label->SetForeground(oglWHITE);
00156         label->SetTextShadowed(false);
00157         label->SetVisible(false);
00158 
00159         mButtons.push_back(btn);
00160         mLabels.push_back(label);
00161 
00162         wL = 200;
00163         label = new StaticText(this, xL, yL, wL, hL, "-");
00164         label->SetText(mLocations[mButtons.size()-1]);
00165         label->SetBorderType(BEV_RIDGE);
00166         label->SetBorderBackground(0x80ff002f);
00167         label->SetForeground(oglWHITE);
00168         label->SetTextShadowed(false);
00169         label->SetVisible(false);
00170         mStreetLabels.push_back(label);
00171 
00172         return btn;
00173     }
00174 
00175     bool    ShowTrack()         { return mShowTrack; }
00176     int     NrOfButtons()       { return mButtons.size(); }
00177     int     GetActiveButtonId() { return mCurrent; }
00178     Button* GetActiveButton()   { return GetButton(mCurrent); }
00179 
00180     int GetButtonId(Button* btn)
00181     {
00182         for (int i=0; i<mButtons.size(); i++)
00183             if (btn == mButtons[i])
00184                 return i;
00185         return -1;
00186     }
00187     Button* GetButton(int id)
00188     {
00189         if (id < 0 || id >= mButtons.size())
00190             return 0;
00191         return mButtons[id];
00192     }
00193 
00194     void SetSelectedButton(int id)
00195     {
00196         for (int i=0; i<mButtons.size(); i++)
00197             mButtons[i]->SetBackground((i==id) ? oglRED : 0);
00198         UpdateScene();
00199     }
00200 
00201     void SelectButton(int id)
00202     {
00203         Button* btn = GetButton(id);
00204         if (!btn)
00205             return;
00206         ButtonSelectionEvent(btn, 0);
00207 //        UpdateScene();
00208     }
00209 
00210     void RemoveButtons()
00211     {
00212         for (int i=0 ; i<mButtons.size() ; i++)
00213             delete mButtons[i];
00214         mButtons.clear();
00215         mCurrent = -1;
00216     }
00217 
00218     std::string LocationString(int id)
00219     {
00220         return mLocations[id];
00221     }
00222 
00223     virtual void DisplayFunc()
00224     {
00225         OglGui::WindowView2D::DisplayFunc();
00226         DrawTrack();
00227     }
00228 
00229     void DrawTrack( )
00230     {
00231         if (!mShowTrack)
00232             return;
00233 
00234         glPushMatrix(); // Push modelview onto the matrix stack. 
00235             OGC         myOGC;
00236             OGCSave( &myOGC ); // Save present OpenGL and theOGC settings in myOGC
00237 
00238         int bInfo[3];
00239         oglSys.StartBlend(bInfo);
00240 
00241             SetLineWidth( 8.0f );
00242             SetSolidLineColor( oglRED );
00243 
00244         for (int i = 1; i < mTrackSize; i++)
00245         {
00246             Button* fromBtn = mButtons[mTrackVideoIds[i-1]];
00247             Button* toBtn = mButtons[mTrackVideoIds[i]];
00248             float fromX = (float) fromBtn->X() + 12;
00249             float fromY = (float) fromBtn->Y() + 12;
00250             float toX = (float) toBtn->X() + 12;
00251             float toY = (float) toBtn->Y() + 12;
00252                 DrawColLine(fromX, fromY, toX, toY, 0x60ff6060, oglRED);
00253         }
00254 
00255         oglSys.EndBlend(bInfo);
00256         
00257             OGCRestore( &myOGC ); // Restore theOGC
00258             glPopMatrix(); // Restore modelview matrix
00259     }
00260 
00261     void SetTrack(std::vector<int> videoIds, std::vector<int> timesInSec)
00262     {
00263         ClearTrack();
00264 
00265         mTrackSize = videoIds.size();
00266         mTrackVideoIds = videoIds;
00267 
00268         for (int i = 0; i < mTrackSize; i++)
00269         {
00270             int time0 = clock();
00271 
00272             int hours = timesInSec[i] / 3600;
00273             int remainingSec = timesInSec[i] % 3600;
00274             int minutes = remainingSec / 60;
00275             int sec = remainingSec % 60;
00276 
00277             char buf[100];
00278             sprintf(buf, "%02d:%02d:%02d", hours, minutes, sec);
00279 
00280             std::ostrstream fullDescr;
00281             //fullDescr << hours << ':' << minutes << ':' << sec;
00282             fullDescr << buf;
00283             fullDescr << ' ' << mLocations[videoIds[i]] << std::ends;
00284             std::string message = std::string(fullDescr.str());
00285 
00286             mLabels[videoIds[i]]->SetText(message);
00287             mLabels[videoIds[i]]->SetVisible(true);
00288 
00289             std::cout << (clock() - time0) / CLOCKS_PER_SEC << " sec.s for setting track" << std::endl;
00290         }
00291 
00292         mShowTrack = mTrackSize > 0;
00293 
00294         UpdateScene(); // refresh window
00295     }
00296 
00297     void ClearTrack()
00298     {
00299         mShowTrack = false;
00300 
00301         for (int i = 0; i < mLabels.size(); i++)
00302             mLabels[i]->SetVisible(false);
00303 
00304         mTrackVideoIds.clear();
00305         mTrackSize = 0;
00306 
00307         UpdateScene(); // refresh window
00308     }
00309 
00310     const std::vector<const std::string* const> GetCamAddresses(const std::vector<int>& cams)
00311     {
00312         std::vector<const std::string* const> addresses;
00313         for (int i = 0; i < cams.size(); i++)
00314             addresses.push_back(&mLocations[cams[i]]);
00315         return addresses;
00316     }
00317 
00318 private:
00319 
00320     SurveillanceMapListener*    mListener;
00321     void*                       mListenerData;
00322     int                         mCurrent;
00323     int mDisplayCounter;
00324 
00325     std::vector<Button*> mButtons;
00326     std::vector<StaticText*> mLabels;
00327     std::vector<StaticText*> mStreetLabels;
00328     std::vector<int> mLabelPositions; 
00329     std::vector<std::string> mLocations;
00330     bool mShowTrack;
00331     int mTrackSize;
00332     std::vector<int> mTrackVideoIds;
00333 
00334         void Init(int w, int h)
00335         {
00336         mListener = 0;
00337         mCurrent = -1;
00338         mView->texturing = 0;
00339         mDisplayCounter = 0;
00340         mShowTrack = false;
00341         mTrackSize = 0;
00342 
00343         mLocations.push_back("Keileweg zuid");
00344         mLocations.push_back("Keileweg noord");
00345         mLocations.push_back("Benjamin Franklinstraat");
00346         mLocations.push_back("Van Helmontstraat");
00347         mLocations.push_back("Ohmstraat");
00348         mLocations.push_back("Vierhavenstraat zuid");
00349         mLocations.push_back("Marconiplein zuid");
00350         mLocations.push_back("Marconiplein noord");
00351         mLocations.push_back("Marconiplein/Math.dijk");
00352         mLocations.push_back("Mathenesserdijk");
00353         mLocations.push_back("Mathenesserweg");
00354         mLocations.push_back("Vierhavenstraat noord");
00355 
00356         mLocations.push_back("Station Marconiplein #1");
00357         mLocations.push_back("Station Marconiplein #2");
00358         mLocations.push_back("Station Marconiplein #3");
00359 
00360         // 0 = re boven, 1 = re onder, 2 = li onder, 3 = li boven
00361         mLabelPositions.push_back(3);
00362         mLabelPositions.push_back(3);
00363         mLabelPositions.push_back(0);
00364         mLabelPositions.push_back(3);
00365         mLabelPositions.push_back(2);
00366         mLabelPositions.push_back(2);
00367         mLabelPositions.push_back(2);
00368         mLabelPositions.push_back(3);
00369         mLabelPositions.push_back(0);
00370         mLabelPositions.push_back(1);
00371         mLabelPositions.push_back(1);
00372         mLabelPositions.push_back(0);
00373 
00374         mLabelPositions.push_back(3);
00375         mLabelPositions.push_back(3);
00376         mLabelPositions.push_back(3);
00377         }
00378 };
00379 
00380 }
00381 }
00382 }
00383 
00384 #endif

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