KINECT STATS GENERATOR FOR SPORTS VISUALISATION
1.0
|
00001 // filling up the arrays(setters) 00002 // getting those arrays(getters) 00003 00004 #include "PlayerData.h" 00005 00006 /* 00007 LICENSING: You are free to use any part of this project provided I am informed about it via email 00008 at santoshwins@hotmail.com and referenced appropriately in your works 00009 */ 00010 00011 PlayerData::PlayerData() 00012 { 00013 m_playerBallPts.clear(); 00014 m_playerDeepestPtIndices.clear(); 00015 m_playerImpactPtsAllRallies.clear(); 00016 m_playerImpactPtsAllRalliesIn3D.clear(); 00017 m_playerImpactPtsBottomLeft.clear(); 00018 m_playerImpactPtsTopLeft.clear(); 00019 m_playerImpactPtsTopRight.clear(); 00020 m_playerImpactPtsBottomRight.clear(); 00021 m_barGraphVertices.clear(); 00022 m_playerInterpolatedBallPts.clear(); 00023 m_speedData.clear(); 00024 00025 m_dataProcessed = false; 00026 00027 m_bottomLeftPercentage = m_topLeftPercentage = 0; 00028 m_topRightPercentage = m_bottomRightPercentage = 0; 00029 00030 m_rpmData.clear(); 00031 00032 m_twoDStatsGenerator = new TwoDStatsGeneration(); 00033 m_threeDStatsGenerator = new ThreeDStatsGeneration(); 00034 } 00035 00036 PlayerData::~PlayerData() 00037 { 00038 m_playerBallPts.clear(); 00039 m_playerDeepestPtIndices.clear(); 00040 m_playerImpactPtsAllRallies.clear(); 00041 m_playerImpactPtsAllRalliesIn3D.clear(); 00042 m_playerImpactPtsBottomLeft.clear(); 00043 m_playerImpactPtsTopLeft.clear(); 00044 m_playerImpactPtsTopRight.clear(); 00045 m_playerImpactPtsBottomRight.clear(); 00046 m_barGraphVertices.clear(); 00047 m_playerInterpolatedBallPts.clear(); 00048 m_speedData.clear(); 00049 m_rpmData.clear(); 00050 00051 m_dataProcessed = false; 00052 00053 delete m_twoDStatsGenerator; 00054 delete m_threeDStatsGenerator; 00055 } 00056 00057 void PlayerData::setPlayerBallPts(std::vector<std::vector<cv::Point3f> > &_inputPointSetsInWorld) 00058 { 00059 m_playerBallPts = _inputPointSetsInWorld; 00060 } 00061 00062 void PlayerData::setPlayerImpactPtIndices(std::vector<std::vector<int> > &_inputDepthIndices) 00063 { 00064 m_playerDeepestPtIndices = _inputDepthIndices; 00065 } 00066 00067 std::vector<std::vector<cv::Point3f> >& PlayerData::getPlayerBallPtsAll() 00068 { 00069 return m_playerBallPts; 00070 } 00071 00072 std::vector<std::vector<int> >& PlayerData::getPlayerImpactPtIndices() 00073 { 00074 return m_playerDeepestPtIndices; 00075 } 00076 00077 std::vector<cv::Point>& PlayerData::getPlayerImpactPtsAllRallies() 00078 { 00079 // we first check if we have already calculated impact points, if so return, 00080 // else calculate it now 00081 if(m_playerImpactPtsAllRallies.size() != 0) 00082 { 00083 return m_playerImpactPtsAllRallies; 00084 } 00085 else 00086 { 00087 //calculatePlayerImpactPtsFromIndices(); 00088 00089 m_twoDStatsGenerator->calculatePlayerImpactPtsFromIndices(m_playerBallPts,m_playerDeepestPtIndices, 00090 m_playerImpactPtsAllRallies); 00091 return m_playerImpactPtsAllRallies; 00092 } 00093 } 00094 00095 00096 // which percentage requested enum value, 00097 // accordingly compute the required dimensions and send it to the 2dstats generator function 00098 // we should first check if rallyDepthPtsAll has been already filled, 00099 // if not fill them first 00100 // this is so that if later someone chose not to show 00101 // impact pts as a defualt statistic by changing the constructor, 00102 // the other stats would still work independetly 00103 00104 float PlayerData::getPercentageDistributionData(int _width, int _height, WHICH_QUADRANT _whichQuadrant) 00105 { 00106 00107 float tempPercentage = 0.0; 00108 00109 // call calculate if rally points empty 00110 00111 if(m_playerImpactPtsAllRallies.size() == 0) 00112 { 00113 00114 //calculatePlayerImpactPtsFromIndices(); 00115 00116 m_twoDStatsGenerator->calculatePlayerImpactPtsFromIndices(m_playerBallPts,m_playerDeepestPtIndices, 00117 m_playerImpactPtsAllRallies); 00118 } 00119 00120 switch(_whichQuadrant) 00121 { 00122 case BOTTOM_LEFT: 00123 { 00124 m_twoDStatsGenerator->generatePercentageDistribution(_width,_height,m_playerImpactPtsAllRallies,BOTTOM_LEFT, 00125 m_playerImpactPtsBottomLeft,m_bottomLeftPercentage); 00126 tempPercentage = m_bottomLeftPercentage; 00127 break; 00128 } 00129 case TOP_LEFT: 00130 { 00131 m_twoDStatsGenerator->generatePercentageDistribution(_width,_height,m_playerImpactPtsAllRallies,TOP_LEFT, 00132 m_playerImpactPtsTopLeft,m_topLeftPercentage); 00133 tempPercentage = m_topLeftPercentage; 00134 break; 00135 } 00136 case TOP_RIGHT: 00137 { 00138 m_twoDStatsGenerator->generatePercentageDistribution(_width,_height,m_playerImpactPtsAllRallies,TOP_RIGHT, 00139 m_playerImpactPtsTopRight,m_topRightPercentage); 00140 tempPercentage = m_topRightPercentage; 00141 break; 00142 } 00143 case BOTTOM_RIGHT: 00144 { 00145 m_twoDStatsGenerator->generatePercentageDistribution(_width,_height,m_playerImpactPtsAllRallies,BOTTOM_RIGHT, 00146 m_playerImpactPtsBottomRight,m_bottomRightPercentage); 00147 tempPercentage = m_bottomRightPercentage; 00148 break; 00149 } 00150 case ALL: 00151 { 00152 // in case data is needed for all quads, caller has to call this function 4 times 00153 // and save the returning floats separately 00154 break; 00155 } 00156 } 00157 00158 return tempPercentage; 00159 } 00160 00161 std::vector<cv::Point>& PlayerData::getQuadSpecificPoints(WHICH_QUADRANT _whichQuad) 00162 { 00163 00164 if(_whichQuad == BOTTOM_LEFT) 00165 { 00166 return m_playerImpactPtsBottomLeft; 00167 } 00168 else if(_whichQuad == TOP_LEFT) 00169 { 00170 return m_playerImpactPtsTopLeft; 00171 } 00172 else if(_whichQuad == TOP_RIGHT) 00173 { 00174 return m_playerImpactPtsTopRight; 00175 } 00176 else if(_whichQuad == BOTTOM_RIGHT) 00177 { 00178 return m_playerImpactPtsBottomRight; 00179 } 00180 } 00181 00182 std::vector<cv::Point3f>& PlayerData::getBarGraphVertices(cv::Point _inputTopXY, int _width, int _height, int _gridResolution) 00183 { 00184 00185 if(m_barGraphVertices.size() != 0) 00186 { 00187 return m_barGraphVertices; 00188 } 00189 00190 else 00191 { 00192 // call calculate if rally points empty 00193 if(m_playerImpactPtsAllRallies.size() == 0) 00194 { 00195 00196 //calculatePlayerImpactPtsFromIndices(); 00197 00198 m_twoDStatsGenerator->calculatePlayerImpactPtsFromIndices(m_playerBallPts,m_playerDeepestPtIndices, 00199 m_playerImpactPtsAllRallies); 00200 } 00201 00202 m_threeDStatsGenerator->generatePitchDensityGraphData(_inputTopXY,_width,_height,_gridResolution,m_playerImpactPtsAllRallies, 00203 m_barGraphVertices); 00204 00205 return m_barGraphVertices; 00206 } 00207 } 00208 00209 00210 std::vector<std::vector<cv::Point3f> >& PlayerData::getPlayerInterpolatedBallPtsAll(float _inputDistanceFrmKinectToPlayArea) 00211 { 00212 if(m_playerInterpolatedBallPts.size() != 0) 00213 { 00214 return m_playerInterpolatedBallPts; 00215 } 00216 else 00217 { 00218 m_threeDStatsGenerator->generateInterpolatedDataForAllRallies(m_playerBallPts,m_playerDeepestPtIndices, 00219 _inputDistanceFrmKinectToPlayArea, 00220 m_playerInterpolatedBallPts,m_speedData); 00221 00222 // m_threeDStatsGenerator->generateInterpolatedDataForAllRalliesWithoutImpact(m_playerBallPts,m_playerInterpolatedBallPts); 00223 00224 return m_playerInterpolatedBallPts; 00225 } 00226 } 00227 00228 00229 std::vector<float>& PlayerData::getPlayerSpeedData(float _inputDistanceFrmKinectToPlayArea) 00230 { 00231 // this will be available only when interpolatedballpts function is called 00232 // as that is where speed data is filled 00233 00234 //so if interpolatedballpts vec is empty, call the getinterpballpts function 00235 // and then check if speed data not empty and then return the speeddata vec 00236 if(m_playerInterpolatedBallPts.size() == 0) 00237 { 00238 m_threeDStatsGenerator->generateInterpolatedDataForAllRallies(m_playerBallPts,m_playerDeepestPtIndices, 00239 _inputDistanceFrmKinectToPlayArea, 00240 m_playerInterpolatedBallPts,m_speedData); 00241 } 00242 //if(m_speedData.size() != 0) 00243 { 00244 return m_speedData; 00245 } 00246 } 00247 00248 std::vector<cv::Point3f>& PlayerData::getPlayerImpactPtsIn3DAllRallies() 00249 { 00250 if(m_playerImpactPtsAllRalliesIn3D.size() != 0) 00251 { 00252 return m_playerImpactPtsAllRalliesIn3D; 00253 } 00254 else 00255 { 00256 m_threeDStatsGenerator->calculatePlayerImpactPtsIn3DFromIndices(m_playerBallPts,m_playerDeepestPtIndices, 00257 m_playerImpactPtsAllRalliesIn3D); 00258 return m_playerImpactPtsAllRalliesIn3D; 00259 } 00260 } 00261 00262 std::vector<float>& PlayerData::getRevolutionsPerMinute(float _inputDiameterInMeters, 00263 float _inputDistanceFrmKinectToPlayArea) 00264 { 00265 00266 // this make sures speed data is generated first 00267 // which would then feed into rpm calculations 00268 if(m_playerInterpolatedBallPts.size() == 0) 00269 { 00270 m_threeDStatsGenerator->generateInterpolatedDataForAllRallies(m_playerBallPts,m_playerDeepestPtIndices, 00271 _inputDistanceFrmKinectToPlayArea, 00272 m_playerInterpolatedBallPts,m_speedData); 00273 } 00274 00275 if(m_rpmData.size() != 0) 00276 { 00277 return m_rpmData; 00278 } 00279 00280 else 00281 { 00282 for(int i=0;i<m_speedData.size();i++) 00283 { 00284 // this produces revolutions per minute 00285 // input diameter and speed data are in meters scale 00286 float tempRPM = (m_speedData[i] * 60)/(3.14 * _inputDiameterInMeters); 00287 std::cout<<"repm calculated:"<<tempRPM<<"\n"; 00288 m_rpmData.push_back(tempRPM); 00289 } 00290 00291 return m_rpmData; 00292 } 00293 00294 } 00295 00296 void PlayerData::setPlayerDataProcessedFlag() 00297 { 00298 m_dataProcessed = true; 00299 } 00300 00301 bool PlayerData::checkDataProcessed() 00302 { 00303 return m_dataProcessed; 00304 }