Browse files

debugging rasterization

  • Loading branch information...
1 parent e96a997 commit 59d66b44f1b7df3eeb8d9997f32b94f8cefb582e rtv committed Apr 7, 2009
View
2 examples/ctrl/fasr.cc
@@ -504,7 +504,7 @@ extern "C" int Init( Model* mod )
{
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 );
View
128 libstage/block.cc
@@ -316,24 +316,31 @@ void Block::GenerateCandidateCells()
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 @@ void Block::Rasterize( uint8_t* data,
//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 );
+// }
+
}
}
}
View
90 libstage/model.cc
@@ -218,6 +218,7 @@ Model::Model( World* world,
power_pack( NULL ),
pps_charging(NULL),
props(NULL),
+ rastervis(),
rebuild_displaylist(true),
say_string(NULL),
stall(false),
@@ -263,6 +264,8 @@ Model::Model( World* world,
// 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::RegisterOption( Option* opt )
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;
}
+
+
View
2 libstage/powerpack.cc
@@ -266,7 +266,7 @@ void PowerPack::DissipationVis::Visualize( Model* mod, Camera* cam )
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 );
View
2 libstage/stage.cc
@@ -351,7 +351,7 @@ int Stg::stg_rotrects_from_image_file( const char* filename,
// 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;
View
22 libstage/stage.hh
@@ -1631,7 +1631,23 @@ namespace Stg
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 @@ namespace Stg
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
View
BIN worlds/bitmaps/SFU_1920x1280.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 59d66b4

Please sign in to comment.