Visual Servoing Platform  version 3.6.1 under development (2024-04-27)
drawingHelpers.cpp
1 /*
2  * ViSP, open source Visual Servoing Platform software.
3  * Copyright (C) 2005 - 2023 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 
31 #include "drawingHelpers.h"
32 
33 #include <visp3/core/vpImageConvert.h>
34 
35 #if defined(VISP_HAVE_X11)
41 #elif defined(HAVE_OPENCV_HIGHGUI)
47 #elif defined(VISP_HAVE_GTK)
53 #elif defined(VISP_HAVE_GDI)
59 #elif defined(VISP_HAVE_D3D9)
65 #endif
66 
68  vpImage<unsigned char> *p_dIy, vpImage<unsigned char> *p_IcannyimgFilter)
69 {
70 #if defined(VISP_HAVE_DISPLAY)
71  d_Iinput.init(Iinput, 10, 10);
72  d_IcannyVisp.init(IcannyVisp, 10, Iinput.getHeight() + 10 * 2);
73  if (p_dIx != nullptr) {
74  d_dIx.init(*p_dIx, Iinput.getWidth() + 2 * 10, 10);
75  }
76  if (p_dIy != nullptr) {
77  d_dIy.init(*p_dIy, 2 * Iinput.getWidth() + 3 * 10, 10);
78  }
79  if (p_IcannyimgFilter != nullptr) {
80  d_IcannyImgFilter.init(*p_IcannyimgFilter, Iinput.getWidth() + 2 * 10, Iinput.getHeight() + 10 * 2);
81  }
82 #else
83  (void)Iinput;
84  (void)IcannyVisp;
85  (void)p_dIx;
86  (void)p_dIy;
87  (void)p_IcannyimgFilter;
88 #endif
89 }
90 
91 void drawingHelpers::display(vpImage<unsigned char> &I, const std::string &title)
92 {
94  vpDisplay::setTitle(I, title);
96 }
97 
98 bool drawingHelpers::waitForClick(const vpImage<unsigned char> &I, const bool &blockingMode)
99 {
100  vpDisplay::displayText(I, 15, 15, "Left click to continue...", vpColor::red);
101  vpDisplay::displayText(I, 35, 15, "Right click to stop...", vpColor::red);
102  vpDisplay::flush(I);
104  vpDisplay::getClick(I, button, blockingMode);
105  bool hasToContinue = true;
106  if (button == vpMouseButton::button3) {
107  // Right click => stop the program
108  hasToContinue = false;
109  }
110 
111  return hasToContinue;
112 }
static const vpColor red
Definition: vpColor.h:211
Display for windows using Direct3D 3rd party. Thus to enable this class Direct3D should be installed....
Definition: vpDisplayD3D.h:101
Display for windows using GDI (available on any windows 32 platform).
Definition: vpDisplayGDI.h:128
The vpDisplayGTK allows to display image using the GTK 3rd party library. Thus to enable this class G...
Definition: vpDisplayGTK.h:128
The vpDisplayOpenCV allows to display image using the OpenCV library. Thus to enable this class OpenC...
Use the X11 console to display images on unix-like OS. Thus to enable this class X11 should be instal...
Definition: vpDisplayX.h:128
void init(vpImage< unsigned char > &I, int win_x=-1, int win_y=-1, const std::string &win_title="") vp_override
static bool getClick(const vpImage< unsigned char > &I, bool blocking=true)
static void display(const vpImage< unsigned char > &I)
static void setTitle(const vpImage< unsigned char > &I, const std::string &windowtitle)
static void flush(const vpImage< unsigned char > &I)
static void displayText(const vpImage< unsigned char > &I, const vpImagePoint &ip, const std::string &s, const vpColor &color)
unsigned int getWidth() const
Definition: vpImage.h:245
unsigned int getHeight() const
Definition: vpImage.h:184
vpDisplayX d_IcannyVisp
vpDisplayX d_IcannyImgFilter
bool waitForClick(const vpImage< unsigned char > &I, const bool &blockingMode)
Catch the user clicks to know if the user wants to stop the program.
vpDisplayX d_dIx
vpDisplayX d_dIy
void display(vpImage< unsigned char > &I, const std::string &title)
Display a gray-scale image.
void init(vpImage< unsigned char > &Iinput, vpImage< unsigned char > &IcannyVisp, vpImage< unsigned char > *p_dIx, vpImage< unsigned char > *p_dIy, vpImage< unsigned char > *p_IcannyimgFilter)
Initialize the different displays.
vpDisplayX d_Iinput