Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 15 additions & 14 deletions ExampleViewOpenGL/src/ExampleGLWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
#include <util/Exception.h>

#include <QPainter>
#include <QRectF>

ExampleGLWidget::ExampleGLWidget() :
QOpenGLWidget(),
_isInitialized(false),
_backgroundColor(235, 235, 235, 255),
_pointRenderer(),
_pointRenderer(this),
_pixelRatio(1.0f),
_points(),
_colors(),
_bounds()
_colors()
{
setAcceptDrops(true);

Expand All @@ -39,7 +39,6 @@ ExampleGLWidget::ExampleGLWidget() :
surfaceFormat.setSamples(16);

setFormat(surfaceFormat);

}

ExampleGLWidget::~ExampleGLWidget()
Expand All @@ -59,29 +58,31 @@ void ExampleGLWidget::setData(const std::vector<mv::Vector2f>& 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);

_pointRenderer.setPointSize(pointSize);
_pointRenderer.setAlpha(pointOpacity);

_pointRenderer.initView();

// Calls paintGL()
update();
}
Expand Down
2 changes: 0 additions & 2 deletions ExampleViewOpenGL/src/ExampleGLWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#include <renderers/PointRenderer.h>
#include <graphics/Vector2f.h>
#include <graphics/Vector3f.h>
#include <graphics/Bounds.h>

#include <QOpenGLWidget>
#include <QOpenGLFunctions>
Expand Down Expand Up @@ -42,7 +41,6 @@ class ExampleGLWidget : public QOpenGLWidget, protected QOpenGLFunctions
float _pixelRatio; /* device pixel ratio */
std::vector<Vector2f> _points; /* 2D coordinates of points */
std::vector<Vector3f> _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 */
};