Revision: 6667 http://playerstage.svn.sourceforge.net/playerstage/?rev=6667&view=rev Author: alexcb Date: 2008-06-23 14:17:23 -0700 (Mon, 23 Jun 2008)
Log Message: ----------- added color to camera data visualization, and created a floor used instead of grid for camera model rendering Modified Paths: -------------- code/stage/trunk/libstage/canvas.cc code/stage/trunk/libstage/model_camera.cc code/stage/trunk/libstage/stage.hh Modified: code/stage/trunk/libstage/canvas.cc =================================================================== --- code/stage/trunk/libstage/canvas.cc 2008-06-23 19:04:30 UTC (rev 6666) +++ code/stage/trunk/libstage/canvas.cc 2008-06-23 21:17:23 UTC (rev 6667) @@ -437,8 +437,21 @@ glDisable(GL_POLYGON_OFFSET_FILL ); } +void StgCanvas::DrawFloor() +{ + stg_bounds3d_t bounds = world->GetExtent(); + glColor3f( 0.6, 0.6, 1.0 ); + glBegin(GL_QUADS); + glVertex3f( bounds.x.min, bounds.y.min, 0 ); + glVertex3f( bounds.x.max, bounds.y.min, 0 ); + glVertex3f( bounds.x.max, bounds.y.max, 0 ); + glVertex3f( bounds.x.min, bounds.y.max, 0 ); + glEnd(); +} + void StgCanvas::renderFrame( bool robot_camera ) { + //create a localy scopped showflags variable - WARNING: changing it will NOT change the class instance's value uint32_t showflags = this->showflags; if( robot_camera == true ) showflags = STG_SHOW_BLOCKS; @@ -446,10 +459,13 @@ if( ! (showflags & STG_SHOW_TRAILS) || robot_camera == true ) glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); - if( showflags & STG_SHOW_GRID && robot_camera == false ) + if( robot_camera == true ) + DrawFloor(); + else if( showflags & STG_SHOW_GRID ) DrawGlobalGrid(); - if( (showflags & STG_SHOW_QUADTREE) || (showflags & STG_SHOW_OCCUPANCY) && robot_camera == false ) + + if( (showflags & STG_SHOW_QUADTREE) || (showflags & STG_SHOW_OCCUPANCY) ) { glPushMatrix(); glScalef( 1.0/world->Resolution(), 1.0/world->Resolution(), 0 ); @@ -753,7 +769,7 @@ if( (showflags & STG_SHOW_FOLLOW) && last_selection ) { //Follow the selected robot stg_pose_t gpose = last_selection->GetGlobalPose(); - perspective_camera.setPose( gpose.x, gpose.y, 0.1 ); + perspective_camera.setPose( gpose.x, gpose.y, 0.2 ); perspective_camera.setYaw( rtod( gpose.a ) - 90.0 ); } Modified: code/stage/trunk/libstage/model_camera.cc =================================================================== --- code/stage/trunk/libstage/model_camera.cc 2008-06-23 19:04:30 UTC (rev 6666) +++ code/stage/trunk/libstage/model_camera.cc 2008-06-23 21:17:23 UTC (rev 6667) @@ -12,6 +12,7 @@ //#define DEBUG 1 #include "stage_internal.hh" #include <sstream> +#include <iomanip> StgModelCamera::StgModelCamera( StgWorld* world, StgModel* parent ) @@ -130,12 +131,51 @@ return NULL; //_frame_data; } +void StgModelCamera::PrintData( void ) const +{ + //create depth matrix + std::cout << "depth <- matrix( c( "; + for( int j = 0; j < _height; j++ ) { + for( int i = 0; i < _width; i++ ) { + int index = i + j * _width; + const GLubyte* color = _frame_color_data + index * 4; //TODO might be buggy indexing + const float length = _frame_data[ index ]; + if( i != 0 || j != 0 ) + std::cout << " ,"; + std::cout << length; + } + } + std::cout << "), " << std::dec << _width << ", " << _height << " )\n\n"; + + //create color matrix + std::cout << "hex_cols <- matrix( c( "; + for( int j = 0; j < _height; j++ ) { + for( int i = 0; i < _width; i++ ) { + int index = i + j * _width; + const GLubyte* color = _frame_color_data + index * 4; //TODO might be buggy indexing + const float length = _frame_data[ index ]; + if( i != 0 || j != 0 ) + std::cout << " ,"; + std::cout << "\"#" + << std::setw( 2 ) << std::setfill('0') << std::hex << (int)color[ 0 ] + << std::setw( 2 ) << std::setfill('0') << std::hex << (int)color[ 1 ] + << std::setw( 2 ) << std::setfill('0') << std::hex << (int)color[ 2 ] + << "\"" ; + } + } + std::cout << "), " << std::dec << _width << ", " << _height << " )\n\n"; + + std::cout << std::endl; +} + //TODO create lines outlineing camera frustrum, then iterate over each depth measurement and create a square void StgModelCamera::DataVisualize( void ) { if( _frame_data == NULL ) return; + //PrintData(); + float w_fov = _camera.horizFov(); float h_fov = _camera.vertFov(); @@ -233,9 +273,9 @@ //colour the points //TODO color is buggy - scaled_vertex->r = 0x00; //color[ 0 ]; - scaled_vertex->g = 0x00; //color[ 1 ]; - scaled_vertex->b = 0x00; //color[ 2 ]; + scaled_vertex->r = color[ 0 ]; + scaled_vertex->g = color[ 1 ]; + scaled_vertex->b = color[ 2 ]; scaled_vertex->a = 0xFF; } Modified: code/stage/trunk/libstage/stage.hh =================================================================== --- code/stage/trunk/libstage/stage.hh 2008-06-23 19:04:30 UTC (rev 6666) +++ code/stage/trunk/libstage/stage.hh 2008-06-23 21:17:23 UTC (rev 6667) @@ -1944,6 +1944,7 @@ void DrawRays(); void ClearRays(); void DrawGlobalGrid(); + void DrawFloor(); //simpler floor compared to grid public: @@ -2483,6 +2484,8 @@ StgPerspectiveCamera _camera; int _yaw_offset; + void PrintData( void ) const; + public: StgModelCamera( StgWorld* world, StgModel* parent ); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. ------------------------------------------------------------------------- Check out the new SourceForge.net Marketplace. It's the best place to buy or sell services for just about anything Open Source. http://sourceforge.net/services/buy/index.php _______________________________________________ Playerstage-commit mailing list Playerstage-commit@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/playerstage-commit