Ignition Gui

API Reference

1.0.0
Scene3D.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 IGNITION_GUI_PLUGINS_SCENE3D_HH_
19 #define IGNITION_GUI_PLUGINS_SCENE3D_HH_
20 
21 #include <string>
22 #include <memory>
23 #include <mutex>
24 
25 #include <ignition/math/Color.hh>
26 #include <ignition/math/Pose3.hh>
27 #include <ignition/math/Vector2.hh>
28 #include <ignition/math/Vector3.hh>
29 
30 #include <ignition/common/MouseEvent.hh>
31 
32 #include <ignition/rendering/Camera.hh>
33 #include <ignition/rendering/OrbitViewController.hh>
34 
35 #include "ignition/gui/qt.h"
36 #include "ignition/gui/Plugin.hh"
37 
38 namespace ignition
39 {
40 namespace gui
41 {
42 namespace plugins
43 {
44  class IgnRendererPrivate;
45  class RenderWindowItemPrivate;
46  class Scene3DPrivate;
47 
64  class Scene3D : public Plugin
65  {
66  Q_OBJECT
67 
69  public: Scene3D();
70 
72  public: virtual ~Scene3D();
73 
74  // Documentation inherited
75  public: virtual void LoadConfig(const tinyxml2::XMLElement *_pluginElem)
76  override;
77 
80  private: std::unique_ptr<Scene3DPrivate> dataPtr;
81  };
82 
90  {
92  public: IgnRenderer();
93 
95  public: ~IgnRenderer();
96 
98  public: void Render();
99 
101  public: void Initialize();
102 
104  public: void Destroy();
105 
109  public: void NewMouseEvent(const common::MouseEvent &_e,
110  const math::Vector2d &_drag = math::Vector2d::Zero);
111 
113  private: void HandleMouseEvent();
114 
119  private: math::Vector3d ScreenToScene(const math::Vector2i &_screenPos)
120  const;
121 
123  public: GLuint textureId = 0u;
124 
126  public: std::string engineName = "ogre";
127 
129  public: std::string sceneName = "scene";
130 
132  public: math::Pose3d cameraPose = math::Pose3d(0, 0, 2, 0, 0.4, 0);
133 
135  public: math::Color backgroundColor = math::Color::Black;
136 
138  public: math::Color ambientLight = math::Color(0.3, 0.3, 0.3, 1.0);
139 
141  public: bool initialized = false;
142 
144  public: QSize textureSize = QSize(1024, 1024);
145 
147  public: bool textureDirty = false;
148 
153 
157 
160 
165 
168  private: std::unique_ptr<IgnRendererPrivate> dataPtr;
169  };
170 
172  class RenderThread : public QThread
173  {
174  Q_OBJECT
175 
177  public: RenderThread();
178 
180  public slots: void RenderNext();
181 
183  public slots: void ShutDown();
184 
186  public slots: void SizeChanged();
187 
192  signals: void TextureReady(int _id, const QSize &_size);
193 
195  public: QOffscreenSurface *surface = nullptr;
196 
198  public: QOpenGLContext *context = nullptr;
199 
202  };
203 
204 
206  class RenderWindowItem : public QQuickItem
207  {
208  Q_OBJECT
209 
212  public: explicit RenderWindowItem(QQuickItem *_parent = nullptr);
213 
215  public: virtual ~RenderWindowItem();
216 
219  public: void SetBackgroundColor(const math::Color &_color);
220 
223  public: void SetAmbientLight(const math::Color &_ambient);
224 
227  public: void SetEngineName(const std::string &_name);
228 
231  public: void SetSceneName(const std::string &_name);
232 
235  public: void SetCameraPose(const math::Pose3d &_pose);
236 
241  public: void SetSceneService(const std::string &_service);
242 
247  public: void SetPoseTopic(const std::string &_topic);
248 
253  public: void SetDeletionTopic(const std::string &_topic);
254 
258  public: void SetSceneTopic(const std::string &_topic);
259 
261  public Q_SLOTS: void Ready();
262 
263  // Documentation inherited
264  protected: virtual void mousePressEvent(QMouseEvent *_e) override;
265 
266  // Documentation inherited
267  protected: virtual void mouseReleaseEvent(QMouseEvent *_e) override;
268 
269  // Documentation inherited
270  protected: virtual void mouseMoveEvent(QMouseEvent *_e) override;
271 
272  // Documentation inherited
273  protected: virtual void wheelEvent(QWheelEvent *_e) override;
274 
281  private: QSGNode *updatePaintNode(QSGNode *_oldNode,
282  QQuickItem::UpdatePaintNodeData *_data) override;
283 
287  };
288 
290  class TextureNode : public QObject, public QSGSimpleTextureNode
291  {
292  Q_OBJECT
293 
296  public: explicit TextureNode(QQuickWindow *_window);
297 
299  public: ~TextureNode() override;
300 
305  public slots: void NewTexture(int _id, const QSize &_size);
306 
309  public slots: void PrepareNode();
310 
313  signals: void TextureInUse();
314 
317  signals: void PendingNewTexture();
318 
320  public: int id = 0;
321 
323  public: QSize size = QSize(0, 0);
324 
326  public: QMutex mutex;
327 
329  public: QSGTexture *texture = nullptr;
330 
332  public: QQuickWindow *window = nullptr;
333  };
334 }
335 }
336 }
337 
338 #endif
std::string sceneService
Scene service. If not empty, a request will be made to get the scene information using this service a...
Definition: Scene3D.hh:152
virtual ~Scene3D()
Destructor.
Base class for Ignition GUI plugins.
Definition: Plugin.hh:47
STL class.
std::string poseTopic
Scene pose topic. If not empty, a node will subcribe to this topic to get pose updates of objects in ...
Definition: Scene3D.hh:156
Creates a new ignition rendering scene or adds a user-camera to an existing scene. It is possible to orbit the camera around the scene with the mouse. Use other plugins to manage objects in the scene.
Definition: Scene3D.hh:64
A QQUickItem that manages the render window.
Definition: Scene3D.hh:206
std::string deletionTopic
Ign-transport deletion topic name.
Definition: Scene3D.hh:159
virtual void LoadConfig(const tinyxml2::XMLElement *_pluginElem) override
Load the plugin with a configuration file. Override this on custom plugins to handle custom configura...
Ign-rendering renderer. All ign-rendering calls should be performed inside this class as it makes sur...
Definition: Scene3D.hh:89
Rendering thread.
Definition: Scene3D.hh:172
QMutex mutex
Mutex to protect the texture variables.
Definition: Scene3D.hh:326
Texture node for displaying the render texture from ign-renderer.
Definition: Scene3D.hh:290
Definition: Application.hh:33
std::string sceneTopic
Ign-transport scene topic name New scene messages will be published to this topic when an entities ar...
Definition: Scene3D.hh:164
IgnRenderer ignRenderer
Ign-rendering renderer.
Definition: Scene3D.hh:201