OSGWidget.hpp 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. osg::ref_ptr<osg::Group> getVerifyGroup();
  31. PickHandler* getPicker();
  32. TrackPointRenderer* getPointRenderer();
  33. void loadSteamvrThread();
  34. void loadSteamvrCollision();
  35. void clear();
  36. osg::ref_ptr<osg::Geometry> _steamvrThreadMesh;
  37. osg::ref_ptr<osg::Geometry> _steamvrTrackerMesh;
  38. protected:
  39. virtual void paintEvent(QPaintEvent* paintEvent);
  40. virtual void paintGL();
  41. virtual void resizeGL(int width, int height);
  42. virtual void keyPressEvent(QKeyEvent* event);
  43. virtual void keyReleaseEvent(QKeyEvent* event);
  44. virtual void mouseMoveEvent(QMouseEvent* event);
  45. virtual void mousePressEvent(QMouseEvent* event);
  46. virtual void mouseReleaseEvent(QMouseEvent* event);
  47. virtual void wheelEvent(QWheelEvent* event);
  48. virtual bool event(QEvent* event);
  49. private:
  50. virtual void onHome();
  51. virtual void onResize(int width, int height);
  52. osg::ref_ptr<osg::Group> createAxesPreview();
  53. osgGA::EventQueue* getEventQueue() const;
  54. PickHandler* _picker;
  55. TrackPointRenderer* _pointRenderer;
  56. osg::ref_ptr<osgViewer::GraphicsWindowEmbedded> graphicsWindow_;
  57. osg::ref_ptr<osgWidget::Viewer> _viewer;
  58. osgViewer::View* _view;
  59. osg::ref_ptr<osg::Group> _root;
  60. osg::ref_ptr<osg::Group> _pointRoot;
  61. osg::ref_ptr<osg::Group> _verifyGroup;
  62. osg::ref_ptr<osg::Group> _coordinateAxes;
  63. osg::ref_ptr<osg::Geode> _mesh;
  64. QPoint selectionStart_;
  65. QPoint selectionEnd_;
  66. bool selectionActive_;
  67. bool selectionFinished_;
  68. bool _steamvrLoaded = false;
  69. bool _steamvrCollisionLoaded = false;
  70. };