Permalink
Browse files

replaced stg_color_t with Color class and added static named construc…

…tors
  • Loading branch information...
1 parent ff51521 commit 4ccc5cd77713aa3b87e3268fde7b1f53c9f400ad rtv committed Jul 3, 2009
View
@@ -53,8 +53,10 @@ CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/config.h.in
${CMAKE_CURRENT_SOURCE_DIR}/config.h @ONLY)
# Enable -Wall by default
-SET (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O2 -Wall")
-SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O2 -Wall")
+#SET (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O2 -Wall")
+#SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O2 -Wall")
+SET (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall")
+SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
message( STATUS "Checking for libtool" )
find_path( LTDL_INCLUDE_DIR ltdl.h DOC "Libtool include dir" )
View
@@ -18,7 +18,7 @@ extern "C" int Init( Model* mod )
int Update( Model* mod, void* dummy )
{
if( mod->GetWorld()->GetUpdateCount() % INTERVAL == 0 )
- mod->PushFlag( new Flag( stg_color_pack( 1,1,0,0), FLAGSZ ) );
+ mod->PushFlag( new Flag( Color( 1,1,0,0), FLAGSZ ) );
return 0; // run again
}
View
@@ -8,6 +8,7 @@ set( stageSrcs
block.cc
blockgroup.cc
camera.cc
+ color.cc
file_manager.cc
file_manager.hh
gl.cc
@@ -37,11 +38,11 @@ set( stageSrcs
stage.cc
stage.hh
texture_manager.cc
- typetable.cc
- vis_strip.cc
- waypoint.cc
- world.cc
- worldfile.cc
+ typetable.cc
+ vis_strip.cc
+ waypoint.cc
+ world.cc
+ worldfile.cc
worldgui.cc
canvas.cc
options_dlg.cc
View
@@ -19,18 +19,21 @@ Ancestor::~Ancestor()
void Ancestor::AddChild( Model* mod )
{
-
// poke a name into the child
char* buf = new char[TOKEN_MAX];
+
+ // printf( "adding child of type %d token %s\n", mod->type, mod->Token() );
+
+ std::string typestr = Model::type_map[ mod->type ];
if( token ) // if this object has a name, use it
snprintf( buf, TOKEN_MAX, "%s.%s:%d",
- token,
- typetable[mod->type].token,
- child_type_counts[mod->type] );
+ token,
+ typestr.c_str(),
+ child_type_counts[mod->type] );
else
snprintf( buf, TOKEN_MAX, "%s:%d",
- typetable[mod->type].token,
+ typestr.c_str(),
child_type_counts[mod->type] );
//printf( "%s generated a name for my child %s\n", token, buf );
View
@@ -12,7 +12,7 @@ Block::Block( Model* mod,
size_t pt_count,
stg_meters_t zmin,
stg_meters_t zmax,
- stg_color_t color,
+ Color color,
bool inherit_color
) :
mod( mod ),
@@ -134,7 +134,7 @@ void Block::SetZ( double min, double max )
mod->blockgroup.BuildDisplayList( mod );
}
-stg_color_t Block::GetColor()
+Color Block::GetColor()
{
return( inherit_color ? mod->color : color );
}
@@ -390,8 +390,10 @@ void Block::DrawFootPrint()
void Block::Draw( Model* mod )
{
// draw filled color polygons
- stg_color_t col = inherit_color ? mod->color : color;
+ Color col = inherit_color ? mod->color : color;
+ col.Print( "block color" );
+
mod->PushColor( col );
glEnable(GL_POLYGON_OFFSET_FILL);
glPolygonOffset(1.0, 1.0);
@@ -400,9 +402,10 @@ void Block::Draw( Model* mod )
glDisable(GL_POLYGON_OFFSET_FILL);
// // draw the block outline in a darker version of the same color
- double r,g,b,a;
- stg_color_unpack( col, &r, &g, &b, &a );
- mod->PushColor( stg_color_pack( r/2.0, g/2.0, b/2.0, a ));
+ //double r,g,b,a;
+ //stg_color_unpack( col, &r, &g, &b, &a );
+ //mod->PushColor( stg_color_pack( r/2.0, g/2.0, b/2.0, a ));
+ mod->PushColor( Color( col.r/2.0, col.g/2.0, col.b/2.0, col.a ));
glPolygonMode( GL_FRONT_AND_BACK, GL_LINE );
glDepthMask(GL_FALSE);
@@ -445,7 +448,7 @@ void Block::Load( Worldfile* wf, int entity )
const char* colorstr = wf->ReadString( entity, "color", NULL );
if( colorstr )
{
- color = stg_lookup_color( colorstr );
+ color = Color( colorstr );
inherit_color = false;
}
else
View
@@ -200,18 +200,27 @@ void BlockGroup::BuildDisplayList( Model* mod )
glPolygonMode( GL_FRONT_AND_BACK, GL_LINE );
glDepthMask(GL_FALSE);
- double r,g,b,a;
- stg_color_unpack( mod->color, &r, &g, &b, &a );
- mod->PushColor( stg_color_pack( r/2.0, g/2.0, b/2.0, a ));
-
+ Color c = mod->color;
+ c.r /= 2.0;
+ c.g /= 2.0;
+ c.b /= 2.0;
+ mod->PushColor( c );
+
+ //c.Print( "color" );
+
+
FOR_EACH( it, blocks )
{
Block* blk = *it;
if( (!blk->inherit_color) && (blk->color != mod->color) )
{
- stg_color_unpack( blk->color, &r, &g, &b, &a );
- mod->PushColor( stg_color_pack( r/2.0, g/2.0, b/2.0, a ));
+ Color c = blk->color;
+ c.r /= 2.0;
+ c.g /= 2.0;
+ c.b /= 2.0;
+ mod->PushColor( c );
+ //c.Print( "bar" );
blk->DrawSolid();
mod->PopColor();
}
@@ -277,7 +286,7 @@ void BlockGroup::LoadBitmap( Model* mod, const char* bitmapfile, Worldfile* wf )
if( rects && (rect_count > 0) )
{
// TODO fix this
- stg_color_t col = stg_color_pack( 1.0, 0,0,1.0 );
+ Color col( 1.0, 0.0, 1.0, 1.0 );
for( unsigned int r=0; r<rect_count; r++ )
{
View
@@ -791,7 +791,7 @@ void Canvas::renderFrame()
GLfloat scale = 1.0/world->Resolution();
glScalef( scale, scale, 1.0 ); // XX TODO - this seems slightly
- world->PushColor( stg_color_pack( 0,0,1,0.5) );
+ world->PushColor( Color( 0,0,1,0.5) );
glPolygonMode( GL_FRONT_AND_BACK, GL_FILL );
@@ -822,7 +822,7 @@ void Canvas::renderFrame()
glEnd();
#if 1
- world->PushColor( stg_color_pack( 0,1,0,0.2) );
+ world->PushColor( Color( 0,1,0,0.2) );
glBegin( GL_LINE_STRIP );
for( unsigned int i=0;
i < world->rt_cells.size();
@@ -844,7 +844,7 @@ void Canvas::renderFrame()
GLfloat scale = 1.0/world->Resolution();
glScalef( scale, scale, 1.0 ); // XX TODO - this seems slightly
- world->PushColor( stg_color_pack( 1,0,0,0.5) );
+ world->PushColor( Color( 1,0,0,0.5) );
glPolygonMode( GL_FRONT_AND_BACK, GL_LINE );
@@ -865,7 +865,7 @@ void Canvas::renderFrame()
world->rt_candidate_cells[i].x+1, world->rt_candidate_cells[i].y+1 );
}
- world->PushColor( stg_color_pack( 0,1,0,0.2) );
+ world->PushColor( Color( 0,1,0,0.2) );
glBegin( GL_LINE_STRIP );
for( unsigned int i=0;
i < world->rt_candidate_cells.size();
View
@@ -16,7 +16,7 @@ class GlColorStack
void Push( GLdouble col[4] );
void Push( double r, double g, double b, double a );
void Push( double r, double g, double b );
- void Push( stg_color_t col );
+ void Push( Color col );
void Pop();
@@ -121,7 +121,7 @@ public:
inline void setDirtyBuffer( void ) { dirty_buffer = true; }
inline bool dirtyBuffer( void ) const { return dirty_buffer; }
- inline void PushColor( stg_color_t col )
+ inline void PushColor( Color col )
{ colorstack.Push( col ); }
void PushColor( double r, double g, double b, double a )
View
@@ -46,14 +46,14 @@ void GlColorStack::Push( double r, double g, double b, double a )
Push( col );
}
-void GlColorStack::Push( stg_color_t col )
+void GlColorStack::Push( Color col )
{
GLdouble d[4];
- d[0] = ((col & 0x00FF0000) >> 16) / 256.0;
- d[1] = ((col & 0x0000FF00) >> 8) / 256.0;
- d[2] = ((col & 0x000000FF) >> 0) / 256.0;
- d[3] = (((col & 0xFF000000) >> 24) / 256.0);
+ d[0] = col.r;
+ d[1] = col.g;
+ d[2] = col.b;
+ d[3] = col.a;
Push( d );
}
View
@@ -112,6 +112,9 @@ uint32_t Model::count = 0;
//GHashTable* Model::modelsbyid = g_hash_table_new( NULL, NULL );
std::map<stg_id_t,Model*> Model::modelsbyid;
+std::map<std::string, stg_creator_t> Model::name_map;
+std::map<stg_model_type_t, std::string> Model::type_map;
+
void Size::Load( Worldfile* wf, int section, const char* keyword )
{
x = wf->ReadTupleLength( section, keyword, 0, x );
@@ -186,37 +189,36 @@ void GuiState::Load( Worldfile* wf, int wf_entity )
// constructor
Model::Model( World* world,
- Model* parent,
- const stg_model_type_t type )
+ Model* parent,
+ const stg_model_type_t type )
: Ancestor(),
access_mutex(NULL),
blinkenlights( g_ptr_array_new() ),
blockgroup(),
blocks_dl(0),
boundary(false),
callbacks( g_hash_table_new( g_direct_hash, g_direct_equal ) ),
- color( 0xFFFF0000 ), // red
+ color( 1,0,0 ), // red
data_fresh(false),
disabled(false),
- custom_visual_list( NULL ),
+ custom_visual_list( NULL ),
flag_list(NULL),
geom(),
has_default_block( true ),
id( Model::count++ ),
initfunc(NULL),
interval((stg_usec_t)1e4), // 10msec
last_update(0),
- log_state(false),
+ log_state(false),
map_resolution(0.1),
mass(0),
- // on_update_list( false ),
on_velocity_list( false ),
parent(parent),
pose(),
- power_pack( NULL ),
- pps_charging(NULL),
+ power_pack( NULL ),
+ pps_charging(NULL),
props(NULL),
- rastervis(),
+ rastervis(),
rebuild_displaylist(true),
say_string(NULL),
stall(false),
@@ -70,7 +70,7 @@ ModelBlinkenlight::ModelBlinkenlight( World* world,
// Set up sensible defaults
- this->SetColor( stg_lookup_color( "green" ) );
+ this->SetColor( Color( "green" ) );
Geom geom;
@@ -111,20 +111,23 @@ static bool blob_match( Model* candidate,
}
-static bool ColorMatchIgnoreAlpha( stg_color_t a, stg_color_t b )
+static bool ColorMatchIgnoreAlpha( Color a, Color b )
{
- return( (a & 0x00FFFFFF) == (b & 0x00FFFFFF ) );
+ double epsilon = 1e-5; // small
+ return( fabs(a.r - b.r) < epsilon &&
+ fabs(a.g - b.g) < epsilon &&
+ fabs(a.b - b.b) < epsilon );
}
-void ModelBlobfinder::ModelBlobfinder::AddColor( stg_color_t col )
+void ModelBlobfinder::ModelBlobfinder::AddColor( Color col )
{
colors.push_back( col );
}
/** Stop tracking blobs with this color */
-void ModelBlobfinder::RemoveColor( stg_color_t col )
+void ModelBlobfinder::RemoveColor( Color col )
{
- for( std::vector<stg_color_t>::iterator it = colors.begin();
+ for( std::vector<Color>::iterator it = colors.begin();
it != colors.end();
++it )
{
@@ -166,7 +169,7 @@ void ModelBlobfinder::Load( void )
if( ! colorstr )
break;
else
- AddColor( stg_lookup_color( colorstr ));
+ AddColor( Color( colorstr ));
}
}
}
@@ -194,7 +197,7 @@ void ModelBlobfinder::Update( void )
continue; // we saw nothing
unsigned int right = s;
- stg_color_t blobcol = samples[s].color;
+ Color blobcol = samples[s].color;
//printf( "blob start %d color %X\n", blobleft, blobcol );
@@ -351,14 +354,14 @@ void ModelBlobfinder::Vis::Visualize( Model* mod, Camera* cam )
glScalef( 0.025, 0.025, 1 );
// draw a white screen with a black border
- bf->PushColor( 0xFFFFFFFF );
+ bf->PushColor( 1,1,1,1 );
glRectf( 0,0, bf->scan_width, bf->scan_height );
bf->PopColor();
glTranslatef(0,0,0.01 );
glPolygonMode( GL_FRONT_AND_BACK, GL_LINE );
- bf->PushColor( 0xFF000000 );
+ bf->PushColor( 1,0,0,1 );
glRectf( 0,0, bf->scan_width, bf->scan_height );
bf->PopColor();
glPolygonMode( GL_FRONT_AND_BACK, GL_FILL );
View
@@ -120,7 +120,7 @@ _pitch_offset( 0.0 )
SetGeom( geom );
// set default color
- SetColor( stg_lookup_color(DEFAULT_GEOM_COLOR));
+ SetColor( Color( DEFAULT_GEOM_COLOR) );
RegisterOption( &showCameraData );
Oops, something went wrong.

0 comments on commit 4ccc5cd

Please sign in to comment.