Visual Servoing Platform  version 3.6.1 under development (2024-11-14)
vpSimulator Class Reference

#include <visp3/ar/vpSimulator.h>

+ Inheritance diagram for vpSimulator:

Public Types

enum  vpImageType { grayImage , colorImage }
 
enum  vpSimulatorViewType { INTERNAL , EXTERNAL }
 

Public Member Functions

 vpSimulator ()
 
virtual ~vpSimulator ()
 
virtual void mainLoop ()
 
virtual void initInternalViewer (unsigned int nlig, unsigned int ncol)
 
void initExternalViewer (unsigned int nlig, unsigned int ncol)
 
void initApplication (void *(*start_routine)(void *))
 
void initApplication (void *(*start_routine)(void *), void *data)
 
void initMainApplication ()
 
void closeMainApplication ()
 
unsigned int getInternalWidth () const
 
unsigned int getInternalHeight () const
 
void addObject (SoSeparator *newObject, const vpHomogeneousMatrix &fMo)
 
void redraw ()
 
void load (const char *file_name)
 
void load (const char *iv_filename, const vpHomogeneousMatrix &fMo)
 
void save (const char *name, bool binary=false)
 
void addAbsoluteFrame (float zoom=1)
 
void addFrame (const vpHomogeneousMatrix &fMo, float zoom=1)
 
void setZoomFactor (float zoom)
 
void setCameraPosition (vpHomogeneousMatrix &cMf)
 
void getCameraPosition (vpHomogeneousMatrix &_cMf)
 
void moveInternalCamera (vpHomogeneousMatrix &cMf)
 
void setInternalCameraParameters (vpCameraParameters &cam)
 
void setExternalCameraParameters (vpCameraParameters &cam)
 
void getExternalCameraPosition (vpHomogeneousMatrix &cMf)
 
void getInternalImage (vpImage< unsigned char > &I)
 
void getInternalImage (vpImage< vpRGBa > &I)
 
void changeZoomFactor (float zoom, int index)
 
unsigned char * getBufferedOffScreenRenderer ()
 
void getSizeInternalView (int &width, int &height)
 
void getCameraParameters (vpCameraParameters &cam)
 

Public Attributes

vpImageType typeImage
 
GLubyte * image_background
 
unsigned char * bufferView
 
int get
 

Protected Member Functions

void init ()
 
void kill ()
 
void initSoApplication ()
 
void initSceneGraph ()
 
void addObject (SoSeparator *object, const vpHomogeneousMatrix &fMo, SoSeparator *root)
 
void offScreenRendering (vpSimulatorViewType view=vpSimulator::EXTERNAL, int *width=nullptr, int *height=nullptr)
 

Protected Attributes

HWND mainWindow
 
bool mainWindowInitialized
 
vpViewerinternalView
 
vpViewerexternalView
 
SbThread * mainThread
 
unsigned int internal_width
 
unsigned int internal_height
 
unsigned int external_width
 
unsigned int external_height
 
SoSeparator * scene
 
SoSeparator * internalRoot
 
SoSeparator * externalRoot
 
SoPerspectiveCamera * internalCamera
 
SoPerspectiveCamera * externalCamera
 
SoTransform * internalCameraPosition
 
SoTransform * extrenalCameraPosition
 
SoSeparator * internalCameraObject
 
float zoomFactor
 
bool cameraPositionInitialized
 
vpHomogeneousMatrix cMf
 
vpCameraParameters internalCameraParameters
 
vpCameraParameters externalCameraParameters
 
SbTime * realtime
 
SoOffscreenRenderer * offScreenRenderer
 

Detailed Description

Implementation of a simulator based on Coin3d (www.coin3d.org).

The simulator uses the vpViewer class.

Warning
This class is only available if Coin3D and one of the GUI (SoWin, SoXT, SoQt) are installed.
Examples
manSimu4Dots.cpp, manSimu4Points.cpp, simulateCircle2DCamVelocity.cpp, simulateFourPoints2DCartesianCamVelocity.cpp, and simulateFourPoints2DPolarCamVelocity.cpp.

Definition at line 94 of file vpSimulator.h.

Member Enumeration Documentation

◆ vpImageType

Enumerator
grayImage 
colorImage 

Definition at line 123 of file vpSimulator.h.

◆ vpSimulatorViewType

Enumerator
INTERNAL 
EXTERNAL 

Definition at line 263 of file vpSimulator.h.

Constructor & Destructor Documentation

◆ vpSimulator()

vpSimulator::vpSimulator ( )

constructor

Definition at line 322 of file vpSimulator.cpp.

References init().

◆ ~vpSimulator()

vpSimulator::~vpSimulator ( )
virtual

Definition at line 341 of file vpSimulator.cpp.

References kill().

Member Function Documentation

◆ addAbsoluteFrame()

void vpSimulator::addAbsoluteFrame ( float  zoom = 1)

Add the representation of the absolute frame.

Parameters
zoom: Zoom factor.
Examples
simulateCircle2DCamVelocity.cpp.

Definition at line 724 of file vpSimulator.cpp.

References scene.

◆ addFrame()

void vpSimulator::addFrame ( const vpHomogeneousMatrix fMo,
float  zoom = 1 
)

Add the representation of a frame.

Add the representation of a frame.

Parameters
fMo: desired position of the frame
zoom: Zoom factor.

Definition at line 705 of file vpSimulator.cpp.

References addObject(), and externalRoot.

◆ addObject() [1/2]

void vpSimulator::addObject ( SoSeparator *  newObject,
const vpHomogeneousMatrix fMo 
)

Add a new object in the scene graph ad a given location.

Add a new object in the scene graph.

Parameters
newObject: pointer toward the new object
fMo: position of the object wrt the reference frame

Definition at line 763 of file vpSimulator.cpp.

References addObject(), and scene.

◆ addObject() [2/2]

void vpSimulator::addObject ( SoSeparator *  object,
const vpHomogeneousMatrix fMo,
SoSeparator *  root 
)
protected

Add a new object in the scene graph ad a given location.

Add an object in a sub scene graph.

Parameters
object: pointer toward the new object
fMo: position of the object wrt the reference frame
root: pointer toward the subscene graph

Definition at line 781 of file vpSimulator.cpp.

Referenced by addFrame(), addObject(), and load().

◆ changeZoomFactor()

void vpSimulator::changeZoomFactor ( float  zoomFactor,
int  index 
)

Change the zoom factor associated to the child given by index. In order to create multiple zoom factor for multiple object to display, objects loaded the load() function, you have to know the index of the scale object associated to.

Usually, if you define the main zoom factor (for example for the frames) and then load two differents objects, You can change the zoom factor of all the objects using: changeZoomFactor(newZoom, 0)

If you want to change the zoom factor of the first object, use changeZoomFactor(newZoom, 1)

And for the second object, use changeZoomFactor(newZoom, 3)

Parameters
zoomFactor: the new zoom use to specify the apparent size of the object
index: the index of the Scale object to modify (see comments)

Definition at line 440 of file vpSimulator.cpp.

References scene, and zoomFactor.

◆ closeMainApplication()

void vpSimulator::closeMainApplication ( )

performed some thread destruction in the main program thread should be locate at the end of the main program

Examples
manSimu4Dots.cpp, manSimu4Points.cpp, simulateCircle2DCamVelocity.cpp, simulateFourPoints2DCartesianCamVelocity.cpp, and simulateFourPoints2DPolarCamVelocity.cpp.

Definition at line 854 of file vpSimulator.cpp.

◆ getBufferedOffScreenRenderer()

unsigned char* vpSimulator::getBufferedOffScreenRenderer ( )
inline

get the image corresponding to the internal view

Definition at line 282 of file vpSimulator.h.

◆ getCameraParameters()

void vpSimulator::getCameraParameters ( vpCameraParameters cam)
inline

get the intrinsic parameters of the camera

Examples
manSimu4Dots.cpp, and manSimu4Points.cpp.

Definition at line 288 of file vpSimulator.h.

◆ getCameraPosition()

void vpSimulator::getCameraPosition ( vpHomogeneousMatrix _cMf)
inline

get the camera position (from an homogeneous matrix)

Examples
simulateFourPoints2DCartesianCamVelocity.cpp, and simulateFourPoints2DPolarCamVelocity.cpp.

Definition at line 244 of file vpSimulator.h.

◆ getExternalCameraPosition()

void vpSimulator::getExternalCameraPosition ( vpHomogeneousMatrix cMf)

get the external camera position

Definition at line 543 of file vpSimulator.cpp.

References cMf, externalCamera, and vpHomogeneousMatrix::inverse().

◆ getInternalHeight()

unsigned int vpSimulator::getInternalHeight ( ) const
inline

Return the height of the internal view.

Returns
The height of the internal view.
Examples
manSimu4Dots.cpp.

Definition at line 175 of file vpSimulator.h.

Referenced by vpViewer::actualRedraw().

◆ getInternalImage() [1/2]

void vpSimulator::getInternalImage ( vpImage< unsigned char > &  I)

get an Image of the internal view

Make a copy of the current internal view

Parameters
I: destination image
Examples
manSimu4Dots.cpp.

Definition at line 994 of file vpSimulator.cpp.

References vpImage< Type >::bitmap, bufferView, get, internal_height, internal_width, vpImage< Type >::resize(), and vpImageConvert::RGBToGrey().

◆ getInternalImage() [2/2]

void vpSimulator::getInternalImage ( vpImage< vpRGBa > &  I)

get an Image of the internal view

Make a copy of the current internal view

Parameters
I: destination image

Definition at line 981 of file vpSimulator.cpp.

References vpImage< Type >::bitmap, bufferView, get, internal_height, internal_width, vpImage< Type >::resize(), and vpImageConvert::RGBToRGBa().

◆ getInternalWidth()

unsigned int vpSimulator::getInternalWidth ( ) const
inline

Return the width of the internal view.

Returns
The width of the internal view.
Examples
manSimu4Dots.cpp.

Definition at line 169 of file vpSimulator.h.

Referenced by vpViewer::actualRedraw().

◆ getSizeInternalView()

void vpSimulator::getSizeInternalView ( int &  width,
int &  height 
)

get the size of the internal view

Definition at line 969 of file vpSimulator.cpp.

References internalView.

◆ init()

◆ initApplication() [1/2]

void vpSimulator::initApplication ( void *(*)(void *)  start_routine)

begin the main program

init the main program thread

Examples
manSimu4Dots.cpp, manSimu4Points.cpp, simulateCircle2DCamVelocity.cpp, simulateFourPoints2DCartesianCamVelocity.cpp, and simulateFourPoints2DPolarCamVelocity.cpp.

Definition at line 824 of file vpSimulator.cpp.

References mainThread.

◆ initApplication() [2/2]

void vpSimulator::initApplication ( void *(*)(void *)  start_routine,
void *  data 
)

Set the function used for the simulation loop and the data to pass to this function. As the data are represented using a generic pointer, care should be taken to ensure there is no memory corruption.

Parameters
start_routine: A pointer to the function used as a main simulation loop for the simulation.
data: The data to pass to the main loop.

Definition at line 839 of file vpSimulator.cpp.

References mainThread.

◆ initExternalViewer()

◆ initInternalViewer()

◆ initMainApplication()

void vpSimulator::initMainApplication ( )

perform some initialization in the main program thread

performed some initialization in the main program thread should be locate at the beginning of the main program

Examples
manSimu4Dots.cpp, manSimu4Points.cpp, simulateCircle2DCamVelocity.cpp, simulateFourPoints2DCartesianCamVelocity.cpp, and simulateFourPoints2DPolarCamVelocity.cpp.

Definition at line 846 of file vpSimulator.cpp.

References vpTime::wait().

◆ initSceneGraph()

void vpSimulator::initSceneGraph ( )
protected

◆ initSoApplication()

void vpSimulator::initSoApplication ( )
protected

open the SoGui application

Definition at line 343 of file vpSimulator.cpp.

References mainWindow, and mainWindowInitialized.

Referenced by initExternalViewer(), and initInternalViewer().

◆ kill()

void vpSimulator::kill ( )
protected

perform some destruction

Definition at line 302 of file vpSimulator.cpp.

References bufferView, externalView, image_background, and internalView.

Referenced by vpAR::~vpAR(), and ~vpSimulator().

◆ load() [1/2]

void vpSimulator::load ( const char *  file_name)

◆ load() [2/2]

void vpSimulator::load ( const char *  iv_filename,
const vpHomogeneousMatrix fMo 
)

load an iv file, set the location of this scene

Add a new object in the scene graph.

Parameters
iv_filename: name of.iv file to load
fMo: position of the object wrt the reference frame

Definition at line 734 of file vpSimulator.cpp.

References addObject().

◆ mainLoop()

◆ moveInternalCamera()

void vpSimulator::moveInternalCamera ( vpHomogeneousMatrix cMf)

modify the position of the camera in the scene graph

Definition at line 582 of file vpSimulator.cpp.

References cMf, internalCamera, internalCameraPosition, and vpHomogeneousMatrix::inverse().

Referenced by redraw().

◆ offScreenRendering()

void vpSimulator::offScreenRendering ( vpSimulatorViewType  view = vpSimulator::EXTERNAL,
int *  width = nullptr,
int *  height = nullptr 
)
protected

Definition at line 870 of file vpSimulator.cpp.

References externalView, INTERNAL, internalView, and offScreenRenderer.

◆ redraw()

void vpSimulator::redraw ( )

display the scene (handle with care)

this function MUST NOT be called from a thread where the vpSimulator and its mainloop are not

Definition at line 614 of file vpSimulator.cpp.

References cMf, externalView, internalView, and moveInternalCamera().

◆ save()

void vpSimulator::save ( const char *  name,
bool  binary = false 
)

save the scene in an iv file

Definition at line 686 of file vpSimulator.cpp.

References scene.

◆ setCameraPosition()

void vpSimulator::setCameraPosition ( vpHomogeneousMatrix cMf)

◆ setExternalCameraParameters()

void vpSimulator::setExternalCameraParameters ( vpCameraParameters cam)

◆ setInternalCameraParameters()

◆ setZoomFactor()

void vpSimulator::setZoomFactor ( float  zoom)

set the size of the camera/frame

Define the zoom factor used to define the size of the objects (frame, camera, ...)

Parameters
zoomzoom factor of the objects. By default, 1.
Examples
simulateCircle2DCamVelocity.cpp, simulateFourPoints2DCartesianCamVelocity.cpp, and simulateFourPoints2DPolarCamVelocity.cpp.

Definition at line 406 of file vpSimulator.cpp.

References scene, and zoomFactor.

Member Data Documentation

◆ bufferView

unsigned char* vpSimulator::bufferView

image of the internal view

Definition at line 274 of file vpSimulator.h.

Referenced by vpViewer::actualRedraw(), getInternalImage(), init(), initInternalViewer(), and kill().

◆ cameraPositionInitialized

bool vpSimulator::cameraPositionInitialized
protected

Definition at line 232 of file vpSimulator.h.

Referenced by init(), and setCameraPosition().

◆ cMf

vpHomogeneousMatrix vpSimulator::cMf
protected

internal camera position

Definition at line 234 of file vpSimulator.h.

Referenced by getExternalCameraPosition(), moveInternalCamera(), redraw(), and setCameraPosition().

◆ external_height

unsigned int vpSimulator::external_height
protected

Definition at line 161 of file vpSimulator.h.

Referenced by init(), initExternalViewer(), and setExternalCameraParameters().

◆ external_width

unsigned int vpSimulator::external_width
protected

Definition at line 160 of file vpSimulator.h.

Referenced by init(), initExternalViewer(), and setExternalCameraParameters().

◆ externalCamera

SoPerspectiveCamera* vpSimulator::externalCamera
protected

external camera

Definition at line 189 of file vpSimulator.h.

Referenced by getExternalCameraPosition(), init(), initSceneGraph(), and setExternalCameraParameters().

◆ externalCameraParameters

vpCameraParameters vpSimulator::externalCameraParameters
protected

internal camera parameters

Definition at line 238 of file vpSimulator.h.

Referenced by setExternalCameraParameters().

◆ externalRoot

SoSeparator* vpSimulator::externalRoot
protected

root node of the external view

Definition at line 184 of file vpSimulator.h.

Referenced by addFrame(), init(), initExternalViewer(), and initSceneGraph().

◆ externalView

vpViewer* vpSimulator::externalView
protected

view from an external camera

Definition at line 134 of file vpSimulator.h.

Referenced by init(), initExternalViewer(), kill(), offScreenRendering(), and redraw().

◆ extrenalCameraPosition

SoTransform* vpSimulator::extrenalCameraPosition
protected

external camera position

Definition at line 195 of file vpSimulator.h.

Referenced by init().

◆ get

int vpSimulator::get

Flag to protect the read and write of the framebuffer (between the simulator and the viewer).

Definition at line 278 of file vpSimulator.h.

Referenced by vpViewer::actualRedraw(), getInternalImage(), and init().

◆ image_background

GLubyte* vpSimulator::image_background

◆ internal_height

unsigned int vpSimulator::internal_height
protected

◆ internal_width

unsigned int vpSimulator::internal_width
protected

◆ internalCamera

SoPerspectiveCamera* vpSimulator::internalCamera
protected

internal camera

Definition at line 187 of file vpSimulator.h.

Referenced by init(), initSceneGraph(), moveInternalCamera(), and setInternalCameraParameters().

◆ internalCameraObject

SoSeparator* vpSimulator::internalCameraObject
protected

representation of the camera in the external view

Definition at line 198 of file vpSimulator.h.

Referenced by init(), and initSceneGraph().

◆ internalCameraParameters

vpCameraParameters vpSimulator::internalCameraParameters
protected

internal camera parameters

Definition at line 236 of file vpSimulator.h.

Referenced by setInternalCameraParameters().

◆ internalCameraPosition

SoTransform* vpSimulator::internalCameraPosition
protected

internal camera position

Definition at line 192 of file vpSimulator.h.

Referenced by init(), initSceneGraph(), and moveInternalCamera().

◆ internalRoot

SoSeparator* vpSimulator::internalRoot
protected

root node of the internal view

Definition at line 182 of file vpSimulator.h.

Referenced by init(), initInternalViewer(), and initSceneGraph().

◆ internalView

vpViewer* vpSimulator::internalView
protected

view from the camera

Definition at line 132 of file vpSimulator.h.

Referenced by getSizeInternalView(), init(), initInternalViewer(), kill(), offScreenRendering(), and redraw().

◆ mainThread

SbThread* vpSimulator::mainThread
protected

thread with the main program

Definition at line 144 of file vpSimulator.h.

Referenced by init(), and initApplication().

◆ mainWindow

HWND vpSimulator::mainWindow
protected

main Widget

Definition at line 110 of file vpSimulator.h.

Referenced by init(), initExternalViewer(), initInternalViewer(), and initSoApplication().

◆ mainWindowInitialized

bool vpSimulator::mainWindowInitialized
protected

◆ offScreenRenderer

SoOffscreenRenderer* vpSimulator::offScreenRenderer
protected

Definition at line 269 of file vpSimulator.h.

Referenced by init(), and offScreenRendering().

◆ realtime

SbTime* vpSimulator::realtime
protected

Definition at line 268 of file vpSimulator.h.

Referenced by init(), and initSceneGraph().

◆ scene

SoSeparator* vpSimulator::scene
protected

root node of the scene : contains everything except stuff specific to each view

Definition at line 180 of file vpSimulator.h.

Referenced by addAbsoluteFrame(), addObject(), changeZoomFactor(), init(), initSceneGraph(), load(), save(), and setZoomFactor().

◆ typeImage

vpImageType vpSimulator::typeImage

Definition at line 124 of file vpSimulator.h.

Referenced by vpViewer::actualRedraw(), init(), and vpAR::initInternalViewer().

◆ zoomFactor

float vpSimulator::zoomFactor
protected

Definition at line 228 of file vpSimulator.h.

Referenced by changeZoomFactor(), init(), initSceneGraph(), load(), and setZoomFactor().