From aff525a1ca7f7b080f15bfee698db4972613050b Mon Sep 17 00:00:00 2001 From: Alexander Vieth Date: Mon, 14 Apr 2025 09:52:37 +0200 Subject: [PATCH 1/4] Fix build --- ExampleViewOpenGL/src/ExampleGLWidget.cpp | 24 +++++++++++------------ ExampleViewOpenGL/src/ExampleGLWidget.h | 2 -- 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/ExampleViewOpenGL/src/ExampleGLWidget.cpp b/ExampleViewOpenGL/src/ExampleGLWidget.cpp index 51868a1..48e751f 100644 --- a/ExampleViewOpenGL/src/ExampleGLWidget.cpp +++ b/ExampleViewOpenGL/src/ExampleGLWidget.cpp @@ -3,6 +3,7 @@ #include #include +#include ExampleGLWidget::ExampleGLWidget() : QOpenGLWidget(), @@ -11,8 +12,7 @@ ExampleGLWidget::ExampleGLWidget() : _pointRenderer(), _pixelRatio(1.0f), _points(), - _colors(), - _bounds() + _colors() { setAcceptDrops(true); @@ -59,23 +59,23 @@ void ExampleGLWidget::setData(const std::vector& points, float poi constexpr mv::Vector3f pointColor = {0.f, 0.f, 0.f}; for(unsigned long i = 0; i < numPoints; i++) - _colors.emplace_back(pointColor); + _colors.push_back(pointColor); - _bounds = Bounds::Max; + Bounds bounds = Bounds::Max; - for (const Vector2f& point : _points) + for (const Vector2f& point : points) { - _bounds.setLeft(std::min(point.x, _bounds.getLeft())); - _bounds.setRight(std::max(point.x, _bounds.getRight())); - _bounds.setBottom(std::min(point.y, _bounds.getBottom())); - _bounds.setTop(std::max(point.y, _bounds.getTop())); + bounds.setLeft(std::min(point.x, bounds.getLeft())); + bounds.setRight(std::max(point.x, bounds.getRight())); + bounds.setBottom(std::min(point.y, bounds.getBottom())); + bounds.setTop(std::max(point.y, bounds.getTop())); } - _bounds.makeSquare(); - _bounds.expand(0.1f); + bounds.makeSquare(); + bounds.expand(0.1f); // Send the data to the renderer - _pointRenderer.setBounds(_bounds); + _pointRenderer.setDataBounds(QRectF(QPointF(bounds.getLeft(), bounds.getBottom()), QSizeF(bounds.getWidth(), bounds.getHeight()))); _pointRenderer.setData(_points); _pointRenderer.setColors(_colors); diff --git a/ExampleViewOpenGL/src/ExampleGLWidget.h b/ExampleViewOpenGL/src/ExampleGLWidget.h index 0fd3e60..cd63c81 100644 --- a/ExampleViewOpenGL/src/ExampleGLWidget.h +++ b/ExampleViewOpenGL/src/ExampleGLWidget.h @@ -3,7 +3,6 @@ #include #include #include -#include #include #include @@ -42,7 +41,6 @@ class ExampleGLWidget : public QOpenGLWidget, protected QOpenGLFunctions float _pixelRatio; /* device pixel ratio */ std::vector _points; /* 2D coordinates of points */ std::vector _colors; /* Color of points - here we use a constant color for simplicity */ - Bounds _bounds; /* Min and max point coordinates for camera placement */ QColor _backgroundColor; /* Background color */ bool _isInitialized; /* Whether OpenGL is initialized */ }; From 8c026459131dc5cf1441cf56ea2766d129877b68 Mon Sep 17 00:00:00 2001 From: Alexander Vieth Date: Mon, 14 Apr 2025 10:14:48 +0200 Subject: [PATCH 2/4] Reset view --- ExampleViewOpenGL/src/ExampleGLWidget.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ExampleViewOpenGL/src/ExampleGLWidget.cpp b/ExampleViewOpenGL/src/ExampleGLWidget.cpp index 48e751f..b29915a 100644 --- a/ExampleViewOpenGL/src/ExampleGLWidget.cpp +++ b/ExampleViewOpenGL/src/ExampleGLWidget.cpp @@ -82,6 +82,8 @@ void ExampleGLWidget::setData(const std::vector& points, float poi _pointRenderer.setPointSize(pointSize); _pointRenderer.setAlpha(pointOpacity); + _pointRenderer.getNavigator().resetView(); + // Calls paintGL() update(); } From f29f2e9f1ad881f0123a3981177fbf1ed5555742 Mon Sep 17 00:00:00 2001 From: Alexander Vieth Date: Mon, 14 Apr 2025 13:17:55 +0200 Subject: [PATCH 3/4] init navigator --- ExampleViewOpenGL/src/ExampleGLWidget.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ExampleViewOpenGL/src/ExampleGLWidget.cpp b/ExampleViewOpenGL/src/ExampleGLWidget.cpp index b29915a..f9d20e1 100644 --- a/ExampleViewOpenGL/src/ExampleGLWidget.cpp +++ b/ExampleViewOpenGL/src/ExampleGLWidget.cpp @@ -40,6 +40,7 @@ ExampleGLWidget::ExampleGLWidget() : setFormat(surfaceFormat); + _pointRenderer.getNavigator().initialize(this); } ExampleGLWidget::~ExampleGLWidget() @@ -82,7 +83,7 @@ void ExampleGLWidget::setData(const std::vector& points, float poi _pointRenderer.setPointSize(pointSize); _pointRenderer.setAlpha(pointOpacity); - _pointRenderer.getNavigator().resetView(); + _pointRenderer.getNavigator().resetView(true); // Calls paintGL() update(); From 201aec24b59a107742851543fe6508bdff876ef5 Mon Sep 17 00:00:00 2001 From: Alexander Vieth Date: Mon, 14 Apr 2025 13:57:29 +0200 Subject: [PATCH 4/4] Use helper functions --- ExampleViewOpenGL/src/ExampleGLWidget.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/ExampleViewOpenGL/src/ExampleGLWidget.cpp b/ExampleViewOpenGL/src/ExampleGLWidget.cpp index f9d20e1..75755cf 100644 --- a/ExampleViewOpenGL/src/ExampleGLWidget.cpp +++ b/ExampleViewOpenGL/src/ExampleGLWidget.cpp @@ -9,7 +9,7 @@ ExampleGLWidget::ExampleGLWidget() : QOpenGLWidget(), _isInitialized(false), _backgroundColor(235, 235, 235, 255), - _pointRenderer(), + _pointRenderer(this), _pixelRatio(1.0f), _points(), _colors() @@ -39,8 +39,6 @@ ExampleGLWidget::ExampleGLWidget() : surfaceFormat.setSamples(16); setFormat(surfaceFormat); - - _pointRenderer.getNavigator().initialize(this); } ExampleGLWidget::~ExampleGLWidget() @@ -83,7 +81,7 @@ void ExampleGLWidget::setData(const std::vector& points, float poi _pointRenderer.setPointSize(pointSize); _pointRenderer.setAlpha(pointOpacity); - _pointRenderer.getNavigator().resetView(true); + _pointRenderer.initView(); // Calls paintGL() update();