ViSP
testDisplayRoi.cpp
1 /****************************************************************************
2  *
3  * $Id: testDisplayRoi.cpp 4776 2014-07-11 10:11:02Z 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 roi display.
36  *
37  * Authors:
38  * Fabien Spindler
39  *
40  *****************************************************************************/
41 
49 #include <stdlib.h>
50 
51 #include <visp/vpImage.h>
52 #include <visp/vpDisplayX.h>
53 #include <visp/vpDisplayGTK.h>
54 #include <visp/vpDisplayGDI.h>
55 #include <visp/vpDisplayD3D.h>
56 #include <visp/vpDisplayOpenCV.h>
57 #include <visp/vpParseArgv.h>
58 #include <visp/vpRect.h>
59 
60 // List of allowed command line options
61 #define GETOPTARGS "cdh"
62 
63 void usage(const char *name, const char *badparam);
64 bool getOptions(int argc, const char **argv, bool &click_allowed, bool &display);
65 
74 void usage(const char *name, const char *badparam)
75 {
76  fprintf(stdout, "\n\
77 Read an image on the disk, display it using X11, display some\n\
78 features (line, circle, caracters) in overlay and finaly write \n\
79 the image and the overlayed features in an image on the disk.\n\
80 \n\
81 SYNOPSIS\n\
82  %s [-c] [-d] [-h]\n", name);
83 
84  fprintf(stdout, "\n\
85 OPTIONS: Default\n\
86  -c\n\
87  Disable the mouse click. Useful to automate the \n\
88  execution of this program without humain intervention.\n\
89 \n\
90  -d \n\
91  Disable the image display. This can be useful \n\
92  for automatic tests using crontab under Unix or \n\
93  using the task manager under Windows.\n\
94 \n\
95  -h\n\
96  Print the help.\n\n");
97 
98  if (badparam) {
99  fprintf(stderr, "ERROR: \n" );
100  fprintf(stderr, "\nBad parameter [%s]\n", badparam);
101  }
102 
103 }
104 
120 bool getOptions(int argc, const char **argv, bool &click_allowed, bool &display)
121 {
122  const char *optarg_;
123  int c;
124  while ((c = vpParseArgv::parse(argc, argv, GETOPTARGS, &optarg_)) > 1) {
125 
126  switch (c) {
127  case 'c': click_allowed = false; break;
128  case 'd': display = false; break;
129  case 'h': usage(argv[0], NULL); return false; break;
130 
131  default:
132  usage(argv[0], optarg_); return false; break;
133  }
134  }
135 
136  if ((c == 1) || (c == -1)) {
137  // standalone param or error
138  usage(argv[0], NULL);
139  std::cerr << "ERROR: " << std::endl;
140  std::cerr << " Bad argument " << optarg_ << std::endl << std::endl;
141  return false;
142  }
143 
144  return true;
145 }
146 
147 int main(int argc, const char ** argv)
148 {
149 #ifdef VISP_HAVE_DISPLAY
150  bool opt_click_allowed = true;
151  bool opt_display = true;
152 
153  // Read the command line options
154  if (getOptions(argc, argv, opt_click_allowed, opt_display) == false) {
155  exit (-1);
156  }
157 
158  if (opt_display) {
159 
160  vpImage<unsigned char> I(480,640,255);
161 
162 #if defined(VISP_HAVE_X11)
163  vpDisplayX d;
164 #elif defined(VISP_HAVE_GTK)
165  vpDisplayGTK d;
166 #elif defined(VISP_HAVE_GDI)
167  vpDisplayGDI d;
168 #elif defined(VISP_HAVE_D3D9)
169  vpDisplayD3D d;
170 #elif defined(VISP_HAVE_OPENCV)
171  vpDisplayOpenCV d;
172 #endif
173  d.init(I);
175  vpDisplay::flush(I);
176 
177  I = 0;
178 
179  vpRect roi(I.getWidth()/4, I.getHeight()/4, I.getWidth()/2, I.getHeight()/2);
180  vpDisplay::displayROI(I, roi);
181  vpDisplay::flush(I);
182  if (opt_click_allowed) {
183  std::cout << "A click in the image to continue..." << std::endl;
185  }
186  vpDisplay::close(I);
187 
188  vpImage<vpRGBa> C(480,640,vpRGBa(255,0,0,0));
189 
190  //vpDisplayX d;
191  d.init(C);
193  vpDisplay::flush(C);
194 
195  C = vpRGBa(0,255,0,0);
196 
197  vpDisplay::displayROI(C, roi);
198  vpDisplay::flush(C);
199  if (opt_click_allowed) {
200  std::cout << "A click in the image to exit..." << std::endl;
202  }
203  }
204 #else
205  (void)argc;
206  (void)argv;
207 #endif
208  return 0;
209 }
void init(vpImage< unsigned char > &I, int winx=-1, int winy=-1, const char *title=NULL)
static void close(vpImage< unsigned char > &I)
Definition: vpDisplay.cpp:2269
unsigned int getWidth() const
Definition: vpImage.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
static void flush(const vpImage< unsigned char > &I)
Definition: vpDisplay.cpp:2232
static bool parse(int *argcPtr, const char **argv, vpArgvInfo *argTable, int flags)
Definition: vpParseArgv.cpp:80
Class that defines a RGB 32 bits structure.
Definition: vpRGBa.h:68
Display for windows using Direct3D.
Definition: vpDisplayD3D.h:109
static void display(const vpImage< unsigned char > &I)
Definition: vpDisplay.cpp:210
The vpDisplayOpenCV allows to display image using the opencv library.
The vpDisplayGTK allows to display image using the GTK+ library version 1.2.
Definition: vpDisplayGTK.h:145
unsigned int getHeight() const
Definition: vpImage.h:152
Defines a rectangle in the plane.
Definition: vpRect.h:85
static void displayROI(const vpImage< unsigned char > &I, const vpRect &roi)
Definition: vpDisplay.cpp:229
virtual bool getClick(bool blocking=true)=0