Revision: 6529
          http://playerstage.svn.sourceforge.net/playerstage/?rev=6529&view=rev
Author:   alexcb
Date:     2008-06-10 15:22:24 -0700 (Tue, 10 Jun 2008)

Log Message:
-----------
added getFrame method to take a snapshot from the robot's camera

Modified Paths:
--------------
    code/stage/trunk/libstage/camera.cc
    code/stage/trunk/libstage/canvas.cc
    code/stage/trunk/libstage/model_camera.cc
    code/stage/trunk/libstage/stage.hh
    code/stage/trunk/libstage/texture_manager.cc

Modified: code/stage/trunk/libstage/camera.cc
===================================================================
--- code/stage/trunk/libstage/camera.cc 2008-06-10 21:44:07 UTC (rev 6528)
+++ code/stage/trunk/libstage/camera.cc 2008-06-10 22:22:24 UTC (rev 6529)
@@ -33,7 +33,7 @@
        glMatrixMode (GL_PROJECTION);
        glLoadIdentity ();
 
-       gluPerspective( 60.0, pixels_width/pixels_height, 0.01, 100 );
+       gluPerspective( 120.0, pixels_width/pixels_height, 0.01, 100 );
 
        glMatrixMode (GL_MODELVIEW);
 }

Modified: code/stage/trunk/libstage/canvas.cc
===================================================================
--- code/stage/trunk/libstage/canvas.cc 2008-06-10 21:44:07 UTC (rev 6528)
+++ code/stage/trunk/libstage/canvas.cc 2008-06-10 22:22:24 UTC (rev 6529)
@@ -335,14 +335,18 @@
        PopColor();
 }
 
-void StgCanvas::renderFrame()
+void StgCanvas::renderFrame( bool robot_camera )
 {      
 
-       if( ! (showflags & STG_SHOW_TRAILS) )
+       uint32_t showflags = this->showflags;
+       if( robot_camera == true )
+               showflags = STG_SHOW_BLOCKS;
+       
+       if( ! (showflags & STG_SHOW_TRAILS) || robot_camera )
                glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
 
        // if following selected, shift the view to above the selected robot
-       if( (showflags & STG_SHOW_FOLLOW)  && last_selection )
+       if( (showflags & STG_SHOW_FOLLOW)  && last_selection && robot_camera == 
false )
        {      
                glLoadIdentity ();
                double zclip = 20 * camera.getScale(); //hypot(world->Width(), 
world->Height()) * camera.getScale();
@@ -372,7 +376,7 @@
 
        glDisable(GL_POLYGON_OFFSET_FILL);
 
-       if( (showflags & STG_SHOW_QUADTREE) || (showflags & STG_SHOW_OCCUPANCY) 
)
+       if( (showflags & STG_SHOW_QUADTREE) || (showflags & STG_SHOW_OCCUPANCY) 
&& robot_camera == false )
        {
                glDisable( GL_LINE_SMOOTH );
                glLineWidth( 1 );
@@ -392,7 +396,7 @@
 
        glPopMatrix();
 
-       if( showflags & STG_SHOW_GRID )
+       if( showflags & STG_SHOW_GRID && robot_camera == false )
                DrawGlobalGrid();
 
        for( GList* it=selected_models; it; it=it->next )

Modified: code/stage/trunk/libstage/model_camera.cc
===================================================================
--- code/stage/trunk/libstage/model_camera.cc   2008-06-10 21:44:07 UTC (rev 
6528)
+++ code/stage/trunk/libstage/model_camera.cc   2008-06-10 22:22:24 UTC (rev 
6529)
@@ -11,38 +11,49 @@
 
 //#define DEBUG 1
 #include "stage_internal.hh"
+#include <sstream>
 
+
 StgModelCamera::StgModelCamera( StgWorld* world, 
                StgModel* parent,
                stg_id_t id,
                char* typestr )
-: StgModel( world, parent, id, typestr )
+: StgModel( world, parent, id, typestr ),
+_frame_data( NULL ), _frame_data_width( 0 ), _frame_data_height( 0 )
 {
        PRINT_DEBUG2( "Constructing StgModelCamera %d (%s)\n", 
                        id, typestr );
 
+       StgWorldGui* world_gui = dynamic_cast< StgWorldGui* >( world );
+       
+       if( world_gui == NULL ) {
+               printf( "Unable to use Camera Model - it must be run with a GUI 
world\n" );
+               assert( 0 );
+       }
+       
+       _canvas = world_gui->GetCanvas();
+       
        // Set up sensible defaults
 
-       this->SetColor( stg_lookup_color( "green" ) );
+       SetColor( stg_lookup_color( "green" ) );
 
-
        stg_geom_t geom;
        memset( &geom, 0, sizeof(geom)); // no size
-       geom.size.x = 0.02;
-       geom.size.y = 0.02;
-       geom.size.z = 0.02;
-       this->SetGeom( geom );
+       //TODO can't draw this as it blocks the laser
+       SetGeom( geom );
 
-       this->Startup();
+       Startup();
 }
 
 StgModelCamera::~StgModelCamera()
 {
+       if( _frame_data != NULL )
+               delete _frame_data;
 }
 
 void StgModelCamera::Load( void )
 {
-       StgModel::Load();       
+       StgModel::Load();
        Worldfile* wf = world->GetWorldFile();
 
 }
@@ -51,15 +62,39 @@
 void StgModelCamera::Update( void )
 {   
        StgModel::Update();
-       static StgPerspectiveCamera camera;
+}
+
+
+const char* StgModelCamera::GetFrame( int width, int height )
+{
+       static StgPerspectiveCamera camera; //shared between _ALL_ instances
+       
+       if( width == 0 || height == 0 )
+               return NULL;
+       
+       if( width != _frame_data_width || height != _frame_data_height ) {
+               if( _frame_data != NULL )
+                       delete _frame_data;
+               _frame_data = new char[ 3 * width * height ];
+       }
+       
+       glViewport( 0, 0, width, height );
+       
        camera.update();
-       camera.SetProjection( 400, 300, 0.01, 200.0 );
+       camera.SetProjection( width, height, 0.01, 200.0 );
        camera.setPose( parent->GetGlobalPose().x, parent->GetGlobalPose().y, 
0.1 );
        camera.setYaw( rtod( parent->GetGlobalPose().a ) - 90.0 );
-       //camera.setPose( 0.1, 0.1, 0.1 );
        camera.Draw();
-       std::cout << "updated" << std::endl;
-       std::cout << parent->GetGlobalPose().x << std::endl;
+       
+       _canvas->renderFrame( true );
+       
+       glReadPixels(0, 0, width, height,
+                                GL_RGB,
+                                GL_UNSIGNED_BYTE,
+                                _frame_data );
+       
+       _canvas->invalidate();
+       return _frame_data;
 }
 
 

Modified: code/stage/trunk/libstage/stage.hh
===================================================================
--- code/stage/trunk/libstage/stage.hh  2008-06-10 21:44:07 UTC (rev 6528)
+++ code/stage/trunk/libstage/stage.hh  2008-06-10 22:22:24 UTC (rev 6529)
@@ -1819,7 +1819,8 @@
        StgWorld* world;
 
        void FixViewport(int W,int H);
-       virtual void renderFrame();
+       //robot_camera = true
+       virtual void renderFrame( bool robot_camera = false );
        virtual void draw();
        virtual int handle( int event );
        void resize(int X,int Y,int W,int H);
@@ -1897,6 +1898,8 @@
 
        void DrawTree( bool leaves );
        void DrawFloor();
+       
+       StgCanvas* GetCanvas( void ) { return canvas; }
 };
 
 
@@ -2343,6 +2346,13 @@
 // CAMERA MODEL ----------------------------------------------------
 class StgModelCamera : public StgModel
 {
+       private:
+               StgCanvas* _canvas;
+
+               char* _frame_data;
+               int _frame_data_width;
+               int _frame_data_height;
+       
        public:
 
                StgModelCamera( StgWorld* world,
@@ -2355,6 +2365,9 @@
                virtual void Load();
                virtual void Update();
                virtual void Draw( uint32_t flags, StgCanvas* canvas );
+       
+               ///Take a screenshot from the camera's perspective
+               const char* GetFrame( int width, int height );
 
                // static wrapper for the constructor - all models must 
implement
                // this method and add an entry in typetable.cc

Modified: code/stage/trunk/libstage/texture_manager.cc
===================================================================
--- code/stage/trunk/libstage/texture_manager.cc        2008-06-10 21:44:07 UTC 
(rev 6528)
+++ code/stage/trunk/libstage/texture_manager.cc        2008-06-10 22:22:24 UTC 
(rev 6529)
@@ -16,7 +16,7 @@
        if( filename[ 0 ] == '/' || filename[ 0 ] == '~' )
                return Fl_Shared_Image::get( filename );
        
-       //TODO move this somewhere else, and include STAGE_PATH, and path 
relative to user supplied world file
+       //TODO move this somewhere else, and include STAGEPATH, and path 
relative to user supplied world file
        const char* prefixes[] = {
                ".",
                INSTALL_PREFIX "/share/stage",


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
[email protected]
https://lists.sourceforge.net/lists/listinfo/playerstage-commit

Reply via email to