ViSP
manDisplay.cpp
1 /****************************************************************************
2  *
3  * $Id: manDisplay.cpp 5004 2014-11-24 08:24:18Z fspindle $
4  *
5  * This file is part of the ViSP software.
6  * Copyright (C) 2005 - 2014 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  try {
59  // Create a grey level image
60  vpImage<vpRGBa> I ;
61 
62  // Create image points for pixel coordinates
63  vpImagePoint ip, ip1, ip2;
64 
65  // Load a grey image from the disk. Klimt.ppm image is part of the ViSP
66  // image data set available from http://www.irisa.fr/lagadic/visp/download.html
67  std::string filename = "./Klimt.ppm";
68  vpImageIo::read(I, filename) ;
69 
70 #ifdef VISP_HAVE_GTK
71  // Create a display using GTK
72  vpDisplayGTK display;
73 
74  // For this grey level image, open a GTK display at position 100,100
75  // in the screen, and with title "GTK display"
76  display.init(I, 100, 100, "GTK display") ;
77 
78  // Display the image
80 
81  // Display in overlay a red cross at position 100,10 in the
82  // image. The lines are 20 pixels long
83  ip.set_i( 200 );
84  ip.set_j( 200 );
85  vpDisplay::displayCross(I, ip, 20, vpColor::red, 3) ;
86 
87  // Display in overlay a horizontal red line
88  ip1.set_i( 10 );
89  ip1.set_j( 0 );
90  ip2.set_i( 10 );
91  ip2.set_j( I.getWidth() );
92  vpDisplay::displayLine(I, ip1, ip2, vpColor::red, 3) ;
93 
94  // Display in overlay a vertical green dot line
95  ip1.set_i( 0 );
96  ip1.set_j( 20 );
97  ip2.set_i( I.getWidth() );
98  ip2.set_j( 20 );
99  vpDisplay::displayDotLine(I, ip1, ip2, vpColor::green, 3) ;
100 
101  // Display in overlay a blue arrow
102  ip1.set_i( 0 );
103  ip1.set_j( 0 );
104  ip2.set_i( 100 );
105  ip2.set_j( 100 );
106  vpDisplay::displayArrow(I, ip1, ip2, vpColor::blue, 8, 4, 3) ;
107 
108  // Display in overlay some circles. The position of the center is 200, 200
109  // the radius is increased by 20 pixels for each circle
110  for (unsigned i=0 ; i < 5 ; i++) {
111  ip.set_i( 200 );
112  ip.set_j( 200 );
113  vpDisplay::displayCircle(I, ip, 20*i, vpColor::white, false, 3) ;
114  }
115 
116  // Display in overlay a rectangle.
117  // The position of the top left corner is 300, 200.
118  // The width is 200. The height is 100.
119  ip.set_i( 280 );
120  ip.set_j( 150 );
121  vpDisplay::displayRectangle(I, ip, 270, 30,vpColor::purple, false, 3) ;
122 
123  // Display in overlay a yellow string
124  ip.set_i( 300 );
125  ip.set_j( 160 );
127  "ViSP is a marvelous software",
128  vpColor::black) ;
129  //Flush the display : without this line nothing will appear on the screen
130  vpDisplay::flush(I);
131 
132  // Create a color image
133  vpImage<vpRGBa> Ioverlay ;
134  // Updates the color image with the original loaded image and the overlay
135  vpDisplay::getImage(I, Ioverlay) ;
136 
137  // Write the color image on the disk
138  filename = "./Klimt.overlay.ppm";
139  vpImageIo::write(Ioverlay, filename) ;
140 
141  // If click is allowed, wait for a mouse click to close the display
142  std::cout << "\nA click to close the windows..." << std::endl;
143  // Wait for a blocking mouse click
145 
146  // Close the display
147  vpDisplay::close(I);
148 #endif
149 
150  return 0;
151  }
152  catch(vpException e) {
153  std::cout << "Catch an exception: " << e << std::endl;
154  return 1;
155  }
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:476
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:2269
unsigned int getWidth() const
Definition: vpImage.h:161
static const vpColor black
Definition: vpColor.h:161
static void displayText(const vpImage< unsigned char > &I, const vpImagePoint &ip, const std::string &s, const vpColor &color)
Definition: vpDisplay.cpp:887
error that can be emited by ViSP classes.
Definition: vpException.h:76
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:2232
static const vpColor red
Definition: vpColor.h:167
void set_i(const double ii)
Definition: vpImagePoint.h:159
static void display(const vpImage< unsigned char > &I)
Definition: vpDisplay.cpp:210
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:328
virtual void displayDotLine(const vpImagePoint &ip1, const vpImagePoint &ip2, const vpColor &color, unsigned int thickness=1)=0
void set_j(const double jj)
Definition: vpImagePoint.h:170
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:93
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:278
static const vpColor purple
Definition: vpColor.h:178
static const vpColor white
Definition: vpColor.h:162
static const vpColor blue
Definition: vpColor.h:173