OSGWidget.hpp 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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);
  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. protected:
  33. virtual void paintEvent(QPaintEvent* paintEvent);
  34. virtual void paintGL();
  35. virtual void resizeGL(int width, int height);
  36. virtual void keyPressEvent(QKeyEvent* event);
  37. virtual void keyReleaseEvent(QKeyEvent* event);
  38. virtual void mouseMoveEvent(QMouseEvent* event);
  39. virtual void mousePressEvent(QMouseEvent* event);
  40. virtual void mouseReleaseEvent(QMouseEvent* event);
  41. virtual void wheelEvent(QWheelEvent* event);
  42. virtual bool event(QEvent* event);
  43. private:
  44. virtual void onHome();
  45. virtual void onResize(int width, int height);
  46. osg::ref_ptr<osg::Group> createAxesPreview();
  47. osgGA::EventQueue* getEventQueue() const;
  48. PickHandler* _picker;
  49. TrackPointRenderer* _pointRenderer;
  50. osg::ref_ptr<osgViewer::GraphicsWindowEmbedded> graphicsWindow_;
  51. osg::ref_ptr<osgWidget::Viewer> _viewer;
  52. osgViewer::View* _view;
  53. osg::ref_ptr<osg::Group> _root;
  54. osg::ref_ptr<osg::Group> _pointRoot;
  55. osg::ref_ptr<osg::Group> _coordinateAxes;
  56. osg::ref_ptr<osg::Geode> _mesh;
  57. QPoint selectionStart_;
  58. QPoint selectionEnd_;
  59. bool selectionActive_;
  60. bool selectionFinished_;
  61. };