Visual Servoing Platform  version 3.0.1
manDisplay.cpp
1 /****************************************************************************
2  *
3  * This file is part of the ViSP software.
4  * Copyright (C) 2005 - 2017 by Inria. All rights reserved.
5  *
6  * This software is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * ("GPL") version 2 as published by the Free Software Foundation.
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 http://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  * Description:
31  * Display example.
32  *
33  * Authors:
34  * Anthony Saunier
35  * Fabien Spindler
36  *
37  *****************************************************************************/
38 
46 #include <visp3/core/vpImage.h>
47 #include <visp3/io/vpImageIo.h>
48 #include <visp3/core/vpColor.h>
49 #include <visp3/gui/vpDisplayGTK.h>
50 #include <visp3/core/vpImagePoint.h>
51 
52 int main()
53 {
54  try {
55  // Create a grey level image
56  vpImage<vpRGBa> I ;
57 
58  // Create image points for pixel coordinates
59  vpImagePoint ip, ip1, ip2;
60 
61  // Load a grey image from the disk. Klimt.ppm image is part of the ViSP
62  // image data set available from http://www.irisa.fr/lagadic/visp/download.html
63  std::string filename = "./Klimt.ppm";
64  vpImageIo::read(I, filename) ;
65 
66 #ifdef VISP_HAVE_GTK
67  // Create a display using GTK
68  vpDisplayGTK display;
69 
70  // For this grey level image, open a GTK display at position 100,100
71  // in the screen, and with title "GTK display"
72  display.init(I, 100, 100, "GTK display") ;
73 
74  // Display the image
76 
77  // Display in overlay a red cross at position 100,10 in the
78  // image. The lines are 20 pixels long
79  ip.set_i( 200 );
80  ip.set_j( 200 );
81  vpDisplay::displayCross(I, ip, 20, vpColor::red, 3) ;
82 
83  // Display in overlay a horizontal red line
84  ip1.set_i( 10 );
85  ip1.set_j( 0 );
86  ip2.set_i( 10 );
87  ip2.set_j( I.getWidth() );
88  vpDisplay::displayLine(I, ip1, ip2, vpColor::red, 3) ;
89 
90  // Display in overlay a vertical green dot line
91  ip1.set_i( 0 );
92  ip1.set_j( 20 );
93  ip2.set_i( I.getWidth() );
94  ip2.set_j( 20 );
95  vpDisplay::displayDotLine(I, ip1, ip2, vpColor::green, 3) ;
96 
97  // Display in overlay a blue arrow
98  ip1.set_i( 0 );
99  ip1.set_j( 0 );
100  ip2.set_i( 100 );
101  ip2.set_j( 100 );
102  vpDisplay::displayArrow(I, ip1, ip2, vpColor::blue, 8, 4, 3) ;
103 
104  // Display in overlay some circles. The position of the center is 200, 200
105  // the radius is increased by 20 pixels for each circle
106  for (unsigned i=0 ; i < 5 ; i++) {
107  ip.set_i( 200 );
108  ip.set_j( 200 );
109  vpDisplay::displayCircle(I, ip, 20*i, vpColor::white, false, 3) ;
110  }
111 
112  // Display in overlay a rectangle.
113  // The position of the top left corner is 300, 200.
114  // The width is 200. The height is 100.
115  ip.set_i( 280 );
116  ip.set_j( 150 );
117  vpDisplay::displayRectangle(I, ip, 270, 30,vpColor::purple, false, 3) ;
118 
119  // Display in overlay a yellow string
120  ip.set_i( 300 );
121  ip.set_j( 160 );
123  "ViSP is a marvelous software",
124  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 0;
147  }
148  catch(vpException &e) {
149  std::cout << "Catch an exception: " << e << std::endl;
150  return 1;
151  }
152 }
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:157
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:73
static const vpColor green
Definition: vpColor.h:166
static void flush(const vpImage< unsigned char > &I)
static const vpColor red
Definition: vpColor.h:163
static void write(const vpImage< unsigned char > &I, const std::string &filename)
Definition: vpImageIo.cpp:368
void set_i(const double ii)
Definition: vpImagePoint.h:163
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)
The vpDisplayGTK allows to display image using the GTK 3rd party library. Thus to enable this class G...
Definition: vpDisplayGTK.h:138
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:155
void init(vpImage< unsigned char > &I, int winx=-1, int winy=-1, const std::string &title="")
void set_j(const double jj)
Definition: vpImagePoint.h:174
static void displayCircle(const vpImage< unsigned char > &I, const vpImagePoint &center, unsigned int radius, const vpColor &color, bool fill=false, unsigned int thickness=1)
static void displayCross(const vpImage< unsigned char > &I, const vpImagePoint &ip, unsigned int size, const vpColor &color, unsigned int thickness=1)
static void read(vpImage< unsigned char > &I, const std::string &filename)
Definition: vpImageIo.cpp:205
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
Definition: vpImagePoint.h:88
static void displayLine(const vpImage< unsigned char > &I, const vpImagePoint &ip1, const vpImagePoint &ip2, const vpColor &color, unsigned int thickness=1)
static const vpColor purple
Definition: vpColor.h:174
static const vpColor white
Definition: vpColor.h:158
unsigned int getWidth() const
Definition: vpImage.h:226
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:169