Gazebo Gui

API Reference

3.12.1
ImageDisplay.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2017 Open Source Robotics Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16 */
17 
18 #ifndef GZ_GUI_PLUGINS_IMAGEDISPLAY_HH_
19 #define GZ_GUI_PLUGINS_IMAGEDISPLAY_HH_
20 
21 #include <algorithm>
22 #include <memory>
23 #include <QQuickImageProvider>
24 
25 #ifdef _MSC_VER
26 #pragma warning(push, 0)
27 #endif
28 #include <gz/msgs/image.pb.h>
29 #ifdef _MSC_VER
30 #pragma warning(pop)
31 #endif
32 
33 #ifndef _WIN32
34 # define ImageDisplay_EXPORTS_API
35 #else
36 # if (defined(ImageDisplay_EXPORTS))
37 # define ImageDisplay_EXPORTS_API __declspec(dllexport)
38 # else
39 # define ImageDisplay_EXPORTS_API __declspec(dllimport)
40 # endif
41 #endif
42 
43 #include "gz/gui/Plugin.hh"
44 
45 namespace ignition
46 {
47 namespace gui
48 {
49 namespace plugins
50 {
51  class ImageDisplayPrivate;
52 
53  class ImageProvider : public QQuickImageProvider
54  {
55  public: ImageProvider()
56  : QQuickImageProvider(QQuickImageProvider::Image)
57  {
58  }
59 
60  public: QImage requestImage(const QString &, QSize *,
61  const QSize &) override
62  {
63  if (!this->img.isNull())
64  {
65  // Must return a copy
66  QImage copy(this->img);
67  return copy;
68  }
69 
70  // Placeholder in case we have no image yet
71  QImage i(400, 400, QImage::Format_RGB888);
72  i.fill(QColor(128, 128, 128, 100));
73  return i;
74  }
75 
76  public: void SetImage(const QImage &_image)
77  {
78  this->img = _image;
79  }
80 
81  private: QImage img;
82  };
83 
92  {
93  Q_OBJECT
94 
96  Q_PROPERTY(
97  QStringList topicList
98  READ TopicList
99  WRITE SetTopicList
100  NOTIFY TopicListChanged
101  )
102 
103 
104  public: ImageDisplay();
105 
107  public: virtual ~ImageDisplay();
108 
109  // Documentation inherited
110  public: virtual void LoadConfig(const tinyxml2::XMLElement *_pluginElem);
111 
113  public slots: void OnRefresh();
114 
116  public slots: void OnTopic(const QString _topic);
117 
121  public: Q_INVOKABLE QStringList TopicList() const;
122 
126  public: Q_INVOKABLE void SetTopicList(const QStringList &_topicList);
127 
129  signals: void TopicListChanged();
130 
132  signals: void newImage();
133 
135  private slots: void ProcessImage();
136 
138  private: void UpdateFromRgbInt8();
139 
141  private: void UpdateFromFloat32();
142 
144  private: void UpdateFromLInt16();
145 
148  private: void OnImageMsg(const gz::msgs::Image &_msg);
149 
152  private: std::unique_ptr<ImageDisplayPrivate> dataPtr;
153  };
154 }
155 }
156 }
157 
158 #endif
void fill(uint pixelValue)
void SetImage(const QImage &_image)
Definition: ImageDisplay.hh:76
#define ImageDisplay_EXPORTS_API
Definition: ImageDisplay.hh:34
Base class for Gazebo GUI plugins.
Definition: gz/gui/Plugin.hh:54
Display images coming through an Gazebo transport topic.
Definition: ImageDisplay.hh:91
Definition: ImageDisplay.hh:53
bool isNull() const
ImageProvider()
Definition: ImageDisplay.hh:55
QImage requestImage(const QString &, QSize *, const QSize &) override
Definition: ImageDisplay.hh:60
STL namespace.
Definition: gz/gui/Application.hh:35