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

MapModule.h

Go to the documentation of this file.
00001 /*
00002  * MapModule.h
00003  *
00004  *  Created on: 26-aug-2009
00005  *      Author: dodijk
00006  */
00007 
00008 #ifndef MAPMODULE_H_
00009 #define MAPMODULE_H_
00010 
00011 #include "OglGui/GroupBox.h"
00012 #include "OglGui/WindowView2D.h"
00013 #include "OglGui/ZoomPanControl.h"
00014 
00015 #include "../TableDataStore.h"
00016 #include "../TableDataView.h"
00017 
00018 #include "Application/TagsLife/ViewListenerCircles.h"
00019 
00020 namespace Impala {
00021 namespace Application {
00022 namespace MediaTable {
00023 
00024 class MapModule : public VisualizationModule {
00025 
00026     typedef OglGui::WindowView2D                WindowView2D;
00027     typedef OglGui::ZoomPanControl              ZoomPanControl;
00028 
00029 public:
00030         MapModule() : VisualizationModule("Map") {}
00031 
00032     void ButtonSelectionEvent(OglGui::Button *src, void *userData)
00033     {
00034                 if(src->GetLabel() == "New " + GetName())
00035         {
00036                         StoreConfigWindowValues();
00037                         DoHandleNewWindow("Map", mConfigWindow);
00038                         delete mConfigWindow;
00039                         DoReleaseConfigWindow();
00040                 }
00041         // RvB: Here was a BUG. Added else clause as otherwise
00042         // a reference to something that was deleted above would be passed on
00043         else
00044             VisualizationModule::ButtonSelectionEvent(src, userData);
00045     }
00046 
00047         void ViewSelected() {
00048                 VisualizationModule::DrawConfigWindow();
00049                 OglGui::GroupBox* grp = new OglGui::GroupBox(mConfigWindow, mConfigWindow->W()-2, 362, "");
00050 
00051                 AddSelectorWithColumnsOfType(grp, "Latitude", mStringValues["View"],
00052                                 TableDataSource::TYPE_FLAG_NUMBER, true);
00053                 AddSelectorWithColumnsOfType(grp, "Longitude", mStringValues["View"],
00054                                 TableDataSource::TYPE_FLAG_NUMBER, true);
00055                 AddSelectorWithColumnsOfType(grp, "Magnitude", mStringValues["View"],
00056                                 TableDataSource::TYPE_FLAG_NUMBER, true);
00057                 (new OglGui::Button(grp, grp->W()-4, 26, "New "+GetName(), BEV_ETCHED))
00058                         ->SetButtonListener(this);
00059 
00060                 grp->RepositionViewports();
00061                 grp->ScaleChildren();
00062         }
00063 
00064         void NewWindow(OglGui::Window* mMapWnd)
00065     {
00066         OGLIMAGE* oglIm = TryReadPNG("world.png");
00067         WindowView2D* mGlobeMap =
00068             new WindowView2D(mMapWnd,0,92,mMapWnd->W(),mMapWnd->H()-92,oglIm);
00069         mGlobeMap->SetBorderType(1);
00070         mGlobeMap->SetScaleToWindow(false);
00071         mGlobeMap->ConnectTo(mMapWnd);
00072 
00073         // Turn the C-Based OGLVIEW2D into a C++ based View with listener
00074         OGLVIEW* oglView = mGlobeMap->GetOglView();
00075         new OglGui::View(oglView, &mViewListenerCircles);
00076 
00077         ZoomPanControl* mZoomPanControl =
00078             new ZoomPanControl(mMapWnd,0,0,400,90,mGlobeMap->GetOGLWND(),5,1);
00079                 mZoomPanControl->PanWindow()->SetRoundness(0,0,0,0);
00080                 mZoomPanControl->ConnectTo(mMapWnd,OglGui::TOBOTTOM|OglGui::TOLEFTRIGHT);
00081 
00082         // Turn the C-Based OGLVIEW2D into a C++ based View with listener
00083         OGLWND* oglWnd = mZoomPanControl->PanWindow()->GetOGLWND();
00084         oglView = (OGLVIEW*) oglWnd->objectList->info;
00085         new OglGui::View(oglView, &mViewListenerCircles);
00086 
00087                 TableDataView* view =
00088             TableDataStore::GetInstance()->GetTableDataView(mStringValues["View"]);
00089         view->SetStartRow(0);
00090         view->SetNumberOfRows(view->GetTotalRows());
00091         //mCache = new TableViewCache(this, mSource);
00092 
00093         float lat2ym65 = lat2y(-65), lat2y85 = lat2y(85);
00094 
00095         double longitude, latitude;
00096         for (int i=0; i<view->GetTotalRows(); i++)
00097         {
00098             longitude = view->GetSortedDoubleData(mStringValues["Latitude"], i);
00099             latitude = view->GetSortedDoubleData(mStringValues["Longitude"], i);
00100             int x = map(longitude, -180, 180, 0, oglIm->w);
00101             int y = map(lat2y(latitude), lat2ym65, lat2y85, 0, oglIm->h);
00102             int r = view->GetSortedIntData(mStringValues["Magnitude"], i)+3;
00103                 mViewListenerCircles.AddCircle(x, y, r);
00104         }
00105         ReleaseOglImage(oglIm);
00106     }
00107 
00108     float y2lat(float a) { return 180/M_PI * (2 * atan(exp(a*M_PI/180)) - M_PI/2); }
00109     float lat2y(float a) { return 180/M_PI * log(tan(M_PI/4+a*(M_PI/180)/2)); }
00110 
00111     float map(float v, float vmin, float vmax, float min, float max)
00112     {
00113         float r = (v-vmin)/(vmax-vmin);
00114         r *= (max-min);
00115         r += min;
00116         return r;
00117     }
00118 
00119     TagsLife::ViewListenerCircles mViewListenerCircles;
00120 };
00121 
00122 } } }  /* Namespace Impala::Application::MediaTable */
00123 
00124 #endif /* MapModule_H_ */

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