KINECT STATS GENERATOR FOR SPORTS VISUALISATION
1.0
|
00001 #include "DepthDebugVisualization.h" 00002 #include <iostream> 00003 #include <libfreenect.hpp> 00004 #include <libfreenect_sync.h> 00005 #include <Mutex.h> 00006 #include <QDebug> 00007 #include <KinectInterface.h> 00008 #include <ngl/NGLInit.h> 00009 #include <ngl/ShaderLib.h> 00010 #include "opencv2/features2d/features2d.hpp" 00011 #include "opencv2/nonfree/features2d.hpp" 00012 00013 /* 00014 LICENSING: You are free to use any part of this project provided I am informed about it via email 00015 at santoshwins@hotmail.com and referenced appropriately in your works 00016 */ 00017 00018 //---------------------------------------------------------------------------------------------------------------------- 00019 DepthDebugVisualization::DepthDebugVisualization(QWidget *_parent) : QGLWidget( new CreateCoreGLContext(QGLFormat::defaultFormat()), _parent ) 00020 00021 { 00022 00023 // set this widget to have the initial keyboard focus 00024 // setFocus(); 00025 // re-size the widget to that of the parent (in this case the GLFrame passed in on construction) 00026 this->resize(_parent->size()); 00027 startTimer(20); 00028 m_depth = cvCreateMat(480,640,CV_8UC1); 00029 00030 } 00031 00032 // This virtual function is called once before the first call to paintGL() or resizeGL(), 00033 //and then once whenever the widget has been assigned a new QGLContext. 00034 // This function should set up any required OpenGL context rendering flags, defining display lists, etc. 00035 00036 //---------------------------------------------------------------------------------------------------------------------- 00037 void DepthDebugVisualization::initializeGL() 00038 { 00039 // 00040 ngl::NGLInit *Init = ngl::NGLInit::instance(); 00041 Init->initGlew(); 00042 00043 // now we have valid GL can create shaders etc 00044 ngl::ShaderLib *shader = ngl::ShaderLib::instance(); 00045 shader->createShaderProgram("TextureDepth"); 00046 00047 shader->attachShader("TextureVertex",ngl::VERTEX); 00048 shader->attachShader("TextureFragment",ngl::FRAGMENT); 00049 shader->loadShaderSource("TextureVertex","shaders/TextureVert.glsl"); 00050 shader->loadShaderSource("TextureFragment","shaders/LumFrag.glsl"); 00051 00052 shader->compileShader("TextureVertex"); 00053 shader->compileShader("TextureFragment"); 00054 shader->attachShaderToProgram("TextureDepth","TextureVertex"); 00055 shader->attachShaderToProgram("TextureDepth","TextureFragment"); 00056 00057 shader->linkProgramObject("TextureDepth"); 00058 (*shader)["TextureDepth"]->use(); 00059 shader->setShaderParam1i("tex",0); 00060 00061 m_screen = new ScreenQuad(640,480,"TextureDepth"); 00062 // set this to draw depth textures 00063 m_screen->setTextureMode(GL_DEPTH_COMPONENT ); 00064 00065 //frame rate GUNDU 00066 //m_text=new ngl::Text(QFont("Arial",14)); 00067 //currentTime = currentTime.currentTime(); 00068 } 00069 00070 //---------------------------------------------------------------------------------------------------------------------- 00071 //This virtual function is called whenever the widget has been resized. 00072 // The new size is passed in width and height. 00073 void DepthDebugVisualization::resizeGL( 00074 int _w, 00075 int _h 00076 ) 00077 { 00078 glViewport(0,0,_w,_h); 00079 00080 //m_text->setScreenSize(_w,_h); 00081 } 00082 00083 //---------------------------------------------------------------------------------------------------------------------- 00084 //This virtual function is called whenever the widget needs to be painted. 00085 // this is our main drawing routine 00086 void DepthDebugVisualization::paintGL() 00087 { 00088 //int temp = 0; 00089 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 00090 00091 KinectInterface *kinect=KinectInterface::instance(); 00092 // this is the raw data will need to be processed 00093 kinect->getDepthSliced(m_depth); 00094 00095 m_screen->draw(&m_depth); 00096 } 00097 00098 //---------------------------------------------------------------------------------------------------------------------- 00099 void DepthDebugVisualization::mouseMoveEvent ( QMouseEvent * _event) 00100 { 00101 Q_UNUSED(_event); 00102 } 00103 00104 00105 //---------------------------------------------------------------------------------------------------------------------- 00106 void DepthDebugVisualization::mousePressEvent (QMouseEvent * _event ) 00107 { 00108 Q_UNUSED(_event); 00109 00110 } 00111 00112 //---------------------------------------------------------------------------------------------------------------------- 00113 void DepthDebugVisualization::mouseReleaseEvent ( QMouseEvent * _event ) 00114 { 00115 // this event is called when the mouse button is released 00116 // we then set Rotate to false 00117 Q_UNUSED(_event); 00118 00119 } 00120 00121 void DepthDebugVisualization::timerEvent( QTimerEvent *_event ) 00122 { 00123 Q_UNUSED(_event); 00124 // re-draw GL 00125 updateGL(); 00126 00127 } 00128 00129 DepthDebugVisualization::~DepthDebugVisualization() 00130 { 00131 if(m_screen) 00132 { 00133 delete m_screen; 00134 } 00135 } 00136 00137 00138