Visual Servoing Platform  version 3.6.1 under development (2024-07-17)
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 #ifndef DOXYGEN_SHOULD_SKIP_THIS
36 
37 #ifdef ENABLE_VISP_NAMESPACE
38 using namespace VISP_NAMESPACE_NAME;
39 #endif
40 
41 #if defined(VISP_HAVE_X11)
42 vpDisplayX drawingHelpers::d_Iinput;
43 vpDisplayX drawingHelpers::d_dIx;
44 vpDisplayX drawingHelpers::d_dIy;
45 vpDisplayX drawingHelpers::d_IcannyVisp;
46 vpDisplayX drawingHelpers::d_IcannyImgFilter;
47 #elif defined(HAVE_OPENCV_HIGHGUI)
48 vpDisplayOpenCV drawingHelpers::d_Iinput;
49 vpDisplayOpenCV drawingHelpers::d_dIx;
50 vpDisplayOpenCV drawingHelpers::d_dIy;
51 vpDisplayOpenCV drawingHelpers::d_IcannyVisp;
52 vpDisplayOpenCV drawingHelpers::d_IcannyImgFilter;
53 #elif defined(VISP_HAVE_GTK)
54 vpDisplayGTK drawingHelpers::d_Iinput;
55 vpDisplayGTK drawingHelpers::d_dIx;
56 vpDisplayGTK drawingHelpers::d_dIy;
57 vpDisplayGTK drawingHelpers::d_IcannyVisp;
58 vpDisplayGTK drawingHelpers::d_IcannyImgFilter;
59 #elif defined(VISP_HAVE_GDI)
60 vpDisplayGDI drawingHelpers::d_Iinput;
61 vpDisplayGDI drawingHelpers::d_dIx;
62 vpDisplayGDI drawingHelpers::d_dIy;
63 vpDisplayGDI drawingHelpers::d_IcannyVisp;
64 vpDisplayGDI drawingHelpers::d_IcannyImgFilter;
65 #elif defined(VISP_HAVE_D3D9)
66 vpDisplayD3D drawingHelpers::d_Iinput;
67 vpDisplayD3D drawingHelpers::d_dIx;
68 vpDisplayD3D drawingHelpers::d_dIy;
69 vpDisplayD3D drawingHelpers::d_IcannyVisp;
70 vpDisplayD3D drawingHelpers::d_IcannyImgFilter;
71 #endif
72 
73 void drawingHelpers::init(vpImage<unsigned char> &Iinput, vpImage<unsigned char> &IcannyVisp, vpImage<unsigned char> *p_dIx,
74  vpImage<unsigned char> *p_dIy, vpImage<unsigned char> *p_IcannyimgFilter)
75 {
76 #if defined(VISP_HAVE_DISPLAY)
77  d_Iinput.init(Iinput, 10, 10);
78  d_IcannyVisp.init(IcannyVisp, 10, Iinput.getHeight() + 10 * 2);
79  if (p_dIx != nullptr) {
80  d_dIx.init(*p_dIx, Iinput.getWidth() + 2 * 10, 10);
81  }
82  if (p_dIy != nullptr) {
83  d_dIy.init(*p_dIy, 2 * Iinput.getWidth() + 3 * 10, 10);
84  }
85  if (p_IcannyimgFilter != nullptr) {
86  d_IcannyImgFilter.init(*p_IcannyimgFilter, Iinput.getWidth() + 2 * 10, Iinput.getHeight() + 10 * 2);
87  }
88 #else
89  (void)Iinput;
90  (void)IcannyVisp;
91  (void)p_dIx;
92  (void)p_dIy;
93  (void)p_IcannyimgFilter;
94 #endif
95 }
96 
97 void drawingHelpers::display(vpImage<unsigned char> &I, const std::string &title)
98 {
100  vpDisplay::setTitle(I, title);
101  vpDisplay::flush(I);
102 }
103 
104 bool drawingHelpers::waitForClick(const vpImage<unsigned char> &I, const bool &blockingMode)
105 {
106  vpDisplay::displayText(I, 15, 15, "Left click to continue...", vpColor::red);
107  vpDisplay::displayText(I, 35, 15, "Right click to stop...", vpColor::red);
108  vpDisplay::flush(I);
110  vpDisplay::getClick(I, button, blockingMode);
111  bool hasToContinue = true;
112  if (button == vpMouseButton::button3) {
113  // Right click => stop the program
114  hasToContinue = false;
115  }
116 
117  return hasToContinue;
118 }
119 
120 #endif
static const vpColor red
Definition: vpColor.h:217
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...
Use the X11 console to display images on unix-like OS. Thus to enable this class X11 should be instal...
Definition: vpDisplayX.h:135
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:242
unsigned int getHeight() const
Definition: vpImage.h:181