Visual Servoing Platform  version 3.4.0
testDisplayRoi.cpp
1 /****************************************************************************
2  *
3  * ViSP, open source Visual Servoing Platform software.
4  * Copyright (C) 2005 - 2019 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 http://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 roi display.
33  *
34  * Authors:
35  * Fabien Spindler
36  *
37  *****************************************************************************/
38 
46 #include <stdlib.h>
47 
48 #include <visp3/core/vpImage.h>
49 #include <visp3/core/vpRect.h>
50 #include <visp3/gui/vpDisplayD3D.h>
51 #include <visp3/gui/vpDisplayGDI.h>
52 #include <visp3/gui/vpDisplayGTK.h>
53 #include <visp3/gui/vpDisplayOpenCV.h>
54 #include <visp3/gui/vpDisplayX.h>
55 #include <visp3/io/vpParseArgv.h>
56 
57 // List of allowed command line options
58 #define GETOPTARGS "cdh"
59 
60 void usage(const char *name, const char *badparam);
61 bool getOptions(int argc, const char **argv, bool &click_allowed, bool &display);
62 
71 void usage(const char *name, const char *badparam)
72 {
73  fprintf(stdout, "\n\
74 Read an image on the disk, display it using X11, display some\n\
75 features (line, circle, caracters) in overlay and finaly write \n\
76 the image and the overlayed features in an image on the disk.\n\
77 \n\
78 SYNOPSIS\n\
79  %s [-c] [-d] [-h]\n", name);
80 
81  fprintf(stdout, "\n\
82 OPTIONS: Default\n\
83  -c\n\
84  Disable the mouse click. Useful to automate the \n\
85  execution of this program without humain intervention.\n\
86 \n\
87  -d \n\
88  Disable the image display. This can be useful \n\
89  for automatic tests using crontab under Unix or \n\
90  using the task manager under Windows.\n\
91 \n\
92  -h\n\
93  Print the help.\n\n");
94 
95  if (badparam) {
96  fprintf(stderr, "ERROR: \n");
97  fprintf(stderr, "\nBad parameter [%s]\n", badparam);
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':
124  click_allowed = false;
125  break;
126  case 'd':
127  display = false;
128  break;
129  case 'h':
130  usage(argv[0], NULL);
131  return false;
132  break;
133 
134  default:
135  usage(argv[0], optarg_);
136  return false;
137  break;
138  }
139  }
140 
141  if ((c == 1) || (c == -1)) {
142  // standalone param or error
143  usage(argv[0], NULL);
144  std::cerr << "ERROR: " << std::endl;
145  std::cerr << " Bad argument " << optarg_ << std::endl << std::endl;
146  return false;
147  }
148 
149  return true;
150 }
151 
152 int main(int argc, const char **argv)
153 {
154 #ifdef VISP_HAVE_DISPLAY
155  bool opt_click_allowed = true;
156  bool opt_display = true;
157 
158  // Read the command line options
159  if (getOptions(argc, argv, opt_click_allowed, opt_display) == false) {
160  exit(-1);
161  }
162 
163  if (opt_display) {
164 
165  vpImage<unsigned char> I(480, 640, 255);
166 
167 #if defined(VISP_HAVE_X11)
168  vpDisplayX d;
169 #elif defined(VISP_HAVE_GTK)
170  vpDisplayGTK d;
171 #elif defined(VISP_HAVE_GDI)
172  vpDisplayGDI d;
173 #elif defined(VISP_HAVE_D3D9)
174  vpDisplayD3D d;
175 #elif defined(VISP_HAVE_OPENCV)
176  vpDisplayOpenCV d;
177 #endif
178  d.init(I);
180  vpDisplay::flush(I);
181 
182  I = 0;
183 
184  vpRect roi(I.getWidth() / 4, I.getHeight() / 4, I.getWidth() / 2, I.getHeight() / 2);
185  vpDisplay::displayROI(I, roi);
186  vpDisplay::flush(I);
187  if (opt_click_allowed) {
188  std::cout << "A click in the image to continue..." << std::endl;
190  }
191  vpDisplay::close(I);
192 
193  vpImage<vpRGBa> C(480, 640, vpRGBa(255, 0, 0, 0));
194 
195  // vpDisplayX d;
196  d.init(C);
198  vpDisplay::flush(C);
199 
200  C = vpRGBa(0, 255, 0, 0);
201 
202  vpDisplay::displayROI(C, roi);
203  vpDisplay::flushROI(C, roi);
204  if (opt_click_allowed) {
205  std::cout << "A click in the image to exit..." << std::endl;
207  }
208  }
209 #else
210  (void)argc;
211  (void)argv;
212 #endif
213  return 0;
214 }
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:246
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:150
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:69
Definition: vpRGBa.h:66
Display for windows using Direct3D 3rd party. Thus to enable this class Direct3D should be installed...
Definition: vpDisplayD3D.h:106
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:134
unsigned int getHeight() const
Definition: vpImage.h:188
Defines a rectangle in the plane.
Definition: vpRect.h:79
static void flushROI(const vpImage< unsigned char > &I, const vpRect &roi)
static void displayROI(const vpImage< unsigned char > &I, const vpRect &roi)