Visual Servoing Platform version 3.7.0
Loading...
Searching...
No Matches
testVideoDeviceDual.cpp
1/*
2 * ViSP, open source Visual Servoing Platform software.
3 * Copyright (C) 2005 - 2025 by Inria. All rights reserved.
4 *
5 * This software is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 * See the file LICENSE.txt at the root directory of this source
10 * distribution for additional information about the GNU GPL.
11 *
12 * For using ViSP with software that can not be combined with the GNU
13 * GPL, please contact Inria about acquiring a ViSP Professional
14 * Edition License.
15 *
16 * See https://visp.inria.fr for more information.
17 *
18 * This software was developed at:
19 * Inria Rennes - Bretagne Atlantique
20 * Campus Universitaire de Beaulieu
21 * 35042 Rennes Cedex
22 * France
23 *
24 * If you have questions regarding the use of this file, please contact
25 * Inria at visp@inria.fr
26 *
27 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
28 * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
29 *
30 * Description:
31 * Test for image display.
32 */
33
34#include <iostream>
35#include <stdlib.h>
36#include <visp3/core/vpConfig.h>
37#include <visp3/core/vpDebug.h>
38#include <visp3/core/vpDisplay.h>
39#include <visp3/core/vpImage.h>
40#include <visp3/gui/vpDisplayD3D.h>
41#include <visp3/gui/vpDisplayGDI.h>
42#include <visp3/gui/vpDisplayGTK.h>
43#include <visp3/gui/vpDisplayOpenCV.h>
44#include <visp3/gui/vpDisplayX.h>
45#include <visp3/io/vpParseArgv.h>
46#if (defined(VISP_HAVE_GTK) || defined(VISP_HAVE_X11) || defined(VISP_HAVE_GDI) || defined(VISP_HAVE_D3D9) || \
47 defined(VISP_HAVE_OPENCV))
48
55
56// List of allowed command line options
57#define GETOPTARGS "hlt:dc"
58
59#ifdef ENABLE_VISP_NAMESPACE
60using namespace VISP_NAMESPACE_NAME;
61#endif
62
63typedef enum
64{
65 vpX11,
66 vpGTK,
67 vpGDI,
68 vpD3D,
69 vpCV
70} vpDisplayType;
71
72void usage(const char *name, const char *badparam, vpDisplayType &dtype);
73bool getOptions(int argc, const char **argv, vpDisplayType &dtype, bool &list, bool &click_allowed, bool &display);
74
84void usage(const char *name, const char *badparam, vpDisplayType &dtype)
85{
86 fprintf(stdout, "\n\
87Test to open video devices or display.\n\
88\n\
89SYNOPSIS\n\
90 %s [-t <type of video device>] [-l] [-c] [-d] [-h]\n\
91",
92name);
93
94 std::string display;
95 switch (dtype) {
96 case vpX11:
97 display = "X11";
98 break;
99 case vpGTK:
100 display = "GTK";
101 break;
102 case vpGDI:
103 display = "GDI";
104 break;
105 case vpD3D:
106 display = "D3D";
107 break;
108 case vpCV:
109 display = "CV";
110 break;
111 }
112
113 fprintf(stdout, "\n\
114OPTIONS: Default\n\
115 -t <type of video device> \"%s\"\n\
116 String specifying the video device to use.\n\
117 Possible values:\n\
118 \"X11\": only on UNIX platforms,\n\
119 \"GTK\": on all plaforms,\n\
120 \"GDI\": only on Windows platform (Graphics Device Interface),\n\
121 \"D3D\": only on Windows platform (Direct3D).\n\
122 \"CV\" : (OpenCV).\n\
123\n\
124 -c\n\
125 Disable the mouse click. Useful to automate the \n\
126 execution of this program without human intervention.\n\
127\n\
128 -d \n\
129 Turn off the display.\n\
130\n\
131 -l\n\
132 Print the list of video-devices available and exit.\n\
133\n\
134 -h\n\
135 Print the help.\n\n",
136 display.c_str());
137
138 if (badparam)
139 fprintf(stdout, "\nERROR: Bad parameter [%s]\n", badparam);
140}
141
155bool getOptions(int argc, const char **argv, vpDisplayType &dtype, bool &list, bool &click_allowed, bool &display)
156{
157 const char *optarg_;
158 int c;
159 std::string sDisplayType;
160 while ((c = vpParseArgv::parse(argc, argv, GETOPTARGS, &optarg_)) > 1) {
161
162 switch (c) {
163 case 'l':
164 list = true;
165 break;
166 case 't':
167 sDisplayType = optarg_;
168 // Parse the display type option
169 if (sDisplayType.compare("X11") == 0) {
170 dtype = vpX11;
171 }
172 else if (sDisplayType.compare("GTK") == 0) {
173 dtype = vpGTK;
174 }
175 else if (sDisplayType.compare("GDI") == 0) {
176 dtype = vpGDI;
177 }
178 else if (sDisplayType.compare("D3D") == 0) {
179 dtype = vpD3D;
180 }
181 else if (sDisplayType.compare("CV") == 0) {
182 dtype = vpCV;
183 }
184
185 break;
186 case 'h':
187 usage(argv[0], nullptr, dtype);
188 return false;
189 case 'c':
190 click_allowed = false;
191 break;
192 case 'd':
193 display = false;
194 break;
195
196 default:
197 usage(argv[0], optarg_, dtype);
198 return false;
199 }
200 }
201
202 if ((c == 1) || (c == -1)) {
203 // standalone param or error
204 usage(argv[0], nullptr, dtype);
205 std::cerr << "ERROR: " << std::endl;
206 std::cerr << " Bad argument " << optarg_ << std::endl << std::endl;
207 return false;
208 }
209
210 return true;
211}
212
213int main(int argc, const char **argv)
214{
215 try {
216 bool opt_list = false; // To print the list of video devices
217 vpDisplayType opt_dtype; // Type of display to use
218 bool opt_click_allowed = true;
219 bool opt_display = true;
220
221// Default display is one available
222#if defined(VISP_HAVE_GTK)
223 opt_dtype = vpGTK;
224#elif defined(VISP_HAVE_X11)
225 opt_dtype = vpX11;
226#elif defined(VISP_HAVE_GDI)
227 opt_dtype = vpGDI;
228#elif defined(VISP_HAVE_D3D9)
229 opt_dtype = vpD3D;
230#elif defined VISP_HAVE_OPENCV
231 opt_dtype = vpCV;
232#endif
233
234 // Read the command line options
235 if (getOptions(argc, argv, opt_dtype, opt_list, opt_click_allowed, opt_display) == false) {
236 return EXIT_FAILURE;
237 }
238
239 // Print the list of video-devices available
240 if (opt_list) {
241 unsigned nbDevices = 0;
242 std::cout << "List of video-devices available: \n";
243#if defined(VISP_HAVE_GTK)
244 std::cout << " GTK (use \"-t GTK\" option to use it)\n";
245 nbDevices++;
246#endif
247#if defined(VISP_HAVE_X11)
248 std::cout << " X11 (use \"-t X11\" option to use it)\n";
249 nbDevices++;
250#endif
251#if defined(VISP_HAVE_GDI)
252
253 std::cout << " GDI (use \"-t GDI\" option to use it)\n";
254 nbDevices++;
255#endif
256#if defined(VISP_HAVE_D3D9)
257 std::cout << " D3D (use \"-t D3D\" option to use it)\n";
258 nbDevices++;
259#endif
260#if defined VISP_HAVE_OPENCV
261 std::cout << " CV (use \"-t CV\" option to use it)\n";
262 nbDevices++;
263#endif
264 if (!nbDevices) {
265 std::cout << " No display is available\n";
266 }
267 return EXIT_FAILURE;
268 }
269
270 // Create 2 images
271 vpImage<unsigned char> I1(240, 320), I2(240, 320);
272 I1 = 128;
273 I2 = 255;
274
275 // Create 2 display
276 vpDisplay *d1 = nullptr, *d2 = nullptr;
277
278 // Initialize the displays
279 switch (opt_dtype) {
280 case vpX11:
281 std::cout << "Requested X11 display functionalities..." << std::endl;
282#if defined(VISP_HAVE_X11)
283 d1 = new vpDisplayX;
284 d2 = new vpDisplayX;
285 break;
286#else
287 std::cout << " Sorry, X11 video device is not available.\n";
288 std::cout << "Use \"" << argv[0] << " -l\" to print the list of available devices.\n";
289 return EXIT_FAILURE;
290#endif
291 case vpGTK:
292 std::cout << "Requested GTK display functionalities..." << std::endl;
293#if defined(VISP_HAVE_GTK)
294 d1 = new vpDisplayGTK;
295 d2 = new vpDisplayGTK;
296 break;
297#else
298 std::cout << " Sorry, GTK video device is not available.\n";
299 std::cout << "Use \"" << argv[0] << " -l\" to print the list of available devices.\n";
300 return EXIT_FAILURE;
301#endif
302 case vpGDI:
303 std::cout << "Requested GDI display functionalities..." << std::endl;
304#if defined(VISP_HAVE_GDI)
305 d1 = new vpDisplayGDI;
306 d2 = new vpDisplayGDI;
307 break;
308#else
309 std::cout << " Sorry, GDI video device is not available.\n";
310 std::cout << "Use \"" << argv[0] << " -l\" to print the list of available devices.\n";
311 return EXIT_FAILURE;
312#endif
313 case vpD3D:
314 std::cout << "Requested D3D display functionalities..." << std::endl;
315#if defined(VISP_HAVE_D3D9)
316 d1 = new vpDisplayD3D;
317 d2 = new vpDisplayD3D;
318 break;
319#else
320 std::cout << " Sorry, D3D video device is not available.\n";
321 std::cout << "Use \"" << argv[0] << " -l\" to print the list of available devices.\n";
322 return EXIT_FAILURE;
323#endif
324 case vpCV:
325 std::cout << "Requested OpenCV display functionalities..." << std::endl;
326#if defined(HAVE_OPENCV_HIGHGUI)
327 d1 = new vpDisplayOpenCV;
328 d2 = new vpDisplayOpenCV;
329 break;
330#else
331 std::cout << " Sorry, OpenCV video device is not available.\n";
332 std::cout << "Use \"" << argv[0] << " -l\" to print the list of available devices.\n";
333 return EXIT_FAILURE;
334#endif
335 }
336
337 if (opt_display) {
338 int winx1 = 100, winy1 = 200;
339 d1->init(I1, winx1, winy1, "Display 1");
340
341 int winx2 = winx1 + 10 + static_cast<int>(I1.getWidth()), winy2 = winy1;
342 d2->init(I2, winx2, winy2, "Display 2");
343
346
349 }
350
351 std::cout << "A click in display 1 to exit..." << std::endl;
352 if (opt_click_allowed)
354
355 delete d1;
356 delete d2;
357 return EXIT_SUCCESS;
358 }
359 catch (const vpException &e) {
360 std::cout << "Catch an exception: " << e << std::endl;
361 return EXIT_FAILURE;
362 }
363}
364
365#else
366int main() { vpERROR_TRACE("You do not have display functionalities..."); }
367
368#endif
Display for windows using Direct3D 3rd party. Thus to enable this class Direct3D should be installed....
Display for windows using GDI (available on any windows 32 platform).
The vpDisplayGTK allows to display image using the GTK 3rd party library. Thus to enable this class G...
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:135
Class that defines generic functionalities for display.
Definition vpDisplay.h:171
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)
error that can be emitted by ViSP classes.
Definition vpException.h:60
Definition of the vpImage class member functions.
Definition vpImage.h:131
static bool parse(int *argcPtr, const char **argv, vpArgvInfo *argTable, int flags)
#define vpERROR_TRACE
Definition vpDebug.h:423