Revision: 7596
http://playerstage.svn.sourceforge.net/playerstage/?rev=7596&view=rev
Author: rtv
Date: 2009-04-11 06:22:41 +0000 (Sat, 11 Apr 2009)
Log Message:
-----------
spring cleaning
Modified Paths:
--------------
code/stage/trunk/libstage/block.cc
code/stage/trunk/libstage/model_callbacks.cc
code/stage/trunk/libstage/stage.cc
code/stage/trunk/libstage/stage.hh
code/stage/trunk/libstage/world.cc
Modified: code/stage/trunk/libstage/block.cc
===================================================================
--- code/stage/trunk/libstage/block.cc 2009-04-11 05:32:07 UTC (rev 7595)
+++ code/stage/trunk/libstage/block.cc 2009-04-11 06:22:41 UTC (rev 7596)
@@ -56,7 +56,7 @@
{
if( mapped ) UnMap();
- stg_points_destroy( pts );
+ if( pts ) delete[] pts;
g_ptr_array_free( rendered_cells, TRUE );
g_ptr_array_free( candidate_cells, TRUE );
@@ -349,29 +349,27 @@
mpt2.y += mod->geom.size.y/2.0;
// convert from meters to cells
- int xa = floor( mpt1.x / cellwidth );
- int ya = floor( mpt1.y / cellheight );
- int xb = floor( mpt2.x / cellwidth );
- int yb = floor( mpt2.y / cellheight );
-
- //printf( " line (%d,%d) to (%d,%d)\n", xa,ya,xb,yb );
+ stg_point_int_t a( floor( mpt1.x / cellwidth ),
+ floor( mpt1.y
/ cellheight ));
+ stg_point_int_t b( floor( mpt2.x / cellwidth ),
+ floor( mpt2.y
/ cellheight ) );
- bool steep = abs( yb-ya ) > abs( xb-xa );
+ bool steep = abs( b.y-a.y ) > abs( b.x-a.x );
if( steep )
{
- swap( xa, ya );
- swap( xb, yb );
+ swap( a.x, a.y );
+ swap( b.x, b.y );
}
- if( xa > xb )
+ if( a.x > b.x )
{
- swap( xa, xb );
- swap( ya, yb );
+ swap( a.x, b.x );
+ swap( a.y, b.y );
}
- double dydx = (double) (yb - ya) / (double) (xb - xa);
- double y = ya;
- for(int x=xa; x<=xb; x++)
+ double dydx = (double) (b.y - a.y) / (double) (b.x - a.x);
+ double y = a.y;
+ for(int x=a.x; x<=b.x; x++)
{
if( steep )
{
@@ -473,10 +471,10 @@
//printf( "Block::Load entity %d\n", entity );
if( pts )
- stg_points_destroy( pts );
+ delete[] pts;
pt_count = wf->ReadInt( entity, "points", 0);
- pts = stg_points_create( pt_count );
+ pts = new stg_point_t[ pt_count ];
//printf( "reading %d points\n",
// pt_count );
Modified: code/stage/trunk/libstage/model_callbacks.cc
===================================================================
--- code/stage/trunk/libstage/model_callbacks.cc 2009-04-11 05:32:07 UTC
(rev 7595)
+++ code/stage/trunk/libstage/model_callbacks.cc 2009-04-11 06:22:41 UTC
(rev 7596)
@@ -19,7 +19,7 @@
// mod->token, *key );
// add the callback & argument to the list
- cb_list = g_list_prepend( cb_list, cb_create( cb, user ) );
+ cb_list = g_list_prepend( cb_list, new stg_cb_t( cb, user ) );
// and replace the list in the hash table
g_hash_table_insert( callbacks, address, cb_list );
@@ -56,12 +56,7 @@
// we're done with that
//free( el->data );
- // TODO - fix leak of cb_t
-
- // if we just removed a model's last update callback,
- // remove this model from the world's update list
- //if( (member == (void*)&update) && (cb_list == NULL) )
- //stg_world_stop_updating_model( world, this );
+ // TODO - fix leak of stg_cb_t
}
else
{
Modified: code/stage/trunk/libstage/stage.cc
===================================================================
--- code/stage/trunk/libstage/stage.cc 2009-04-11 05:32:07 UTC (rev 7595)
+++ code/stage/trunk/libstage/stage.cc 2009-04-11 06:22:41 UTC (rev 7596)
@@ -152,53 +152,6 @@
return (stg_color_t)0;
}
-//////////////////////////////////////////////////////////////////////////
-// scale an array of rectangles so they fit in a unit square
-void Stg::stg_rotrects_normalize( stg_rotrect_t* rects, int num )
-{
- // assuming the rectangles fit in a square +/- one billion units
- double minx, miny, maxx, maxy;
- minx = miny = billion;
- maxx = maxy = -billion;
-
- int r;
- for( r=0; r<num; r++ )
- {
- // test the origin of the rect
- if( rects[r].pose.x < minx ) minx = rects[r].pose.x;
- if( rects[r].pose.y < miny ) miny = rects[r].pose.y;
- if( rects[r].pose.x > maxx ) maxx = rects[r].pose.x;
- if( rects[r].pose.y > maxy ) maxy = rects[r].pose.y;
-
- // test the extremes of the rect
- if( (rects[r].pose.x+rects[r].size.x) < minx )
- minx = (rects[r].pose.x+rects[r].size.x);
-
- if( (rects[r].pose.y+rects[r].size.y) < miny )
- miny = (rects[r].pose.y+rects[r].size.y);
-
- if( (rects[r].pose.x+rects[r].size.x) > maxx )
- maxx = (rects[r].pose.x+rects[r].size.x);
-
- if( (rects[r].pose.y+rects[r].size.y) > maxy )
- maxy = (rects[r].pose.y+rects[r].size.y);
- }
-
- // now normalize all lengths so that the rects all fit inside
- // rectangle from 0,0 to 1,1
- double scalex = maxx - minx;
- double scaley = maxy - miny;
-
- for( r=0; r<num; r++ )
- {
- rects[r].pose.x = (rects[r].pose.x - minx) / scalex;
- rects[r].pose.y = (rects[r].pose.y - miny) / scaley;
- rects[r].size.x = rects[r].size.x / scalex;
- rects[r].size.y = rects[r].size.y / scaley;
- }
-}
-
-
// returns the resultant of vector [p1] and [p2]
Pose Stg::pose_scale( const Pose& p1, const double sx, const double sy, const
double sz )
{
@@ -219,25 +172,6 @@
return( pixels + index );
}
-/*
-static void pb_set_pixel( Fl_Shared_Image* pb, int x, int y, uint8_t val )
-{
- // bounds checking
- int width = pb->w();
- int height = pb->h();
- if( x >=0 && x < width && y >= 0 && y < height )
- {
- // zeroing
- guchar* pix = pb_get_pixel( pb, x, y );
- unsigned int bytes_per_sample = 1;
- unsigned int num_samples = pb->d();
- memset( pix, val, num_samples * bytes_per_sample );
- }
- else
- PRINT_WARN4( "pb_set_pixel coordinate %d,%d out of range (image
dimensions %d by %d)", x, y, width, height );
-}
-*/
-
// set all the pixels in a rectangle
static void pb_set_rect( Fl_Shared_Image* pb, int x, int y, int width, int
height, uint8_t val )
{
@@ -363,9 +297,9 @@
//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 );
+// 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,
@@ -382,20 +316,9 @@
// POINTS -----------------------------------------------------------
-stg_point_t* Stg::stg_points_create( size_t count )
-{
- return( (stg_point_t*)g_new( stg_point_t, count ));
-}
-
-void Stg::stg_points_destroy( stg_point_t* pts )
-{
- g_free( pts );
-}
-
-
stg_point_t* Stg::stg_unit_square_points_create( void )
{
- stg_point_t * pts = stg_points_create( 4 );
+ stg_point_t * pts = new stg_point_t[4];
pts[0].x = 0;
pts[0].y = 0;
@@ -409,22 +332,6 @@
return pts;
}
-
-// CALLBACKS -------------------------------------------------------
-
-stg_cb_t* Stg::cb_create( stg_model_callback_t callback, void* arg )
-{
- stg_cb_t* cb = (stg_cb_t*)g_new( stg_cb_t, 1 );
- cb->callback = callback;
- cb->arg = arg;
- return cb;
-}
-
-void Stg::cb_destroy( stg_cb_t* cb )
-{
- free( cb );
-}
-
// return a value based on val, but limited minval <= val >= maxval
double Stg::constrain( double val, double minval, double maxval )
{
Modified: code/stage/trunk/libstage/stage.hh
===================================================================
--- code/stage/trunk/libstage/stage.hh 2009-04-11 05:32:07 UTC (rev 7595)
+++ code/stage/trunk/libstage/stage.hh 2009-04-11 06:22:41 UTC (rev 7596)
@@ -209,7 +209,7 @@
typedef double stg_watts_t;
/** boolean */
- typedef uint32_t stg_bool_t;
+ typedef bool stg_bool_t;
/** 32-bit ARGB color packed 0xAARRGGBB */
typedef uint32_t stg_color_t;
@@ -358,27 +358,25 @@
/// smallest value in range, initially zero
double min;
- Bounds() : max(0), min(0)
- { /* empty*/ };
+ Bounds() : max(0), min(0) { /* empty*/ }
};
-
- /** Bound a volume along the x,y,z axes. All bounds initialized to zero. */
- typedef struct
+
+ /** Define a three-dimensional bounding box, initialized to zero */
+ class stg_bounds3d_t
{
+ public:
/// volume extent along x axis, intially zero
Bounds x;
/// volume extent along y axis, initially zero
Bounds y;
/// volume extent along z axis, initially zero
Bounds z;
- } stg_bounds3d_t;
+
+ stg_bounds3d_t() : x(), y(), z() {}
+ stg_bounds3d_t( const Bounds& x, const Bounds& y, const Bounds& z)
+ : x(x), y(y), z(z) {}
+ };
- /** Define a three-dimensional bounding box, initialized to zero */
- typedef struct
- {
- Bounds x, y, z;
- } stg_bbox3d_t;
-
/** Define a field-of-view: an angle and range bounds */
typedef struct
{
@@ -391,60 +389,38 @@
{
public:
stg_meters_t x, y;
-
- // init
- stg_point_t( stg_meters_t x, stg_meters_t y )
- : x(x), y(y){}
-
- // init
- stg_point_t() : x(0), y(0){}
-
- // copy
- stg_point_t( const stg_point_t& pt) : x(pt.x), y(pt.y){}
+ stg_point_t( stg_meters_t x, stg_meters_t y ) : x(x), y(y){}
+ stg_point_t() : x(0.0), y(0.0){}
};
-
+
/** Define a point in 3d space */
- typedef struct
+ class stg_point3_t
{
- float x, y, z;
- } stg_vertex_t;
-
- /** Define vertex and its color */
- typedef struct
- {
- float x, y, z, r, g, b, a;
- } stg_colorvertex_t;
-
- /** Define a point in 3d space */
- typedef struct
- {
- stg_meters_t x, y, z;
- } stg_point3_t;
+ public:
+ stg_meters_t x,y,z;
+ stg_point3_t( int x, int y ) : x(x), y(y){}
+ stg_point3_t() : x(0.0), y(0.0), z(0.0) {}
+ };
/** Define an integer point on the 2d plane */
- typedef struct
+ class stg_point_int_t
{
- int32_t x,y;
- } stg_point_int_t;
+ public:
+ int x,y;
+ stg_point_int_t( int x, int y ) : x(x), y(y){}
+ stg_point_int_t() : x(0), y(0){}
+ };
+
- /** Create an array of [count] points. Caller must free the returned
- pointer, preferably with stg_points_destroy(). */
- stg_point_t* stg_points_create( size_t count );
-
- /** frees a point array */
- void stg_points_destroy( stg_point_t* pts );
-
/** create an array of 4 points containing the corners of a unit
square. */
stg_point_t* stg_unit_square_points_create();
+
+ typedef uint32_t stg_movemask_t;
+ const stg_movemask_t STG_MOVE_TRANS = (1 << 0); ///< bitmask
+ const stg_movemask_t STG_MOVE_ROT = (1 << 1); ///< bitmask
+ const stg_movemask_t STG_MOVE_SCALE = (1 << 2); ///< bitmask
-
- typedef uint32_t stg_movemask_t;
-
- const uint32_t STG_MOVE_TRANS = (1 << 0); ///< bitmask for stg_movemask_t
- const uint32_t STG_MOVE_ROT = (1 << 1); ///< bitmask for stg_movemask_t
- const uint32_t STG_MOVE_SCALE = (1 << 2); ///< bitmask for stg_movemask_t
-
const char MP_PREFIX[] = "_mp_";
const char MP_POSE[] = "_mp_pose";
const char MP_VELOCITY[] = "_mp_velocity";
@@ -458,7 +434,6 @@
const char MP_GRIPPER_RETURN[] = "_mp_gripper_return";
const char MP_MASS[] = "_mp_mass";
-
/// laser return value
typedef enum
{
@@ -466,7 +441,6 @@
LaserVisible, ///< detected by laser with a reflected intensity of 0
LaserBright ///< detected by laser with a reflected intensity of 1
} stg_laser_return_t;
-
/** Convenient OpenGL drawing routines, used by visualization
code. */
@@ -688,15 +662,18 @@
/** container for a callback function and a single argument, so
they can be stored together in a list with a single pointer. */
- typedef struct
+ class stg_cb_t
{
+ public:
stg_model_callback_t callback;
void* arg;
- } stg_cb_t;
+
+ stg_cb_t( stg_model_callback_t cb, void* arg )
+ : callback(cb), arg(arg) {}
+
+ stg_cb_t() : callback(NULL), arg(NULL) {}
+ };
- stg_cb_t* cb_create( stg_model_callback_t callback, void* arg );
- void cb_destroy( stg_cb_t* cb );
-
/** Defines a rectangle of [size] located at [pose] */
typedef struct
{
@@ -704,11 +681,6 @@
Size size;
} stg_rotrect_t; // rotated rectangle
- /** normalizes the set [rects] of [num] rectangles, so that they fit
- exactly in a unit square.
- */
- void stg_rotrects_normalize( stg_rotrect_t* rects, int num );
-
/** load the image file [filename] and convert it to an array of
rectangles, filling in the number of rects, width and
height. Memory is allocated for the rectangle array [rects], so
@@ -824,7 +796,7 @@
{ return token; }
void SetToken( const char* str )
- { token = strdup( str ); } // little memory leak
+ { token = strdup( str ); } // minor memory leak
};
/** raytrace sample
@@ -1177,10 +1149,9 @@
written, and the pointers to the rendered and potential cells
are
switched for next time (avoiding a memory copy).*/
GPtrArray* candidate_cells;
-
- // find the position of a block's internal point in meters
- // relative to the model
+ /** find the position of a block's point in model coordinates
+ (m) */
stg_point_t BlockPointToModelMeters( const stg_point_t& bpt );
/** Update the cache of block points converted to model coordinates */
Modified: code/stage/trunk/libstage/world.cc
===================================================================
--- code/stage/trunk/libstage/world.cc 2009-04-11 05:32:07 UTC (rev 7595)
+++ code/stage/trunk/libstage/world.cc 2009-04-11 06:22:41 UTC (rev 7596)
@@ -683,8 +683,8 @@
// x,y, dx,dy, n );
// superregion coords
- stg_point_int_t lastsup = {INT_MAX, INT_MAX };
- stg_point_int_t lastreg = {INT_MAX, INT_MAX };
+ stg_point_int_t lastsup( INT_MAX, INT_MAX );
+ stg_point_int_t lastreg( INT_MAX, INT_MAX );
SuperRegion* sr = NULL;
Region* r = NULL;
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