Visual Servoing Platform  version 3.6.1 under development (2024-04-27)
wireframeSimulator.cpp

Demonstration of the wireframe simulator.

/****************************************************************************
*
* ViSP, open source Visual Servoing Platform software.
* Copyright (C) 2005 - 2023 by Inria. All rights reserved.
*
* This software is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
* See the file LICENSE.txt at the root directory of this source
* distribution for additional information about the GNU GPL.
*
* For using ViSP with software that can not be combined with the GNU
* GPL, please contact Inria about acquiring a ViSP Professional
* Edition License.
*
* See https://visp.inria.fr for more information.
*
* This software was developed at:
* Inria Rennes - Bretagne Atlantique
* Campus Universitaire de Beaulieu
* 35042 Rennes Cedex
* France
*
* If you have questions regarding the use of this file, please contact
* Inria at visp@inria.fr
*
* This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
* WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* Description:
* Demonstration of the wireframe simulator
*
*****************************************************************************/
#include <stdlib.h>
#include <visp3/core/vpCameraParameters.h>
#include <visp3/core/vpHomogeneousMatrix.h>
#include <visp3/core/vpImage.h>
#include <visp3/core/vpIoTools.h>
#include <visp3/core/vpMath.h>
#include <visp3/gui/vpDisplayD3D.h>
#include <visp3/gui/vpDisplayGDI.h>
#include <visp3/gui/vpDisplayGTK.h>
#include <visp3/gui/vpDisplayOpenCV.h>
#include <visp3/gui/vpDisplayX.h>
#include <visp3/io/vpImageIo.h>
#include <visp3/io/vpParseArgv.h>
#include <visp3/robot/vpWireFrameSimulator.h>
#define GETOPTARGS "cdh"
#ifdef VISP_HAVE_DISPLAY
void usage(const char *name, const char *badparam);
bool getOptions(int argc, const char **argv, bool &display, bool &click);
void usage(const char *name, const char *badparam)
{
fprintf(stdout, "\n\
Demonstration of the wireframe simulator.\n\
\n\
The goal of this example is to present the basic functionalities of the wire frame simulator.\n\
\n\
SYNOPSIS\n\
%s [-c] [-d] [-h]\n",
name);
fprintf(stdout, "\n\
OPTIONS: Default\n\
-c \n\
Disable mouse click.\n\
\n\
-d \n\
Turn off the display.\n\
\n\
-h\n\
Print the help.\n");
if (badparam)
fprintf(stdout, "\nERROR: Bad parameter [%s]\n", badparam);
}
bool getOptions(int argc, const char **argv, bool &display, bool &click)
{
const char *optarg_;
int c;
while ((c = vpParseArgv::parse(argc, argv, GETOPTARGS, &optarg_)) > 1) {
switch (c) {
case 'c':
click = false;
break;
case 'd':
display = false;
break;
case 'h':
usage(argv[0], nullptr);
return false;
break;
default:
usage(argv[0], optarg_);
return false;
break;
}
}
if ((c == 1) || (c == -1)) {
// standalone param or error
usage(argv[0], nullptr);
std::cerr << "ERROR: " << std::endl;
std::cerr << " Bad argument " << optarg_ << std::endl << std::endl;
return false;
}
return true;
}
int main(int argc, const char **argv)
{
try {
bool opt_display = true;
bool opt_click = true;
// Read the command line options
if (getOptions(argc, argv, opt_display, opt_click) == false) {
return EXIT_FAILURE;
}
/*
Three vpImage are created : one for the main camera and the others
for two external cameras
*/
vpImage<vpRGBa> Iint(480, 640, 255);
vpImage<vpRGBa> Iext1(480, 640, 255);
vpImage<vpRGBa> Iext2(480, 640, 255);
/*
Create a display for each different cameras.
*/
#if defined(VISP_HAVE_X11)
#elif defined(HAVE_OPENCV_HIGHGUI)
#elif defined(VISP_HAVE_GDI)
#elif defined(VISP_HAVE_D3D9)
#elif defined(VISP_HAVE_GTK)
#endif
if (opt_display) {
// Display size is automatically defined by the image (I) size
display[0].init(Iint, 100, 100, "The internal view");
display[1].init(Iext1, 100, 100, "The first external view");
display[2].init(Iext2, 100, 100, "The second external view");
}
// The homogeneous matrix which gives the current position of the main
// camera relative to the object
vpHomogeneousMatrix cMo(0, 0.05, 1.3, vpMath::rad(15), vpMath::rad(25), 0);
// The homogeneous matrix which gives the desired position of the main
// camera relative to the object
// Declaration of the simulator
/*
Set the scene. It enables to choose the shape of the object and the shape
of the desired object which is displayed in the main camera view. It
exists several objects in ViSP. See the html documentation of the
simulator class to have the complete list.
Note : if you don't want to have a desired object displayed in the main
camera view you can use the initObject Method.
Here the object is a plate with 4 points and it is the same object which
is used to display the object at the desired position.
*/
/*
The object at the current position will be displayed in blue
The object at the desired position will be displayed in red
The camera will be display in green
*/
/*
Set the position of the object frame in the current and desired camera frame
*/
/*
Set the main external camera's position relative to the world reference
frame. More information about the different frames are given in the html
documentation.
*/
/*
Set the parameters of the cameras (internal and external)
*/
vpCameraParameters camera(1000, 1000, 320, 240);
vpHomogeneousMatrix camoMw(vpHomogeneousMatrix(-0.3, 0.2, 2.5, vpMath::rad(0), vpMath::rad(10), 0));
if (opt_display) {
// Get the view of the internal camera
sim.getInternalImage(Iint);
// Get the view of the main external camera
sim.getExternalImage(Iext1);
// Get the view of an external camera that you can positionned thanks
// to a vpHomogeneousMatrix which describes the position of the world reference frame in the camera frame
sim.getExternalImage(Iext2, camoMw);
// Display the views.
}
std::cout << std::endl;
std::cout << "Here are presented the effect of the basic functions of "
"the simulator"
<< std::endl;
std::cout << std::endl;
if (opt_display) {
if (opt_click) {
std::cout << "Click on the internal view window to continue. the "
"object will move. The external cameras are fixed. The "
"main camera moves too because the homogeneous matrix "
"cMo didn't change."
<< std::endl;
}
}
/*
To move the object you have to define a vpHomogeneousMatrix which gives
the position of the object relative to the world refrenece frame.
*/
vpHomogeneousMatrix mov(0.05, 0.05, 0.2, vpMath::rad(10), 0, 0);
sim.set_fMo(mov);
if (opt_display) {
// Get the view of the internal camera
sim.getInternalImage(Iint);
// Get the view of the main external camera
sim.getExternalImage(Iext1);
// Get the view of an external camera that you can positionned thanks
// to a vpHomogeneousMatrix which describes the position of the world reference frame in the camera frame
sim.getExternalImage(Iext2, camoMw);
// Display the views.
}
std::cout << std::endl;
if (opt_display) {
if (opt_click) {
std::cout << "Click on the internal view window to continue" << std::endl;
}
}
std::cout << std::endl;
std::cout << "Now you can move the main external camera. Click inside "
"the corresponding window with one of the three buttons of "
"your mouse and move the pointer."
<< std::endl;
std::cout << std::endl;
std::cout << "Click on the internal view window when you are finished" << std::endl;
/*
To move the main external camera you need a loop containing the
getExternalImage method. This functionnality is only available for the
main external camera.
*/
if (opt_display && opt_click) {
while (!vpDisplay::getClick(Iint, false)) {
sim.getExternalImage(Iext1);
}
}
std::cout << std::endl;
std::cout << "You have seen the main capabilities of the simulator. "
"Other specific functionalities are available. Please "
"refers to the html documentation to access the list of all "
"functions"
<< std::endl;
return EXIT_SUCCESS;
} catch (const vpException &e) {
std::cout << "Catch an exception: " << e << std::endl;
return EXIT_SUCCESS;
}
}
#else
int main()
{
std::cout << "You do not have X11, or GDI (Graphical Device Interface), or GTK functionalities to display images..."
<< std::endl;
std::cout << "Tip if you are on a unix-like system:" << std::endl;
std::cout << "- Install X11, configure again ViSP using cmake and build again this example" << std::endl;
std::cout << "Tip if you are on a windows-like system:" << std::endl;
std::cout << "- Install GDI, configure again ViSP using cmake and build again this example" << std::endl;
return EXIT_SUCCESS;
}
#endif
Generic class defining intrinsic camera parameters.
static const vpColor red
Definition: vpColor.h:211
static const vpColor blue
Definition: vpColor.h:217
static const vpColor green
Definition: vpColor.h:214
Display for windows using Direct3D 3rd party. Thus to enable this class Direct3D should be installed....
Definition: vpDisplayD3D.h:101
Display for windows using GDI (available on any windows 32 platform).
Definition: vpDisplayGDI.h:128
The vpDisplayGTK allows to display image using the GTK 3rd party library. Thus to enable this class G...
Definition: vpDisplayGTK.h:128
The vpDisplayOpenCV allows to display image using the OpenCV library. Thus to enable this class OpenC...
Use the X11 console to display images on unix-like OS. Thus to enable this class X11 should be instal...
Definition: vpDisplayX.h:128
static bool getClick(const vpImage< unsigned char > &I, bool blocking=true)
static void display(const vpImage< unsigned char > &I)
static void flush(const vpImage< unsigned char > &I)
static void setWindowPosition(const vpImage< unsigned char > &I, int winx, int winy)
error that can be emitted by ViSP classes.
Definition: vpException.h:59
Implementation of an homogeneous matrix and operations on such kind of matrices.
static double rad(double deg)
Definition: vpMath.h:127
static bool parse(int *argcPtr, const char **argv, vpArgvInfo *argTable, int flags)
Definition: vpParseArgv.cpp:69
Implementation of a wire frame simulator. Compared to the vpSimulator class, it does not require thir...
void setCameraPositionRelObj(const vpHomogeneousMatrix &cMo_)
void getInternalImage(vpImage< unsigned char > &I)
void initScene(const vpSceneObject &obj, const vpSceneDesiredObject &desiredObject)
void setCurrentViewColor(const vpColor &col)
void setCameraColor(const vpColor &col)
void setDesiredViewColor(const vpColor &col)
void setExternalCameraPosition(const vpHomogeneousMatrix &cam_Mf)
void set_fMo(const vpHomogeneousMatrix &fMo_)
void setDesiredCameraPosition(const vpHomogeneousMatrix &cdMo_)
void setInternalCameraParameters(const vpCameraParameters &cam)
void setExternalCameraParameters(const vpCameraParameters &cam)
void getExternalImage(vpImage< unsigned char > &I)
void display(vpImage< unsigned char > &I, const std::string &title)
Display a gray-scale image.