Visual Servoing Platform  version 3.6.1 under development (2024-11-15)
testDisplayRoi.cpp
1 /*
2  * ViSP, open source Visual Servoing Platform software.
3  * Copyright (C) 2005 - 2024 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 roi display.
32  */
33 
41 #include <stdlib.h>
42 
43 #include <visp3/core/vpImage.h>
44 #include <visp3/core/vpRect.h>
45 #include <visp3/gui/vpDisplayD3D.h>
46 #include <visp3/gui/vpDisplayGDI.h>
47 #include <visp3/gui/vpDisplayGTK.h>
48 #include <visp3/gui/vpDisplayOpenCV.h>
49 #include <visp3/gui/vpDisplayX.h>
50 #include <visp3/io/vpParseArgv.h>
51 
52 // List of allowed command line options
53 #define GETOPTARGS "cdh"
54 
55 #ifdef ENABLE_VISP_NAMESPACE
56 using namespace VISP_NAMESPACE_NAME;
57 #endif
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, characters) in overlay and finally 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",
79  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 human 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], nullptr);
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], nullptr);
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  return EXIT_FAILURE;
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(HAVE_OPENCV_HIGHGUI)
176  vpDisplayOpenCV d;
177 #endif
178  d.init(I);
180  vpDisplay::flush(I);
181 
182  I = 0u;
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 EXIT_SUCCESS;
214 }
Display for windows using Direct3D 3rd party. Thus to enable this class Direct3D should be installed....
Definition: vpDisplayD3D.h:106
Display for windows using GDI (available on any windows 32 platform).
Definition: vpDisplayGDI.h:130
The vpDisplayGTK allows to display image using the GTK 3rd party library. Thus to enable this class G...
Definition: vpDisplayGTK.h:133
The vpDisplayOpenCV allows to display image using the OpenCV library. Thus to enable this class OpenC...
void init(vpImage< unsigned char > &I, int winx=-1, int winy=-1, const std::string &title="") VP_OVERRIDE
static bool getClick(const vpImage< unsigned char > &I, bool blocking=true)
static void displayROI(const vpImage< unsigned char > &I, const vpRect &roi)
static void display(const vpImage< unsigned char > &I)
static void flushROI(const vpImage< unsigned char > &I, const vpRect &roi)
static void close(vpImage< unsigned char > &I)
static void flush(const vpImage< unsigned char > &I)
unsigned int getWidth() const
Definition: vpImage.h:242
unsigned int getHeight() const
Definition: vpImage.h:181
static bool parse(int *argcPtr, const char **argv, vpArgvInfo *argTable, int flags)
Definition: vpParseArgv.cpp:70
Definition: vpRGBa.h:65
Defines a rectangle in the plane.
Definition: vpRect.h:79