Visual Servoing Platform version 3.7.0
Loading...
Searching...
No Matches
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
40
41#include <stdlib.h>
42
43#include <visp3/core/vpImage.h>
44#include <visp3/core/vpRect.h>
45#include <visp3/gui/vpDisplayFactory.h>
46#include <visp3/io/vpParseArgv.h>
47
48// List of allowed command line options
49#define GETOPTARGS "cdh"
50
51#ifdef ENABLE_VISP_NAMESPACE
52using namespace VISP_NAMESPACE_NAME;
53#endif
54
55void usage(const char *name, const char *badparam);
56bool getOptions(int argc, const char **argv, bool &click_allowed, bool &display);
57
66void usage(const char *name, const char *badparam)
67{
68 fprintf(stdout, "\n\
69Read an image on the disk, display it using X11, display some\n\
70features (line, circle, characters) in overlay and finally write \n\
71the image and the overlayed features in an image on the disk.\n\
72\n\
73SYNOPSIS\n\
74 %s [-c] [-d] [-h]\n",
75 name);
76
77 fprintf(stdout, "\n\
78OPTIONS: Default\n\
79 -c\n\
80 Disable the mouse click. Useful to automate the \n\
81 execution of this program without human intervention.\n\
82\n\
83 -d \n\
84 Disable the image display. This can be useful \n\
85 for automatic tests using crontab under Unix or \n\
86 using the task manager under Windows.\n\
87\n\
88 -h\n\
89 Print the help.\n\n");
90
91 if (badparam) {
92 fprintf(stderr, "ERROR: \n");
93 fprintf(stderr, "\nBad parameter [%s]\n", badparam);
94 }
95}
96
112bool getOptions(int argc, const char **argv, bool &click_allowed, bool &display)
113{
114 const char *optarg_;
115 int c;
116 while ((c = vpParseArgv::parse(argc, argv, GETOPTARGS, &optarg_)) > 1) {
117
118 switch (c) {
119 case 'c':
120 click_allowed = false;
121 break;
122 case 'd':
123 display = false;
124 break;
125 case 'h':
126 usage(argv[0], nullptr);
127 return false;
128
129 default:
130 usage(argv[0], optarg_);
131 return false;
132 }
133 }
134
135 if ((c == 1) || (c == -1)) {
136 // standalone param or error
137 usage(argv[0], nullptr);
138 std::cerr << "ERROR: " << std::endl;
139 std::cerr << " Bad argument " << optarg_ << std::endl << std::endl;
140 return false;
141 }
142
143 return true;
144}
145
146int main(int argc, const char **argv)
147{
148#ifdef VISP_HAVE_DISPLAY
149 bool opt_click_allowed = true;
150 bool opt_display = true;
151
152 // Read the command line options
153 if (getOptions(argc, argv, opt_click_allowed, opt_display) == false) {
154 return EXIT_FAILURE;
155 }
156
157 if (opt_display) {
158
159 vpImage<unsigned char> I(480, 640, 255);
160
161#if(VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
162 std::shared_ptr<vpDisplay> d = vpDisplayFactory::createDisplay();
163#else
165#endif
166 d->init(I);
169
170 I = 0u;
171
172 vpRect roi(I.getWidth() / 4, I.getHeight() / 4, I.getWidth() / 2, I.getHeight() / 2);
173 vpDisplay::displayROI(I, roi);
175 if (opt_click_allowed) {
176 std::cout << "A click in the image to continue..." << std::endl;
178 }
180
181 vpImage<vpRGBa> C(480, 640, vpRGBa(255, 0, 0, 0));
182
183 d->init(C);
186
187 C = vpRGBa(0, 255, 0, 0);
188
189 vpDisplay::displayROI(C, roi);
190 vpDisplay::flushROI(C, roi);
191 if (opt_click_allowed) {
192 std::cout << "A click in the image to exit..." << std::endl;
194 }
195#if(VISP_CXX_STANDARD < VISP_CXX_STANDARD_11)
196 delete d;
197#endif
198 }
199#else
200 (void)argc;
201 (void)argv;
202#endif
203 return EXIT_SUCCESS;
204}
Class that defines generic functionalities for display.
Definition vpDisplay.h:171
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)
Definition of the vpImage class member functions.
Definition vpImage.h:131
static bool parse(int *argcPtr, const char **argv, vpArgvInfo *argTable, int flags)
Defines a rectangle in the plane.
Definition vpRect.h:79
std::shared_ptr< vpDisplay > createDisplay()
Return a smart pointer vpDisplay specialization if a GUI library is available or nullptr otherwise.
vpDisplay * allocateDisplay()
Return a newly allocated vpDisplay specialization if a GUI library is available or nullptr otherwise.