OSGWidget.hpp 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. #pragma once
  2. // Include dependencies
  3. #include <QPoint>
  4. #include <QOpenGLWidget>
  5. #include <osg/ref_ptr>
  6. #include <osgViewer/GraphicsWindow>
  7. #include <osgViewer/CompositeViewer>
  8. namespace osgWidget {
  9. //! The subclass of osgViewer::CompositeViewer we use
  10. /*!
  11. * This subclassing allows us to remove the annoying automatic
  12. * setting of the CPU affinity to core 0 by osgViewer::ViewerBase,
  13. * osgViewer::CompositeViewer's base class.
  14. */
  15. class Viewer: public osgViewer::CompositeViewer {
  16. public:
  17. virtual void setupThreading();
  18. };
  19. }
  20. class PickHandler; // Forward declaration
  21. class TrackPointRenderer; // Forward declaration
  22. class OSGWidget : public QOpenGLWidget {
  23. Q_OBJECT
  24. public:
  25. static void fixMaterialState(osg::ref_ptr<osg::Node> node, osg::Vec4* color = nullptr);
  26. OSGWidget(QWidget* parent = nullptr);
  27. virtual ~OSGWidget();
  28. void renderBaseMesh(const osg::ref_ptr<osg::Vec3Array> vertices, const osg::ref_ptr<osg::Vec3Array> normals);
  29. osg::ref_ptr<osg::Geode> getMesh();
  30. PickHandler* getPicker();
  31. TrackPointRenderer* getPointRenderer();
  32. void loadSteamvrThread();
  33. osg::ref_ptr<osg::Geometry> _steamvrThreadMesh;
  34. protected:
  35. virtual void paintEvent(QPaintEvent* paintEvent);
  36. virtual void paintGL();
  37. virtual void resizeGL(int width, int height);
  38. virtual void keyPressEvent(QKeyEvent* event);
  39. virtual void keyReleaseEvent(QKeyEvent* event);
  40. virtual void mouseMoveEvent(QMouseEvent* event);
  41. virtual void mousePressEvent(QMouseEvent* event);
  42. virtual void mouseReleaseEvent(QMouseEvent* event);
  43. virtual void wheelEvent(QWheelEvent* event);
  44. virtual bool event(QEvent* event);
  45. private:
  46. virtual void onHome();
  47. virtual void onResize(int width, int height);
  48. osg::ref_ptr<osg::Group> createAxesPreview();
  49. osgGA::EventQueue* getEventQueue() const;
  50. PickHandler* _picker;
  51. TrackPointRenderer* _pointRenderer;
  52. osg::ref_ptr<osgViewer::GraphicsWindowEmbedded> graphicsWindow_;
  53. osg::ref_ptr<osgWidget::Viewer> _viewer;
  54. osgViewer::View* _view;
  55. osg::ref_ptr<osg::Group> _root;
  56. osg::ref_ptr<osg::Group> _pointRoot;
  57. osg::ref_ptr<osg::Group> _coordinateAxes;
  58. osg::ref_ptr<osg::Geode> _mesh;
  59. QPoint selectionStart_;
  60. QPoint selectionEnd_;
  61. bool selectionActive_;
  62. bool selectionFinished_;
  63. bool _steamvrLoaded = false;
  64. };