Visual Servoing Platform  version 3.2.1 under development (2019-05-20)
vpDisplay.h
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  * Image display.
33  *
34  * Authors:
35  * Eric Marchand
36  * Fabien Spindler
37  *
38  *****************************************************************************/
39 
40 #ifndef vpDisplay_h
41 #define vpDisplay_h
42 
43 #include <sstream>
44 #include <string>
45 
46 #include <visp3/core/vpCameraParameters.h>
47 #include <visp3/core/vpColor.h>
48 #include <visp3/core/vpHomogeneousMatrix.h>
49 #include <visp3/core/vpImage.h>
50 #include <visp3/core/vpImagePoint.h>
51 #include <visp3/core/vpMouseButton.h>
52 #include <visp3/core/vpRect.h>
53 
171 class VISP_EXPORT vpDisplay
172 {
173 public:
176  typedef enum {
177  SCALE_AUTO,
180  SCALE_2,
182  SCALE_3,
184  SCALE_4,
186  SCALE_5,
188  SCALE_6,
190  SCALE_7,
192  SCALE_8,
194  SCALE_9,
196  SCALE_10,
198  SCALE_DEFAULT
200  } vpScaleType;
201 
202 protected:
209  unsigned int m_width;
210  unsigned int m_height;
211  std::string m_title;
212  unsigned int m_scale;
213  vpScaleType m_scaleType;
214 
215  void setScale(vpScaleType scaleType, unsigned int width, unsigned int height);
216 
217 public:
218  vpDisplay();
219  vpDisplay(const vpDisplay &d);
220  virtual ~vpDisplay();
221 
224  unsigned int computeAutoScale(unsigned int width, unsigned int height);
229  unsigned int getDownScalingFactor() { return m_scale; }
234  inline unsigned int getHeight() const { return m_height; }
239  inline unsigned int getWidth() const { return m_width; }
240 
245  int getWindowXPosition() const { return m_windowXPosition; }
250  int getWindowYPosition() const { return m_windowYPosition; }
251 
257  inline bool isInitialised() { return m_displayHasBeenInitialized; }
258  virtual void setDownScalingFactor(unsigned int scale);
259  virtual void setDownScalingFactor(vpScaleType scaleType);
261 
262 #ifndef DOXYGEN_SHOULD_SKIP_THIS
263 
269  virtual void clearDisplay(const vpColor &color = vpColor::white) = 0;
273  virtual void closeDisplay() = 0;
274 
284  virtual void displayArrow(const vpImagePoint &ip1, const vpImagePoint &ip2, const vpColor &color = vpColor::white,
285  unsigned int w = 4, unsigned int h = 2, unsigned int thickness = 1) = 0;
297  virtual void displayCharString(const vpImagePoint &ip, const char *text, const vpColor &color = vpColor::green) = 0;
307  virtual void displayCircle(const vpImagePoint &center, unsigned int radius, const vpColor &color, bool fill = false,
308  unsigned int thickness = 1) = 0;
316  virtual void displayCross(const vpImagePoint &ip, unsigned int size, const vpColor &color,
317  unsigned int thickness = 1) = 0;
325  virtual void displayDotLine(const vpImagePoint &ip1, const vpImagePoint &ip2, const vpColor &color,
326  unsigned int thickness = 1) = 0;
334  virtual void displayLine(const vpImagePoint &ip1, const vpImagePoint &ip2, const vpColor &color,
335  unsigned int thickness = 1) = 0;
336 
348  virtual void displayImage(const vpImage<unsigned char> &I) = 0;
349 
361  virtual void displayImage(const vpImage<vpRGBa> &I) = 0;
362 
363  virtual void displayImageROI(const vpImage<unsigned char> &I, const vpImagePoint &iP, const unsigned int width,
364  const unsigned int height) = 0;
365  virtual void displayImageROI(const vpImage<vpRGBa> &I, const vpImagePoint &iP, const unsigned int width,
366  const unsigned int height) = 0;
367 
374  virtual void displayPoint(const vpImagePoint &ip, const vpColor &color, unsigned int thickness = 1) = 0;
375 
390  virtual void displayRectangle(const vpImagePoint &topLeft, unsigned int width, unsigned int height,
391  const vpColor &color, bool fill = false, unsigned int thickness = 1) = 0;
405  virtual void displayRectangle(const vpImagePoint &topLeft, const vpImagePoint &bottomRight, const vpColor &color,
406  bool fill = false, unsigned int thickness = 1) = 0;
420  virtual void displayRectangle(const vpRect &rectangle, const vpColor &color, bool fill = false,
421  unsigned int thickness = 1) = 0;
422 
427  virtual void flushDisplay() = 0;
428 
433  virtual void flushDisplayROI(const vpImagePoint &iP, const unsigned int width, const unsigned int height) = 0;
434 
435  /* Simple interface with the mouse event */
436 
452  virtual bool getClick(bool blocking = true) = 0;
453 
469  virtual bool getClick(vpImagePoint &ip, bool blocking = true) = 0;
488  virtual bool getClick(vpImagePoint &ip, vpMouseButton::vpMouseButtonType &button, bool blocking = true) = 0;
511  virtual bool getClickUp(vpImagePoint &ip, vpMouseButton::vpMouseButtonType &button, bool blocking = true) = 0;
512 
528  virtual bool getKeyboardEvent(bool blocking = true) = 0;
548  virtual bool getKeyboardEvent(std::string &key, bool blocking = true) = 0;
559  virtual bool getPointerMotionEvent(vpImagePoint &ip) = 0;
560 
571  virtual bool getPointerPosition(vpImagePoint &ip) = 0;
572 
576  virtual unsigned int getScreenHeight() = 0;
581  virtual void getScreenSize(unsigned int &width, unsigned int &height) = 0;
585  virtual unsigned int getScreenWidth() = 0;
586 
595  virtual void init(vpImage<unsigned char> &I, int x = -1, int y = -1, const std::string &title = "") = 0;
605  virtual void init(vpImage<vpRGBa> &I, int x = -1, int y = -1, const std::string &title = "") = 0;
606 
667  virtual void init(unsigned int width, unsigned int height, int x = -1, int y = -1, const std::string &title = "") = 0;
668 
682  virtual void setFont(const std::string &font) = 0;
687  virtual void setTitle(const std::string &title) = 0;
695  virtual void setWindowPosition(int x, int y) = 0;
697 #endif // ifndef DOXYGEN_SHOULD_SKIP_THIS
698 
703  static void close(vpImage<unsigned char> &I);
704  static void display(const vpImage<unsigned char> &I);
705  static void displayArrow(const vpImage<unsigned char> &I, const vpImagePoint &ip1, const vpImagePoint &ip2,
706  const vpColor &color = vpColor::white, unsigned int w = 4, unsigned int h = 2,
707  unsigned int thickness = 1);
708  static void displayArrow(const vpImage<unsigned char> &I, int i1, int j1, int i2, int j2,
709  const vpColor &color = vpColor::white, unsigned int w = 4, unsigned int h = 2,
710  unsigned int thickness = 1);
711  static void displayCamera(const vpImage<unsigned char> &I, const vpHomogeneousMatrix &cMo,
712  const vpCameraParameters &cam, double size, const vpColor &color, unsigned int thickness);
713  static void displayCharString(const vpImage<unsigned char> &I, const vpImagePoint &ip, const char *string,
714  const vpColor &color);
715  static void displayCharString(const vpImage<unsigned char> &I, int i, int j, const char *string,
716  const vpColor &color);
717  static void displayCircle(const vpImage<unsigned char> &I, const vpImagePoint &center, unsigned int radius,
718  const vpColor &color, bool fill = false, unsigned int thickness = 1);
719  static void displayCircle(const vpImage<unsigned char> &I, int i, int j, unsigned int radius, const vpColor &color,
720  bool fill = false, unsigned int thickness = 1);
721  static void displayCross(const vpImage<unsigned char> &I, const vpImagePoint &ip, unsigned int size,
722  const vpColor &color, unsigned int thickness = 1);
723  static void displayCross(const vpImage<unsigned char> &I, int i, int j, unsigned int size, const vpColor &color,
724  unsigned int thickness = 1);
725  static void displayDotLine(const vpImage<unsigned char> &I, const vpImagePoint &ip1, const vpImagePoint &ip2,
726  const vpColor &color, unsigned int thickness = 1);
727  static void displayDotLine(const vpImage<unsigned char> &I, int i1, int j1, int i2, int j2, const vpColor &color,
728  unsigned int thickness = 1);
729  static void displayDotLine(const vpImage<unsigned char> &I, const std::vector<vpImagePoint> &ips,
730  const bool closeTheShape, const vpColor &color, unsigned int thickness = 1);
731  static void displayEllipse(const vpImage<unsigned char> &I, const vpImagePoint &center, const double &coef1,
732  const double &coef2, const double &coef3, bool use_centered_moments, const vpColor &color,
733  unsigned int thickness = 1);
734  static void displayEllipse(const vpImage<unsigned char> &I, const vpImagePoint &center, const double &coef1,
735  const double &coef2, const double &coef3, const double &theta1, const double &theta2,
736  bool use_centered_moments, const vpColor &color, unsigned int thickness = 1);
737  static void displayFrame(const vpImage<unsigned char> &I, const vpHomogeneousMatrix &cMo,
738  const vpCameraParameters &cam, double size, const vpColor &color = vpColor::none,
739  unsigned int thickness = 1, const vpImagePoint &offset = vpImagePoint(0, 0));
740  static void displayLine(const vpImage<unsigned char> &I, const vpImagePoint &ip1, const vpImagePoint &ip2,
741  const vpColor &color, unsigned int thickness = 1);
742  static void displayLine(const vpImage<unsigned char> &I, int i1, int j1, int i2, int j2, const vpColor &color,
743  unsigned int thickness = 1);
744  static void displayLine(const vpImage<unsigned char> &I, const std::vector<vpImagePoint> &ips,
745  const bool closeTheShape, const vpColor &color, unsigned int thickness = 1);
746  static void displayPoint(const vpImage<unsigned char> &I, const vpImagePoint &ip, const vpColor &color,
747  unsigned int thickness = 1);
748  static void displayPoint(const vpImage<unsigned char> &I, int i, int j, const vpColor &color,
749  unsigned int thickness = 1);
750  static void displayPolygon(const vpImage<unsigned char> &I, const std::vector<vpImagePoint> &vip,
751  const vpColor &color, unsigned int thickness = 1);
752  static void displayRectangle(const vpImage<unsigned char> &I, const vpImagePoint &topLeft, unsigned int width,
753  unsigned int height, const vpColor &color, bool fill = false,
754  unsigned int thickness = 1);
755  static void displayRectangle(const vpImage<unsigned char> &I, const vpImagePoint &topLeft,
756  const vpImagePoint &bottomRight, const vpColor &color, bool fill = false,
757  unsigned int thickness = 1);
758  static void displayRectangle(const vpImage<unsigned char> &I, const vpRect &rectangle, const vpColor &color,
759  bool fill = false, unsigned int thickness = 1);
760  static void displayRectangle(const vpImage<unsigned char> &I, const vpImagePoint &center, float angle,
761  unsigned int width, unsigned int height, const vpColor &color,
762  unsigned int thickness = 1);
763  static void displayRectangle(const vpImage<unsigned char> &I, int i, int j, unsigned int width, unsigned int height,
764  const vpColor &color, bool fill = false, unsigned int thickness = 1);
765  static void displayRectangle(const vpImage<unsigned char> &I, unsigned int i, unsigned int j, float angle,
766  unsigned int width, unsigned int height, const vpColor &color,
767  unsigned int thickness = 1);
768  static void displayROI(const vpImage<unsigned char> &I, const vpRect &roi);
769  static void displayText(const vpImage<unsigned char> &I, const vpImagePoint &ip, const std::string &s,
770  const vpColor &color);
771  static void displayText(const vpImage<unsigned char> &I, int i, int j, const std::string &s, const vpColor &color);
772 
773  static void flush(const vpImage<unsigned char> &I);
774  static void flushROI(const vpImage<unsigned char> &I, const vpRect &roi);
775 
776  static bool getClick(const vpImage<unsigned char> &I, bool blocking = true);
777  static bool getClick(const vpImage<unsigned char> &I, vpImagePoint &ip, bool blocking = true);
778  static bool getClick(const vpImage<unsigned char> &I, vpImagePoint &ip, vpMouseButton::vpMouseButtonType &button,
779  bool blocking = true);
780  static bool getClick(const vpImage<unsigned char> &I, vpMouseButton::vpMouseButtonType &button, bool blocking = true);
781  static bool getClickUp(const vpImage<unsigned char> &I, vpImagePoint &ip, vpMouseButton::vpMouseButtonType &button,
782  bool blocking = true);
783  static bool getClickUp(const vpImage<unsigned char> &I, vpMouseButton::vpMouseButtonType &button,
784  bool blocking = true);
785  static unsigned int getDownScalingFactor(const vpImage<unsigned char> &I);
786  static void getImage(const vpImage<unsigned char> &Is, vpImage<vpRGBa> &Id);
787  static bool getKeyboardEvent(const vpImage<unsigned char> &I, bool blocking = true);
788  static bool getKeyboardEvent(const vpImage<unsigned char> &I, std::string &key, bool blocking = true);
789  static bool getKeyboardEvent(const vpImage<unsigned char> &I, char *key, bool blocking = true);
790  static bool getPointerMotionEvent(const vpImage<unsigned char> &I, vpImagePoint &ip);
791  static bool getPointerPosition(const vpImage<unsigned char> &I, vpImagePoint &ip);
792 
793  static void setBackground(const vpImage<unsigned char> &I, const vpColor &color);
794  static void setFont(const vpImage<unsigned char> &I, const std::string &font);
795  static void setTitle(const vpImage<unsigned char> &I, const std::string &windowtitle);
796  static void setWindowPosition(const vpImage<unsigned char> &I, int winx, int winy);
798 
803  static void close(vpImage<vpRGBa> &I);
804  static void display(const vpImage<vpRGBa> &I);
805  static void displayArrow(const vpImage<vpRGBa> &I, const vpImagePoint &ip1, const vpImagePoint &ip2,
806  const vpColor &color = vpColor::white, unsigned int w = 4, unsigned int h = 2,
807  unsigned int thickness = 1);
808  static void displayArrow(const vpImage<vpRGBa> &I, int i1, int j1, int i2, int j2,
809  const vpColor &color = vpColor::white, unsigned int w = 4, unsigned int h = 2,
810  unsigned int thickness = 1);
811  static void displayCamera(const vpImage<vpRGBa> &I, const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam,
812  double size, const vpColor &color, unsigned int thickness);
813  static void displayCharString(const vpImage<vpRGBa> &I, const vpImagePoint &ip, const char *string,
814  const vpColor &color);
815  static void displayCharString(const vpImage<vpRGBa> &I, int i, int j, const char *string, const vpColor &color);
816  static void displayCircle(const vpImage<vpRGBa> &I, const vpImagePoint &center, unsigned int radius,
817  const vpColor &color, bool fill = false, unsigned int thickness = 1);
818  static void displayCircle(const vpImage<vpRGBa> &I, int i, int j, unsigned int radius, const vpColor &color,
819  bool fill = false, unsigned int thickness = 1);
820  static void displayCross(const vpImage<vpRGBa> &I, const vpImagePoint &ip, unsigned int size, const vpColor &color,
821  unsigned int thickness = 1);
822  static void displayCross(const vpImage<vpRGBa> &I, int i, int j, unsigned int size, const vpColor &color,
823  unsigned int thickness = 1);
824  static void displayDotLine(const vpImage<vpRGBa> &I, const vpImagePoint &ip1, const vpImagePoint &ip2,
825  const vpColor &color, unsigned int thickness = 1);
826  static void displayDotLine(const vpImage<vpRGBa> &I, int i1, int j1, int i2, int j2, const vpColor &color,
827  unsigned int thickness = 1);
828  static void displayDotLine(const vpImage<vpRGBa> &I, const std::vector<vpImagePoint> &ips, const bool closeTheShape,
829  const vpColor &color, unsigned int thickness = 1);
830  static void displayEllipse(const vpImage<vpRGBa> &I, const vpImagePoint &center, const double &coef1,
831  const double &coef2, const double &coef3, bool use_centered_moments, const vpColor &color,
832  unsigned int thickness = 1);
833  static void displayEllipse(const vpImage<vpRGBa> &I, const vpImagePoint &center, const double &coef1,
834  const double &coef2, const double &coef3, const double &theta1, const double &theta2,
835  bool use_centered_moments, const vpColor &color, unsigned int thickness = 1);
836  static void displayFrame(const vpImage<vpRGBa> &I, const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam,
837  double size, const vpColor &color = vpColor::none, unsigned int thickness = 1,
838  const vpImagePoint &offset = vpImagePoint(0, 0));
839  static void displayLine(const vpImage<vpRGBa> &I, const vpImagePoint &ip1, const vpImagePoint &ip2,
840  const vpColor &color, unsigned int thickness = 1);
841  static void displayLine(const vpImage<vpRGBa> &I, int i1, int j1, int i2, int j2, const vpColor &color,
842  unsigned int thickness = 1);
843  static void displayLine(const vpImage<vpRGBa> &I, const std::vector<vpImagePoint> &ips, const bool closeTheShape,
844  const vpColor &color, unsigned int thickness = 1);
845  static void displayPoint(const vpImage<vpRGBa> &I, const vpImagePoint &ip, const vpColor &color,
846  unsigned int thickness = 1);
847  static void displayPoint(const vpImage<vpRGBa> &I, int i, int j, const vpColor &color, unsigned int thickness = 1);
848  static void displayPolygon(const vpImage<vpRGBa> &I, const std::vector<vpImagePoint> &vip, const vpColor &color,
849  unsigned int thickness = 1);
850  static void displayRectangle(const vpImage<vpRGBa> &I, const vpImagePoint &topLeft, unsigned int width,
851  unsigned int height, const vpColor &color, bool fill = false,
852  unsigned int thickness = 1);
853  static void displayRectangle(const vpImage<vpRGBa> &I, const vpImagePoint &topLeft, const vpImagePoint &bottomRight,
854  const vpColor &color, bool fill = false, unsigned int thickness = 1);
855  static void displayRectangle(const vpImage<vpRGBa> &I, const vpRect &rectangle, const vpColor &color,
856  bool fill = false, unsigned int thickness = 1);
857  static void displayRectangle(const vpImage<vpRGBa> &I, const vpImagePoint &center, float angle, unsigned int width,
858  unsigned int height, const vpColor &color, unsigned int thickness = 1);
859  static void displayRectangle(const vpImage<vpRGBa> &I, int i, int j, unsigned int width, unsigned int height,
860  const vpColor &color, bool fill = false, unsigned int thickness = 1);
861  static void displayRectangle(const vpImage<vpRGBa> &I, unsigned int i, unsigned int j, float angle,
862  unsigned int width, unsigned int height, const vpColor &color,
863  unsigned int thickness = 1);
864  static void displayROI(const vpImage<vpRGBa> &I, const vpRect &roi);
865  static void displayText(const vpImage<vpRGBa> &I, const vpImagePoint &ip, const std::string &s, const vpColor &color);
866  static void displayText(const vpImage<vpRGBa> &I, int i, int j, const std::string &s, const vpColor &color);
867 
868  static void flush(const vpImage<vpRGBa> &I);
869  static void flushROI(const vpImage<vpRGBa> &I, const vpRect &roi);
870 
871  static bool getClick(const vpImage<vpRGBa> &I, bool blocking = true);
872  static bool getClick(const vpImage<vpRGBa> &I, vpImagePoint &ip, bool blocking = true);
873  static bool getClick(const vpImage<vpRGBa> &I, vpImagePoint &ip, vpMouseButton::vpMouseButtonType &button,
874  bool blocking = true);
875  static bool getClick(const vpImage<vpRGBa> &I, vpMouseButton::vpMouseButtonType &button, bool blocking = true);
876  static bool getClickUp(const vpImage<vpRGBa> &I, vpImagePoint &ip, vpMouseButton::vpMouseButtonType &button,
877  bool blocking = true);
878  static bool getClickUp(const vpImage<vpRGBa> &I, vpMouseButton::vpMouseButtonType &button, bool blocking = true);
879  static unsigned int getDownScalingFactor(const vpImage<vpRGBa> &I);
880  static void getImage(const vpImage<vpRGBa> &Is, vpImage<vpRGBa> &Id);
881  static bool getKeyboardEvent(const vpImage<vpRGBa> &I, bool blocking = true);
882  static bool getKeyboardEvent(const vpImage<vpRGBa> &I, std::string &key, bool blocking = true);
883  static bool getKeyboardEvent(const vpImage<vpRGBa> &I, char *key, bool blocking = true);
884  static bool getPointerMotionEvent(const vpImage<vpRGBa> &I, vpImagePoint &ip);
885  static bool getPointerPosition(const vpImage<vpRGBa> &I, vpImagePoint &ip);
886 
887  static void setBackground(const vpImage<vpRGBa> &I, const vpColor &color);
888  static void setFont(const vpImage<vpRGBa> &I, const std::string &font);
889  static void setTitle(const vpImage<vpRGBa> &I, const std::string &windowtitle);
890  static void setWindowPosition(const vpImage<vpRGBa> &I, int winx, int winy);
892 
893 private:
895  virtual void getImage(vpImage<vpRGBa> &I) = 0;
896 };
897 
898 #endif
unsigned int m_height
Definition: vpDisplay.h:210
bool isInitialised()
Definition: vpDisplay.h:257
int m_windowYPosition
display position
Definition: vpDisplay.h:208
Class that defines generic functionnalities for display.
Definition: vpDisplay.h:171
Implementation of an homogeneous matrix and operations on such kind of matrices.
unsigned int getWidth() const
Definition: vpDisplay.h:239
Class to define colors available for display functionnalities.
Definition: vpColor.h:120
static const vpColor none
Definition: vpColor.h:192
bool m_displayHasBeenInitialized
display has been initialized
Definition: vpDisplay.h:204
static const vpColor green
Definition: vpColor.h:183
int m_windowXPosition
display position
Definition: vpDisplay.h:206
unsigned int m_scale
Definition: vpDisplay.h:212
Generic class defining intrinsic camera parameters.
vpScaleType m_scaleType
Definition: vpDisplay.h:213
std::string m_title
Definition: vpDisplay.h:211
int getWindowYPosition() const
Definition: vpDisplay.h:250
unsigned int m_width
Definition: vpDisplay.h:209
unsigned int getDownScalingFactor()
Definition: vpDisplay.h:229
Defines a rectangle in the plane.
Definition: vpRect.h:78
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
Definition: vpImagePoint.h:88
static const vpColor white
Definition: vpColor.h:175
unsigned int getHeight() const
Definition: vpDisplay.h:234
int getWindowXPosition() const
Definition: vpDisplay.h:245