33#include < util/Exception.h>
44
55#include < QPainter>
6+ #include < QRectF>
67
78ExampleGLWidget::ExampleGLWidget () :
89 QOpenGLWidget(),
910 _isInitialized(false ),
1011 _backgroundColor(235 , 235 , 235 , 255 ),
11- _pointRenderer(),
12+ _pointRenderer(this ),
1213 _pixelRatio(1 .0f ),
1314 _points(),
14- _colors(),
15- _bounds()
15+ _colors()
1616{
1717 setAcceptDrops (true );
1818
@@ -39,7 +39,6 @@ ExampleGLWidget::ExampleGLWidget() :
3939 surfaceFormat.setSamples (16 );
4040
4141 setFormat (surfaceFormat);
42-
4342}
4443
4544ExampleGLWidget::~ExampleGLWidget ()
@@ -59,29 +58,31 @@ void ExampleGLWidget::setData(const std::vector<mv::Vector2f>& points, float poi
5958 constexpr mv::Vector3f pointColor = {0 .f , 0 .f , 0 .f };
6059
6160 for (unsigned long i = 0 ; i < numPoints; i++)
62- _colors.emplace_back (pointColor);
61+ _colors.push_back (pointColor);
6362
64- _bounds = Bounds::Max;
63+ Bounds bounds = Bounds::Max;
6564
66- for (const Vector2f& point : _points )
65+ for (const Vector2f& point : points )
6766 {
68- _bounds .setLeft (std::min (point.x , _bounds .getLeft ()));
69- _bounds .setRight (std::max (point.x , _bounds .getRight ()));
70- _bounds .setBottom (std::min (point.y , _bounds .getBottom ()));
71- _bounds .setTop (std::max (point.y , _bounds .getTop ()));
67+ bounds .setLeft (std::min (point.x , bounds .getLeft ()));
68+ bounds .setRight (std::max (point.x , bounds .getRight ()));
69+ bounds .setBottom (std::min (point.y , bounds .getBottom ()));
70+ bounds .setTop (std::max (point.y , bounds .getTop ()));
7271 }
7372
74- _bounds .makeSquare ();
75- _bounds .expand (0 .1f );
73+ bounds .makeSquare ();
74+ bounds .expand (0 .1f );
7675
7776 // Send the data to the renderer
78- _pointRenderer.setBounds (_bounds );
77+ _pointRenderer.setDataBounds ( QRectF ( QPointF (bounds. getLeft (), bounds. getBottom ()), QSizeF (bounds. getWidth (), bounds. getHeight ())) );
7978 _pointRenderer.setData (_points);
8079 _pointRenderer.setColors (_colors);
8180
8281 _pointRenderer.setPointSize (pointSize);
8382 _pointRenderer.setAlpha (pointOpacity);
8483
84+ _pointRenderer.initView ();
85+
8586 // Calls paintGL()
8687 update ();
8788}
0 commit comments