Gazebo Gui

API Reference

9.0.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 <QImage>
22#include <QString>
23#include <QStringList>
24#include <QQuickImageProvider>
25
26#include <gz/msgs/image.pb.h>
27
28#ifndef _WIN32
29# define ImageDisplay_EXPORTS_API __attribute__ ((visibility ("default")))
30#else
31# if (defined(ImageDisplay_EXPORTS))
32# define ImageDisplay_EXPORTS_API __declspec(dllexport)
33# else
34# define ImageDisplay_EXPORTS_API __declspec(dllimport)
35# endif
36#endif
37
38#include "gz/gui/Plugin.hh"
39
40#include <gz/utils/ImplPtr.hh>
41
42namespace gz::gui::plugins
43{
44 class ImageProvider : public QQuickImageProvider
45 {
46 public: ImageProvider()
47 : QQuickImageProvider(QQuickImageProvider::Image)
48 {
49 }
50
51 public: QImage requestImage(const QString &, QSize *,
52 const QSize &) override
53 {
54 if (!this->img.isNull())
55 {
56 // Must return a copy
57 return this->img;
58 }
59
60 // Placeholder in case we have no image yet
61 QImage i(400, 400, QImage::Format_RGB888);
62 i.fill(QColor(128, 128, 128, 100));
63 return i;
64 }
65
66 public: void SetImage(const QImage &_image)
67 {
68 this->img = _image;
69 }
70
71 private: QImage img;
72 };
73
84 {
85 Q_OBJECT
86
88 Q_PROPERTY(
89 QStringList topicList
90 READ TopicList
91 WRITE SetTopicList
92 NOTIFY TopicListChanged
93 )
94
95
96 public: ImageDisplay();
97
99 public: virtual ~ImageDisplay();
100
101 // Documentation inherited
102 public: virtual void LoadConfig(const tinyxml2::XMLElement *_pluginElem);
103
105 public slots: void OnRefresh();
106
108 public slots: void OnTopic(const QString _topic);
109
113 public: Q_INVOKABLE QStringList TopicList() const;
114
118 public: Q_INVOKABLE void SetTopicList(const QStringList &_topicList);
119
122 public: Q_INVOKABLE void RegisterImageProvider(const QString &_uniqueName);
123
125 public: Q_INVOKABLE QString ImageProviderName();
126
132 public: inline void SetEnableDepthFlip(bool _enable);
133
138 public: Q_INVOKABLE void SetFlipDepthVisualization(bool _value);
139
141 signals: void TopicListChanged();
142
144 signals: void newImage();
145
146 private slots: void ProcessImage();
147
150 private: void OnImageMsg(const gz::msgs::Image &_msg);
151
154 GZ_UTILS_UNIQUE_IMPL_PTR(dataPtr)
155 };
156} // namespace gz::gui::plugins
157
158#endif // GZ_GUI_PLUGINS_IMAGEDISPLAY_HH_