1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359
|
/****************************************************************************
*
* 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
*
*****************************************************************************/
/*!
\example wireframeSimulator.cpp
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);
/*!
Print the program options.
\param name : Program name.
\param badparam : Bad parameter name.
*/
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);
}
/*!
Set the program options.
\param argc : Command line number of parameters.
\param argv : Array of command line parameters.
\param display : Display activation.
\param click : Activates mouse click.
\return false if the program has to be stopped, true otherwise.
*/
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], NULL);
return false;
break;
default:
usage(argv[0], optarg_);
return false;
break;
}
}
if ((c == 1) || (c == -1)) {
// standalone param or error
usage(argv[0], NULL);
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)
vpDisplayX display[3];
#elif defined(HAVE_OPENCV_HIGHGUI)
vpDisplayOpenCV display[3];
#elif defined(VISP_HAVE_GDI)
vpDisplayGDI display[3];
#elif defined(VISP_HAVE_D3D9)
vpDisplayD3D display[3];
#elif defined(VISP_HAVE_GTK)
vpDisplayGTK display[3];
#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");
vpDisplay::setWindowPosition(Iint, 0, 0);
vpDisplay::setWindowPosition(Iext1, 700, 0);
vpDisplay::setWindowPosition(Iext2, 0, 550);
vpDisplay::display(Iint);
vpDisplay::flush(Iint);
vpDisplay::display(Iext1);
vpDisplay::flush(Iext1);
vpDisplay::display(Iext2);
vpDisplay::flush(Iext2);
}
// 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
vpHomogeneousMatrix cdMo(vpHomogeneousMatrix(0.0, 0.0, 1.0, vpMath::rad(0), vpMath::rad(0), vpMath::rad(0)));
// Declaration of the simulator
vpWireFrameSimulator sim;
/*
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.
*/
sim.initScene(vpWireFrameSimulator::PLATE, vpWireFrameSimulator::D_STANDARD);
/*
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
*/
sim.setCurrentViewColor(vpColor::blue);
sim.setDesiredViewColor(vpColor::red);
sim.setCameraColor(vpColor::green);
/*
Set the position of the object frame in the current and desired camera frame
*/
sim.setCameraPositionRelObj(cMo);
sim.setDesiredCameraPosition(cdMo);
/*
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.
*/
vpHomogeneousMatrix camMw(vpHomogeneousMatrix(0.0, 0, 4.5, vpMath::rad(0), vpMath::rad(-30), 0));
sim.setExternalCameraPosition(camMw);
/*
Set the parameters of the cameras (internal and external)
*/
vpCameraParameters camera(1000, 1000, 320, 240);
sim.setInternalCameraParameters(camera);
sim.setExternalCameraParameters(camera);
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.
vpDisplay::flush(Iint);
vpDisplay::flush(Iext1);
vpDisplay::flush(Iext2);
}
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;
vpDisplay::getClick(Iint);
}
vpDisplay::display(Iint);
vpDisplay::display(Iext1);
vpDisplay::display(Iext2);
}
/*
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.
vpDisplay::flush(Iint);
vpDisplay::flush(Iext1);
vpDisplay::flush(Iext2);
}
std::cout << std::endl;
if (opt_display) {
if (opt_click) {
std::cout << "Click on the internal view window to continue" << std::endl;
vpDisplay::getClick(Iint);
}
}
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)) {
vpDisplay::display(Iext1);
sim.getExternalImage(Iext1);
vpDisplay::flush(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
|