Visual Servoing Platform  version 3.5.0 under development (2022-02-15)
manDisplay.cpp
1 /****************************************************************************
2  *
3  * ViSP, open source Visual Servoing Platform software.
4  * Copyright (C) 2005 - 2019 by Inria. All rights reserved.
5  *
6  * This software is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  * See the file LICENSE.txt at the root directory of this source
11  * distribution for additional information about the GNU GPL.
12  *
13  * For using ViSP with software that can not be combined with the GNU
14  * GPL, please contact Inria about acquiring a ViSP Professional
15  * Edition License.
16  *
17  * See http://visp.inria.fr for more information.
18  *
19  * This software was developed at:
20  * Inria Rennes - Bretagne Atlantique
21  * Campus Universitaire de Beaulieu
22  * 35042 Rennes Cedex
23  * France
24  *
25  * If you have questions regarding the use of this file, please contact
26  * Inria at visp@inria.fr
27  *
28  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
29  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
30  *
31  * Description:
32  * Display example.
33  *
34  * Authors:
35  * Anthony Saunier
36  * Fabien Spindler
37  *
38  *****************************************************************************/
39 
47 #include <visp3/core/vpColor.h>
48 #include <visp3/core/vpImage.h>
49 #include <visp3/core/vpImagePoint.h>
50 #include <visp3/gui/vpDisplayGTK.h>
51 #include <visp3/io/vpImageIo.h>
52 
53 int main()
54 {
55  try {
56  // Create a grey level image
58 
59  // Create image points for pixel coordinates
60  vpImagePoint ip, ip1, ip2;
61 
62  // Load a grey image from the disk. Klimt.ppm image is part of the ViSP
63  // image data set available from
64  // http://www.irisa.fr/lagadic/visp/download.html
65  std::string filename = "./Klimt.ppm";
66  vpImageIo::read(I, filename);
67 
68 #ifdef VISP_HAVE_GTK
69  // Create a display using GTK
70  vpDisplayGTK display;
71 
72  // For this grey level image, open a GTK display at position 100,100
73  // in the screen, and with title "GTK display"
74  display.init(I, 100, 100, "GTK display");
75 
76  // Display the image
78 
79  // Display in overlay a red cross at position 100,10 in the
80  // image. The lines are 20 pixels long
81  ip.set_i(200);
82  ip.set_j(200);
84 
85  // Display in overlay a horizontal red line
86  ip1.set_i(10);
87  ip1.set_j(0);
88  ip2.set_i(10);
89  ip2.set_j(I.getWidth());
90  vpDisplay::displayLine(I, ip1, ip2, vpColor::red, 3);
91 
92  // Display in overlay a vertical green dot line
93  ip1.set_i(0);
94  ip1.set_j(20);
95  ip2.set_i(I.getWidth());
96  ip2.set_j(20);
98 
99  // Display in overlay a blue arrow
100  ip1.set_i(0);
101  ip1.set_j(0);
102  ip2.set_i(100);
103  ip2.set_j(100);
104  vpDisplay::displayArrow(I, ip1, ip2, vpColor::blue, 8, 4, 3);
105 
106  // Display in overlay some circles. The position of the center is 200, 200
107  // the radius is increased by 20 pixels for each circle
108  for (unsigned i = 0; i < 5; i++) {
109  ip.set_i(200);
110  ip.set_j(200);
111  vpDisplay::displayCircle(I, ip, 20 * i, vpColor::white, false, 3);
112  }
113 
114  // Display in overlay a rectangle.
115  // The position of the top left corner is 300, 200.
116  // The width is 200. The height is 100.
117  ip.set_i(280);
118  ip.set_j(150);
119  vpDisplay::displayRectangle(I, ip, 270, 30, vpColor::purple, false, 3);
120 
121  // Display in overlay a yellow string
122  ip.set_i(300);
123  ip.set_j(160);
124  vpDisplay::displayText(I, ip, "ViSP is a marvelous software", vpColor::black);
125  // Flush the display : without this line nothing will appear on the screen
126  vpDisplay::flush(I);
127 
128  // Create a color image
129  vpImage<vpRGBa> Ioverlay;
130  // Updates the color image with the original loaded image and the overlay
131  vpDisplay::getImage(I, Ioverlay);
132 
133  // Write the color image on the disk
134  filename = "./Klimt.overlay.ppm";
135  vpImageIo::write(Ioverlay, filename);
136 
137  // If click is allowed, wait for a mouse click to close the display
138  std::cout << "\nA click to close the windows..." << std::endl;
139  // Wait for a blocking mouse click
141 
142  // Close the display
143  vpDisplay::close(I);
144 #endif
145 
146  return EXIT_SUCCESS;
147  } catch (const vpException &e) {
148  std::cout << "Catch an exception: " << e << std::endl;
149  return EXIT_FAILURE;
150  }
151 }
static void read(vpImage< unsigned char > &I, const std::string &filename, int backend=IO_DEFAULT_BACKEND)
Definition: vpImageIo.cpp:149
static bool getClick(const vpImage< unsigned char > &I, bool blocking=true)
static void close(vpImage< unsigned char > &I)
static const vpColor black
Definition: vpColor.h:211
static void displayText(const vpImage< unsigned char > &I, const vpImagePoint &ip, const std::string &s, const vpColor &color)
error that can be emited by ViSP classes.
Definition: vpException.h:71
static const vpColor green
Definition: vpColor.h:220
static void flush(const vpImage< unsigned char > &I)
static void write(const vpImage< unsigned char > &I, const std::string &filename, int backend=IO_DEFAULT_BACKEND)
Definition: vpImageIo.cpp:293
static const vpColor red
Definition: vpColor.h:217
void set_i(double ii)
Definition: vpImagePoint.h:166
static void displayArrow(const vpImage< unsigned char > &I, const vpImagePoint &ip1, const vpImagePoint &ip2, const vpColor &color=vpColor::white, unsigned int w=4, unsigned int h=2, unsigned int thickness=1)
static void display(const vpImage< unsigned char > &I)
void init(vpImage< unsigned char > &I, int win_x=-1, int win_y=-1, const std::string &win_title="")
The vpDisplayGTK allows to display image using the GTK 3rd party library. Thus to enable this class G...
Definition: vpDisplayGTK.h:134
static void displayRectangle(const vpImage< unsigned char > &I, const vpImagePoint &topLeft, unsigned int width, unsigned int height, const vpColor &color, bool fill=false, unsigned int thickness=1)
static void getImage(const vpImage< unsigned char > &Is, vpImage< vpRGBa > &Id)
Definition: vpDisplay.cpp:144
static void displayCircle(const vpImage< unsigned char > &I, const vpImagePoint &center, unsigned int radius, const vpColor &color, bool fill=false, unsigned int thickness=1)
void set_j(double jj)
Definition: vpImagePoint.h:177
static void displayCross(const vpImage< unsigned char > &I, const vpImagePoint &ip, unsigned int size, const vpColor &color, unsigned int thickness=1)
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
Definition: vpImagePoint.h:87
static const vpColor purple
Definition: vpColor.h:228
static const vpColor white
Definition: vpColor.h:212
unsigned int getWidth() const
Definition: vpImage.h:246
static void displayLine(const vpImage< unsigned char > &I, const vpImagePoint &ip1, const vpImagePoint &ip2, const vpColor &color, unsigned int thickness=1, bool segment=true)
static void displayDotLine(const vpImage< unsigned char > &I, const vpImagePoint &ip1, const vpImagePoint &ip2, const vpColor &color, unsigned int thickness=1)
static const vpColor blue
Definition: vpColor.h:223