Revision: 7548
http://playerstage.svn.sourceforge.net/playerstage/?rev=7548&view=rev
Author: rtv
Date: 2009-03-27 07:18:14 +0000 (Fri, 27 Mar 2009)
Log Message:
-----------
reworked CustomVisualizer => Visualizer - tweaked API. See ModelLaser for
example
Modified Paths:
--------------
code/stage/trunk/libstage/model_draw.cc
code/stage/trunk/libstage/model_laser.cc
code/stage/trunk/libstage/stage.hh
Modified: code/stage/trunk/libstage/model_draw.cc
===================================================================
--- code/stage/trunk/libstage/model_draw.cc 2009-03-27 02:13:08 UTC (rev
7547)
+++ code/stage/trunk/libstage/model_draw.cc 2009-03-27 07:18:14 UTC (rev
7548)
@@ -245,35 +245,36 @@
glPopMatrix();
}
-void Model::AddCustomVisualizer( CustomVisualizer* custom_visual )
+void Model::AddVisualizer( Visualizer* custom_visual )
{
if( !custom_visual )
return;
//Visualizations can only be added to stage when run in a GUI
- if( world_gui == NULL ) {
- printf( "Unable to add custom visualization - it must be run
with a GUI world\n" );
- return;
- }
-
+ if( world_gui == NULL )
+ {
+ printf( "Unable to add custom visualization - it must be run
with a GUI world\n" );
+ return;
+ }
+
//save visual instance
custom_visual_list = g_list_append(custom_visual_list, custom_visual );
//register option for all instances which share the same name
Canvas* canvas = world_gui->GetCanvas();
- std::map< std::string, Option* >::iterator i =
canvas->_custom_options.find( custom_visual->name() );
+ std::map< std::string, Option* >::iterator i =
canvas->_custom_options.find( custom_visual->GetMenuName() );
if( i == canvas->_custom_options.end() ) {
- Option* op = new Option( custom_visual->name(),
-
custom_visual->name(),
-
"",
-
true,
-
world_gui );
- canvas->_custom_options[ custom_visual->name() ] = op;
+ Option* op = new Option( custom_visual->GetMenuName(),
+
custom_visual->GetWorldfileName(),
+
"",
+
true,
+
world_gui );
+ canvas->_custom_options[ custom_visual->GetMenuName() ] = op;
RegisterOption( op );
}
}
-void Model::RemoveCustomVisualizer( CustomVisualizer* custom_visual )
+void Model::RemoveVisualizer( Visualizer* custom_visual )
{
if( custom_visual )
custom_visual_list = g_list_remove(custom_visual_list,
custom_visual );
@@ -537,20 +538,6 @@
void Model::DataVisualize( Camera* cam )
{
-// if( power_pack )
-// {
-// // back into global coords to get rid of my rotation
-// glPushMatrix();
-// gl_pose_inverse_shift( GetGlobalPose() );
-
-// // shift to the top left corner of the model (roughly)
-// glTranslatef( pose.x - geom.size.x/2.0,
-// pose.y + geom.size.y/2.0,
-// pose.z + geom.size.z );
-
-// power_pack->Visualize( cam );
-// glPopMatrix();
-// }
}
void Model::DataVisualizeTree( Camera* cam )
@@ -558,14 +545,13 @@
PushLocalCoords();
DataVisualize( cam ); // virtual function overridden by most model types
- CustomVisualizer* vis;
+ Visualizer* vis;
for( GList* item = custom_visual_list; item; item = item->next ) {
- vis = static_cast< CustomVisualizer* >( item->data );
- if( world_gui->GetCanvas()->_custom_options[ vis->name() ]->isEnabled()
)
- vis->DataVisualize( cam );
+ vis = static_cast<Visualizer* >( item->data );
+ if( world_gui->GetCanvas()->_custom_options[ vis->GetMenuName()
]->isEnabled() )
+ vis->Visualize( this, cam );
}
-
// and draw the children
LISTMETHODARG( children, Model*, DataVisualizeTree, cam );
Modified: code/stage/trunk/libstage/model_laser.cc
===================================================================
--- code/stage/trunk/libstage/model_laser.cc 2009-03-27 02:13:08 UTC (rev
7547)
+++ code/stage/trunk/libstage/model_laser.cc 2009-03-27 07:18:14 UTC (rev
7548)
@@ -32,10 +32,10 @@
static const char* DEFAULT_COLOR = "blue";
//TODO make instance attempt to register an option (as customvisualizations do)
-Option ModelLaser::showLaserData( "Laser scans", "show_laser", "", true, NULL
);
-Option ModelLaser::showLaserStrikes( "Laser strikes", "show_laser_strikes",
"", false, NULL );
-Option ModelLaser::showLaserFov( "Laser FOV", "show_laser_fov", "", false,
NULL );
-Option ModelLaser::showLaserBeams( "Laser beams", "show_laser_beams", "",
false, NULL );
+Option ModelLaser::Vis::showArea( "Laser scans", "show_laser", "", true, NULL
);
+Option ModelLaser::Vis::showStrikes( "Laser strikes", "show_laser_strikes",
"", false, NULL );
+Option ModelLaser::Vis::showFov( "Laser FOV", "show_laser_fov", "", false,
NULL );
+Option ModelLaser::Vis::showBeams( "Laser beams", "show_laser_beams", "",
false, NULL );
/**
@ingroup model
@@ -75,9 +75,122 @@
Only calculate the true range of every nth laser sample. The missing
samples are filled in with a linear interpolation. Generally it would be better
to use fewer samples, but some (poorly implemented!) programs expect a fixed
number of samples. Setting this number > 1 allows you to reduce the amount of
computation required for your fixed-size laser vector.
*/
+// create static vis objects
+
+ModelLaser::Vis::Vis( World* world )
+ : Visualizer( "Laser", "laser_vis" )
+{
+ world->RegisterOption( &showArea );
+ world->RegisterOption( &showStrikes );
+ world->RegisterOption( &showFov );
+ world->RegisterOption( &showBeams );
+}
+
+void ModelLaser::Vis::Visualize( Model* mod, Camera* cam )
+{
+ ModelLaser* laser = dynamic_cast<ModelLaser*>(mod);
+ unsigned int sample_count = 0;
+ stg_laser_sample_t* samples = laser->GetSamples( &sample_count );
+
+ if( ! (samples && sample_count) )
+ return;
+
+ glPushMatrix();
+ glPolygonMode( GL_FRONT_AND_BACK, GL_FILL );
+
+ glTranslatef( 0,0, laser->GetGeom().size.z/2.0 ); // shoot the laser beam
out at the right height
+
+ // pack the laser hit points into a vertex array for fast rendering
+ static float* pts = NULL;
+ pts = (float*)g_realloc( pts, 2 * (sample_count+1) * sizeof(float));
+
+ pts[0] = 0.0;
+ pts[1] = 0.0;
+
+ laser->PushColor( 1, 0, 0, 0.5 );
+ glDepthMask( GL_FALSE );
+ glPointSize( 2 );
+
+ for( unsigned int s=0; s<sample_count; s++ )
+ {
+ double ray_angle = (s * (laser->fov / (sample_count-1))) -
laser->fov/2.0;
+ pts[2*s+2] = (float)(samples[s].range * cos(ray_angle) );
+ pts[2*s+3] = (float)(samples[s].range * sin(ray_angle) );
+
+ // if the sample is unusually bright, draw a little blob
+ if( samples[s].reflectance > 0 )
+ {
+ glBegin( GL_POINTS );
+ glVertex2f( pts[2*s+2], pts[2*s+3] );
+ glEnd();
+ }
+ }
+
+ glVertexPointer( 2, GL_FLOAT, 0, pts );
+
+ laser->PopColor();
+
+ if( showArea )
+ {
+ // draw the filled polygon in transparent blue
+ laser->PushColor( 0, 0, 1, 0.1 );
+ glDrawArrays( GL_POLYGON, 0, sample_count+1 );
+ laser->PopColor();
+ //glDepthMask( GL_TRUE );
+ }
+
+ glDepthMask( GL_TRUE );
+
+ if( showStrikes )
+ {
+ // draw the beam strike points
+ laser->PushColor( 0, 0, 1, 0.8 );
+ glDrawArrays( GL_POINTS, 0, sample_count+1 );
+ laser->PopColor();
+ }
+
+ if( showFov )
+ {
+ for( unsigned int s=0; s<sample_count; s++ )
+ {
+ double ray_angle = (s * (laser->fov /
(sample_count-1))) - laser->fov/2.0;
+ pts[2*s+2] = (float)(laser->range_max * cos(ray_angle)
);
+ pts[2*s+3] = (float)(laser->range_max * sin(ray_angle) );
+ }
+
+ glPolygonMode( GL_FRONT_AND_BACK, GL_LINE );
+ laser->PushColor( 0, 0, 1, 0.5 );
+ glDrawArrays( GL_POLYGON, 0, sample_count+1 );
+ laser->PopColor();
+ // glPolygonMode( GL_FRONT_AND_BACK,
GL_LINE );
+ }
+
+ if( showBeams )
+ {
+ laser->PushColor( 0, 0, 1, 0.5 );
+ glBegin( GL_LINES );
+
+ for( unsigned int s=0; s<sample_count; s++ )
+ {
+
+ glVertex2f( 0,0 );
+ double ray_angle = (s * (laser->fov /
(sample_count-1))) - laser->fov/2.0;
+ glVertex2f( samples[s].range * cos(ray_angle),
+ samples[s].range *
sin(ray_angle) );
+
+ }
+ glEnd();
+ laser->PopColor();
+ }
+
+ glPopMatrix();
+}
+
+
ModelLaser::ModelLaser( World* world,
Model* parent )
: Model( world, parent, MODEL_TYPE_LASER ),
+ vis( world ),
data_dl(0),
data_dirty( true ),
samples( NULL ), // don't allocate sample buffer memory until Update()
is called
@@ -104,13 +217,8 @@
// set default color
SetColor( stg_lookup_color(DEFAULT_COLOR));
-
- RegisterOption( &showLaserData );
- RegisterOption( &showLaserStrikes );
- RegisterOption( &showLaserFov );
- RegisterOption( &showLaserBeams );
-
- //AddCustomVisualizer( new LaserScanVis( this ));
+
+ AddVisualizer( &vis );
}
@@ -130,8 +238,8 @@
fov = wf->ReadAngle( wf_entity, "fov", fov );
resolution = wf->ReadInt( wf_entity, "resolution", resolution );
- showLaserData.Load( wf, wf_entity );
- showLaserStrikes.Load( wf, wf_entity );
+ //showLaserData.Load( wf, wf_entity );
+ //showLaserStrikes.Load( wf, wf_entity );
if( resolution < 1 )
{
@@ -300,132 +408,5 @@
}
-void ModelLaser::DataVisualize( Camera* cam )
-{
- if( ! (samples && sample_count) )
- return;
-
- if ( ! (showLaserData || showLaserStrikes || showLaserFov || showLaserBeams
) )
- return;
-
- glPushMatrix();
-
- glPolygonMode( GL_FRONT_AND_BACK, GL_FILL );
- // we only regenerate the list if there's new data
- if( 1 ) // data_dirty ) // TODO - hmm, why doesn't this work?
- {
- data_dirty = false;
- if( data_dl < 1 )
- data_dl = glGenLists(1);
-
- glNewList( data_dl, GL_COMPILE );
-
- glTranslatef( 0,0, geom.size.z/2.0 ); // shoot the laser beam out at the
right height
-
- // DEBUG - draw the origin of the laser beams
- PushColor( 0,0,0,1.0 );
- glPointSize( 4.0 );
- glBegin( GL_POINTS );
- glVertex2f( 0,0 );
- glEnd();
- PopColor();
-
- // pack the laser hit points into a vertex array for fast rendering
- static float* pts = NULL;
- pts = (float*)g_realloc( pts, 2 * (sample_count+1) * sizeof(float));
-
- pts[0] = 0.0;
- pts[1] = 0.0;
-
- PushColor( 0, 0, 1, 0.5 );
- glDepthMask( GL_FALSE );
- glPointSize( 2 );
-
- for( unsigned int s=0; s<sample_count; s++ )
- {
- double ray_angle = (s * (fov / (sample_count-1))) - fov/2.0;
- pts[2*s+2] = (float)(samples[s].range * cos(ray_angle) );
- pts[2*s+3] = (float)(samples[s].range * sin(ray_angle) );
-
- // if the sample is unusually bright, draw a little blob
- if( showLaserData && (samples[s].reflectance > 0) )
- {
- glBegin( GL_POINTS );
- glVertex2f( pts[2*s+2], pts[2*s+3] );
- glEnd();
- }
- }
-
- glVertexPointer( 2, GL_FLOAT, 0, pts );
-
- PopColor();
-
- if( showLaserData )
- {
- // draw the filled polygon in transparent blue
- PushColor( 0, 0, 1, 0.1 );
- glDrawArrays( GL_POLYGON, 0, sample_count+1 );
- PopColor();
- }
-
- if( showLaserStrikes )
- {
- // draw the beam strike points
- PushColor( 0, 0, 1, 0.8 );
- glDrawArrays( GL_POINTS, 0, sample_count+1 );
- PopColor();
- }
-
- if( showLaserFov )
- {
- for( unsigned int s=0; s<sample_count; s++ )
- {
- double ray_angle = (s * (fov / (sample_count-1))) - fov/2.0;
- pts[2*s+2] = (float)(range_max * cos(ray_angle) );
- pts[2*s+3] = (float)(range_max * sin(ray_angle) );
- }
-
- glPolygonMode( GL_FRONT_AND_BACK, GL_LINE );
- PushColor( 0, 0, 1, 0.5 );
- glDrawArrays( GL_POLYGON, 0, sample_count+1 );
- PopColor();
- // glPolygonMode( GL_FRONT_AND_BACK, GL_LINE );
-
- }
-
- if( showLaserBeams )
- {
- PushColor( 0, 0, 1, 0.5 );
- glBegin( GL_LINES );
-
- for( unsigned int s=0; s<sample_count; s++ )
- {
-
- glVertex2f( 0,0 );
- double ray_angle = (s * (fov / (sample_count-1))) - fov/2.0;
- glVertex2f( samples[s].range * cos(ray_angle),
- samples[s].range * sin(ray_angle) );
-
- }
- glEnd();
- PopColor();
- }
-
-
- glDepthMask( GL_TRUE );
- glEndList();
- } // end if ( data_dirty )
-
- glCallList( data_dl );
-
- glPopMatrix();
-}
-
-
-// void ModelLaser::LaserScanVis::DataVisualize( Camera* cam )
-// {
-// puts( "LSV DataVisualize" );
-// laser->DataVisualize( cam );
-// }
Modified: code/stage/trunk/libstage/stage.hh
===================================================================
--- code/stage/trunk/libstage/stage.hh 2009-03-27 02:13:08 UTC (rev 7547)
+++ code/stage/trunk/libstage/stage.hh 2009-03-27 07:18:14 UTC (rev 7548)
@@ -1461,12 +1461,23 @@
};
/** Abstract class for adding visualizations to models. DataVisualize must
be overloaded, and is then called in the models local coord system */
- class CustomVisualizer {
+ class Visualizer {
+ private:
+ const std::string menu_name;
+ const std::string worldfile_name;
+
public:
- //TODO allow user to specify name - which will show up in display
filter
- virtual ~CustomVisualizer( void ) { }
- virtual void DataVisualize( Camera* cam ) = 0;
- virtual const std::string& name() = 0; //must return a name for
visualization (careful not to return stack-memory)
+ Visualizer( const std::string& menu_name,
+ const std::string& worldfile_name )
+ : menu_name( menu_name ),
+ worldfile_name( worldfile_name )
+ { }
+
+ virtual ~Visualizer( void ) { }
+ virtual void Visualize( Model* mod, Camera* cam ) = 0;
+
+ const std::string& GetMenuName() { return menu_name; }
+ const std::string& GetWorldfileName() { return worldfile_name; }
};
@@ -1759,6 +1770,13 @@
void DataVisualizeTree( Camera* cam );
+ void DrawFlagList();
+
+ void DrawPose( Pose pose );
+
+ void LoadDataBaseEntries( Worldfile* wf, int entity );
+
+ public:
virtual void PushColor( stg_color_t col )
{ world->PushColor( col ); }
@@ -1767,13 +1785,7 @@
virtual void PopColor(){ world->PopColor(); }
- void DrawFlagList();
- void DrawPose( Pose pose );
-
- void LoadDataBaseEntries( Worldfile* wf, int entity );
-
- public:
PowerPack* FindPowerPack();
void RecordRenderPoint( GSList** head, GSList* link,
@@ -1797,10 +1809,10 @@
void Say( const char* str );
/** Attach a user supplied visualization to a model. */
- void AddCustomVisualizer( CustomVisualizer* custom_visual );
+ void AddVisualizer( Visualizer* custom_visual );
/** remove user supplied visualization to a model - supply the same
ptr passed to AddCustomVisualizer */
- void RemoveCustomVisualizer( CustomVisualizer* custom_visual );
+ void RemoveVisualizer( Visualizer* custom_visual );
void BecomeParentOf( Model* child );
@@ -2182,10 +2194,28 @@
stg_usec_t interval;
} stg_laser_cfg_t;
+
/// %ModelLaser class
class ModelLaser : public Model
{
private:
+
+ class Vis : public Visualizer
+ {
+ private:
+ static Option showArea;
+ static Option showStrikes;
+ static Option showFov;
+ static Option showBeams;
+
+ public:
+ Vis( World* world );
+ virtual ~Vis( void ){}
+ virtual void Visualize( Model* mod, Camera* cam );
+ };
+
+ Vis vis;
+
/** OpenGL displaylist for laser data */
int data_dl;
bool data_dirty;
@@ -2195,32 +2225,7 @@
stg_meters_t range_max;
stg_radians_t fov;
uint32_t resolution;
-
- static Option showLaserData;
- static Option showLaserStrikes;
- static Option showLaserFov;
- static Option showLaserBeams;
-
-// class LaserScanVis : public CustomVisualizer
-// {
-// public:
-// LaserScanVis( ModelLaser* laser ) :
-// CustomVisualizer(),
-// laser( laser )
-// { /* nothing to do */ };
-
-// virtual void DataVisualize( Camera* cam );
-
-// // rtv - surely a static string member would be easier here?
-// //must return a name for visualization (careful not to return
stack-memory)
-
-// virtual const std::string& name() { return "LaserScanVisName";
} ;
-
-// private:
-// ModelLaser* laser;
-// };
-
-
+
public:
static const char* typestr;
// constructor
@@ -2235,7 +2240,6 @@
virtual void Update();
virtual void Load();
virtual void Print( char* prefix );
- virtual void DataVisualize( Camera* cam );
uint32_t GetSampleCount(){ return sample_count; }
@@ -2257,14 +2261,6 @@
{
public:
- // class Viz : public CustomVisualizer
-// {
-
-
-// };
-
-// static Viz viz;
-
enum paddle_state_t {
PADDLE_OPEN = 0, // default state
PADDLE_CLOSED,
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
_______________________________________________
Playerstage-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/playerstage-commit