Visual Servoing Platform version 3.7.0
Loading...
Searching...
No Matches
drawingHelpers.cpp
1/*
2 * ViSP, open source Visual Servoing Platform software.
3 * Copyright (C) 2005 - 2025 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
38using namespace VISP_NAMESPACE_NAME;
39#endif
40
41#if defined(VISP_HAVE_X11)
42vpDisplayX drawingHelpers::d_Iinput;
43vpDisplayX drawingHelpers::d_dIx;
44vpDisplayX drawingHelpers::d_dIy;
45vpDisplayX drawingHelpers::d_IcannyVisp;
46vpDisplayX drawingHelpers::d_IcannyImgFilter;
47#elif defined(HAVE_OPENCV_HIGHGUI)
48VP_ATTRIBUTE_NO_DESTROY vpDisplayOpenCV drawingHelpers::d_Iinput;
49VP_ATTRIBUTE_NO_DESTROY vpDisplayOpenCV drawingHelpers::d_dIx;
50VP_ATTRIBUTE_NO_DESTROY vpDisplayOpenCV drawingHelpers::d_dIy;
51VP_ATTRIBUTE_NO_DESTROY vpDisplayOpenCV drawingHelpers::d_IcannyVisp;
52VP_ATTRIBUTE_NO_DESTROY vpDisplayOpenCV drawingHelpers::d_IcannyImgFilter;
53#elif defined(VISP_HAVE_GTK)
54vpDisplayGTK drawingHelpers::d_Iinput;
55vpDisplayGTK drawingHelpers::d_dIx;
56vpDisplayGTK drawingHelpers::d_dIy;
57vpDisplayGTK drawingHelpers::d_IcannyVisp;
58vpDisplayGTK drawingHelpers::d_IcannyImgFilter;
59#elif defined(VISP_HAVE_GDI)
60VP_ATTRIBUTE_NO_DESTROY vpDisplayGDI drawingHelpers::d_Iinput;
61VP_ATTRIBUTE_NO_DESTROY vpDisplayGDI drawingHelpers::d_dIx;
62VP_ATTRIBUTE_NO_DESTROY vpDisplayGDI drawingHelpers::d_dIy;
63VP_ATTRIBUTE_NO_DESTROY vpDisplayGDI drawingHelpers::d_IcannyVisp;
64VP_ATTRIBUTE_NO_DESTROY vpDisplayGDI drawingHelpers::d_IcannyImgFilter;
65#elif defined(VISP_HAVE_D3D9)
66VP_ATTRIBUTE_NO_DESTROY vpDisplayD3D drawingHelpers::d_Iinput;
67VP_ATTRIBUTE_NO_DESTROY vpDisplayD3D drawingHelpers::d_dIx;
68VP_ATTRIBUTE_NO_DESTROY vpDisplayD3D drawingHelpers::d_dIy;
69VP_ATTRIBUTE_NO_DESTROY vpDisplayD3D drawingHelpers::d_IcannyVisp;
70VP_ATTRIBUTE_NO_DESTROY vpDisplayD3D drawingHelpers::d_IcannyImgFilter;
71#endif
72
73void 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
97void drawingHelpers::display(vpImage<unsigned char> &I, const std::string &title)
98{
100 vpDisplay::setTitle(I, title);
102}
103
104bool 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);
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:198
Display for windows using Direct3D 3rd party. Thus to enable this class Direct3D should be installed....
Display for windows using GDI (available on any windows 32 platform).
The vpDisplayGTK allows to display image using the GTK 3rd party library. Thus to enable this class G...
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)
Definition of the vpImage class member functions.
Definition vpImage.h:131
unsigned int getWidth() const
Definition vpImage.h:242
unsigned int getHeight() const
Definition vpImage.h:181