The QTOpenGL user functions. More...

#include <qtopengl_user_functions.h>

Inheritance diagram for argos::CQTOpenGLUserFunctions:
Collaboration diagram for argos::CQTOpenGLUserFunctions:

Classes

class  CFunctionHolder
 The base function holder. More...
 
class  CFunctionHolderImpl
 The actual function holder. More...
 

Public Member Functions

 CQTOpenGLUserFunctions ()
 Class constructor. More...
 
virtual ~CQTOpenGLUserFunctions ()
 Class destructor. More...
 
virtual void Init (TConfigurationNode &t_tree)
 Initializes the resource. More...
 
virtual void Reset ()
 Resets the resource. More...
 
virtual void Destroy ()
 Undoes whatever was done by Init(). More...
 
virtual void KeyPressed (QKeyEvent *pc_event)
 Called when a key press event occurs. More...
 
virtual void KeyReleased (QKeyEvent *pc_event)
 Called when a key release event occurs. More...
 
virtual void MouseKeyPressed (QMouseEvent *pc_event)
 Called when a mouse key is pressed. More...
 
virtual void MouseKeyReleased (QMouseEvent *pc_event)
 Called when a mouse key is released. More...
 
virtual void MouseMoved (QMouseEvent *pc_event)
 Called when the mouse is moved. More...
 
virtual void EntitySelected (CEntity &c_entity)
 Called every time an entity is selected. More...
 
virtual void EntityDeselected (CEntity &c_entity)
 Called every time an entity is deselected. More...
 
virtual void EntityMoved (CEntity &c_entity, const CVector3 &c_old_pos, const CVector3 &c_new_pos)
 Called every time an entity is moved. More...
 
virtual void EntityRotated (CEntity &c_entity, const CQuaternion &c_old_orientation, const CQuaternion &c_new_orientation)
 Called every time an entity is rotated. More...
 
CEntityGetSelectedEntity ()
 Returns the currently selected entity, or NULL. More...
 
virtual void SelectEntity (CEntity &c_entity)
 Selects the specified entity. More...
 
virtual void DeselectEntity ()
 Deselects the currently selected entity. More...
 
virtual void Draw (CFloorEntity &c_entity)
 Drawing hook executed after the floor is drawn. More...
 
virtual void DrawInWorld ()
 Drawing hook executed after all objects have been drawn. More...
 
virtual void DrawOverlay (QPainter &c_painter)
 Drawing hook to put graphics on top of the OpenGL window. More...
 
CQTOpenGLMainWindowGetMainWindow ()
 Returns the QTOpenGL main window. More...
 
void SetMainWindow (CQTOpenGLMainWindow &c_main_win)
 Sets the QTOpenGL main window for these user functions. More...
 
CQTOpenGLWidgetGetQTOpenGLWidget ()
 Returns the QTOpenGLWidget. More...
 
void SetColor (const CColor &c_color)
 Sets the current drawing color. More...
 
void DrawPoint (const CVector3 &c_position, const CColor &c_color=CColor::RED, Real f_diameter=5.0)
 Draws a point. More...
 
void DrawTriangle (const CVector3 &c_position, const CQuaternion &c_orientation, Real f_base, Real f_height, const CColor &c_color=CColor::RED, const bool b_fill=true)
 Draws an isosceles triangle. More...
 
void DrawPolygon (const CVector3 &c_position, const CQuaternion &c_orientation, const std::vector< CVector2 > &vec_points, const CColor &c_color=CColor::RED, const bool b_fill=true)
 Draws a 2D polygon. More...
 
void DrawCircle (const CVector3 &c_position, const CQuaternion &c_orientation, Real f_radius, const CColor &c_color=CColor::RED, const bool b_fill=true, GLuint un_vertices=20)
 Draws a circle. More...
 
void DrawCylinder (const CVector3 &c_position, const CQuaternion &c_orientation, Real f_radius, Real f_height, const CColor &c_color=CColor::RED, GLuint un_vertices=20)
 Draws a cylinder, with the height perpendicular to the XY plane. More...
 
void DrawBox (const CVector3 &c_position, const CQuaternion &c_orientation, const CVector3 &c_size, const CColor &c_color=CColor::RED)
 Draws a box. More...
 
void DrawRay (const CRay3 &c_ray, const CColor &c_color=CColor::RED, Real f_width=1.0f)
 Draws a ray, with optional endpoint markers. More...
 
void DrawText (const CVector3 &c_position, const std::string &str_text, const CColor &c_color=CColor::BLACK, const QFont &c_font=QFont())
 Draws a string of text. More...
 
template<typename USER_IMPL , typename ENTITY >
void RegisterUserFunction (void(USER_IMPL::*pt_function)(ENTITY &))
 Registers a user method. More...
 
virtual void Call (CEntity &c_entity)
 Calls a user method for the given entity. More...
 
- Public Member Functions inherited from argos::CBaseConfigurableResource
virtual ~CBaseConfigurableResource ()
 Class destructor. More...
 

Protected Types

typedef void(CQTOpenGLUserFunctions::* TThunk) (CEntity &)
 Pointer-to-thunk type definition. More...
 

Protected Member Functions

template<typename USER_IMPL , typename ENTITY >
void Thunk (CEntity &c_entity)
 A templetized thunk. More...
 

Protected Attributes

CVTable< CQTOpenGLUserFunctions, CEntity, TThunkm_cThunks
 The vtable storing the thunks. More...
 
std::vector< CFunctionHolder * > m_vecFunctionHolders
 A vector of function holders. More...
 

Detailed Description

The QTOpenGL user functions.

The QTOpenGL user functions allows you to draw objects on the graphical widget that shows the 3D robot arena (CQTOpenGLWidget). You have three ways to draw stuff.

The first is to use DrawInWorld(). This method is called after everything else has been drawn in the 3D world, and it allows you to draw custom objects anywhere in the world. When you use this method, coordinates are relative to the origin of the 3D arena, and you must use OpenGL primitives.

The second way to draw custom stuff is to use DrawOverlay(). This method is called after DrawInWorld(). It allows you to draw stuff as overlay of the 3D arena widget. This method requires you to use the methods in the Qt class QPainter.

The third way to draw custom stuff is to define an entity-specific method, as follows:

class MyOpenGLUserFunctions : public CQTOpenGLUserFunctions {
public:
   MyOpenGLUserFunctions();
   void Draw(CFootBotEntity& c_entity);
   ...
};

<p<blockquote>

The signature of the method must be as in the example, i.e., the return value must be void, and the function must have as a unique argument an entity (i.e., a descendant of CEntity). The actual name of the function (e.g., Draw) can be anything you like. To tell ARGoS to use this function, you need to register it in the class constructor as in this example:

MyOpenGLUserFunctions::MyOpenGLUserFunctions() {
   ...
   RegisterUserFunction<MyOpenGLUserFunctions,CFootBotEntity>(&MyOpenGLUserFunctions::Draw);
   ...
}

<p<blockquote>

After registration, ARGoS will call your method right after drawing an entity of the corresponding type. The method allows you to draw additional information around the robot. You must use OpenGL primitives. The coordinate system is relative to the robot reference point, which, for robots, is usually its base.

Definition at line 74 of file qtopengl_user_functions.h.

Member Typedef Documentation

◆ TThunk

typedef void(CQTOpenGLUserFunctions::* argos::CQTOpenGLUserFunctions::TThunk) (CEntity &)
protected

Pointer-to-thunk type definition.

See also
Thunk

Definition at line 384 of file qtopengl_user_functions.h.

Constructor & Destructor Documentation

◆ CQTOpenGLUserFunctions()

argos::CQTOpenGLUserFunctions::CQTOpenGLUserFunctions ( )

Class constructor.

Definition at line 39 of file qtopengl_user_functions.cpp.

◆ ~CQTOpenGLUserFunctions()

argos::CQTOpenGLUserFunctions::~CQTOpenGLUserFunctions ( )
virtual

Class destructor.

Definition at line 48 of file qtopengl_user_functions.cpp.

Member Function Documentation

◆ Call()

void argos::CQTOpenGLUserFunctions::Call ( CEntity c_entity)
virtual

Calls a user method for the given entity.

Parameters
Themethod to pass as parameter.

Definition at line 490 of file qtopengl_user_functions.cpp.

◆ DeselectEntity()

void argos::CQTOpenGLUserFunctions::DeselectEntity ( )
virtual

Deselects the currently selected entity.

  • If no entity was selected, nothing is done.
  • If an entity was previously selected, EntityDeselected() is called for that entity.

Definition at line 86 of file qtopengl_user_functions.cpp.

◆ Destroy()

virtual void argos::CQTOpenGLUserFunctions::Destroy ( )
inlinevirtual

Undoes whatever was done by Init().

Implements argos::CBaseConfigurableResource.

Definition at line 90 of file qtopengl_user_functions.h.

◆ Draw()

virtual void argos::CQTOpenGLUserFunctions::Draw ( CFloorEntity c_entity)
inlinevirtual

Drawing hook executed after the floor is drawn.

Definition at line 218 of file qtopengl_user_functions.h.

◆ DrawBox()

void argos::CQTOpenGLUserFunctions::DrawBox ( const CVector3 c_position,
const CQuaternion c_orientation,
const CVector3 c_size,
const CColor c_color = CColor::RED 
)

Draws a box.

By default the box is red and positioned in the origin. The reference system is positioned at the center of mass.

Parameters
c_positionThe position of the box center.
c_orientationThe orientation of the box.
c_sizeThe size of the box.
c_colorThe box color.

Definition at line 306 of file qtopengl_user_functions.cpp.

◆ DrawCircle()

void argos::CQTOpenGLUserFunctions::DrawCircle ( const CVector3 c_position,
const CQuaternion c_orientation,
Real  f_radius,
const CColor c_color = CColor::RED,
const bool  b_fill = true,
GLuint  un_vertices = 20 
)

Draws a circle.

By default the circle is parallel to the XY plane and filled in red. The circle reference system is positioned at the circle center.

Parameters
c_positionThe circle position.
c_orientationThe circle orientation.
f_radiusThe circle radius.
c_colorThe circle color.
b_fillWhen true, the triangle is filled.
un_verticesThe number of vertices used to draw the circle.

Definition at line 220 of file qtopengl_user_functions.cpp.

◆ DrawCylinder()

void argos::CQTOpenGLUserFunctions::DrawCylinder ( const CVector3 c_position,
const CQuaternion c_orientation,
Real  f_radius,
Real  f_height,
const CColor c_color = CColor::RED,
GLuint  un_vertices = 20 
)

Draws a cylinder, with the height perpendicular to the XY plane.

By default the cylinder is red and positioned in the origin. The reference system is positioned at the center of mass.

Parameters
c_positionThe cylinder position.
c_orientationThe cylinder orientation of the cylinder.
f_radiusThe cylinder radius.
f_heightThe cylinder height.
c_colorThe cylinder color.
un_verticesThe number of vertices used to draw the cylinder bases.

Definition at line 256 of file qtopengl_user_functions.cpp.

◆ DrawInWorld()

virtual void argos::CQTOpenGLUserFunctions::DrawInWorld ( )
inlinevirtual

Drawing hook executed after all objects have been drawn.

Use this hook to draw your own stuff in the world. You must use OpenGL primitives. Coordinates are expressed wrt the world's origin.

Definition at line 225 of file qtopengl_user_functions.h.

◆ DrawOverlay()

virtual void argos::CQTOpenGLUserFunctions::DrawOverlay ( QPainter &  c_painter)
inlinevirtual

Drawing hook to put graphics on top of the OpenGL window.

Extend this method to draw stuff on top of the 3D graphical window. Use the methods in the Qt4 QPainter class to add all the stuff you want, such as text, shapes and so on.

Parameters
c_painterThe QPainter object to draw the overlay.

Definition at line 234 of file qtopengl_user_functions.h.

◆ DrawPoint()

void argos::CQTOpenGLUserFunctions::DrawPoint ( const CVector3 c_position,
const CColor c_color = CColor::RED,
Real  f_diameter = 5.0 
)

Draws a point.

By default the point drawn in red.

Parameters
c_positionThe point position.
c_colorThe point color.
f_diameterThe point diameter.

Definition at line 130 of file qtopengl_user_functions.cpp.

◆ DrawPolygon()

void argos::CQTOpenGLUserFunctions::DrawPolygon ( const CVector3 c_position,
const CQuaternion c_orientation,
const std::vector< CVector2 > &  vec_points,
const CColor c_color = CColor::RED,
const bool  b_fill = true 
)

Draws a 2D polygon.

By default the polygon is parallel to the XY plane and its fill color is red.

Parameters
c_positionThe polygon position.
c_orientationThe polygon orientation.
vec_pointsThe polygon vertices.
c_colorThe polygon color.
b_fillWhen true, the polygon is filled.

Definition at line 184 of file qtopengl_user_functions.cpp.

◆ DrawRay()

void argos::CQTOpenGLUserFunctions::DrawRay ( const CRay3 c_ray,
const CColor c_color = CColor::RED,
Real  f_width = 1.0f 
)

Draws a ray, with optional endpoint markers.

By default the ray is drawn in red without end points markers. The end point markers default color is red.

Parameters
c_rayThe ray coordinates.
c_colorThe ray color.
f_widthThe ray width.

Definition at line 366 of file qtopengl_user_functions.cpp.

◆ DrawText()

void argos::CQTOpenGLUserFunctions::DrawText ( const CVector3 c_position,
const std::string &  str_text,
const CColor c_color = CColor::BLACK,
const QFont &  c_font = QFont() 
)

Draws a string of text.

By default the text is black and aligned left.

Parameters
c_positionThe text position.
str_textThe text to display
c_colorThe text color
c_fontA Qt font configuration

Definition at line 421 of file qtopengl_user_functions.cpp.

◆ DrawTriangle()

void argos::CQTOpenGLUserFunctions::DrawTriangle ( const CVector3 c_position,
const CQuaternion c_orientation,
Real  f_base,
Real  f_height,
const CColor c_color = CColor::RED,
const bool  b_fill = true 
)

Draws an isosceles triangle.

By default the triangle is parallel to the XY plane, equilateral, with the height along the X axis. The triangle reference system is positioned in at the center of the triangle base.

Parameters
c_positionThe triangle position.
c_orientationThe triangle orientation.
f_baseThe length of the triangle base.
f_heightThe length of the triangle height.
c_colorThe triangle color.
b_fillWhen true, the triangle is filled.

Definition at line 151 of file qtopengl_user_functions.cpp.

◆ EntityDeselected()

virtual void argos::CQTOpenGLUserFunctions::EntityDeselected ( CEntity c_entity)
inlinevirtual

Called every time an entity is deselected.

Parameters
c_entityThe deselected entity.

Definition at line 170 of file qtopengl_user_functions.h.

◆ EntityMoved()

virtual void argos::CQTOpenGLUserFunctions::EntityMoved ( CEntity c_entity,
const CVector3 c_old_pos,
const CVector3 c_new_pos 
)
inlinevirtual

Called every time an entity is moved.

Parameters
c_entityThe moved entity.
c_old_posThe old position of the entity.
c_new_posThe new position of the entity.

Definition at line 178 of file qtopengl_user_functions.h.

◆ EntityRotated()

virtual void argos::CQTOpenGLUserFunctions::EntityRotated ( CEntity c_entity,
const CQuaternion c_old_orientation,
const CQuaternion c_new_orientation 
)
inlinevirtual

Called every time an entity is rotated.

Parameters
c_entityThe rotated entity.
c_old_orientationThe old orientation of the entity.
c_new_orientationThe new orientation of the entity.

Definition at line 188 of file qtopengl_user_functions.h.

◆ EntitySelected()

virtual void argos::CQTOpenGLUserFunctions::EntitySelected ( CEntity c_entity)
inlinevirtual

Called every time an entity is selected.

Parameters
c_entityThe selected entity.

Definition at line 164 of file qtopengl_user_functions.h.

◆ GetMainWindow()

CQTOpenGLMainWindow & argos::CQTOpenGLUserFunctions::GetMainWindow ( )

Returns the QTOpenGL main window.

Returns
The QTOpenGL main window.

Definition at line 93 of file qtopengl_user_functions.cpp.

◆ GetQTOpenGLWidget()

CQTOpenGLWidget & argos::CQTOpenGLUserFunctions::GetQTOpenGLWidget ( )

Returns the QTOpenGLWidget.

Returns
The QTOpenGLWidget.

Definition at line 107 of file qtopengl_user_functions.cpp.

◆ GetSelectedEntity()

CEntity * argos::CQTOpenGLUserFunctions::GetSelectedEntity ( )

Returns the currently selected entity, or NULL.

Definition at line 72 of file qtopengl_user_functions.cpp.

◆ Init()

virtual void argos::CQTOpenGLUserFunctions::Init ( TConfigurationNode t_tree)
inlinevirtual

Initializes the resource.

Parameters
t_treethe base of the XML configuration tree to parse
Exceptions
CARGoSExceptionif an error occurs

Implements argos::CBaseConfigurableResource.

Definition at line 88 of file qtopengl_user_functions.h.

◆ KeyPressed()

void argos::CQTOpenGLUserFunctions::KeyPressed ( QKeyEvent *  pc_event)
virtual

Called when a key press event occurs.

The focus must be on the QTOpenGL widget. QTOpenGL reserves the following keys for camera movement:

Definition at line 58 of file qtopengl_user_functions.cpp.

◆ KeyReleased()

void argos::CQTOpenGLUserFunctions::KeyReleased ( QKeyEvent *  pc_event)
virtual

Called when a key release event occurs.

The focus must be on the QTOpenGL widget. QTOpenGL reserves the following keys for camera movement:

Definition at line 65 of file qtopengl_user_functions.cpp.

◆ MouseKeyPressed()

virtual void argos::CQTOpenGLUserFunctions::MouseKeyPressed ( QMouseEvent *  pc_event)
inlinevirtual

Called when a mouse key is pressed.

The focus must be on the QTOpenGL widget.

QTOpenGL reserves the following events:

  • mouse pressed with no key modifier
  • mouse pressed while shift is pressed
  • mouse pressed while ctrl is pressed

Other combinations, e.g., mouse pressed while alt is pressed, are available.

Definition at line 133 of file qtopengl_user_functions.h.

◆ MouseKeyReleased()

virtual void argos::CQTOpenGLUserFunctions::MouseKeyReleased ( QMouseEvent *  pc_event)
inlinevirtual

Called when a mouse key is released.

The focus must be on the QTOpenGL widget.

QTOpenGL reserves the following events:

  • mouse released with no key modifier
  • mouse released while shift is pressed
  • mouse released while ctrl is pressed

Other combinations, e.g., mouse released while alt is pressed, are available.

Definition at line 148 of file qtopengl_user_functions.h.

◆ MouseMoved()

virtual void argos::CQTOpenGLUserFunctions::MouseMoved ( QMouseEvent *  pc_event)
inlinevirtual

Called when the mouse is moved.

The focus must be on the QTOpenGL widget.

QTOpenGL reserves the following events:

  • mouse moved while mouse is grabbed. This happens when the camera is being moved.

Definition at line 158 of file qtopengl_user_functions.h.

◆ RegisterUserFunction()

template<typename USER_IMPL , typename ENTITY >
void argos::CQTOpenGLUserFunctions::RegisterUserFunction ( void(USER_IMPL::*)(ENTITY &)  pt_function)

Registers a user method.

Parameters
USER_IMPLA user-defined subclass of CQTOpenGLUserFunctions.
ENTITYThe entity type to pass as a parameter to the user-defined method.
pt_functionThe actual user-defined pointer-to-method.

Definition at line 481 of file qtopengl_user_functions.h.

◆ Reset()

virtual void argos::CQTOpenGLUserFunctions::Reset ( )
inlinevirtual

Resets the resource.

Implements argos::CBaseConfigurableResource.

Definition at line 89 of file qtopengl_user_functions.h.

◆ SelectEntity()

void argos::CQTOpenGLUserFunctions::SelectEntity ( CEntity c_entity)
virtual

Selects the specified entity.

  • If no entity was previously selected, the specified entity is selected and EntitySelected() is called.
  • If an entity was previously selected, EntityDeselected() is called for that entity; then, the specified entity is selected and EntitySelected() is called.

Definition at line 79 of file qtopengl_user_functions.cpp.

◆ SetColor()

void argos::CQTOpenGLUserFunctions::SetColor ( const CColor c_color)

Sets the current drawing color.

Parameters
c_colorThe desired color.

Definition at line 114 of file qtopengl_user_functions.cpp.

◆ SetMainWindow()

void argos::CQTOpenGLUserFunctions::SetMainWindow ( CQTOpenGLMainWindow c_main_win)

Sets the QTOpenGL main window for these user functions.

Parameters
c_widgetThe QTOpenGL main window.

Definition at line 100 of file qtopengl_user_functions.cpp.

◆ Thunk()

template<typename USER_IMPL , typename ENTITY >
void argos::CQTOpenGLUserFunctions::Thunk ( CEntity c_entity)
protected

A templetized thunk.

This is a trampoline function that internally performs the dispatch to a user-defined method.

Parameters
USER_IMPLA user-defined subclass of CQTOpenGLUserFunctions.
ENTITYThe entity type to pass as a parameter to the user-defined method.
c_entityThe entity to pass as parameter.
See also
TThunk

Definition at line 461 of file qtopengl_user_functions.h.

Member Data Documentation

◆ m_cThunks

CVTable<CQTOpenGLUserFunctions, CEntity, TThunk> argos::CQTOpenGLUserFunctions::m_cThunks
protected

The vtable storing the thunks.

See also
TThunk
Thunk

Definition at line 423 of file qtopengl_user_functions.h.

◆ m_vecFunctionHolders

std::vector<CFunctionHolder*> argos::CQTOpenGLUserFunctions::m_vecFunctionHolders
protected

A vector of function holders.

See also
CFunctionHolder

Definition at line 429 of file qtopengl_user_functions.h.