ViSP
 All Classes Functions Variables Enumerations Enumerator Friends Groups Pages
testDisplays.cpp
1 /****************************************************************************
2  *
3  * $Id: testDisplays.cpp 4658 2014-02-09 09:50:14Z fspindle $
4  *
5  * This file is part of the ViSP software.
6  * Copyright (C) 2005 - 2014 by INRIA. All rights reserved.
7  *
8  * This software is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * ("GPL") version 2 as published by the Free Software Foundation.
11  * See the file LICENSE.txt at the root directory of this source
12  * distribution for additional information about the GNU GPL.
13  *
14  * For using ViSP with software that can not be combined with the GNU
15  * GPL, please contact INRIA about acquiring a ViSP Professional
16  * Edition License.
17  *
18  * See http://www.irisa.fr/lagadic/visp/visp.html for more information.
19  *
20  * This software was developed at:
21  * INRIA Rennes - Bretagne Atlantique
22  * Campus Universitaire de Beaulieu
23  * 35042 Rennes Cedex
24  * France
25  * http://www.irisa.fr/lagadic
26  *
27  * If you have questions regarding the use of this file, please contact
28  * INRIA at visp@inria.fr
29  *
30  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
31  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
32  *
33  *
34  * Description:
35  * Test for image display.
36  *
37  * Authors:
38  * Anthony Saunier
39  *
40  *****************************************************************************/
41 
42 #include <visp/vpConfig.h>
43 #include <visp/vpDebug.h>
44 
45 #include <stdlib.h>
46 #include <iostream>
47 #include <string>
48 
49 #if (defined (VISP_HAVE_GTK) || defined(VISP_HAVE_X11) || defined(VISP_HAVE_GDI) || defined(VISP_HAVE_D3D9) || defined(VISP_HAVE_OPENCV))
50 
51 #include <visp/vpImage.h>
52 #include <visp/vpImageIo.h>
53 #include <visp/vpParseArgv.h>
54 #include <visp/vpIoTools.h>
55 #include <visp/vpRect.h>
56 
57 #include <visp/vpDisplayOpenCV.h>
58 #include <visp/vpDisplayGTK.h>
59 #include <visp/vpDisplayX.h>
60 #include <visp/vpDisplayGDI.h>
61 #include <visp/vpDisplayD3D.h>
62 
70 // List of allowed command line options
71 #define GETOPTARGS "hl:dc"
72 
73 void usage(const char *name, const char *badparam);
74 bool getOptions(int argc, const char **argv, bool &list, bool &click_allowed, bool &display);
75 void draw(vpImage<vpRGBa> &I);
76 
85 void usage(const char *name, const char *badparam)
86 {
87  fprintf(stdout, "\n\
88 Test video devices or display.\n\
89 \n\
90 SYNOPSIS\n\
91  %s [-t <type of video device>] [-l] [-c] [-d] [-h]\n\
92 ", name);
93 
94  std::string display;
95 
96  fprintf(stdout, "\n\
97 OPTIONS: Default\n\
98  -c\n\
99  Disable the mouse click. Useful to automaze the \n\
100  execution of this program without humain intervention.\n\
101 \n\
102  -d \n\
103  Turn off the display.\n\
104 \n\
105  -l\n\
106  Print the list of video-devices available and exit.\n\
107 \n\
108  -h\n\
109  Print the help.\n\n");
110 
111  if (badparam)
112  fprintf(stdout, "\nERROR: Bad parameter [%s]\n", badparam);
113 }
114 
127 bool getOptions(int argc, const char **argv, bool &list, bool &click_allowed, bool &display)
128 {
129  const char *optarg_;
130  int c;
131  std::string sDisplayType;
132  while ((c = vpParseArgv::parse(argc, argv, GETOPTARGS, &optarg_)) > 1) {
133 
134  switch (c) {
135  case 'l': list = true; break;
136  case 'h': usage(argv[0], NULL); return false; break;
137  case 'c': click_allowed = false; break;
138  case 'd': display = false; break;
139 
140  default:
141  usage(argv[0], optarg_); return false; break;
142  }
143  }
144 
145  if ((c == 1) || (c == -1)) {
146  // standalone param or error
147  usage(argv[0], NULL);
148  std::cerr << "ERROR: " << std::endl;
149  std::cerr << " Bad argument " << optarg_ << std::endl << std::endl;
150  return false;
151  }
152 
153  return true;
154 }
155 
156 
157 void draw(vpImage<vpRGBa> &I)
158 {
159  vpImagePoint iP1, iP2;
160  unsigned int w,h;
161 
162  iP1.set_i(20);
163  iP1.set_j(10);
164  iP2.set_i(20);
165  iP2.set_j(30);
166  vpDisplay::displayArrow (I, iP1, iP2, vpColor::green, 4, 2, 3);
167 
168  iP1.set_i(20);
169  iP1.set_j(60);
170  vpDisplay::displayCharString (I, iP1, "Test...", vpColor::black);
171 
172  iP1.set_i(80);
173  iP1.set_j(220);
174  iP2.set_i(80);
175  iP2.set_j(480);
176  vpDisplay::displayCircle (I, iP1, 30, vpColor::red, false, 3);
177  vpDisplay::displayCircle (I, iP2, 30, vpColor::red, true, 3);
178 
179  iP1.set_i(20);
180  iP1.set_j(220);
181  vpDisplay::displayCross (I, iP1, 5, vpColor::blue, 1);
182 
183  iP1.set_i(140);
184  iP1.set_j(10);
185  iP2.set_i(140);
186  iP2.set_j(50);
187  vpDisplay::displayDotLine (I, iP1, iP2, vpColor::blue, 3);
188 
189  iP1.set_i(120);
190  iP1.set_j(180);
191  iP2.set_i(160);
192  iP2.set_j(250);
193  vpDisplay::displayDotLine (I, iP1, iP2, vpColor::blue, 3);
194 
195  iP1.set_i(160);
196  iP1.set_j(280);
197  iP2.set_i(120);
198  iP2.set_j(340);
199  vpDisplay::displayDotLine (I, iP1, iP2, vpColor::blue, 3);
200 
201  //static void displayFrame (const vpImage< vpRGBa > &I, const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam, double size, vpColor color)
202 
203  iP1.set_i(140);
204  iP1.set_j(80);
205  iP2.set_i(140);
206  iP2.set_j(150);
207  vpDisplay::displayLine (I, iP1, iP2, vpColor::orange, 3);
208 
209  iP1.set_i(140);
210  iP1.set_j(400);
212 
213  iP1.set_i(350);
214  iP1.set_j(20);
215  w = 60;
216  h = 50;
217  vpDisplay::displayRectangle (I, iP1, w, h, vpColor::red, false, 3);
218 
219  iP1.set_i(350);
220  iP1.set_j(110);
221  vpDisplay::displayRectangle (I, iP1, w, h, vpColor::red, true, 3);
222 
223  iP1.set_i(350);
224  iP1.set_j(200);
225  iP2.set_i(400);
226  iP2.set_j(260);
227  vpDisplay::displayRectangle (I, iP1, iP2, vpColor::orange, false, 3);
228 
229  iP1.set_i(350);
230  iP1.set_j(290);
231  iP2.set_i(400);
232  iP2.set_j(350);
233  vpRect rectangle(iP1, iP2);
234  vpDisplay::displayRectangle (I, rectangle, vpColor::yellow, false, 3);
235 
236  iP1.set_i(380);
237  iP1.set_j(400);
238  vpDisplay::displayRectangle (I, iP1, 45, w, h, vpColor::green, 3);
239 
240 
241 }
242 
243 int
244 main(int argc, const char ** argv)
245 {
246  try{
247  bool opt_list = false; // To print the list of video devices
248  bool opt_click_allowed = true;
249  bool opt_display = true;
250 
251 
252  // Read the command line options
253  if (getOptions(argc, argv, opt_list,
254  opt_click_allowed, opt_display) == false) {
255  exit (-1);
256  }
257 
258  // Print the list of video-devices available
259  if (opt_list) {
260  unsigned nbDevices = 0;
261  std::cout << "List of video-devices available: \n";
262 #if defined VISP_HAVE_GTK
263  std::cout << " GTK (use \"-t GTK\" option to use it)\n";
264  nbDevices ++;
265 #endif
266 #if defined VISP_HAVE_X11
267  std::cout << " X11 (use \"-t X11\" option to use it)\n";
268  nbDevices ++;
269 #endif
270 #if defined VISP_HAVE_GDI
271  std::cout << " GDI (use \"-t GDI\" option to use it)\n";
272  nbDevices ++;
273 #endif
274 #if defined VISP_HAVE_D3D9
275  std::cout << " D3D (use \"-t D3D\" option to use it)\n";
276  nbDevices ++;
277 #endif
278 #if defined VISP_HAVE_OPENCV
279  std::cout << " CV (use \"-t CV\" option to use it)\n";
280  nbDevices ++;
281 #endif
282  if (!nbDevices) {
283  std::cout << " No display is available\n";
284  }
285  return (0);
286  }
287 
288  // Create a grey level image
290  // Create a color image
291  vpImage<vpRGBa> Irgba;
292 
293  // Create a color image for each display.
294  vpImage<vpRGBa> Ix;
295  vpImage<vpRGBa> Igtk;
296  vpImage<vpRGBa> Icv;
297  vpImage<vpRGBa> Igdi;
298  vpImage<vpRGBa> Id3d;
299 
300 #if defined VISP_HAVE_X11
301  vpDisplayX *displayX = NULL;
302  displayX = new vpDisplayX;
303  Ix.init(480, 640, 255);
304  if (opt_display)
305  {
306  displayX->init(Ix, 100, 100,"Display X11") ;
307  vpDisplay::display(Ix) ;
308  draw(Ix);
309  vpDisplay::flush(Ix);
310  if (opt_click_allowed)
312  }
313 #endif
314 
315 #if defined VISP_HAVE_OPENCV
316  vpDisplayOpenCV *displayCv = NULL;
317  displayCv = new vpDisplayOpenCV;
318  Icv.init(480, 640, 255);
319  if (opt_display)
320  {
321  displayCv->init(Icv, 100, 100,"Display OpenCV") ;
322  vpDisplay::display(Icv) ;
323  draw(Icv);
324  vpDisplay::flush(Icv);
325  if (opt_click_allowed)
326  vpDisplay::getClick(Icv);
327  }
328 #endif
329 
330 #if defined VISP_HAVE_GTK
331  vpDisplayGTK *displayGtk = NULL;
332  displayGtk = new vpDisplayGTK;
333  Igtk.init(480, 640, 255);
334  if (opt_display)
335  {
336  displayGtk->init(Igtk, 100, 100,"Display GTK") ;
337  vpDisplay::display(Igtk) ;
338  draw(Igtk);
339  vpDisplay::flush(Igtk);
340  if (opt_click_allowed)
341  vpDisplay::getClick(Igtk);
342  }
343 #endif
344 
345 #if defined VISP_HAVE_GDI
346  vpDisplayGDI *displayGdi = NULL;
347  displayGdi = new vpDisplayGDI;
348  Igdi.init(480, 640, 255);
349  if (opt_display)
350  {
351  displayGdi->init(Igdi, 100, 100,"Display GDI") ;
352  vpDisplay::display(Igdi) ;
353  draw(Igdi);
354  vpDisplay::flush(Igdi);
355  if (opt_click_allowed)
356  vpDisplay::getClick(Igdi);
357  }
358 #endif
359 
360 #if defined VISP_HAVE_D3D9
361  vpDisplayD3D *displayD3d = NULL;
362  displayD3d = new vpDisplayD3D;
363  Id3d.init(480, 640, 255);
364  if (opt_display)
365  {
366  displayD3d->init(Id3d, 100, 100,"Display Direct 3D") ;
367  vpDisplay::display(Id3d) ;
368  draw(Id3d);
369  vpDisplay::flush(Id3d);
370  if (opt_click_allowed)
371  vpDisplay::getClick(Id3d);
372  }
373 #endif
374 
375 
376 
377 #if defined VISP_HAVE_X11
378  delete displayX;
379 #endif
380 
381 #if defined VISP_HAVE_GTK
382  delete displayGtk;
383 #endif
384 
385 #if defined VISP_HAVE_OPENCV
386  delete displayCv;
387 #endif
388 
389 #if defined VISP_HAVE_GDI
390  delete displayGdi;
391 #endif
392 
393 #if defined VISP_HAVE_D3D9
394  delete displayD3d;
395 #endif
396  }
397  catch(...) {
398  vpERROR_TRACE("Error while displaying the image") ;
399  exit(-1);
400  }
401 }
402 
403 #else
404 int
405 main()
406 {
407  vpERROR_TRACE("You do not have display functionalities...");
408 }
409 
410 #endif
virtual void displayCircle(const vpImagePoint &center, unsigned int radius, const vpColor &color, bool fill=false, unsigned int thickness=1)=0
void init(vpImage< unsigned char > &I, int winx=-1, int winy=-1, const char *title=NULL)
virtual void displayArrow(const vpImagePoint &ip1, const vpImagePoint &ip2, const vpColor &color=vpColor::white, unsigned int w=4, unsigned int h=2, unsigned int thickness=1)=0
void init(unsigned int height, unsigned int width)
set the size of the image
Definition: vpImage.h:384
#define vpERROR_TRACE
Definition: vpDebug.h:395
static const vpColor black
Definition: vpColor.h:161
Display for windows using GDI (available on any windows 32 platform).
Definition: vpDisplayGDI.h:132
Define the X11 console to display images.
Definition: vpDisplayX.h:152
void init(vpImage< unsigned char > &I, int winx=-1, int winy=-1, const char *title=NULL)
static const vpColor green
Definition: vpColor.h:170
static void flush(const vpImage< unsigned char > &I)
Definition: vpDisplay.cpp:1994
static bool parse(int *argcPtr, const char **argv, vpArgvInfo *argTable, int flags)
Definition: vpParseArgv.cpp:79
static const vpColor red
Definition: vpColor.h:167
static const vpColor orange
Definition: vpColor.h:177
Display for windows using Direct3D.
Definition: vpDisplayD3D.h:109
void set_i(const double ii)
Definition: vpImagePoint.h:158
static void display(const vpImage< unsigned char > &I)
Definition: vpDisplay.cpp:206
The vpDisplayOpenCV allows to display image using the opencv library.
virtual void displayCross(const vpImagePoint &ip, unsigned int size, const vpColor &color, unsigned int thickness=1)=0
The vpDisplayGTK allows to display image using the GTK+ library version 1.2.
Definition: vpDisplayGTK.h:145
virtual void displayRectangle(const vpImagePoint &topLeft, unsigned int width, unsigned int height, const vpColor &color, bool fill=false, unsigned int thickness=1)=0
void init(vpImage< unsigned char > &I, int winx=-1, int winy=-1, const char *title=NULL)
virtual void displayDotLine(const vpImagePoint &ip1, const vpImagePoint &ip2, const vpColor &color, unsigned int thickness=1)=0
void set_j(const double jj)
Definition: vpImagePoint.h:169
virtual void displayCharString(const vpImagePoint &ip, const char *text, const vpColor &color=vpColor::green)=0
Defines a rectangle in the plane.
Definition: vpRect.h:85
virtual bool getClick(bool blocking=true)=0
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
Definition: vpImagePoint.h:92
virtual void displayLine(const vpImagePoint &ip1, const vpImagePoint &ip2, const vpColor &color, unsigned int thickness=1)=0
void init(vpImage< unsigned char > &I, int winx=-1, int winy=-1, const char *title=NULL)
Definition: vpDisplayX.cpp:191
static const vpColor yellow
Definition: vpColor.h:175
virtual void displayPoint(const vpImagePoint &ip, const vpColor &color)=0
static const vpColor blue
Definition: vpColor.h:173