Ignition Gui

API Reference

5.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/gui/qt.h"
33 #include "ignition/gui/Plugin.hh"
34 
35 namespace ignition
36 {
37 namespace gui
38 {
39 namespace plugins
40 {
41  class IgnRendererPrivate;
42  class RenderWindowItemPrivate;
43  class Scene3DPrivate;
44 
61  class Scene3D : public Plugin
62  {
63  Q_OBJECT
64 
66  public: Scene3D();
67 
69  public: virtual ~Scene3D();
70 
71  // Documentation inherited
72  public: virtual void LoadConfig(const tinyxml2::XMLElement *_pluginElem)
73  override;
74 
77  private: std::unique_ptr<Scene3DPrivate> dataPtr;
78  };
79 
87  {
89  public: IgnRenderer();
90 
92  public: ~IgnRenderer();
93 
95  public: void Render();
96 
98  public: void Initialize();
99 
101  public: void Destroy();
102 
106  public: void NewMouseEvent(const common::MouseEvent &_e,
107  const math::Vector2d &_drag = math::Vector2d::Zero);
108 
110  private: void HandleMouseEvent();
111 
116  private: math::Vector3d ScreenToScene(const math::Vector2i &_screenPos)
117  const;
118 
120  public: GLuint textureId = 0u;
121 
123  public: std::string engineName = "ogre";
124 
126  public: std::string sceneName = "scene";
127 
129  public: math::Pose3d cameraPose = math::Pose3d(0, 0, 2, 0, 0.4, 0);
130 
132  public: math::Color backgroundColor = math::Color::Black;
133 
135  public: math::Color ambientLight = math::Color(0.3f, 0.3f, 0.3f, 1.0f);
136 
138  public: bool initialized = false;
139 
141  public: QSize textureSize = QSize(1024, 1024);
142 
144  public: bool textureDirty = false;
145 
150 
154 
157 
162 
165  private: std::unique_ptr<IgnRendererPrivate> dataPtr;
166  };
167 
169  class RenderThread : public QThread
170  {
171  Q_OBJECT
172 
174  public: RenderThread();
175 
177  public slots: void RenderNext();
178 
180  public slots: void ShutDown();
181 
183  public slots: void SizeChanged();
184 
189  signals: void TextureReady(int _id, const QSize &_size);
190 
192  public: QOffscreenSurface *surface = nullptr;
193 
195  public: QOpenGLContext *context = nullptr;
196 
199  };
200 
201 
203  class RenderWindowItem : public QQuickItem
204  {
205  Q_OBJECT
206 
209  public: explicit RenderWindowItem(QQuickItem *_parent = nullptr);
210 
212  public: virtual ~RenderWindowItem();
213 
216  public: void SetBackgroundColor(const math::Color &_color);
217 
220  public: void SetAmbientLight(const math::Color &_ambient);
221 
224  public: void SetEngineName(const std::string &_name);
225 
228  public: void SetSceneName(const std::string &_name);
229 
232  public: void SetCameraPose(const math::Pose3d &_pose);
233 
238  public: void SetSceneService(const std::string &_service);
239 
244  public: void SetPoseTopic(const std::string &_topic);
245 
250  public: void SetDeletionTopic(const std::string &_topic);
251 
255  public: void SetSceneTopic(const std::string &_topic);
256 
258  public Q_SLOTS: void Ready();
259 
260  // Documentation inherited
261  protected: virtual void mousePressEvent(QMouseEvent *_e) override;
262 
263  // Documentation inherited
264  protected: virtual void mouseReleaseEvent(QMouseEvent *_e) override;
265 
266  // Documentation inherited
267  protected: virtual void mouseMoveEvent(QMouseEvent *_e) override;
268 
269  // Documentation inherited
270  protected: virtual void wheelEvent(QWheelEvent *_e) override;
271 
278  private: QSGNode *updatePaintNode(QSGNode *_oldNode,
279  QQuickItem::UpdatePaintNodeData *_data) override;
280 
284  };
285 
287  class TextureNode : public QObject, public QSGSimpleTextureNode
288  {
289  Q_OBJECT
290 
293  public: explicit TextureNode(QQuickWindow *_window);
294 
296  public: ~TextureNode() override;
297 
302  public slots: void NewTexture(int _id, const QSize &_size);
303 
306  public slots: void PrepareNode();
307 
310  signals: void TextureInUse();
311 
314  signals: void PendingNewTexture();
315 
317  public: int id = 0;
318 
320  public: QSize size = QSize(0, 0);
321 
323  public: QMutex mutex;
324 
326  public: QSGTexture *texture = nullptr;
327 
329  public: QQuickWindow *window = nullptr;
330  };
331 }
332 }
333 }
334 
335 #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:149
virtual ~Scene3D()
Destructor.
Base class for Ignition GUI plugins.
Definition: Plugin.hh:54
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:153
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:61
A QQUickItem that manages the render window.
Definition: Scene3D.hh:203
std::string deletionTopic
Ign-transport deletion topic name.
Definition: Scene3D.hh:156
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:86
Rendering thread.
Definition: Scene3D.hh:169
QMutex mutex
Mutex to protect the texture variables.
Definition: Scene3D.hh:323
Texture node for displaying the render texture from ign-renderer.
Definition: Scene3D.hh:287
Definition: Application.hh:40
std::string sceneTopic
Ign-transport scene topic name New scene messages will be published to this topic when an entities ar...
Definition: Scene3D.hh:161
IgnRenderer ignRenderer
Ign-rendering renderer.
Definition: Scene3D.hh:198