Ignition Gui

API Reference

7.0.0~pre1
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 
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 
74  public slots: void OnHovered(int _mouseX, int _mouseY);
75 
78  public slots: void OnFocusWindow();
79 
80  // Documentation inherited
81  protected: bool eventFilter(QObject *_obj, QEvent *_event) override;
82 
83  // Documentation inherited
84  public: virtual void LoadConfig(const tinyxml2::XMLElement *_pluginElem)
85  override;
86 
89  private: std::unique_ptr<Scene3DPrivate> dataPtr;
90  };
91 
98  class IgnRenderer
99  {
101  public: IgnRenderer();
102 
104  public: ~IgnRenderer();
105 
107  public: void Render();
108 
110  public: void Initialize();
111 
113  public: void Destroy();
114 
118  public: void NewMouseEvent(const common::MouseEvent &_e,
119  const math::Vector2d &_drag = math::Vector2d::Zero);
120 
123  public: void NewHoverEvent(const math::Vector2i &_hoverPos);
124 
127  public: void HandleKeyPress(QKeyEvent *_e);
128 
131  public: void HandleKeyRelease(QKeyEvent *_e);
132 
134  private: void HandleMouseEvent();
135 
137  private: void HandleMouseViewControl();
138 
140  private: void BroadcastHoverPos();
141 
143  private: void BroadcastLeftClick();
144 
146  private: void BroadcastRightClick();
147 
149  private: void BroadcastKeyRelease();
150 
152  private: void BroadcastKeyPress();
153 
158  private: math::Vector3d ScreenToScene(const math::Vector2i &_screenPos)
159  const;
160 
162  public: GLuint textureId = 0u;
163 
165  public: std::string engineName = "ogre";
166 
168  public: std::string sceneName = "scene";
169 
171  public: math::Pose3d cameraPose = math::Pose3d(0, 0, 2, 0, 0.4, 0);
172 
174  public: math::Color backgroundColor = math::Color::Black;
175 
177  public: math::Color ambientLight = math::Color(0.3f, 0.3f, 0.3f, 1.0f);
178 
180  public: bool initialized = false;
181 
183  public: QSize textureSize = QSize(1024, 1024);
184 
186  public: bool textureDirty = false;
187 
191  public: std::string sceneService;
192 
195  public: std::string poseTopic;
196 
198  public: std::string deletionTopic;
199 
203  public: std::string sceneTopic;
204 
207  private: std::unique_ptr<IgnRendererPrivate> dataPtr;
208  };
209 
211  class RenderThread : public QThread
212  {
213  Q_OBJECT
214 
216  public: RenderThread();
217 
219  public slots: void RenderNext();
220 
222  public slots: void ShutDown();
223 
225  public slots: void SizeChanged();
226 
231  signals: void TextureReady(int _id, const QSize &_size);
232 
234  public: QOffscreenSurface *surface = nullptr;
235 
237  public: QOpenGLContext *context = nullptr;
238 
240  public: IgnRenderer ignRenderer;
241  };
242 
243 
245  class RenderWindowItem : public QQuickItem
246  {
247  Q_OBJECT
248 
251  public: explicit RenderWindowItem(QQuickItem *_parent = nullptr);
252 
254  public: virtual ~RenderWindowItem();
255 
258  public: void SetBackgroundColor(const math::Color &_color);
259 
262  public: void SetAmbientLight(const math::Color &_ambient);
263 
266  public: void SetEngineName(const std::string &_name);
267 
270  public: void SetSceneName(const std::string &_name);
271 
274  public: void SetCameraPose(const math::Pose3d &_pose);
275 
280  public: void SetSceneService(const std::string &_service);
281 
286  public: void SetPoseTopic(const std::string &_topic);
287 
292  public: void SetDeletionTopic(const std::string &_topic);
293 
297  public: void SetSceneTopic(const std::string &_topic);
298 
302  public: void OnHovered(const ignition::math::Vector2i &_hoverPos);
303 
305  public Q_SLOTS: void Ready();
306 
309  public: void HandleKeyPress(QKeyEvent *_e);
310 
313  public: void HandleKeyRelease(QKeyEvent *_e);
314 
315  // Documentation inherited
316  protected: virtual void mousePressEvent(QMouseEvent *_e) override;
317 
318  // Documentation inherited
319  protected: virtual void mouseReleaseEvent(QMouseEvent *_e) override;
320 
321  // Documentation inherited
322  protected: virtual void mouseMoveEvent(QMouseEvent *_e) override;
323 
324  // Documentation inherited
325  protected: virtual void wheelEvent(QWheelEvent *_e) override;
326 
327  // Documentation inherited
328  protected: virtual void keyPressEvent(QKeyEvent *_event) override;
329 
330  // Documentation inherited
331  protected: virtual void keyReleaseEvent(QKeyEvent *_event) override;
332 
339  private: QSGNode *updatePaintNode(QSGNode *_oldNode,
340  QQuickItem::UpdatePaintNodeData *_data) override;
341 
345  };
346 
348  class TextureNode : public QObject, public QSGSimpleTextureNode
349  {
350  Q_OBJECT
351 
354  public: explicit TextureNode(QQuickWindow *_window);
355 
357  public: ~TextureNode() override;
358 
363  public slots: void NewTexture(int _id, const QSize &_size);
364 
367  public slots: void PrepareNode();
368 
371  signals: void TextureInUse();
372 
375  signals: void PendingNewTexture();
376 
378  public: int id = 0;
379 
381  public: QSize size = QSize(0, 0);
382 
384  public: QMutex mutex;
385 
387  public: QSGTexture *texture = nullptr;
388 
390  public: QQuickWindow *window = nullptr;
391  };
392 }
393 }
394 }
395 
396 #endif
void OnHovered(int _mouseX, int _mouseY)
Callback when the mouse hovers to a new position.
virtual ~Scene3D()
Destructor.
Base class for Ignition GUI plugins.
Definition: Plugin.hh:54
STL class.
Pose3< double > Pose3d
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: MinimalScene.hh:259
static const Vector2< T > Zero
void OnFocusWindow()
Callback when the mouse enters the render window to focus the window for mouse/key events...
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: MinimalScene.hh:96
bool eventFilter(QObject *_obj, QEvent *_event) override
Rendering thread.
Definition: MinimalScene.hh:225
Texture node for displaying the render texture from ign-renderer.
Definition: MinimalScene.hh:371
static const Color Black