/* * debugview implementation * * Copyright (C) Li Wei, Li Ming * * Released under the GPL version 3. * */ /** * @file * @brief Main programm for dynamic Velodyne SLAM * * @author Li Wei, Wuhan University, China * @author Li Ming, Wuhan University, China */ #ifdef _MSC_VER #ifdef OPENMP #define _OPENMP #endif #endif #ifdef _MSC_VER #include #else #include #endif #include using std::ifstream; using std::ofstream; #include using std::cout; using std::cerr; using std::endl; #include using std::stringstream; #include "slam6d/scan.h" #include "slam6d/Boctree.h" #include "veloslam/veloscan.h" #include "veloslam/trackermanager.h" #include "veloslam/debugview.h" #include "veloslam/velodefs.h" #include #include #include using namespace boost; using boost::thread; boost::mutex draw_mutex; extern TrackerManager trackMgr; extern VeloScan* g_pfirstScan; #ifdef _OPENMP #include #endif #ifdef _MSC_VER #define strcasecmp _stricmp #define strncasecmp _strnicmp #else #include #endif #include using std::flush; #include /* OpenGL header file */ #include /* OpenGL utilities header file */ #ifdef _MSC_VER #include #else #include #endif #include "veloslam/color_util.h" bool DebugDrawFinished =false; bool ICPFinished =false; bool save_animation=false; int anim_frame_rate; extern int scanCount; GLenum buffermode_debugView = GL_BACK; boost::mutex keymutex; boost::condition keycond; GLenum doubleBuffer; int g_frame=0; float rotX = 0.0, rotY = 0.0; int x_lbefore,y_lbefore; int x_rbefore,y_rbefore; int z_before1,z_before2; bool buttonSaveLeft, buttonSaveMiddle , buttonSaveRight; float x_move,y_move,z_move; float x_move_save,y_move_save, z_move_save; float x_rotate,y_rotate,z_rotate; float x_rotate_save,y_rotate_save,z_rotate_save; float m_zoom; float m_aspect; // gluLookAt(0, 0, 80, 0, 0, 0, 0, 1, 0); float m_eyex, m_eyey, m_eyez; float m_centerx, m_centery, m_centerz; float m_upx, m_upy, m_upz; bool g_pause=true; void DrawPointsRGB(Point p, float r, float g, float b) { GLdouble dVect1[3]; glColor3d(r, g, b); dVect1[0]=p.x; dVect1[1]=p.y; dVect1[2]=p.z; glVertex3dv(dVect1); } void DrawText(float x, float y, float z, char * outputstring) { #ifdef _MSC_VER glPushMatrix(); glColor3f(1.0f,1.0f,1.0f); wglUseFontBitmaps(wglGetCurrentDC(), 0, 255, 100); glListBase(100); glRasterPos3f(x, y, z); glCallLists( strlen(outputstring), GL_UNSIGNED_BYTE, outputstring); glPopMatrix(); #endif } void DrawTextRGB(float x, float y, float z, float r, float g, float b, char * outputstring) { #ifdef _MSC_VER glPushMatrix(); glColor3f(r,g,b); wglUseFontBitmaps(wglGetCurrentDC(), 0, 255, 100); glListBase(100); glRasterPos3f(x, y, z); glCallLists( strlen(outputstring), GL_UNSIGNED_BYTE, outputstring); glPopMatrix(); #endif } void DrawTextRGB(Point P, float r, float g, float b, char * outputstring) { #ifdef _MSC_VER glPushMatrix(); glColor3f(r,g,b); wglUseFontBitmaps(wglGetCurrentDC(), 0, 255, 100); glListBase(100); glRasterPos3f(P.x, P.y, P.z); glCallLists( strlen(outputstring), GL_UNSIGNED_BYTE, outputstring); glPopMatrix(); #endif } void Draw_Line_GL_RGB(float x1, float y1, float z1, float x2, float y2, float z2, float r,float g,float b,float width) { GLdouble dVect1[3]; GLdouble dVect2[3]; glLineWidth(width); glBegin(GL_LINES); glColor3d(r, g, b); //////////////////////// dVect1[0]=x1; dVect1[1]=y1; dVect1[2]=z1; glVertex3dv(dVect1); dVect2[0]=x2; dVect2[1]=y2; dVect2[2]=z2; glVertex3dv(dVect2); glEnd(); } void Draw_Line_GL_RGB( Point P1, Point P2, int width, float r,float g,float b, bool arrow) { GLdouble dVect1[3]; GLdouble dVect2[3]; glLineWidth(width); glBegin(GL_LINES); glColor3d(r, g, b); dVect1[0]=P1.x; dVect1[1]=P1.y; dVect1[2]=P1.z; glVertex3dv(dVect1); dVect2[0]=P2.x; dVect2[1]=P2.y; dVect2[2]=P2.z; glVertex3dv(dVect2); glEnd(); if(arrow) { glPushMatrix(); glTranslatef(1.0, 0.0f, 0.0f); glRotatef(90.0f,0.0f,1.0f,0.0f); glutWireCone(0.027,0.09,10,10); glPopMatrix(); } } void Draw_Line_GL(float x1, float y1, float z1,float x2, float y2, float z2) { Draw_Line_GL_RGB(x1,y1,z1, x2,y2,z2, 0,1.0,0); } void Draw_Cube_GL_RGB(float min_x, float min_y, float min_z, float max_x, float max_y, float max_z, float r,float g,float b) { Draw_Line_GL_RGB(min_x,min_y,max_z,max_x,min_y,max_z,r,g,b); Draw_Line_GL_RGB(min_x,max_y,max_z,max_x,max_y,max_z,r,g,b); Draw_Line_GL_RGB(min_x,max_y,min_z,max_x,max_y,min_z,r,g,b); Draw_Line_GL_RGB(min_x,min_y,min_z,max_x,min_y,min_z,r,g,b); Draw_Line_GL_RGB(min_x,min_y,max_z,min_x,max_y,max_z,r,g,b); Draw_Line_GL_RGB(max_x,min_y,max_z,max_x,max_y,max_z,r,g,b); Draw_Line_GL_RGB(min_x,min_y,min_z,min_x,max_y,min_z,r,g,b); Draw_Line_GL_RGB(max_x,min_y,min_z,max_x,max_y,min_z,r,g,b); Draw_Line_GL_RGB(min_x,min_y,min_z,min_x,min_y,max_z,r,g,b); Draw_Line_GL_RGB(max_x,min_y,min_z,max_x,min_y,max_z,r,g,b); Draw_Line_GL_RGB(max_x,max_y,min_z,max_x,max_y,max_z,r,g,b); Draw_Line_GL_RGB(min_x,max_y,min_z,min_x,max_y,max_z,r,g,b); } void Draw_Inclined_Cube_GL_RGB(double rectangleVexPos[4][2],double min_z,double max_z, float r,float g,float b,float width) { Draw_Line_GL_RGB(rectangleVexPos[0][0],rectangleVexPos[0][1],min_z,rectangleVexPos[1][0],rectangleVexPos[1][1],min_z,r,g,b,width); Draw_Line_GL_RGB(rectangleVexPos[1][0],rectangleVexPos[1][1],min_z,rectangleVexPos[2][0],rectangleVexPos[2][1],min_z,r,g,b,width); Draw_Line_GL_RGB(rectangleVexPos[2][0],rectangleVexPos[2][1],min_z,rectangleVexPos[3][0],rectangleVexPos[3][1],min_z,r,g,b,width); Draw_Line_GL_RGB(rectangleVexPos[3][0],rectangleVexPos[3][1],min_z,rectangleVexPos[0][0],rectangleVexPos[0][1],min_z,r,g,b,width); Draw_Line_GL_RGB(rectangleVexPos[0][0],rectangleVexPos[0][1],max_z,rectangleVexPos[1][0],rectangleVexPos[1][1],max_z,r,g,b,width); Draw_Line_GL_RGB(rectangleVexPos[1][0],rectangleVexPos[1][1],max_z,rectangleVexPos[2][0],rectangleVexPos[2][1],max_z,r,g,b,width); Draw_Line_GL_RGB(rectangleVexPos[2][0],rectangleVexPos[2][1],max_z,rectangleVexPos[3][0],rectangleVexPos[3][1],max_z,r,g,b,width); Draw_Line_GL_RGB(rectangleVexPos[3][0],rectangleVexPos[3][1],max_z,rectangleVexPos[0][0],rectangleVexPos[0][1],max_z,r,g,b,width); Draw_Line_GL_RGB(rectangleVexPos[0][0],rectangleVexPos[0][1],min_z,rectangleVexPos[0][0],rectangleVexPos[0][1],max_z,r,g,b,width); Draw_Line_GL_RGB(rectangleVexPos[1][0],rectangleVexPos[1][1],min_z,rectangleVexPos[1][0],rectangleVexPos[1][1],max_z,r,g,b,width); Draw_Line_GL_RGB(rectangleVexPos[2][0],rectangleVexPos[2][1],min_z,rectangleVexPos[2][0],rectangleVexPos[2][1],max_z,r,g,b,width); Draw_Line_GL_RGB(rectangleVexPos[3][0],rectangleVexPos[3][1],min_z,rectangleVexPos[3][0],rectangleVexPos[3][1],max_z,r,g,b,width); } void Draw_Cube_GL_RGB(clusterFeature&f, float r,float g,float b) { Draw_Cube_GL_RGB(f.min_x, f.min_y, f.min_z, f.max_x, f.max_y, f.max_z,r,g,b); } void DrawPoint(Point p, int size , float r, float g, float b) { GLdouble dVect1[3]; glPointSize(size); glBegin(GL_POINTS); glColor3d(r, g, b); dVect1[0]=p.x; dVect1[1]=p.y; dVect1[2]=p.z; glVertex3dv(dVect1); glEnd(); } void DrawPoint(Point p, int size , float r, float g, float b, double deltaMat[16]) { GLdouble dVect1[3]; glPointSize(size); glBegin(GL_POINTS); p.transform(deltaMat); glColor3d(r, g, b); dVect1[0]=p.x; dVect1[1]=p.y; dVect1[2]=p.z; glVertex3dv(dVect1); glEnd(); } // change the mat for the firstScan coodration. void GetCurrecntdelteMat(Scan& CurrentScan , double *deltaMat) { //Point p, q; double tempMat[16]; double temp[16]= { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1} ; M4inv(temp, tempMat); MMult(CurrentScan.get_transMat(), tempMat, deltaMat); } int DrawAll_ScanPoints_Number(vector allScans, int psize, float r, float g, float b, int n) { int i,j,k,colorIdx; Point p; double deltaMat[16]; for(int i =0; i get("xyz")); DataType Pt(CurrentScan->get("type")); GetCurrecntdelteMat(*CurrentScan , deltaMat); int size =xyz.size(); for(j=0; j 360) x_rotate=x_rotate - 360; if (x_rotate < -360) x_rotate=x_rotate + 360; cout << "Ctrl Held" << endl; return; case GLUT_ACTIVE_SHIFT : y_rotate += (y - z_move_save)/100; if (y_rotate > 360) y_rotate=y_rotate - 360; if (y_rotate < -360) y_rotate=y_rotate + 360; cout << "Shift Held" << endl; return; case GLUT_ACTIVE_ALT : float temp = (x - x_move_save)/100; z_rotate += atanf(temp); cout << "Alt Held" << endl; return; } if(buttonSaveLeft) { x_move += (x - x_move_save)/100; z_move += (y - z_move_save)/100; } if(buttonSaveMiddle) { float multiplay = (y - z_move_save)/1000; m_zoom =m_zoom*(1+multiplay); } if(buttonSaveRight) { float multiplay = (y - z_move_save)/1000; m_zoom =m_zoom*(1+multiplay); } cout << "mouse move " << buttonSaveLeft << buttonSaveMiddle < 360) x_rotate=x_rotate - 360; if (x_rotate < -360) x_rotate=x_rotate + 360; break; case GLUT_KEY_F2: x_rotate += -3; if (x_rotate > 360) x_rotate=x_rotate - 360; if (x_rotate < -360) x_rotate=x_rotate + 360; break; case GLUT_KEY_F3: y_rotate += 3; if (y_rotate > 360) y_rotate=y_rotate - 360; if (y_rotate < -360) y_rotate=y_rotate + 360; break; case GLUT_KEY_F4 : y_rotate += -3; if (y_rotate > 360) y_rotate=y_rotate - 360; if (y_rotate < -360) y_rotate=y_rotate + 360; break; case GLUT_KEY_F5: z_rotate += atanf(3); break; case GLUT_KEY_F6: z_rotate += atanf(-3); break; case GLUT_KEY_F7: break; case GLUT_KEY_F8: break; case GLUT_KEY_F11: printf("paseu\n"); g_pause != g_pause; break; case GLUT_KEY_F12: printf("next\n"); keycond.notify_one(); break; } glutPostRedisplay(); } static void Draw(void) { DebugDrawFinished =false; glClearColor(1.0, 1.0, 1.0, 1.0); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glClearColor(1.0, 1.0, 1.0, 1.0); glLoadIdentity(); gluLookAt(m_eyex, m_eyey, m_eyez, m_centerx, m_centery, m_centerz, m_upx, m_upy, m_upz); glRotatef(x_rotate,1,0,0); glRotatef(y_rotate,0,1,0); glRotatef(z_rotate,0,0,1); glTranslatef(x_move,y_move,z_move); glScalef(m_zoom, m_zoom, m_zoom); int scansize = Scan::allScans.size(); Point p1, p2, p3; if (scansize <5) { DebugDrawFinished =true; return ; } Scan *CurrentScan = Scan::allScans[3]; if (CurrentScan == NULL) { DebugDrawFinished =true; return ; } double deltaMat[16]; double deltaMatNext[16]; GetCurrecntdelteMat(*CurrentScan , deltaMat); double PosTheta[3]; double Pos[3]; Matrix4ToEuler(deltaMat, PosTheta, Pos); cout << " pose of current " << " " << PosTheta [0] << " " << PosTheta [1] << " " << PosTheta [2] <