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

Log Message:
-----------
debugging rasterization

Modified Paths:
--------------
    code/stage/trunk/examples/ctrl/fasr.cc
    code/stage/trunk/libstage/block.cc
    code/stage/trunk/libstage/model.cc
    code/stage/trunk/libstage/powerpack.cc
    code/stage/trunk/libstage/stage.cc
    code/stage/trunk/libstage/stage.hh
    code/stage/trunk/worlds/bitmaps/SFU_1920x1280.png

Modified: code/stage/trunk/examples/ctrl/fasr.cc
===================================================================
--- code/stage/trunk/examples/ctrl/fasr.cc      2009-04-06 00:58:00 UTC (rev 
7577)
+++ code/stage/trunk/examples/ctrl/fasr.cc      2009-04-07 01:35:45 UTC (rev 
7578)
@@ -504,7 +504,7 @@
 {  
   if( strcmp( mod->Token(), "r0" ) == 0 )
         {
-               const unsigned int dw = 60, dh = 30;
+               const unsigned int dw = 61, dh = 31;
                uint8_t* data = new uint8_t[dw*dh*2];
                memset( data, 0, sizeof(uint8_t) * dw * dh );
                

Modified: code/stage/trunk/libstage/block.cc
===================================================================
--- code/stage/trunk/libstage/block.cc  2009-04-06 00:58:00 UTC (rev 7577)
+++ code/stage/trunk/libstage/block.cc  2009-04-07 01:35:45 UTC (rev 7578)
@@ -316,24 +316,31 @@
 
 void Block::Rasterize( uint8_t* data, unsigned int width, unsigned int height )
 {
-  Pose pose;// = mod->GetPose();
-  
   // add local offset
-  pose = pose_sum( pose, mod->geom.pose );
+  // pose = pose_sum( pose, mod->geom.pose );
   
   Size bgsize = mod->blockgroup.GetSize();
 
-  double scalex = (width-1) / bgsize.x;
-  double scaley = (height-1) / bgsize.y;
+  double scalex = (double)(width) / (double)bgsize.x;
+  double scaley = (double)(height) / (double)bgsize.y;
+  //double scalex = (width) / bgsize.x;
+  //double scaley = (height) / bgsize.y;
  
   Rasterize( data, width, height, scalex, scaley, 0,0 );  
 }
 
-void swap( int& a, int& b )
+// void swap( int& a, int& b )
+// {
+//   int tmp = a;
+//   a = b;
+//   b = tmp;
+// }
+
+void swap( int* a, int* b )
 {
-  int tmp = a;
-  a = b;
-  b = tmp;
+  int foo = *a;
+  *a = *b;
+  *b = foo;
 }
 
 void Block::Rasterize( uint8_t* data, 
@@ -344,53 +351,86 @@
   //printf( "rasterize block %p : w: %u h: %u  scale %.2f %.2f  offset %.2f 
%.2f\n",
   //    this, width, height, scalex, scaley, offsetx, offsety );
 
-  for( unsigned int p=0; p<pt_count; p++ )
+  unsigned int W=0;
+
+//   W+=20;
+//   W /= 2;
+  
+//   printf( "W is %u", W ); 
+
+  for( W=0; W<pt_count; W++ )
     {
-               int xa = round( (pts[p             ].x + offsetx) * scalex );
-               int ya = round( (pts[p             ].y + offsety) * scaley );
-               int xb = round( (pts[(p+1)%pt_count].x + offsetx) * scalex );
-               int yb = round( (pts[(p+1)%pt_count].y + offsety) * scaley );
+               double px = pts[W             ].x;
+               double py = pts[(W+1)%pt_count].x;
+               unsigned int keep_W = W;
 
+               int xa = floor( (pts[W             ].x + offsetx) * scalex );
+               int ya = floor( (pts[W             ].y + offsety) * scaley );
+               int xb = floor( (pts[(W+1)%pt_count].x + offsetx) * scalex );
+               int yb = floor( (pts[(W+1)%pt_count].y + offsety) * scaley );
+
+               int keep_xa = xa;
+               int keep_xb = xb;
+               
+
                //printf( "  line (%d,%d) to (%d,%d)\n", xa,ya,xb,yb );
                
                bool steep = abs( yb-ya ) > abs( xb-xa );
-               if( steep )
+               if( steep )
+                 {
+                        swap( &xa, &ya );
+                        swap( &xb, &yb );
+                 }
+               
+               if( xa > xb )
                  {
-                        swap( xa, ya );
-                        swap( xb, yb );
+                        swap( &xa, &xb );
+                        swap( &ya, &yb );
                  }
                
-               if( xa > xb )
-                 {
-                        swap( xa, xb );
-                        swap( ya, yb );
-                 }
-               
-               int x;
-               float dydx = (float) (yb - ya) / (float) (xb - xa);
-               float y = ya;
-               for (x=xa; x<=xb; x++) 
+               double dydx = (double) (yb - ya) / (double) (xb - xa);
+               double y = ya;
+               for(int x=xa; x<=xb; x++) 
                  {
-                        if( steep )
-                               {
-                                 if( ! (round(y) >= 0) ) continue;
-                                 if( ! (round(y) < (int)width) ) continue;
-                                 if( ! (x >= 0) ) continue;
-                                 if( ! (x < height) ) continue;
-                               }
-                        else
-                               {
-                                 if( ! (x >= 0) ) continue;
-                                 if( ! (x < (int)width) ) continue;
-                                 if( ! (round(y) >= 0) ) continue;
-                                 if( ! (round(y) < height) ) continue;
-                               }
+               //       if( steep )
+//                             {
+//                               if( ! (floor(y) >= 0) ) continue;
+//                               if( ! (floor(y) < (int)width) ) continue;
+//                               if( ! (x >= 0) ) continue;
+//                               if( ! (x < (int)height) ) continue;
+//                             }
+//                      else
+//                             {
+//                               if( ! (x >= 0) ) continue;
+//                               if( ! (x < (int)width) ) continue;
+//                               if( ! (floor(y) >= 0) ) continue;
+//                               if( ! (floor(y) < (int)height) ) continue;
+//                             }
                         
                         if( steep )
-                               data[ (int)round(y) + (x * width)] = 1;
+                               data[ (int)floor(y) + (x * width)] = 1;         
         
                         else
-                               data[ x + ((int)round(y) * width)] = 1;
-                        y = y + dydx;
+                               data[ x + ((int)floor(y) * width)] = 1;
+                        y += dydx;
+
+//                      if( (floor(y) == 75) &&
+//                               x == 119 )
+//                             {
+//                               puts( "foo" );
+//                               // while(1) {}
+
+//                               printf( "W: %u keep_W: %u  px: %.4f\npy: 
%.4f\n",
+//                                                      W, keep_W,
+//                                                      px, py );
+
+//                               printf( "XA: %.4f\nXB: %.4f\n",
+//                                                      (pts[W             ].x 
+ offsetx) * scalex,
+//                                                      (pts[(W+1)%pt_count].x 
+ offsetx) * scalex );
+
+//                               printf( "KEEP: %d %d\n", keep_xa, keep_xb );
+//                               printf( "NOW: %d %d\n", xa, xb );
+//                             }
+
                  }
         }
 }

Modified: code/stage/trunk/libstage/model.cc
===================================================================
--- code/stage/trunk/libstage/model.cc  2009-04-06 00:58:00 UTC (rev 7577)
+++ code/stage/trunk/libstage/model.cc  2009-04-07 01:35:45 UTC (rev 7578)
@@ -218,6 +218,7 @@
         power_pack( NULL ),
         pps_charging(NULL),
     props(NULL),
+        rastervis(),
     rebuild_displaylist(true),
     say_string(NULL),
     stall(false),       
@@ -263,6 +264,8 @@
   // now we can add the basic square shape
   AddBlockRect( -0.5, -0.5, 1.0, 1.0, 1.0 );
 
+  AddVisualizer( &rastervis, true );
+
   PRINT_DEBUG2( "finished model %s @ %p", this->token, this );
 }
 
@@ -1023,4 +1026,91 @@
 void Model::Rasterize( uint8_t* data, unsigned int width, unsigned int height )
 {
   blockgroup.Rasterize( data, width, height );
+  rastervis.SetData( data, width, height );
 }
+
+//***************************************************************
+// Raster data visualizer
+//
+Model::RasterVis::RasterVis() 
+  : Visualizer( "Rasterization", "raster_vis" ),
+        data(NULL),
+        width(0),
+        height(0)
+{
+}
+
+void Model::RasterVis::Visualize( Model* mod, Camera* cam ) 
+{
+  if( data == NULL )
+        return;
+
+  // go into world coordinates  
+  glPushMatrix();
+  mod->PushColor( 0,0,0,0.5 );
+
+  Gl::pose_inverse_shift( mod->GetGlobalPose() );
+
+  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 );
+
+  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 ] )
+                        glRectf( x, y, x+1, y+1 );
+               }
+
+  glTranslatef( 0,0,0.01 );
+
+  mod->PushColor( 0,0,0,1 );
+  glPolygonMode( GL_FRONT, GL_LINE );
+  for( unsigned int y=0; y<height; y++ )
+        for( unsigned int x=0; x<width; x++ )
+               {
+                 //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 );                
+               }
+
+
+  glPolygonMode( GL_FRONT, GL_FILL );
+
+  mod->PopColor();
+  mod->PopColor();
+
+  mod->PushColor( 0,0,0,1 );
+  char buf[128];
+  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 )
+{
+  // copy the raster for test visualization
+  if( this->data ) 
+        free( this->data );  
+  size_t len = sizeof(uint8_t) * width * height;
+  this->data = (uint8_t*)malloc( len );
+  memcpy( this->data, data, len );
+  this->width = width;
+  this->height = height;
+}
+
+

Modified: code/stage/trunk/libstage/powerpack.cc
===================================================================
--- code/stage/trunk/libstage/powerpack.cc      2009-04-06 00:58:00 UTC (rev 
7577)
+++ code/stage/trunk/libstage/powerpack.cc      2009-04-07 01:35:45 UTC (rev 
7578)
@@ -266,7 +266,7 @@
   
   glPushMatrix();
 
-  Gl::pose_inverse_shift( mod->GetPose() );
+  Gl::pose_inverse_shift( mod->GetGlobalPose() );
 
   glTranslatef( -width/2.0, -height/2.0, 0.01 );
   glScalef( cellsize, cellsize, 1 );

Modified: code/stage/trunk/libstage/stage.cc
===================================================================
--- code/stage/trunk/libstage/stage.cc  2009-04-06 00:58:00 UTC (rev 7577)
+++ code/stage/trunk/libstage/stage.cc  2009-04-07 01:35:45 UTC (rev 7578)
@@ -351,7 +351,7 @@
                        // inverting the original image.
                        stg_rotrect_t *latest = &(*rects)[(*rect_count)-1];
                        latest->pose.x = startx;
-                       latest->pose.y = img_height - (starty + height);
+                       latest->pose.y = img_height-1 - (starty + height);
                        latest->pose.a = 0.0;
                        latest->size.x = x - startx;
                        latest->size.y = height;

Modified: code/stage/trunk/libstage/stage.hh
===================================================================
--- code/stage/trunk/libstage/stage.hh  2009-04-06 00:58:00 UTC (rev 7577)
+++ code/stage/trunk/libstage/stage.hh  2009-04-07 01:35:45 UTC (rev 7578)
@@ -1631,7 +1631,23 @@
         static GHashTable*  modelsbyid;
         std::vector<Option*> drawOptions;
         const std::vector<Option*>& getOptions() const { return drawOptions; }
-  
+        
+        class RasterVis : public Visualizer
+        {
+        private:
+               uint8_t* data;
+               unsigned int width, height;
+               
+        public:
+               RasterVis();
+               virtual ~RasterVis( void ){}
+               virtual void Visualize( Model* mod, Camera* cam );
+               
+               void SetData( uint8_t* data, 
+                                                 unsigned int width, 
+                                                 unsigned int height );
+        };
+        
   protected:
         GMutex* access_mutex;
         GPtrArray* blinkenlights;  
@@ -1699,6 +1715,10 @@
                  by derived model types to store properties, and for user code
                  to associate arbitrary items with a model. */
         GData* props;
+
+        /** Visualize the most recent rasterization operation performed by 
this model */
+        RasterVis rastervis;
+
         bool rebuild_displaylist; ///< iff true, regenerate block display list 
before redraw
         char* say_string;   ///< if non-null, this string is displayed in the 
GUI 
 

Modified: code/stage/trunk/worlds/bitmaps/SFU_1920x1280.png
===================================================================
(Binary files differ)


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
Playerstage-commit@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/playerstage-commit

Reply via email to