ViSP
 All Classes Functions Variables Enumerations Enumerator Friends Groups Pages
manDisplay.cpp
1 /****************************************************************************
2  *
3  * $Id: manDisplay.cpp 4056 2013-01-05 13:04:42Z fspindle $
4  *
5  * This file is part of the ViSP software.
6  * Copyright (C) 2005 - 2013 by INRIA. All rights reserved.
7  *
8  * This software is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * ("GPL") version 2 as published by the Free Software Foundation.
11  * See the file LICENSE.txt at the root directory of this source
12  * distribution for additional information about the GNU GPL.
13  *
14  * For using ViSP with software that can not be combined with the GNU
15  * GPL, please contact INRIA about acquiring a ViSP Professional
16  * Edition License.
17  *
18  * See http://www.irisa.fr/lagadic/visp/visp.html for more information.
19  *
20  * This software was developed at:
21  * INRIA Rennes - Bretagne Atlantique
22  * Campus Universitaire de Beaulieu
23  * 35042 Rennes Cedex
24  * France
25  * http://www.irisa.fr/lagadic
26  *
27  * If you have questions regarding the use of this file, please contact
28  * INRIA at visp@inria.fr
29  *
30  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
31  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
32  *
33  *
34  * Description:
35  * Display example.
36  *
37  * Authors:
38  * Anthony Saunier
39  * Fabien Spindler
40  *
41  *****************************************************************************/
42 
50 #include <visp/vpImage.h>
51 #include <visp/vpImageIo.h>
52 #include <visp/vpColor.h>
53 #include <visp/vpDisplayGTK.h>
54 #include <visp/vpImagePoint.h>
55 
56 int main()
57 {
58  // Create a grey level image
59  vpImage<vpRGBa> I ;
60 
61  // Create image points for pixel coordinates
62  vpImagePoint ip, ip1, ip2;
63 
64  // Load a grey image from the disk. Klimt.ppm image is part of the ViSP
65  // image data set available from http://www.irisa.fr/lagadic/visp/download.html
66  std::string filename = "./Klimt.ppm";
67  vpImageIo::read(I, filename) ;
68 
69 #ifdef VISP_HAVE_GTK
70  // Create a display using GTK
71  vpDisplayGTK display;
72 
73  // For this grey level image, open a GTK display at position 100,100
74  // in the screen, and with title "GTK display"
75  display.init(I, 100, 100, "GTK display") ;
76 
77  // Display the image
79 
80  // Display in overlay a red cross at position 100,10 in the
81  // image. The lines are 20 pixels long
82  ip.set_i( 200 );
83  ip.set_j( 200 );
84  vpDisplay::displayCross(I, ip, 20, vpColor::red, 3) ;
85 
86  // Display in overlay a horizontal red line
87  ip1.set_i( 10 );
88  ip1.set_j( 0 );
89  ip2.set_i( 10 );
90  ip2.set_j( I.getWidth() );
91  vpDisplay::displayLine(I, ip1, ip2, vpColor::red, 3) ;
92 
93  // Display in overlay a vertical green dot line
94  ip1.set_i( 0 );
95  ip1.set_j( 20 );
96  ip2.set_i( I.getWidth() );
97  ip2.set_j( 20 );
98  vpDisplay::displayDotLine(I, ip1, ip2, vpColor::green, 3) ;
99 
100  // Display in overlay a blue arrow
101  ip1.set_i( 0 );
102  ip1.set_j( 0 );
103  ip2.set_i( 100 );
104  ip2.set_j( 100 );
105  vpDisplay::displayArrow(I, ip1, ip2, vpColor::blue, 8, 4, 3) ;
106 
107  // Display in overlay some circles. The position of the center is 200, 200
108  // the radius is increased by 20 pixels for each circle
109  for (unsigned i=0 ; i < 5 ; i++) {
110  ip.set_i( 200 );
111  ip.set_j( 200 );
112  vpDisplay::displayCircle(I, ip, 20*i, vpColor::white, false, 3) ;
113  }
114 
115  // Display in overlay a rectangle.
116  // The position of the top left corner is 300, 200.
117  // The width is 200. The height is 100.
118  ip.set_i( 280 );
119  ip.set_j( 150 );
120  vpDisplay::displayRectangle(I, ip, 270, 30,vpColor::purple, false, 3) ;
121 
122  // Display in overlay a yellow string
123  ip.set_i( 300 );
124  ip.set_j( 160 );
126  "ViSP is a marvelous software",
127  vpColor::black) ;
128  //Flush the display : without this line nothing will appear on the screen
129  vpDisplay::flush(I);
130 
131  // Create a color image
132  vpImage<vpRGBa> Ioverlay ;
133  // Updates the color image with the original loaded image and the overlay
134  vpDisplay::getImage(I, Ioverlay) ;
135 
136  // Write the color image on the disk
137  filename = "./Klimt.overlay.ppm";
138  vpImageIo::write(Ioverlay, filename) ;
139 
140  // If click is allowed, wait for a mouse click to close the display
141  std::cout << "\nA click to close the windows..." << std::endl;
142  // Wait for a blocking mouse click
144 
145  // Close the display
146  vpDisplay::close(I);
147 #endif
148 
149  return 0;
150 }
void set_j(const double j)
Definition: vpImagePoint.h:156
virtual void displayCircle(const vpImagePoint &center, unsigned int radius, const vpColor &color, bool fill=false, unsigned int thickness=1)=0
static void write(const vpImage< unsigned char > &I, const char *filename)
Definition: vpImageIo.cpp:442
virtual void displayArrow(const vpImagePoint &ip1, const vpImagePoint &ip2, const vpColor &color=vpColor::white, unsigned int w=4, unsigned int h=2, unsigned int thickness=1)=0
static void close(vpImage< unsigned char > &I)
Definition: vpDisplay.cpp:2028
unsigned int getWidth() const
Definition: vpImage.h:159
static const vpColor black
Definition: vpColor.h:161
void set_i(const double i)
Definition: vpImagePoint.h:145
void init(vpImage< unsigned char > &I, int winx=-1, int winy=-1, const char *title=NULL)
static const vpColor green
Definition: vpColor.h:170
static void flush(const vpImage< unsigned char > &I)
Definition: vpDisplay.cpp:1991
static const vpColor red
Definition: vpColor.h:167
static void display(const vpImage< unsigned char > &I)
Definition: vpDisplay.cpp:203
virtual void displayCross(const vpImagePoint &ip, unsigned int size, const vpColor &color, unsigned int thickness=1)=0
The vpDisplayGTK allows to display image using the GTK+ library version 1.2.
Definition: vpDisplayGTK.h:145
virtual void displayRectangle(const vpImagePoint &topLeft, unsigned int width, unsigned int height, const vpColor &color, bool fill=false, unsigned int thickness=1)=0
static void getImage(const vpImage< unsigned char > &Is, vpImage< vpRGBa > &Id)
Definition: vpDisplay.cpp:321
virtual void displayDotLine(const vpImagePoint &ip1, const vpImagePoint &ip2, const vpColor &color, unsigned int thickness=1)=0
virtual void displayCharString(const vpImagePoint &ip, const char *text, const vpColor &color=vpColor::green)=0
virtual bool getClick(bool blocking=true)=0
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
Definition: vpImagePoint.h:92
virtual void displayLine(const vpImagePoint &ip1, const vpImagePoint &ip2, const vpColor &color, unsigned int thickness=1)=0
static void read(vpImage< unsigned char > &I, const char *filename)
Definition: vpImageIo.cpp:277
static const vpColor purple
Definition: vpColor.h:178
static const vpColor white
Definition: vpColor.h:162
static const vpColor blue
Definition: vpColor.h:173