int main(int argc, char **argv) { int i; for(i = 1; i < argc; ++i) if (argv[i][0] != '-') { id = atoi(argv[i]); break; } carmen_ipc_initialize(argc, argv); carmen_velodyne_subscribe_pointcloud_message(NULL, (carmen_handler_t)velodyne_pointcloud_handler, CARMEN_SUBSCRIBE_ALL); signal(SIGINT, velodyne_sigint_handler); atexit(velodyne_finalize); pthread_create(&thread, 0, velodyne_listen, 0); gl_initialize(argc, argv); gl_clear_color(1.0, 1.0, 1.0); gl_clip(0.1, 60.0); gl_camera(0.0, 0.0, 0.0, 0.0, 89.0, 20.0); gl_loop(); while (!pointclouds.empty()) { velodyne_pointcloud_free(&pointclouds.front()); pointclouds.pop_front(); } return 0; }
//_____________________________________________________________________________ // redisplay with the current setting (possibly a different viewpoint) bool VSVR::gl_redisplay( int nslices /*= tex_ni()*/ ) const //----------------------------------------------------------------------------- { if( !_tex) return false ; // sets the openGL attributes and clipping planes gl_set () ; gl_clip() ; //--------------------------------------------------// // gets the direction of the observer double gl_model[16] ; // = { 1.0f,0.0f,0.0f,0.0f, 0.0f,0.0f,-1.0f,0.0f, 0.0f,-1.0f,0.0f,0.0f, 0.0f,0.0f,0.0f,1.0f } ; double gl_proj [16] ; // = { 1.0f,0.0f,0.0f,0.0f, 0.0f,1.0f,0.0f,0.0f, 0.0f,0.0f,1.0f,0.0f, 0.0f,0.0f,0.0f,1.0f } ; int gl_view [ 4] ; ::glGetDoublev (GL_MODELVIEW_MATRIX , gl_model); ::glGetDoublev (GL_PROJECTION_MATRIX, gl_proj ); ::glGetIntegerv(GL_VIEWPORT , gl_view ); //--------------------------------------------------// // gets the bounding box of the grid in the screen coordinates double xmin=FLT_MAX, xmax=-FLT_MAX, ymin=FLT_MAX, ymax=-FLT_MAX, zmin=FLT_MAX, zmax=-FLT_MAX; for( int i = 0; i < 8; ++i ) { float bbx = (i&1) ? (float)tex_ni() : 0.0f ; float bby = (i&2) ? (float)tex_nj() : 0.0f ; float bbz = (i&4) ? (float)tex_nk() : 0.0f ; double x,y,z ; gluProject( bbx,bby,bbz, gl_model, gl_proj, gl_view, &x, &y, &z ) ; if( x < xmin ) xmin = x; if( x > xmax ) xmax = x; if( y < ymin ) ymin = y; if( y > ymax ) ymax = y; if( z < zmin ) zmin = z; if( z > zmax ) zmax = z; } //--------------------------------------------------// // world to tex coordinates double fx = 1.0 / tex_ni() ; double fy = 1.0 / tex_nj() ; double fz = 1.0 / tex_nk() ; //--------------------------------------------------// // draw each slice of the texture in the viewer coordinates float dz = (float)( (zmax-zmin) / nslices ) ; float z = (float)zmax - dz/2.0f ; ::glColor4f(1.0f, 1.0f, 1.0f, 1.0f); ::glBegin( GL_QUADS ) ; { for( int n = nslices-1 ; n >= 0 ; --n, z -= dz ) { GLdouble point[3] ; ::gluUnProject( xmin,ymin,z, gl_model, gl_proj, gl_view, point + 0, point + 1, point + 2 ) ; ::glTexCoord3d( fx*point[0], fy*point[1], fz*point[2] ); ::glVertex3dv( point ) ; ::gluUnProject( xmax,ymin,z, gl_model, gl_proj, gl_view, point + 0, point + 1, point + 2 ) ; ::glTexCoord3d( fx*point[0], fy*point[1], fz*point[2] ); ::glVertex3dv( point ) ; ::gluUnProject( xmax,ymax,z, gl_model, gl_proj, gl_view, point + 0, point + 1, point + 2 ) ; ::glTexCoord3d( fx*point[0], fy*point[1], fz*point[2] ); ::glVertex3dv( point ) ; ::gluUnProject( xmin,ymax,z, gl_model, gl_proj, gl_view, point + 0, point + 1, point + 2 ) ; ::glTexCoord3d( fx*point[0], fy*point[1], fz*point[2] ); ::glVertex3dv( point ) ; } } ::glEnd() ; // GL_QUADS // unsets the openGL attributes and clipping planes gl_unclip() ; gl_unset () ; return true ; }