Revision: 7582
          http://playerstage.svn.sourceforge.net/playerstage/?rev=7582&view=rev
Author:   rtv
Date:     2009-04-07 19:01:36 +0000 (Tue, 07 Apr 2009)

Log Message:
-----------
removed a malloc

Modified Paths:
--------------
    code/stage/trunk/libstage/block.cc
    code/stage/trunk/libstage/blockgroup.cc
    code/stage/trunk/libstage/model.cc
    code/stage/trunk/libstage/model_load.cc
    code/stage/trunk/libstage/stage.cc
    code/stage/trunk/libstage/stage.hh

Modified: code/stage/trunk/libstage/block.cc
===================================================================
--- code/stage/trunk/libstage/block.cc  2009-04-07 01:47:30 UTC (rev 7581)
+++ code/stage/trunk/libstage/block.cc  2009-04-07 19:01:36 UTC (rev 7582)
@@ -360,8 +360,9 @@
 
   for( W=0; W<pt_count; W++ )
     {
-               double px = pts[W             ].x;
-               double py = pts[(W+1)%pt_count].x;
+               double px = pts[W].x;
+               double py = pts[W].y;
+
                unsigned int keep_W = W;
 
                int xa = floor( (pts[W             ].x + offsetx) * scalex );
@@ -369,6 +370,8 @@
                int xb = floor( (pts[(W+1)%pt_count].x + offsetx) * scalex );
                int yb = floor( (pts[(W+1)%pt_count].y + offsety) * scaley );
 
+               mod->rastervis.AddPoint( px, py );
+
                int keep_xa = xa;
                int keep_xb = xb;
                

Modified: code/stage/trunk/libstage/blockgroup.cc
===================================================================
--- code/stage/trunk/libstage/blockgroup.cc     2009-04-07 01:47:30 UTC (rev 
7581)
+++ code/stage/trunk/libstage/blockgroup.cc     2009-04-07 19:01:36 UTC (rev 
7582)
@@ -270,9 +270,12 @@
   
   //printf( "found %d rects in \"%s\" at %p\n", 
   //     rect_count, full, rects );
-  
+                        
   if( rects && (rect_count > 0) )
         {
+               // TODO fix this
+               stg_color_t col = stg_color_pack( 1.0, 0,0,1.0 ); 
+               
                for( unsigned int r=0; r<rect_count; r++ )
                  {
                         stg_point_t pts[4];
@@ -291,9 +294,6 @@
                         pts[3].x = x;
                         pts[3].y = y + h;                                      
                 
                         
-                        // TODO fix this
-                        stg_color_t col = stg_color_pack( 1.0, 0,0,1.0 ); 
-                        
                         AppendBlock( new Block( mod,
                                                                                
         pts,4,
                                                                                
         0,1,
@@ -302,16 +302,11 @@
                  }                      
                free( rects );
         }  
-
+  
   CalcSize();
 }
 
 
-#include <math.h>                     /* for round() */
-extern void output (int x, int y);    /* forward declaration for user-defined 
output */
-
-
-
 void BlockGroup::Rasterize( uint8_t* data, unsigned int width, unsigned int 
height )
 {  
   for( GList* it = blocks; it; it=it->next )

Modified: code/stage/trunk/libstage/model.cc
===================================================================
--- code/stage/trunk/libstage/model.cc  2009-04-07 01:47:30 UTC (rev 7581)
+++ code/stage/trunk/libstage/model.cc  2009-04-07 19:01:36 UTC (rev 7582)
@@ -1025,6 +1025,7 @@
 
 void Model::Rasterize( uint8_t* data, unsigned int width, unsigned int height )
 {
+  rastervis.ClearPts();
   blockgroup.Rasterize( data, width, height );
   rastervis.SetData( data, width, height );
 }
@@ -1036,7 +1037,8 @@
   : Visualizer( "Rasterization", "raster_vis" ),
         data(NULL),
         width(0),
-        height(0)
+        height(0),
+        pts(NULL)
 {
 }
 
@@ -1047,26 +1049,44 @@
 
   // go into world coordinates  
   glPushMatrix();
-  mod->PushColor( 0,0,0,0.5 );
+  mod->PushColor( 1,0,0,0.5 );
 
   Gl::pose_inverse_shift( mod->GetGlobalPose() );
 
+  glPushMatrix();
+
+  Size sz = mod->blockgroup.GetSize();
   glTranslatef( -mod->geom.size.x / 2.0, -mod->geom.size.y/2.0, 0 );
+  glScalef( mod->geom.size.x / sz.x, mod->geom.size.y / sz.y, 1 );
+
+  // now we're in world meters coordinates
+  glPointSize( 4 );
+  glBegin( GL_POINTS );
+  for( GList* it=pts; it; it=it->next )
+        {
+               stg_point_t* pt = (stg_point_t*)it->data;
+               glVertex2f( pt->x, pt->y );
+
+               char buf[128];
+               snprintf( buf, 127, "[%.2f x %.2f]", pt->x, pt->y );
+               Gl::draw_string( pt->x, pt->y, 0, buf );                  
+        }
+  glEnd();
+
+  mod->PopColor();
+
+  glPopMatrix();
+  // go into bitmap pixel coords
+  glTranslatef( -mod->geom.size.x / 2.0, -mod->geom.size.y/2.0, 0 );
   glScalef( mod->geom.size.x / width, mod->geom.size.y / height, 1 );
 
+  mod->PushColor( 0,0,0,0.5 );
   glPolygonMode( GL_FRONT, GL_FILL );
   for( unsigned int y=0; y<height; y++ )
         for( unsigned int x=0; x<width; x++ )
                {
                  // printf( "[%u %u] ", x, y );
-
-                 if( (x == (92/5)) && (y == (750/10) ))
-                        {
-                               mod->PushColor( 1,0,0,0.5 );
-                               glRectf( x, y, x+1, y+1 );
-                               mod->PopColor();
-                        }
-                        else  if( data[ x + y*width ] )
+                 if( data[ x + y*width ] )
                         glRectf( x, y, x+1, y+1 );
                }
 
@@ -1077,9 +1097,9 @@
   for( unsigned int y=0; y<height; y++ )
         for( unsigned int x=0; x<width; x++ )
                {
-                 //if( data[ x + y*width ] )
+                 if( data[ x + y*width ] )
                         glRectf( x, y, x+1, y+1 );
-
+                 
 //               char buf[128];
 //               snprintf( buf, 127, "[%u x %u]", x, y );
 //               Gl::draw_string( x, y, 0, buf );                
@@ -1096,21 +1116,40 @@
   snprintf( buf, 127, "[%u x %u]", width, height );
   glTranslatef( 0,0,0.01 );
   Gl::draw_string( 1, height-1, 0, buf );
+  
   mod->PopColor();
 
   glPopMatrix();
 }
 
-void Model::RasterVis::SetData( uint8_t* data, unsigned int width, unsigned 
int height )
+void Model::RasterVis::SetData( uint8_t* data, 
+                                                                               
  unsigned int width, 
+                                                                               
  unsigned int height )
 {
   // copy the raster for test visualization
   if( this->data ) 
-        free( this->data );  
+        delete[] this->data;  
   size_t len = sizeof(uint8_t) * width * height;
-  this->data = (uint8_t*)malloc( len );
+  printf( "allocating %lu bytes\n", len );
+  this->data = new uint8_t[len];
   memcpy( this->data, data, len );
   this->width = width;
   this->height = height;
 }
 
 
+void Model::RasterVis::AddPoint( stg_meters_t x, stg_meters_t y )
+{
+  stg_point_t* pt = new stg_point_t;
+  pt->x = x;
+  pt->y = y;
+  pts = g_list_prepend( pts, pt );
+}
+
+void Model::RasterVis::ClearPts()
+{
+  if( pts )
+        for( GList* it=pts; it; it=it->next )
+               if( it->data )
+                 delete (stg_point_t*)it->data;
+}

Modified: code/stage/trunk/libstage/model_load.cc
===================================================================
--- code/stage/trunk/libstage/model_load.cc     2009-04-07 01:47:30 UTC (rev 
7581)
+++ code/stage/trunk/libstage/model_load.cc     2009-04-07 19:01:36 UTC (rev 
7582)
@@ -147,16 +147,13 @@
     {
       const char* bitmapfile = wf->ReadString( wf_entity, "bitmap", NULL );
       assert( bitmapfile );
-
+               
       if( has_default_block )
-       {
-         blockgroup.Clear();
-         has_default_block = false;
-       }
-
-      //puts( "clearing blockgroup" );
-      //blockgroup.Clear();
-      //puts( "loading bitmap" );
+                 {
+                        blockgroup.Clear();
+                        has_default_block = false;
+                 }
+               
       blockgroup.LoadBitmap( this, bitmapfile, wf );
     }
   

Modified: code/stage/trunk/libstage/stage.cc
===================================================================
--- code/stage/trunk/libstage/stage.cc  2009-04-07 01:47:30 UTC (rev 7581)
+++ code/stage/trunk/libstage/stage.cc  2009-04-07 19:01:36 UTC (rev 7582)
@@ -284,8 +284,8 @@
        size_t rects_allocated = allocation_unit;
        *rects = (stg_rotrect_t*)calloc( sizeof(stg_rotrect_t), rects_allocated 
);
 
-       int img_width = img->w();//gdk_pixbuf_get_width(pb);
-       int img_height = img->h();//gdk_pixbuf_get_height(pb);
+       int img_width = img->w();
+       int img_height = img->h();
 
        // if the caller wanted to know the dimensions
        if( widthp ) *widthp = img_width;
@@ -356,6 +356,17 @@
                        latest->size.x = x - startx;
                        latest->size.y = height;
 
+                       assert( latest->pose.x >= 0 );
+                       assert( latest->pose.y >= 0 );
+                       assert( latest->pose.x <= img_width );
+                       assert( latest->pose.y <= img_height);
+                       //assert( latest->size.x > 0 );
+                       //assert( latest->size.y > 0 );
+
+                       if( latest->size.x < 1  || latest->size.y < 1 )
+                         printf( "p [%.2f %.2f] s [%.2f %.2f]\n", 
+                                                latest->pose.x, 
latest->pose.y, latest->size.x, latest->size.y );
+
                        //printf( "rect %d (%.2f %.2f %.2f %.2f %.2f\n", 
                        //  *rect_count, 
                        //  latest->x, latest->y, latest->a, latest->w, 
latest->h );

Modified: code/stage/trunk/libstage/stage.hh
===================================================================
--- code/stage/trunk/libstage/stage.hh  2009-04-07 01:47:30 UTC (rev 7581)
+++ code/stage/trunk/libstage/stage.hh  2009-04-07 19:01:36 UTC (rev 7582)
@@ -1637,7 +1637,8 @@
         private:
                uint8_t* data;
                unsigned int width, height;
-               
+               GList* pts;
+
         public:
                RasterVis();
                virtual ~RasterVis( void ){}
@@ -1646,6 +1647,10 @@
                void SetData( uint8_t* data, 
                                                  unsigned int width, 
                                                  unsigned int height );
+
+               void AddPoint( stg_meters_t x, stg_meters_t y );
+               void ClearPts();
+               
         };
         
   protected:


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

------------------------------------------------------------------------------
This SF.net email is sponsored by:
High Quality Requirements in a Collaborative Environment.
Download a free trial of Rational Requirements Composer Now!
http://p.sf.net/sfu/www-ibm-com
_______________________________________________
Playerstage-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/playerstage-commit

Reply via email to