Visual Servoing Platform  version 3.6.1 under development (2024-11-15)
vpAR Class Reference

#include <visp3/ar/vpAR.h>

+ Inheritance diagram for vpAR:

Public Types

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

Public Member Functions

 vpAR ()
 
virtual ~vpAR ()
 
void initInternalViewer (unsigned int width, unsigned int height, vpImageType type=grayImage)
 
void setImage (vpImage< unsigned char > &I)
 
void setImage (vpImage< vpRGBa > &I)
 
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 an augmented reality viewer using Coin3D 3rd party.

Thus to be enabled this class requires Coin3D 3rd party installation. Installation instructions are provided here https://visp.inria.fr/3rd_coin.

This class can be used to display an image behind the internal view of the simulator used for augmented reality application.

Warning
This class is only available if Coin3D and one of the GUI (SoWin, SoXT, SoQt) are installed.

The code below shows how to use the class.

#include <visp3/ar/vpAR.h>
#include <visp3/core/vpCameraParameters.h>
#include <visp3/core/vpHomogeneousMatrix.h>
#include <visp3/core/vpImage.h>
#ifdef ENABLE_VISP_NAMESPACE
using namespace VISP_NAMESPACE_NAME;
#endif
#ifdef VISP_HAVE_COIN3D_AND_GUI
static void *mainloopfunction(void *_simu)
{
vpAR *simu = (vpAR *)_simu ;
//Your code to compute the pose cMo.
//Set the image to use as background.
simu->setImage(I) ;
//Set the camera position thanks to the pose cMo computed before.
simu->setCameraPosition(cMo) ;
}
#endif
int main()
{
#ifdef VISP_HAVE_COIN3D_AND_GUI
vpAR simu;
//Camera parameters.
vpCameraParameters cam(600,600,160,120);
//Initialize the internal view of the simulator.
// Load the cad model. 4points.iv can be downloaded on the website
// with the image package
simu.load("./4points.iv");
//Initialize the internal camera parameters.
simu.initApplication(&mainloopfunction);
simu.mainLoop();
#endif
return 0;
}
Implementation of an augmented reality viewer using Coin3D 3rd party.
Definition: vpAR.h:143
void setImage(vpImage< unsigned char > &I)
Definition: vpAR.cpp:105
void initInternalViewer(unsigned int width, unsigned int height, vpImageType type=grayImage)
Definition: vpAR.cpp:79
Generic class defining intrinsic camera parameters.
Implementation of an homogeneous matrix and operations on such kind of matrices.
void load(const char *file_name)
load an iv file
void setInternalCameraParameters(vpCameraParameters &cam)
set internal camera parameters
virtual void mainLoop()
activate the mainloop
void initMainApplication()
perform some initialization in the main program thread
void initApplication(void *(*start_routine)(void *))
begin the main program
void setCameraPosition(vpHomogeneousMatrix &cMf)
set the camera position (from an homogeneous matrix)
void closeMainApplication()
VISP_EXPORT int wait(double t0, double t)

Definition at line 142 of file vpAR.h.

Member Enumeration Documentation

◆ vpImageType

enum vpSimulator::vpImageType
inherited
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

◆ vpAR()

vpAR::vpAR ( )
inline

Definition at line 149 of file vpAR.h.

◆ ~vpAR()

BEGIN_VISP_NAMESPACE vpAR::~vpAR ( )
virtual

Basic Destructor that calls the kill() method of the vpSimulator class.

Definition at line 70 of file vpAR.cpp.

References vpSimulator::kill().

Member Function Documentation

◆ addAbsoluteFrame()

void vpSimulator::addAbsoluteFrame ( float  zoom = 1)
inherited

Add the representation of the absolute frame.

Parameters
zoom: Zoom factor.
Examples
simulateCircle2DCamVelocity.cpp.

Definition at line 724 of file vpSimulator.cpp.

References vpSimulator::scene.

◆ addFrame()

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

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 vpSimulator::addObject(), and vpSimulator::externalRoot.

◆ addObject() [1/2]

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

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 vpSimulator::addObject(), and vpSimulator::scene.

◆ addObject() [2/2]

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

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 vpSimulator::addFrame(), vpSimulator::addObject(), and vpSimulator::load().

◆ changeZoomFactor()

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

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 vpSimulator::scene, and vpSimulator::zoomFactor.

◆ closeMainApplication()

void vpSimulator::closeMainApplication ( )
inherited

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 ( )
inlineinherited

get the image corresponding to the internal view

Definition at line 282 of file vpSimulator.h.

◆ getCameraParameters()

void vpSimulator::getCameraParameters ( vpCameraParameters cam)
inlineinherited

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)
inlineinherited

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)
inherited

get the external camera position

Definition at line 543 of file vpSimulator.cpp.

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

◆ getInternalHeight()

unsigned int vpSimulator::getInternalHeight ( ) const
inlineinherited

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)
inherited

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, vpSimulator::bufferView, vpSimulator::get, vpSimulator::internal_height, vpSimulator::internal_width, vpImage< Type >::resize(), and vpImageConvert::RGBToGrey().

◆ getInternalImage() [2/2]

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

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, vpSimulator::bufferView, vpSimulator::get, vpSimulator::internal_height, vpSimulator::internal_width, vpImage< Type >::resize(), and vpImageConvert::RGBToRGBa().

◆ getInternalWidth()

unsigned int vpSimulator::getInternalWidth ( ) const
inlineinherited

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 
)
inherited

get the size of the internal view

Definition at line 969 of file vpSimulator.cpp.

References vpSimulator::internalView.

◆ init()

◆ initApplication() [1/2]

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

◆ initApplication() [2/2]

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

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 vpSimulator::mainThread.

◆ initExternalViewer()

◆ initInternalViewer() [1/2]

◆ initInternalViewer() [2/2]

void vpAR::initInternalViewer ( unsigned int  width,
unsigned int  height,
vpImageType  type = grayImage 
)

Initialisation of the internal view of the simulator.

Parameters
width: Width of the internal view.
height: Height of the internal view.
type: Type of background image ie gray scaled or color.

Definition at line 79 of file vpAR.cpp.

References vpSimulator::grayImage, vpSimulator::image_background, vpSimulator::initInternalViewer(), vpSimulator::internal_height, vpSimulator::internal_width, and vpSimulator::typeImage.

◆ initMainApplication()

void vpSimulator::initMainApplication ( )
inherited

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()

◆ initSoApplication()

void vpSimulator::initSoApplication ( )
protectedinherited

open the SoGui application

Definition at line 343 of file vpSimulator.cpp.

References vpSimulator::mainWindow, and vpSimulator::mainWindowInitialized.

Referenced by vpSimulator::initExternalViewer(), and vpSimulator::initInternalViewer().

◆ kill()

void vpSimulator::kill ( )
protectedinherited

◆ load() [1/2]

void vpSimulator::load ( const char *  file_name)
inherited

◆ load() [2/2]

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

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 vpSimulator::addObject().

◆ mainLoop()

◆ moveInternalCamera()

void vpSimulator::moveInternalCamera ( vpHomogeneousMatrix cMf)
inherited

modify the position of the camera in the scene graph

Definition at line 582 of file vpSimulator.cpp.

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

Referenced by vpSimulator::redraw().

◆ offScreenRendering()

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

◆ redraw()

void vpSimulator::redraw ( )
inherited

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 vpSimulator::cMf, vpSimulator::externalView, vpSimulator::internalView, and vpSimulator::moveInternalCamera().

◆ save()

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

save the scene in an iv file

Definition at line 686 of file vpSimulator.cpp.

References vpSimulator::scene.

◆ setCameraPosition()

void vpSimulator::setCameraPosition ( vpHomogeneousMatrix cMf)
inherited

◆ setExternalCameraParameters()

◆ setImage() [1/2]

void vpAR::setImage ( vpImage< unsigned char > &  I)

Set the background image and turn it to deal with the frame of OpenGL.

Parameters
I: Gray scaled image for the background.

Definition at line 105 of file vpAR.cpp.

References vpException::dimensionError, vpImage< Type >::getHeight(), vpImage< Type >::getWidth(), vpSimulator::image_background, vpSimulator::internal_height, and vpSimulator::internal_width.

◆ setImage() [2/2]

void vpAR::setImage ( vpImage< vpRGBa > &  I)

Set the background image and turn it to deal with the frame of OpenGL.

Parameters
I: Color image for the background.

Definition at line 128 of file vpAR.cpp.

References vpException::dimensionError, vpImage< Type >::getHeight(), vpImage< Type >::getWidth(), vpSimulator::image_background, vpSimulator::internal_height, and vpSimulator::internal_width.

◆ setInternalCameraParameters()

◆ setZoomFactor()

void vpSimulator::setZoomFactor ( float  zoom)
inherited

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 vpSimulator::scene, and vpSimulator::zoomFactor.

Member Data Documentation

◆ bufferView

unsigned char* vpSimulator::bufferView
inherited

◆ cameraPositionInitialized

bool vpSimulator::cameraPositionInitialized
protectedinherited

Definition at line 232 of file vpSimulator.h.

Referenced by vpSimulator::init(), and vpSimulator::setCameraPosition().

◆ cMf

vpHomogeneousMatrix vpSimulator::cMf
protectedinherited

◆ external_height

unsigned int vpSimulator::external_height
protectedinherited

◆ external_width

unsigned int vpSimulator::external_width
protectedinherited

◆ externalCamera

SoPerspectiveCamera* vpSimulator::externalCamera
protectedinherited

◆ externalCameraParameters

vpCameraParameters vpSimulator::externalCameraParameters
protectedinherited

internal camera parameters

Definition at line 238 of file vpSimulator.h.

Referenced by vpSimulator::setExternalCameraParameters().

◆ externalRoot

SoSeparator* vpSimulator::externalRoot
protectedinherited

root node of the external view

Definition at line 184 of file vpSimulator.h.

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

◆ externalView

vpViewer* vpSimulator::externalView
protectedinherited

◆ extrenalCameraPosition

SoTransform* vpSimulator::extrenalCameraPosition
protectedinherited

external camera position

Definition at line 195 of file vpSimulator.h.

Referenced by vpSimulator::init().

◆ get

int vpSimulator::get
inherited

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(), vpSimulator::getInternalImage(), and vpSimulator::init().

◆ image_background

GLubyte* vpSimulator::image_background
inherited

◆ internal_height

unsigned int vpSimulator::internal_height
protectedinherited

◆ internal_width

unsigned int vpSimulator::internal_width
protectedinherited

◆ internalCamera

SoPerspectiveCamera* vpSimulator::internalCamera
protectedinherited

◆ internalCameraObject

SoSeparator* vpSimulator::internalCameraObject
protectedinherited

representation of the camera in the external view

Definition at line 198 of file vpSimulator.h.

Referenced by vpSimulator::init(), and vpSimulator::initSceneGraph().

◆ internalCameraParameters

vpCameraParameters vpSimulator::internalCameraParameters
protectedinherited

internal camera parameters

Definition at line 236 of file vpSimulator.h.

Referenced by vpSimulator::setInternalCameraParameters().

◆ internalCameraPosition

SoTransform* vpSimulator::internalCameraPosition
protectedinherited

internal camera position

Definition at line 192 of file vpSimulator.h.

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

◆ internalRoot

SoSeparator* vpSimulator::internalRoot
protectedinherited

root node of the internal view

Definition at line 182 of file vpSimulator.h.

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

◆ internalView

vpViewer* vpSimulator::internalView
protectedinherited

◆ mainThread

SbThread* vpSimulator::mainThread
protectedinherited

thread with the main program

Definition at line 144 of file vpSimulator.h.

Referenced by vpSimulator::init(), and vpSimulator::initApplication().

◆ mainWindow

HWND vpSimulator::mainWindow
protectedinherited

◆ mainWindowInitialized

bool vpSimulator::mainWindowInitialized
protectedinherited

◆ offScreenRenderer

SoOffscreenRenderer* vpSimulator::offScreenRenderer
protectedinherited

Definition at line 269 of file vpSimulator.h.

Referenced by vpSimulator::init(), and vpSimulator::offScreenRendering().

◆ realtime

SbTime* vpSimulator::realtime
protectedinherited

Definition at line 268 of file vpSimulator.h.

Referenced by vpSimulator::init(), and vpSimulator::initSceneGraph().

◆ scene

SoSeparator* vpSimulator::scene
protectedinherited

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

Definition at line 180 of file vpSimulator.h.

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

◆ typeImage

vpImageType vpSimulator::typeImage
inherited

Definition at line 124 of file vpSimulator.h.

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

◆ zoomFactor

float vpSimulator::zoomFactor
protectedinherited