KINECT STATS GENERATOR FOR SPORTS VISUALISATION
1.0
|
00001 #ifndef VISUALIZATIONWINDOW_H 00002 #define VISUALIZATIONWINDOW_H 00003 00004 /* 00005 LICENSING: You are free to use any part of this project provided I am informed about it via email 00006 at santoshwins@hotmail.com and referenced appropriately in your works 00007 */ 00008 00009 #include "ScreenQuad.h" 00010 #include "PlayerData.h" 00011 00012 #include <ngl/Camera.h> 00013 #include <ngl/Colour.h> 00014 #include <ngl/TransformStack.h> 00015 #include <ngl/ShaderLib.h> 00016 #include <ngl/VertexArrayObject.h> 00017 #include <ngl/Text.h> 00018 00019 00020 #include "opencv2/opencv.hpp" 00021 #include <opencv2/core/core.hpp> 00022 #include <iostream> 00023 #include <string> 00024 00025 // must be included after our stuff becuase GLEW needs to be first 00026 #include <QtOpenGL> 00027 00035 00036 00037 typedef enum 00038 { 00039 PLAYERA, 00040 PLAYERB, 00041 BOTH 00042 }WHOSE_STATS; 00043 00044 typedef enum 00045 { 00046 IMPACT_POINTS_VIEW, 00047 IMPACT_PERCENTAGE_DISTRIBUTION_VIEW, 00048 IMPACT_HEIGHT_MAP_VIEW, 00049 TRAJECTORY_VIEW, 00050 VELOCITY_VIEW, 00051 RPM_VIEW 00052 00053 }WHICH_STAT; 00054 00055 struct VertData 00056 { 00057 //GLfloat u; // tex cords 00058 //GLfloat v; // tex cords 00059 GLfloat nx; // normal 00060 GLfloat ny; 00061 GLfloat nz; 00062 GLfloat x; // position 00063 GLfloat y; 00064 GLfloat z; 00065 }; 00066 00067 class StatsVisualization : public QGLWidget 00068 { 00069 Q_OBJECT // must include this if you use Qt signals/slots 00070 public : 00071 00072 //def constructor 00073 StatsVisualization(); 00074 00079 StatsVisualization( 00080 QWidget *_parent, PlayerData *_playerA, PlayerData *_playerB 00081 ); 00082 00083 00089 StatsVisualization( 00090 QWidget *_parent, bool _importFlag 00091 ); 00092 00094 ~StatsVisualization(); 00097 void processKey( 00098 QKeyEvent *_event 00099 ); 00100 00102 void updateDisplay(); 00103 00104 private : 00105 00106 //---------------------------------------------------------------------------------------------------------------------- 00108 //---------------------------------------------------------------------------------------------------------------------- 00109 int m_spinXFace; 00110 //---------------------------------------------------------------------------------------------------------------------- 00112 //---------------------------------------------------------------------------------------------------------------------- 00113 int m_spinYFace; 00114 //---------------------------------------------------------------------------------------------------------------------- 00116 //---------------------------------------------------------------------------------------------------------------------- 00117 bool m_rotate; 00118 //---------------------------------------------------------------------------------------------------------------------- 00120 //---------------------------------------------------------------------------------------------------------------------- 00121 bool m_translate; 00122 //---------------------------------------------------------------------------------------------------------------------- 00124 //---------------------------------------------------------------------------------------------------------------------- 00125 int m_origX; 00126 //---------------------------------------------------------------------------------------------------------------------- 00128 //---------------------------------------------------------------------------------------------------------------------- 00129 int m_origY; 00130 //---------------------------------------------------------------------------------------------------------------------- 00132 //---------------------------------------------------------------------------------------------------------------------- 00133 int m_origXPos; 00134 //---------------------------------------------------------------------------------------------------------------------- 00136 //---------------------------------------------------------------------------------------------------------------------- 00137 int m_origYPos; 00138 //---------------------------------------------------------------------------------------------------------------------- 00140 //---------------------------------------------------------------------------------------------------------------------- 00141 ngl::Vec3 m_modelPos; 00142 //---------------------------------------------------------------------------------------------------------------------- 00143 00145 ngl::Camera *m_cam; 00147 ngl::TransformStack m_transformStack; 00148 00149 //---------------------------------------------------------------------------------------------------------------------- 00151 //---------------------------------------------------------------------------------------------------------------------- 00152 ngl::VertexArrayObject *m_vao; 00153 00155 ScreenQuad *m_2DScreen; 00156 00158 int m_updateTimer; 00159 00160 // stats array 00161 00163 std::vector<cv::Point> m_playerAImpactData; 00165 std::vector<cv::Point> m_playerBImpactData; 00167 float m_percentageABL,m_percentageATL,m_percentageATR,m_percentageABR; 00169 float m_percentageBBL,m_percentageBTL,m_percentageBTR,m_percentageBBR; 00170 00172 std::vector<cv::Point> m_quadSpecABL,m_quadSpecATL,m_quadSpecATR,m_quadSpecABR; 00174 std::vector<cv::Point> m_quadSpecBBL,m_quadSpecBTL,m_quadSpecBTR,m_quadSpecBBR; 00176 std::vector<std::vector<cv::Point3f> > m_playerAInterpPtsMappedToRallies; 00178 std::vector<std::vector<cv::Point3f> > m_playerBInterpPtsMappedToRallies; 00179 00181 std::vector<float> m_playerATrajectoryFromFile; 00183 std::vector<float> m_playerBTrajectoryFromFile; 00184 00186 std::vector<VertData> m_dataVertsA, m_dataVertsB; 00187 00189 std::vector<float> m_speedAData,m_speedBData; 00191 std::vector<cv::Point3f> m_playerAImpactPtsAllRalliesIn3D,m_playerBImpactPtsAllRalliesIn3D; 00193 std::vector<float> m_playerARPM,m_playerBRPM; 00194 00196 cv::Rect m_fieldOfPlay; 00198 float m_finalCourtWidthWorld,m_finalCourtDepthWorld; 00200 int m_width,m_height,m_midTopX,m_midTopY,m_midBottomX,m_midBottomY,m_midLeftX; 00202 int m_midLeftY,m_midRightX,m_midRightY; 00203 00205 PlayerData *m_playerA,*m_playerB; 00206 00208 bool m_impactPtsFilled; 00210 bool m_speedMapBuilt,m_rpmDataBuilt,m_quadMapBuilt,m_trajectoryBuilt; 00211 00213 WHOSE_STATS m_whichPlayer; 00215 WHICH_STAT m_whichStat; 00216 00218 WHICH_QUADRANT m_whichQuad; 00219 00221 bool m_3dFlag; 00222 00226 float m_kinectToPlayAreaInMeters; 00227 float m_diameterOfBAllInMeters; 00228 00229 //---------------------------------------------------------------------------------------------------------------------- 00231 //---------------------------------------------------------------------------------------------------------------------- 00232 ngl::Vec3 m_lightPos; 00233 00234 bool m_importFlag; 00235 00237 ngl::Text *m_text; 00238 00240 GLuint m_crowdTextureName,m_tableTextureName,m_speedLegend,m_rpmLegend,m_trajectoryLegend,m_gridXYHtMap; 00241 GLuint m_heightMapLegend; 00242 00243 //---------------------------------------------------------------------------------------------------------------------- 00245 //---------------------------------------------------------------------------------------------------------------------- 00246 ngl::Mat4 m_view; 00247 //---------------------------------------------------------------------------------------------------------------------- 00249 //---------------------------------------------------------------------------------------------------------------------- 00250 ngl::Mat4 m_projection; 00251 00253 int m_legendWidth,m_legendHeight; 00254 00255 protected: 00256 00259 void initializeGL(); 00260 00264 void resizeGL( 00265 const int _w, 00266 const int _h 00267 ); 00270 void paintGL(); 00271 00272 private : 00273 00275 void drawEntireScene(); 00276 00277 //---------------------------------------------------------------------------------------------------------------------- 00280 //---------------------------------------------------------------------------------------------------------------------- 00281 void mouseMoveEvent ( 00282 QMouseEvent * _event 00283 ); 00284 //---------------------------------------------------------------------------------------------------------------------- 00288 //---------------------------------------------------------------------------------------------------------------------- 00289 void mousePressEvent ( 00290 QMouseEvent *_event 00291 ); 00292 00293 //---------------------------------------------------------------------------------------------------------------------- 00297 //---------------------------------------------------------------------------------------------------------------------- 00298 void mouseReleaseEvent ( 00299 QMouseEvent *_event 00300 ); 00301 00302 //---------------------------------------------------------------------------------------------------------------------- 00306 //---------------------------------------------------------------------------------------------------------------------- 00307 void wheelEvent( 00308 QWheelEvent *_event 00309 ); 00312 void timerEvent( 00313 QTimerEvent *_event 00314 ); 00315 00317 void loadMatricesToADSShader(); 00318 00320 void loadMatricesToTextureShader(); 00321 00323 void loadMatricesToLegendShader(); 00324 00326 void fillAllImpactPointsBothPlayers(); 00328 void buildQuadSpecificData(); 00330 void buildPointGraphBars(); 00332 void buildTrajectory(); 00334 void buildSpeedMap(); 00336 void buildRPMData(); 00337 00339 void calculateFieldOfPlayInWorldCoords(); 00341 void setColorBasedOnSpeedRange(float _inputVelocity); 00343 void setColorBasedOnRPMRange(float _inputRPM); 00344 00346 void fillDataVertsWithNormals(std::vector<cv::Point3f>& _inputVertList, 00347 std::vector<VertData>& o_normalFilledDataVerts); 00348 00350 void fillDataFromFileForBothPlayers(cv::FileStorage& _fs,WHOSE_STATS _whichPlayer); 00351 00353 void drawCrowd(const std::string& _inputPlaneName); 00355 void drawTable(const std::string& _inputTableName); 00356 00358 void renderPercentages(); 00359 00361 void legendWindow(GLuint _inputLegendName); 00362 00364 void drawContainingGridScaleXY(); 00365 00366 public slots: 00367 00369 void setWhichStatToView(int _inputWhichStat); 00370 00371 void setWhoseStatToView(int _inputWhoseStat); 00372 00373 void setWhichQuadToView(int _inputWhichQuad); 00374 00375 void setKinectToPlayAreaDistance(double _inputDistanceInMeters); 00376 00377 void setDiameterOfBallInMeters(double _inputDiaInMeters); 00378 00380 void readFile(QString _inputFileName); 00381 00383 void writeFile(); 00384 00385 }; 00386 00387 #endif // VISUALIZATIONWINDOW_H