KINECT STATS GENERATOR FOR SPORTS VISUALISATION
1.0
|
00001 #include "RGBboundsVisualization.h" 00002 #include "BallTrackingVisualization.h" 00003 #include "BallTrackingUtility.h" 00004 #include "DepthDebugVisualization.h" 00005 #include "StatsVisualization.h" 00006 #include "PlayerData.h" 00007 #include "BallPointsProcessing.h" 00008 00009 #include "MainWindow.h" 00010 #include <QToolBar> 00011 #include <QDoubleSpinBox> 00012 #include <QFormLayout> 00013 #include <QPushButton> 00014 #include <QComboBox> 00015 #include <QApplication> 00016 #include <QLabel> 00017 #include <QRadioButton> 00018 #include <QMdiSubWindow> 00019 #include <QDebug> 00020 #include <ngl/ShaderLib.h> 00021 00022 MainWindow::MainWindow( 00023 QWidget *_parent 00024 ): 00025 QMainWindow(_parent) 00026 { 00027 this->resize(QSize(1920,1200)); 00028 00029 m_liveWindowBuilt = false; 00030 00031 m_toolBarStart = new QToolBar(this); 00032 m_toolBarStart->setObjectName("HomePage"); 00033 QPushButton *live = new QPushButton("GO LIVE"); 00034 QObject::connect(live,SIGNAL(clicked()),this,SLOT(buildLiveWindowSetUp())); 00035 00036 QPushButton *importAnalysis = new QPushButton("IMPORT STATISTICS"); 00037 QObject::connect(importAnalysis,SIGNAL(clicked()),this,SLOT(buildImportWindowSetUp())); 00038 00039 QPushButton *setUp = new QPushButton("SETUP TRACKING"); 00040 QObject::connect(setUp,SIGNAL(clicked()),this,SLOT(buildTrackingVzWindowSetUp())); 00041 00042 00043 this->addToolBar(m_toolBarStart); 00044 00045 00046 QWidget *w = new QWidget(m_toolBarStart); // "this" is a pointer to a QToolBar 00047 QVBoxLayout *vbox = new QVBoxLayout(w); 00048 vbox->addStretch(); 00049 vbox->addWidget(live); 00050 vbox->addWidget(importAnalysis); 00051 vbox->addWidget(setUp); 00052 w->setLayout(vbox); 00053 m_toolBarStart->addWidget(w); 00054 00055 m_toolbarOrig = new QToolBar(this); 00056 m_toolbarOrig->setObjectName("KinectToolbar"); 00057 00058 m_toolbarImport = new QToolBar(this); 00059 m_toolbarImport->setObjectName("ImportToolBar"); 00060 00061 m_toolbarPlayer = new QToolBar(this); 00062 m_toolbarPlayer->setObjectName("PlayerToolBar"); 00063 00064 // this button should only be der in the import window 00065 QPushButton *readFile = new QPushButton("Read File"); 00066 QObject::connect(readFile,SIGNAL(clicked()),this,SLOT(readFile())); 00067 m_toolbarImport->addWidget(readFile); 00068 00069 m_toolbar = new QToolBar(this); 00070 m_toolbar->setObjectName("KinectDebugToolbarLive"); 00071 00072 00073 m_lowerDepthLabel= new QLabel(m_toolbar); 00074 m_lowerDepthLabel->setText("Lower Depth Volume Threshold"); 00075 m_toolbar->addWidget(m_lowerDepthLabel); 00076 00077 m_depthVolumeLowerThresh = new QDoubleSpinBox(m_toolbar); 00078 m_depthVolumeLowerThresh->setMinimum(0.01); 00079 m_depthVolumeLowerThresh->setMaximum(6.0); 00080 m_depthVolumeLowerThresh->setValue(0.02); 00081 m_depthVolumeLowerThresh->setSingleStep(0.1); 00082 m_toolbar->addWidget(m_depthVolumeLowerThresh); 00083 00084 m_higherDepthLabel= new QLabel(m_toolbar); 00085 m_higherDepthLabel->setText("Higher Depth Volume Threshold"); 00086 m_toolbar->addWidget(m_higherDepthLabel); 00087 00088 m_depthVolumeHigherThresh = new QDoubleSpinBox(m_toolbar); 00089 m_depthVolumeHigherThresh->setMinimum(0.20); 00090 m_depthVolumeHigherThresh->setMaximum(6.0); 00091 m_depthVolumeHigherThresh->setValue(1.02); 00092 m_depthVolumeHigherThresh->setSingleStep(0.1); 00093 m_toolbar->addWidget(m_depthVolumeHigherThresh); 00094 00095 00096 m_lowerBinLabel= new QLabel(m_toolbar); 00097 m_lowerBinLabel->setText("Binary Lower Threshold"); 00098 m_toolbar->addWidget(m_lowerBinLabel); 00099 00100 m_binLowerSpinBox = new QDoubleSpinBox(m_toolbar); 00101 m_binLowerSpinBox->setMaximum(255); 00102 m_binLowerSpinBox->setValue(100.0); 00103 m_binLowerSpinBox->setSingleStep(5.0); 00104 m_toolbar->addWidget(m_binLowerSpinBox); 00105 00106 // higher threshold not needed..its max value is to be FIXED as 255 which is done in the BallTrackingVisualization constructor 00107 00108 m_cannyLowerLabel= new QLabel(m_toolbar); 00109 m_cannyLowerLabel->setText("Canny Lower Threshold"); 00110 m_toolbar->addWidget(m_cannyLowerLabel); 00111 00112 m_cannyLowerSpinBox = new QDoubleSpinBox(m_toolbar); 00113 //slider->setMinimum(100); 00114 //slider->setMaximum(255); 00115 m_cannyLowerSpinBox->setMaximum(255); 00116 m_cannyLowerSpinBox->setValue(100.0); 00117 m_cannyLowerSpinBox->setSingleStep(5.0); 00118 //QObject::connect(m_cannyLowerSpinBox,SIGNAL(valueChanged(double)),m_trackingInBackground,SLOT(setCannyLowerThresh(double))); 00119 m_toolbar->addWidget(m_cannyLowerSpinBox); 00120 00121 m_cannyHigherLabel = new QLabel(m_toolbar); 00122 m_cannyHigherLabel->setText("Canny Higher Threshold"); 00123 m_toolbar->addWidget(m_cannyHigherLabel); 00124 00125 m_cannyHigherSpinBox = new QDoubleSpinBox(m_toolbar); 00126 //slider->setMinimum(100); 00127 //slider->setMaximum(255); 00128 m_cannyHigherSpinBox->setMaximum(500); 00129 m_cannyHigherSpinBox->setValue(300.0); 00130 m_cannyHigherSpinBox->setSingleStep(5.0); 00131 //QObject::connect(m_cannyHigherSpinBox,SIGNAL(valueChanged(double)),m_trackingInBackground,SLOT(setCannyHigherThresh(double))); 00132 m_toolbar->addWidget(m_cannyHigherSpinBox); 00133 00134 m_contourAreaLabel = new QLabel(m_toolbar); 00135 m_contourAreaLabel->setText("Contour Area Threshold"); 00136 m_toolbar->addWidget(m_contourAreaLabel); 00137 00138 m_contourAreaThresh = new QDoubleSpinBox(m_toolbar); 00139 //slider->setMinimum(100); 00140 //slider->setMaximum(255); 00141 m_contourAreaThresh->setMinimum(5.0); 00142 m_contourAreaThresh->setMaximum(1500.0); 00143 m_contourAreaThresh->setValue(120.0); 00144 m_contourAreaThresh->setSingleStep(5.0); 00145 //QObject::connect(m_contourAreaThresh,SIGNAL(valueChanged(double)),m_trackingInBackground,SLOT(setContourAreaThresh(double))); 00146 m_toolbar->addWidget(m_contourAreaThresh); 00147 00148 00149 m_impPointDepthMinLabel = new QLabel(m_toolbar); 00150 m_impPointDepthMinLabel->setText("Impact point depth Min thresh"); 00151 m_toolbar->addWidget(m_impPointDepthMinLabel); 00152 00153 m_impactPtMinDepth = new QDoubleSpinBox(m_toolbar); 00154 //slider->setMinimum(100); 00155 //slider->setMaximum(255); 00156 m_impactPtMinDepth->setMinimum(0.02); 00157 m_impactPtMinDepth->setMaximum(5.0); 00158 m_impactPtMinDepth->setValue(0.60); 00159 m_impactPtMinDepth->setSingleStep(0.01); 00160 //QObject::connect(m_impactPtMinDepth,SIGNAL(valueChanged(double)),m_processingUtility,SLOT(setBallImpactDepthMinThreshold(double))); 00161 m_toolbar->addWidget(m_impactPtMinDepth); 00162 00163 m_impPointDepthMaxLabel = new QLabel(m_toolbar); 00164 m_impPointDepthMaxLabel->setText("Impact point depth Max thresh"); 00165 m_toolbar->addWidget(m_impPointDepthMaxLabel); 00166 00167 m_impactPtMaxDepth = new QDoubleSpinBox(m_toolbar); 00168 //slider->setMinimum(100); 00169 //slider->setMaximum(255); 00170 m_impactPtMaxDepth->setMinimum(0.02); 00171 m_impactPtMaxDepth->setMaximum(5.0); 00172 m_impactPtMaxDepth->setValue(0.70); 00173 m_impactPtMaxDepth->setSingleStep(0.01); 00174 //QObject::connect(m_impactPtMaxDepth,SIGNAL(valueChanged(double)),m_processingUtility,SLOT(setBallImpactDepthMaxThreshold(double))); 00175 m_toolbar->addWidget(m_impactPtMaxDepth); 00176 00177 00178 m_diffAreaLabel = new QLabel(m_toolbar); 00179 m_diffAreaLabel->setText("Difference Area Threshold"); 00180 m_toolbar->addWidget(m_diffAreaLabel); 00181 00182 m_diffAreaThresh = new QDoubleSpinBox(m_toolbar); 00183 //slider->setMinimum(100); 00184 //slider->setMaximum(255); 00185 m_diffAreaThresh->setMinimum(5.0); 00186 m_diffAreaThresh->setMaximum(500.0); 00187 m_diffAreaThresh->setValue(30.0); 00188 m_diffAreaThresh->setSingleStep(5.0); 00189 //QObject::connect(m_diffAreaThresh,SIGNAL(valueChanged(double)),m_trackingInBackground,SLOT(setDifferenceInAreaThresh(double))); 00190 m_toolbar->addWidget(m_diffAreaThresh); 00191 00192 m_ellipseLabel = new QLabel(m_toolbar); 00193 m_ellipseLabel->setText("EllipticalStructuring Size"); 00194 m_toolbar->addWidget(m_ellipseLabel); 00195 00196 m_ellipseSize = new QSlider(m_toolbar); 00197 //slider->setMinimum(100); 00198 //slider->setMaximum(255); 00199 m_ellipseSize->setMinimum(1); 00200 m_ellipseSize->setMaximum(20); 00201 m_ellipseSize->setValue(2); 00202 00203 m_ellipseSize->setOrientation(Qt::Horizontal); 00204 //QObject::connect(m_ellipseSize,SIGNAL(sliderMoved(int)),m_trackingInBackground,SLOT(setStructuringElementSize(int))); 00205 m_toolbar->addWidget(m_ellipseSize); 00206 00207 m_blurLabel = new QLabel(m_toolbar); 00208 m_blurLabel->setText("Blur Size"); 00209 m_toolbar->addWidget(m_blurLabel); 00210 00211 m_blurSize = new QSlider(m_toolbar); 00212 //slider->setMinimum(100); 00213 //slider->setMaximum(255); 00214 m_blurSize->setMinimum(1); 00215 m_blurSize->setMaximum(20); 00216 m_blurSize->setValue(5); 00217 00218 m_blurSize->setOrientation(Qt::Horizontal); 00219 //QObject::connect(m_blurSize,SIGNAL(sliderMoved(int)),m_trackingInBackground,SLOT(setBlurSize(int))); 00220 m_toolbar->addWidget(m_blurSize); 00221 m_dialationLabel = new QLabel(m_toolbar); 00222 m_dialationLabel->setText("No of Dialations"); 00223 m_toolbar->addWidget(m_dialationLabel); 00224 m_dialation = new QSlider(m_toolbar); 00225 m_dialation->setMinimum(1); 00226 m_dialation->setMaximum(10); 00227 m_dialation->setValue(2); 00228 m_dialation->setOrientation(Qt::Horizontal); 00229 //QObject::connect(m_dialation,SIGNAL(sliderMoved(int)),m_trackingInBackground,SLOT(setNumerOfDialtions(int))); 00230 m_toolbar->addWidget(m_dialation); 00231 00232 00233 m_startTracking = new QPushButton("START TRACKING"); 00234 QObject::connect(m_startTracking,SIGNAL(clicked()),this,SLOT(setTrackingFlag())); 00235 m_toolbarOrig->addWidget(m_startTracking); 00236 m_distanceToTableLabel = new QLabel(m_toolbar); 00237 m_distanceToTableLabel->setText("Distance Kinect to PlayArea(in Meters)"); 00238 m_toolbar->addWidget(m_distanceToTableLabel); 00239 m_kinectToPlayArea = new QDoubleSpinBox(m_toolbar); 00240 //slider->setMinimum(100); 00241 //slider->setMaximum(255); 00242 m_kinectToPlayArea->setMinimum(0.2); 00243 m_kinectToPlayArea->setMaximum(6.0); 00244 m_kinectToPlayArea->setValue(0.76); 00245 m_kinectToPlayArea->setSingleStep(0.1); 00246 //QObject::connect(m_kinectToPlayArea,SIGNAL(valueChanged(double)),m_vz,SLOT(setKinectToPlayAreaDistance(double))); 00247 m_toolbar->addWidget(m_kinectToPlayArea); 00248 m_diameterBallLabel = new QLabel(m_toolbar); 00249 m_diameterBallLabel->setText("Diameter of ball(in Meters)"); 00250 m_toolbar->addWidget(m_diameterBallLabel); 00251 00252 m_diameterOfBall = new QDoubleSpinBox(m_toolbar); 00253 //slider->setMinimum(100); 00254 //slider->setMaximum(255); 00255 m_diameterOfBall->setMinimum(0.1); 00256 m_diameterOfBall->setMaximum(0.75); 00257 m_diameterOfBall->setValue(0.04); 00258 m_diameterOfBall->setSingleStep(0.01); 00259 //QObject::connect(m_diameterOfBall,SIGNAL(valueChanged(double)),m_vz,SLOT(setDiameterOfBallInMeters(double))); 00260 m_toolbar->addWidget(m_diameterOfBall); 00261 00262 // currently directly connected to ballptsprocessing slot 00263 // later connect it locally to check if tracking has been stopped 00264 // if not warn user to stop processing before processing 00265 00266 // disable process stats and other drop downs by default 00267 // put process stats and other stats in a group box and toggle that groupbox' visibility 00268 processStats = new QPushButton("PROCESS STATS"); 00269 QObject::connect(processStats,SIGNAL(clicked()),this,SLOT(processTrackingData())); 00270 m_toolbarOrig->addWidget(processStats); 00271 00272 processStats->setDisabled(true); 00273 00274 m_writeFile = new QPushButton("Write File"); 00275 //QObject::connect(m_writeFile,SIGNAL(clicked()),m_vz,SLOT(writeFile())); 00276 m_toolbarOrig->addWidget(m_writeFile); 00277 00278 00279 // see IPL app and change names and design UI accordingly 00280 m_choosePlayerLabel = new QLabel(m_toolbarPlayer); 00281 m_choosePlayerLabel->setText("Choose Player"); 00282 m_toolbarPlayer->addWidget(m_choosePlayerLabel); 00283 00284 m_playerSelection = new QComboBox(m_toolbarPlayer); 00285 //slider->setMinimum(100); 00286 //slider->setMaximum(255); 00287 m_playerSelection->addItem("PLAYER A"); // try making this into player names..initialize it by def 00288 // to playera and playerb to use when no name supplied 00289 m_playerSelection->addItem("PLAYER B"); 00290 m_playerSelection->addItem("BOTH"); 00291 m_playerSelection->setCurrentIndex(2); 00292 QObject::connect(m_playerSelection,SIGNAL(currentIndexChanged(int)),this,SLOT(setWhoseStatToView(int))); 00293 m_toolbarPlayer->addWidget(m_playerSelection); 00294 00295 m_chooseStatsLabel = new QLabel(m_toolbarPlayer); 00296 m_chooseStatsLabel->setText("Choose Statistics"); 00297 m_toolbarPlayer->addWidget(m_chooseStatsLabel); 00298 00299 m_statsSelection = new QComboBox(m_toolbarPlayer); 00300 //slider->setMinimum(100); 00301 //slider->setMaximum(255); 00302 m_statsSelection->addItem("PITCH MAP"); // try making this into player names..initialize it by def 00303 // to playera and playerb to use when no name supplied 00304 m_statsSelection->addItem("PERCENTAGE DISTRIBUTION"); 00305 m_statsSelection->addItem("HEIGHT GRAPH"); 00306 m_statsSelection->addItem("TRAJECTORY GRAPH"); 00307 m_statsSelection->addItem("VELOCITY MAP"); 00308 m_statsSelection->addItem("RPM MAP"); 00309 00310 QObject::connect(m_statsSelection,SIGNAL(currentIndexChanged(int)),this,SLOT(setWhichStatToView(int))); 00311 m_toolbarPlayer->addWidget(m_statsSelection); 00312 00313 00314 m_chooseCourtSideLabel = new QLabel(m_toolbarPlayer); 00315 m_chooseCourtSideLabel->setText("Court Sides"); 00316 m_toolbarPlayer->addWidget(m_chooseCourtSideLabel); 00317 00318 m_quadSelection = new QComboBox(m_toolbarPlayer); 00319 //slider->setMinimum(100); 00320 //slider->setMaximum(255); 00321 m_quadSelection->addItem("TOP LEFT"); // try making this into player names..initialize it by def 00322 // to playera and playerb to use when no name supplied 00323 m_quadSelection->addItem("BOTTOM LEFT"); 00324 m_quadSelection->addItem("BOTTOM RIGHT"); 00325 m_quadSelection->addItem("TOP RIGHT"); 00326 m_quadSelection->addItem("FULL COURT"); 00327 00328 m_quadSelection->setCurrentIndex(4); 00329 00330 //QObject::connect(m_quadSelection,SIGNAL(currentIndexChanged(int)),m_vz,SLOT(setWhichQuadToView(int))); 00331 m_toolbarPlayer->addWidget(m_quadSelection); 00332 m_quadSelection->setEnabled(false); 00333 00334 m_toolbarPlayer->setEnabled(false); 00335 00336 00337 00338 this->addToolBar(m_toolbarOrig); 00339 this->addToolBar(m_toolbarImport); 00340 // adds the debug toolbar and is hidden by default 00341 this->addToolBar(m_toolbarPlayer); 00342 this->addToolBar(m_toolbar); 00343 00344 00345 00346 setImportToolBarVisibility(false); 00347 setLiveSetUpToolBarVisibility(false); 00348 setLiveStartUpToolBarVisibility(false); 00349 setPlayerToolBarVisibility(false); 00350 00351 m_mdiArea = new QMdiArea; 00352 m_mdiArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded); 00353 m_mdiArea->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded); 00354 setCentralWidget(m_mdiArea); 00355 this->setWindowTitle(QString("Kinect Ball Tracking/Statistics Generation")); 00356 00357 m_vz = 0; 00358 m_processingUtility = 0; 00359 m_trackingInBackground = 0; 00360 m_trackingInForeground = 0; 00361 m_rgb = 0; 00362 m_depthVz = 0; 00363 m_playerA = m_playerB = 0; 00364 } 00365 00366 00367 00368 MainWindow::~MainWindow() 00369 { 00370 // DELETE EVERYTHING 00371 00372 delete m_vz; 00373 delete m_processingUtility; 00374 delete m_trackingInBackground; 00375 delete m_trackingInForeground; 00376 delete m_depthVz; 00377 delete m_rgb; 00378 delete m_playerA; 00379 delete m_playerB; 00380 } 00381 00382 00383 void MainWindow::keyPressEvent( 00384 QKeyEvent *_event 00385 ) 00386 { 00387 qDebug()<<"key event\n"; 00388 // this method is called every time the main window recives a key eventcompiler error . 00389 // we then switch on the key value and set the camera in the StatsVisualization 00390 switch (_event->key()) 00391 { 00392 case Qt::Key_Escape : m_kinect->shutDownKinect(); QApplication::exit(EXIT_SUCCESS); break; 00393 case Qt::Key_W : glPolygonMode(GL_FRONT_AND_BACK,GL_LINE); break; 00394 case Qt::Key_S : glPolygonMode(GL_FRONT_AND_BACK,GL_FILL); break; 00395 default : break; 00396 } 00397 } 00398 00399 void MainWindow::resizeEvent ( QResizeEvent * _event ) 00400 { 00401 Q_UNUSED(_event); 00402 } 00403 00404 00405 void MainWindow::setTrackingFlag() 00406 { 00407 if(m_kinect->getBounds()) 00408 { 00409 if(m_kinect->getTrackingFlag() == false) 00410 { 00411 m_startTracking->setText("STOP TRACKING"); 00412 00413 // disable process stats button if enabled 00414 processStats->setDisabled(true); 00415 00416 } 00417 else 00418 { 00419 m_startTracking->setText("START TRACKING"); 00420 00421 // enable process stats button 00422 processStats->setDisabled(false); 00423 // we are going to process the data as the tracking has now been stopped 00424 //processingUtility->processTrackingData(); 00425 } 00426 m_kinect->toggleTracking(); 00427 00428 } 00429 else 00430 { 00431 // bounds not yet defined...warn user to define bounds and close the RGB window for performance 00432 QString warningString("Please define field of play before proceeding. "); 00433 warningString += "To define field of play, use your mouse to click and drag in the RGB window."; 00434 warningString += "When finished, click Right mouse button to see the defined bounds in the Stats window."; 00435 warningString += "Once done, close the RGB window for better performance."; 00436 QMessageBox * warning = new QMessageBox(QMessageBox::Warning,QString("FIELD OF PLAY WARNING"),warningString,QMessageBox::Ok); 00437 warning->setModal(true); 00438 warning->setText(warningString); 00439 warning->show(); 00440 } 00441 } 00442 00443 void MainWindow::setWhichStatToView(int _whichStat) 00444 { 00445 // if % distrbn selected, display quad selection 00446 if(_whichStat == IMPACT_PERCENTAGE_DISTRIBUTION_VIEW) 00447 { 00448 m_quadSelection->setEnabled(true); 00449 00450 00451 } 00452 else 00453 { 00454 m_quadSelection->setEnabled(false); 00455 } 00456 00457 00458 // if the user has selected ht map view,velocity view 00459 // or rpm view or trajectory view 00460 // and if the player selection is BOTH, 00461 // then we deault the player to PLAYERA 00462 // and change the value of the player selection 00463 // combo box to PLAYERA 00464 if((_whichStat == IMPACT_HEIGHT_MAP_VIEW) || (_whichStat == VELOCITY_VIEW) || 00465 (_whichStat == RPM_VIEW) || (_whichStat == TRAJECTORY_VIEW)) 00466 { 00467 if(m_playerSelection->currentIndex() == BOTH) 00468 { 00469 m_playerSelection->setCurrentIndex(PLAYERA); 00470 00471 m_vz->setWhoseStatToView(PLAYERA); 00472 00473 } 00474 else 00475 { 00476 m_vz->setWhoseStatToView(m_playerSelection->currentIndex()); 00477 } 00478 } 00479 00480 m_vz->setWhichStatToView(_whichStat); 00481 00482 00483 } 00484 00485 void MainWindow::setWhoseStatToView(int _whoseStat) 00486 { 00487 00488 // if the user has selected ht map view,velocity view 00489 // or rpm view 00490 // and if the player selection is BOTH, 00491 // then we deault the player to PLAYERA 00492 // and change the value of the player selection 00493 // combo box to PLAYERA 00494 if((m_statsSelection->currentIndex() == IMPACT_HEIGHT_MAP_VIEW) || 00495 (m_statsSelection->currentIndex() == VELOCITY_VIEW) || 00496 (m_statsSelection->currentIndex() == RPM_VIEW) || 00497 (m_statsSelection->currentIndex() == TRAJECTORY_VIEW)) 00498 { 00499 if(_whoseStat == BOTH) 00500 { 00501 m_playerSelection->setCurrentIndex(PLAYERA); 00502 m_vz->setWhoseStatToView(PLAYERA); 00503 } 00504 else 00505 { 00506 m_vz->setWhoseStatToView(_whoseStat); 00507 } 00508 00509 } 00510 else 00511 { 00512 m_vz->setWhoseStatToView(_whoseStat); 00513 } 00514 } 00515 00516 void MainWindow::readFile() 00517 { 00518 00519 killExistingWindows(); 00520 buildImportWindowSetUp(); 00521 00522 m_vz = new StatsVisualization(this,true); 00523 m_vz->makeCurrent(); 00524 //QMdiSubWindow *importedStatsWindow = new QMdiSubWindow; 00525 ExtendedQMdiSubWindow *importedStatsWindow = new ExtendedQMdiSubWindow(this); 00526 importedStatsWindow->setWidget(m_vz); 00527 importedStatsWindow->setAccessibleName("Statsvz"); 00528 importedStatsWindow->setAttribute(Qt::WA_DeleteOnClose); 00529 importedStatsWindow->setWindowTitle("Imported Statistical Output"); 00530 importedStatsWindow->resize(640,480); 00531 m_mdiArea->addSubWindow(importedStatsWindow); 00532 00533 // WE NEED TO FIRST CALL THIS SHOW METHOD 00534 // AS THIS WILL CREATE THE VALID GL CONTEXT 00535 // THRU INITIALIZEGL WHICH IS NEEDED FOR CREATING VAOS 00536 // AND PRIMS IN THE READFILE FUNCTION WHICH FOLLOWS THIS 00537 importedStatsWindow->show(); 00538 00539 m_toolbarPlayer->setEnabled(true); 00540 QObject::connect(m_quadSelection,SIGNAL(currentIndexChanged(int)),m_vz,SLOT(setWhichQuadToView(int))); 00541 00542 // call the read function 00543 // pass in the input file name by querying the file input value 00544 00545 QString fileName = QFileDialog::getOpenFileName(this, "Open File","archive"); 00546 00547 00548 // check if filename is valid, if so call read 00549 if(!(fileName.isEmpty())) 00550 { 00551 m_vz->readFile(fileName); 00552 } 00553 } 00554 00555 void MainWindow::processTrackingData() 00556 { 00557 // do not forget to disable the process stats by default and enable it only 00558 // when tracking has been stopped 00559 // again is start tracking is clicked, process stats has to be enabled 00560 00561 m_processingUtility->processTrackingData(); 00562 m_vz->updateDisplay(); 00563 00564 } 00565 00566 00567 void MainWindow::buildImportWindowSetUp() 00568 { 00569 killExistingWindows(); 00570 00571 setLiveSetUpToolBarVisibility(false); 00572 setLiveStartUpToolBarVisibility(false); 00573 // 2 more calls to set visualisation toolbars to hide 00574 00575 // enable import bar visibility for read button 00576 setImportToolBarVisibility(true); 00577 00578 setPlayerToolBarVisibility(true); 00579 } 00580 00581 00582 void MainWindow::buildLiveWindowSetUp() 00583 { 00584 00585 killExistingWindows(); 00586 00587 setImportToolBarVisibility(false); 00588 00589 setPlayerToolBarVisibility(true); 00590 00591 // if(!(m_liveWindowBuilt)) 00592 // { 00593 m_kinect=KinectInterface::instance(); 00594 00595 if(m_kinect == 0) 00596 { 00597 QString warningString("The application could not find a Kinect connected.Please Connet the device and click \"Yes\" when ready."); 00598 QMessageBox msgBox(QMessageBox::Warning,QString("DEVICE CONNECTION WARNING"),warningString,QMessageBox::Yes | QMessageBox::Cancel); 00599 00600 //returns the button clicked value 00601 int ret = msgBox.exec(); 00602 00603 //User get input from returned value (ret). you can handle it here. 00604 switch (ret) 00605 { 00606 case QMessageBox::Yes: 00607 { 00608 // yes was clicked 00609 buildLiveWindowSetUp(); 00610 break; 00611 } 00612 case QMessageBox::Cancel: 00613 { 00614 // cancel was clicked 00615 break; 00616 } 00617 default: 00618 // should never be reached 00619 break; 00620 } 00621 // if the user presses cancel we shud return 00622 return; 00623 } 00624 00625 00626 // we need to reset the bounds defined finally flag here 00627 // so that the user is allowed to redfine the bounds 00628 // once he comes back to live or setup sections of the tool 00629 KinectInterface *kinect = KinectInterface::instance(); 00630 kinect->setBoundsDefined(false); 00631 00632 // Time to create our players and processing object 00633 00634 m_playerA = new PlayerData(); 00635 m_playerB = new PlayerData(); 00636 00637 m_processingUtility = new BallPointsProcessing(m_playerA,m_playerB); 00638 m_trackingInBackground = new BallTrackingUtility(m_processingUtility); 00639 00640 00641 // this needs to be created before any other subwindows as 00642 // mysteriously the ngl text appears in only one window which is created first 00643 // and we need to display ngl text within this window 00644 // for percentage statistics 00645 m_vz = new StatsVisualization(this,m_playerA,m_playerB); 00646 m_vz->makeCurrent(); 00647 ExtendedQMdiSubWindow *statsWindow = new ExtendedQMdiSubWindow(this); 00648 statsWindow->setWidget(m_vz); 00649 statsWindow->setAccessibleName("Statsvz"); 00650 statsWindow->setAttribute(Qt::WA_DeleteOnClose); 00651 statsWindow->setWindowTitle("Statistical Output"); 00652 statsWindow->resize(640,480); 00653 m_mdiArea->addSubWindow(statsWindow); 00654 statsWindow->show(); 00655 00656 00657 m_rgb = new RGBboundsVisualization(this); 00658 m_rgb->makeCurrent(); 00659 ExtendedQMdiSubWindow *rgbBoundsWindow = new ExtendedQMdiSubWindow(this); 00660 rgbBoundsWindow->setWidget(m_rgb); 00661 rgbBoundsWindow->setAccessibleName("Rgbvz"); 00662 rgbBoundsWindow->setAttribute(Qt::WA_DeleteOnClose); 00663 rgbBoundsWindow->setWindowTitle("RGB Output"); 00664 rgbBoundsWindow->resize(640,480); 00665 m_mdiArea->addSubWindow(rgbBoundsWindow); 00666 rgbBoundsWindow->show(); 00667 00668 00669 00670 m_toolbarPlayer->setEnabled(true); 00671 QObject::connect(m_depthVolumeLowerThresh,SIGNAL(valueChanged(double)),m_kinect,SLOT(setDepthVolumeLower(double))); 00672 QObject::connect(m_depthVolumeHigherThresh,SIGNAL(valueChanged(double)),m_kinect,SLOT(setDepthVolumeHigher(double))); 00673 QObject::connect(m_binLowerSpinBox,SIGNAL(valueChanged(double)),m_trackingInBackground,SLOT(setBinaryLowerThresh(double))); 00674 QObject::connect(m_cannyLowerSpinBox,SIGNAL(valueChanged(double)),m_trackingInBackground,SLOT(setCannyLowerThresh(double))); 00675 QObject::connect(m_cannyHigherSpinBox,SIGNAL(valueChanged(double)),m_trackingInBackground,SLOT(setCannyHigherThresh(double))); 00676 QObject::connect(m_contourAreaThresh,SIGNAL(valueChanged(double)),m_trackingInBackground,SLOT(setContourAreaThresh(double))); 00677 QObject::connect(m_impactPtMinDepth,SIGNAL(valueChanged(double)),m_processingUtility,SLOT(setBallImpactDepthMinThreshold(double))); 00678 QObject::connect(m_impactPtMaxDepth,SIGNAL(valueChanged(double)),m_processingUtility,SLOT(setBallImpactDepthMaxThreshold(double))); 00679 QObject::connect(m_diffAreaThresh,SIGNAL(valueChanged(double)),m_trackingInBackground,SLOT(setDifferenceInAreaThresh(double))); 00680 QObject::connect(m_ellipseSize,SIGNAL(sliderMoved(int)),m_trackingInBackground,SLOT(setStructuringElementSize(int))); 00681 QObject::connect(m_blurSize,SIGNAL(sliderMoved(int)),m_trackingInBackground,SLOT(setBlurSize(int))); 00682 QObject::connect(m_dialation,SIGNAL(sliderMoved(int)),m_trackingInBackground,SLOT(setNumerOfDialtions(int))); 00683 QObject::connect(m_quadSelection,SIGNAL(currentIndexChanged(int)),m_vz,SLOT(setWhichQuadToView(int))); 00684 QObject::connect(m_kinectToPlayArea,SIGNAL(valueChanged(double)),m_vz,SLOT(setKinectToPlayAreaDistance(double))); 00685 QObject::connect(m_diameterOfBall,SIGNAL(valueChanged(double)),m_vz,SLOT(setDiameterOfBallInMeters(double))); 00686 00687 QObject::connect(m_writeFile,SIGNAL(clicked()),m_vz,SLOT(writeFile())); 00688 00689 00690 m_writeFile->setEnabled(true); 00691 00692 00693 // m_liveWindowBuilt = true; 00694 00695 // } 00696 00697 setLiveSetUpToolBarVisibility(true); 00698 setLiveStartUpToolBarVisibility(true); 00699 00700 } 00701 00702 00703 void MainWindow::buildTrackingVzWindowSetUp() 00704 { 00705 killExistingWindows(); 00706 00707 setImportToolBarVisibility(false); 00708 00709 setPlayerToolBarVisibility(false); 00710 00711 if(m_writeFile->isEnabled()) 00712 { 00713 m_writeFile->setEnabled(false); 00714 } 00715 00716 //if(!(m_liveWindowBuilt)) 00717 //{ 00718 m_kinect=KinectInterface::instance(); 00719 00720 if(m_kinect == 0) 00721 { 00722 QString warningString("The application could not find a Kinect connected.Please Connet the device and click \"Yes\" when ready."); 00723 QMessageBox msgBox(QMessageBox::Warning,QString("DEVICE CONNECTION WARNING"),warningString,QMessageBox::Yes | QMessageBox::Cancel); 00724 00725 //returns the button clicked value 00726 int ret = msgBox.exec(); 00727 00728 //User get input from returned value (ret). you can handle it here. 00729 switch (ret) 00730 { 00731 case QMessageBox::Yes: 00732 { 00733 // yes was clicked 00734 buildTrackingVzWindowSetUp(); 00735 break; 00736 } 00737 case QMessageBox::Cancel: 00738 { 00739 // cancel was clicked 00740 break; 00741 } 00742 default: 00743 // should never be reached 00744 break; 00745 } 00746 // if the user presses cancel we shud return 00747 return; 00748 } 00749 00750 00751 // we need to reset the bounds defined finally flag here 00752 // so that the user is allowed to redfine the bounds 00753 // once he comes back to live or setup sections of the tool 00754 KinectInterface *kinect = KinectInterface::instance(); 00755 kinect->setBoundsDefined(false); 00756 00757 00758 m_rgb = new RGBboundsVisualization(this); 00759 m_rgb->makeCurrent(); 00760 ExtendedQMdiSubWindow *rgbBoundsWindow = new ExtendedQMdiSubWindow(this); 00761 rgbBoundsWindow->setWidget(m_rgb); 00762 rgbBoundsWindow->setAccessibleName("Rgbvz"); 00763 rgbBoundsWindow->setAttribute(Qt::WA_DeleteOnClose); 00764 rgbBoundsWindow->setWindowTitle("RGB Output"); 00765 rgbBoundsWindow->resize(640,480); 00766 m_mdiArea->addSubWindow(rgbBoundsWindow); 00767 rgbBoundsWindow->show(); 00768 00769 m_depthVz = new DepthDebugVisualization(this); 00770 m_depthVz->makeCurrent(); 00771 ExtendedQMdiSubWindow *depthWindow = new ExtendedQMdiSubWindow(this); 00772 depthWindow->setWidget(m_depthVz); 00773 depthWindow->setAccessibleName("Depthlive"); 00774 depthWindow->setAttribute(Qt::WA_DeleteOnClose); 00775 depthWindow->setWindowTitle("Sliced Depth Realtime Output"); 00776 depthWindow->resize(640,480); 00777 m_mdiArea->addSubWindow(depthWindow); 00778 depthWindow->show(); 00779 00780 m_trackingInForeground = new BallTrackingVisualization(this); 00781 m_trackingInForeground->makeCurrent(); 00782 ExtendedQMdiSubWindow *trackingForeGround = new ExtendedQMdiSubWindow(this); 00783 trackingForeGround->setWidget(m_trackingInForeground); 00784 trackingForeGround->setAccessibleName("Foregroundlive"); 00785 trackingForeGround->setAttribute(Qt::WA_DeleteOnClose); 00786 trackingForeGround->setWindowTitle("Ball Tracking RealTime Output"); 00787 trackingForeGround->resize(640,480); 00788 m_mdiArea->addSubWindow(trackingForeGround); 00789 trackingForeGround->show(); 00790 00791 00792 m_toolbarPlayer->setEnabled(true); 00793 QObject::connect(m_depthVolumeLowerThresh,SIGNAL(valueChanged(double)),m_kinect,SLOT(setDepthVolumeLower(double))); 00794 QObject::connect(m_depthVolumeHigherThresh,SIGNAL(valueChanged(double)),m_kinect,SLOT(setDepthVolumeHigher(double))); 00795 QObject::connect(m_binLowerSpinBox,SIGNAL(valueChanged(double)),m_trackingInForeground,SLOT(setBinaryLowerThresh(double))); 00796 QObject::connect(m_cannyLowerSpinBox,SIGNAL(valueChanged(double)),m_trackingInForeground,SLOT(setCannyLowerThresh(double))); 00797 QObject::connect(m_cannyHigherSpinBox,SIGNAL(valueChanged(double)),m_trackingInForeground,SLOT(setCannyHigherThresh(double))); 00798 QObject::connect(m_contourAreaThresh,SIGNAL(valueChanged(double)),m_trackingInForeground,SLOT(setContourAreaThresh(double))); 00799 QObject::connect(m_diffAreaThresh,SIGNAL(valueChanged(double)),m_trackingInForeground,SLOT(setDifferenceInAreaThresh(double))); 00800 QObject::connect(m_ellipseSize,SIGNAL(sliderMoved(int)),m_trackingInForeground,SLOT(setStructuringElementSize(int))); 00801 QObject::connect(m_blurSize,SIGNAL(sliderMoved(int)),m_trackingInForeground,SLOT(setBlurSize(int))); 00802 QObject::connect(m_dialation,SIGNAL(sliderMoved(int)),m_trackingInForeground,SLOT(setNumerOfDialtions(int))); 00803 setLiveSetUpToolBarVisibility(true); 00804 setLiveStartUpToolBarVisibility(true); 00805 00806 } 00807 00808 // following 3 functions shud be called with appropriate bool value 00809 00810 void MainWindow::setLiveStartUpToolBarVisibility(bool _visibility) 00811 { 00812 // start,clear,process,write containing box 00813 m_toolbarOrig->setVisible(_visibility); 00814 } 00815 00816 void MainWindow::setLiveSetUpToolBarVisibility(bool _visibility) 00817 { 00818 // start,clear,process,write containing box 00819 m_toolbar->setVisible(_visibility); 00820 } 00821 00822 void MainWindow::setImportToolBarVisibility(bool _visibility) 00823 { 00824 // read button containing box visibility 00825 m_toolbarImport->setVisible(_visibility); 00826 } 00827 00828 void MainWindow::setPlayerToolBarVisibility(bool _visibility) 00829 { 00830 m_toolbarPlayer->setVisible(_visibility); 00831 } 00832 00833 00834 00835 void MainWindow::killExistingWindows() 00836 { 00837 // since we have our own Mdi window 00838 // we have overridden the closeevent 00839 // and deleted the containing widget 00840 // and the associated pointers to avoid memory leaks 00841 // for all windows..this is done 00842 // in the ExtendedQMdiSubWindow class 00843 00844 if(m_vz) 00845 { 00846 // this command will close the existing window 00847 // as we are going to create a new stats window if 00848 // user clicks read button 00849 if(m_vz->nativeParentWidget()) 00850 { 00851 m_vz->nativeParentWidget()->close(); 00852 } 00853 } 00854 00855 if(m_rgb) 00856 { 00857 // this command will close the existing window 00858 00859 if(m_rgb->nativeParentWidget()) 00860 { 00861 m_rgb->nativeParentWidget()->close(); 00862 } 00863 } 00864 00865 00866 if(m_depthVz) 00867 { 00868 // this command will close the existing window 00869 00870 if(m_depthVz->nativeParentWidget()) 00871 { 00872 m_depthVz->nativeParentWidget()->close(); 00873 } 00874 00875 } 00876 00877 if(m_trackingInForeground) 00878 { 00879 // this command will close the existing window 00880 00881 if(m_trackingInForeground->nativeParentWidget()) 00882 { 00883 m_trackingInForeground->nativeParentWidget()->close(); 00884 } 00885 } 00886 00887 00888 00889 if(m_trackingInBackground) 00890 { 00891 delete m_trackingInBackground; 00892 m_trackingInBackground = 0; 00893 } 00894 00895 if(m_playerA) 00896 { 00897 delete m_playerA; 00898 m_playerA = 0; 00899 } 00900 00901 if(m_playerB) 00902 { 00903 delete m_playerB; 00904 m_playerB = 0; 00905 } 00906 00907 if(m_processingUtility) 00908 { 00909 delete m_processingUtility; 00910 m_processingUtility = 0; 00911 } 00912 } 00913 00914 void MainWindow::deleteCurrentStatsvz() 00915 { 00916 delete m_vz; 00917 m_vz = 0; 00918 } 00919 00920 void MainWindow::deleteCurrentTrackingvz() 00921 { 00922 delete m_trackingInForeground; 00923 m_trackingInForeground = 0; 00924 } 00925 00926 void MainWindow::deleteCurrentRGBvz() 00927 { 00928 delete m_rgb; 00929 m_rgb = 0; 00930 } 00931 00932 void MainWindow::deleteCurrentDepthvz() 00933 { 00934 delete m_depthVz; 00935 m_depthVz = 0; 00936 00937 } 00938 00939