Visual Servoing Platform  version 3.0.1
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
testDisplayRoi.cpp
1 /****************************************************************************
2  *
3  * This file is part of the ViSP software.
4  * Copyright (C) 2005 - 2017 by Inria. All rights reserved.
5  *
6  * This software is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * ("GPL") version 2 as published by the Free Software Foundation.
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 http://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 roi display.
32  *
33  * Authors:
34  * Fabien Spindler
35  *
36  *****************************************************************************/
37 
45 #include <stdlib.h>
46 
47 #include <visp3/core/vpImage.h>
48 #include <visp3/gui/vpDisplayX.h>
49 #include <visp3/gui/vpDisplayGTK.h>
50 #include <visp3/gui/vpDisplayGDI.h>
51 #include <visp3/gui/vpDisplayD3D.h>
52 #include <visp3/gui/vpDisplayOpenCV.h>
53 #include <visp3/io/vpParseArgv.h>
54 #include <visp3/core/vpRect.h>
55 
56 // List of allowed command line options
57 #define GETOPTARGS "cdh"
58 
59 void usage(const char *name, const char *badparam);
60 bool getOptions(int argc, const char **argv, bool &click_allowed, bool &display);
61 
70 void usage(const char *name, const char *badparam)
71 {
72  fprintf(stdout, "\n\
73 Read an image on the disk, display it using X11, display some\n\
74 features (line, circle, caracters) in overlay and finaly write \n\
75 the image and the overlayed features in an image on the disk.\n\
76 \n\
77 SYNOPSIS\n\
78  %s [-c] [-d] [-h]\n", name);
79 
80  fprintf(stdout, "\n\
81 OPTIONS: Default\n\
82  -c\n\
83  Disable the mouse click. Useful to automate the \n\
84  execution of this program without humain intervention.\n\
85 \n\
86  -d \n\
87  Disable the image display. This can be useful \n\
88  for automatic tests using crontab under Unix or \n\
89  using the task manager under Windows.\n\
90 \n\
91  -h\n\
92  Print the help.\n\n");
93 
94  if (badparam) {
95  fprintf(stderr, "ERROR: \n" );
96  fprintf(stderr, "\nBad parameter [%s]\n", badparam);
97  }
98 
99 }
100 
116 bool getOptions(int argc, const char **argv, bool &click_allowed, bool &display)
117 {
118  const char *optarg_;
119  int c;
120  while ((c = vpParseArgv::parse(argc, argv, GETOPTARGS, &optarg_)) > 1) {
121 
122  switch (c) {
123  case 'c': click_allowed = false; break;
124  case 'd': display = false; break;
125  case 'h': usage(argv[0], NULL); return false; break;
126 
127  default:
128  usage(argv[0], optarg_); return false; break;
129  }
130  }
131 
132  if ((c == 1) || (c == -1)) {
133  // standalone param or error
134  usage(argv[0], NULL);
135  std::cerr << "ERROR: " << std::endl;
136  std::cerr << " Bad argument " << optarg_ << std::endl << std::endl;
137  return false;
138  }
139 
140  return true;
141 }
142 
143 int main(int argc, const char ** argv)
144 {
145 #ifdef VISP_HAVE_DISPLAY
146  bool opt_click_allowed = true;
147  bool opt_display = true;
148 
149  // Read the command line options
150  if (getOptions(argc, argv, opt_click_allowed, opt_display) == false) {
151  exit (-1);
152  }
153 
154  if (opt_display) {
155 
156  vpImage<unsigned char> I(480,640,255);
157 
158 #if defined(VISP_HAVE_X11)
159  vpDisplayX d;
160 #elif defined(VISP_HAVE_GTK)
161  vpDisplayGTK d;
162 #elif defined(VISP_HAVE_GDI)
163  vpDisplayGDI d;
164 #elif defined(VISP_HAVE_D3D9)
165  vpDisplayD3D d;
166 #elif defined(VISP_HAVE_OPENCV)
167  vpDisplayOpenCV d;
168 #endif
169  d.init(I);
171  vpDisplay::flush(I);
172 
173  I = 0;
174 
175  vpRect roi(I.getWidth()/4, I.getHeight()/4, I.getWidth()/2, I.getHeight()/2);
177  vpDisplay::flush(I);
178  if (opt_click_allowed) {
179  std::cout << "A click in the image to continue..." << std::endl;
181  }
182  vpDisplay::close(I);
183 
184  vpImage<vpRGBa> C(480,640,vpRGBa(255,0,0,0));
185 
186  //vpDisplayX d;
187  d.init(C);
189  vpDisplay::flush(C);
190 
191  C = vpRGBa(0,255,0,0);
192 
195  if (opt_click_allowed) {
196  std::cout << "A click in the image to exit..." << std::endl;
198  }
199  }
200 #else
201  (void)argc;
202  (void)argv;
203 #endif
204  return 0;
205 }
static bool getClick(const vpImage< unsigned char > &I, bool blocking=true)
static void close(vpImage< unsigned char > &I)
unsigned int getWidth() const
Definition: vpImage.h:226
Display for windows using GDI (available on any windows 32 platform).
Definition: vpDisplayGDI.h:128
Use the X11 console to display images on unix-like OS. Thus to enable this class X11 should be instal...
Definition: vpDisplayX.h:153
void init(vpImage< unsigned char > &I, int winx=-1, int winy=-1, const std::string &title="")
static void flush(const vpImage< unsigned char > &I)
static bool parse(int *argcPtr, const char **argv, vpArgvInfo *argTable, int flags)
Definition: vpParseArgv.cpp:76
Definition: vpRGBa.h:66
Display for windows using Direct3D 3rd party. Thus to enable this class Direct3D should be installed...
Definition: vpDisplayD3D.h:107
static void display(const vpImage< unsigned char > &I)
The vpDisplayOpenCV allows to display image using the OpenCV library. Thus to enable this class OpenC...
The vpDisplayGTK allows to display image using the GTK 3rd party library. Thus to enable this class G...
Definition: vpDisplayGTK.h:138
unsigned int getHeight() const
Definition: vpImage.h:175
Defines a rectangle in the plane.
Definition: vpRect.h:82
static void flushROI(const vpImage< unsigned char > &I, const vpRect &roi)
static void displayROI(const vpImage< unsigned char > &I, const vpRect &roi)