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