Skip to content
Snippets Groups Projects
Commit 39b7da72 authored by Magne.Stromsnes's avatar Magne.Stromsnes
Browse files

Draw and track a point on the slice

parent fc52adf3
No related branches found
No related tags found
1 merge request!44Point selection 2d
......@@ -66,6 +66,7 @@ void Geometry::allocateObliqueSlice(CubePlaneIntersection& intersection)
cubeIntersectionCoords.data(),
static_cast<int>(cubeIntersectionCoords.size() *
sizeof(cubeIntersectionCoords[0])));
m_sliceCubeIntersectionCoordBuffer.release();
if (m_sliceIndexBuffer.isCreated())
m_sliceIndexBuffer.destroy();
......@@ -74,9 +75,11 @@ void Geometry::allocateObliqueSlice(CubePlaneIntersection& intersection)
m_sliceIndexBuffer.allocate(
sortedOrder.data(),
static_cast<int>(sortedOrder.size() * sizeof(sortedOrder[0])));
m_sliceIndexBuffer.release();
}
void Geometry::allocateLightSource() {
void Geometry::allocateLightSource()
{
m_lightVertexBuffer.create();
m_lightVertexBuffer.bind();
m_lightVertexBuffer.allocate(sizeof(QVector3D));
......@@ -114,17 +117,25 @@ void Geometry::bindObliqueSliceIntersectionCoords()
m_sliceIndexBuffer.bind();
}
void Geometry::releaseObliqueSliceIntersectionCoords()
{
m_sliceCubeIntersectionCoordBuffer.release();
m_sliceIndexBuffer.release();
}
void Geometry::drawObliqueSlice()
{
glDrawElements(GL_TRIANGLE_FAN, m_sliceIndices, GL_UNSIGNED_SHORT, nullptr);
}
void Geometry::bindLightSource() {
void Geometry::bindLightSource()
{
m_lightVertexBuffer.bind();
m_lightIndexBuffer.bind();
}
void Geometry::drawLightSource() {
void Geometry::drawLightSource()
{
glDrawElements(GL_POINTS, 1, GL_UNSIGNED_INT, nullptr);
}
......
......@@ -22,6 +22,7 @@ class Geometry
void drawCube();
void bindObliqueSliceIntersectionCoords();
void releaseObliqueSliceIntersectionCoords();
void drawObliqueSlice();
void bindLightSource();
......
#include "clippingplaneproperties.h"
#include <QDebug>
ClippingPlaneProperties::ClippingPlaneProperties(Plane clippingPlane)
: m_clippingPlane{clippingPlane}
......@@ -7,6 +8,7 @@ ClippingPlaneProperties::ClippingPlaneProperties(Plane clippingPlane)
void ClippingPlaneProperties::updateClippingPlane(Plane clippingPlane)
{
qDebug() << "ClippingPlane Updated";
m_clippingPlane = clippingPlane;
emit clippingPlaneChanged(clippingPlane);
}
......@@ -15,3 +17,9 @@ void ClippingPlaneProperties::reset()
{
updateClippingPlane(Plane{});
}
void ClippingPlaneProperties::updateSelectedPoint(QVector3D point)
{
m_selectedPoint = point;
emit selectedPointChanged(point);
}
......@@ -12,15 +12,19 @@ class ClippingPlaneProperties : public QObject
ClippingPlaneProperties(){};
ClippingPlaneProperties(Plane clippingPlane);
const Plane& plane() const { return m_clippingPlane; };
const QVector3D& selectedPoint() const { return m_selectedPoint;};
public slots:
void updateClippingPlane(Plane clippingPlane);
void updateSelectedPoint(QVector3D point);
void reset();
signals:
void clippingPlaneChanged(Plane clippingPlane);
void selectedPointChanged(const QVector3D&);
private:
Plane m_clippingPlane;
QVector3D m_selectedPoint;
};
#endif // CLIPPINGPLANEPROPERTIES_H
......@@ -2,16 +2,18 @@
#include "../geometry.h"
#include <QPainter>
#include <QVector3D>
ObliqueSliceRenderWidget::ObliqueSliceRenderWidget(
std::unique_ptr<ITextureStore>& textureStore,
const std::shared_ptr<const ISharedProperties> properties, QWidget* parent,
const std::shared_ptr<ISharedProperties> properties, QWidget* parent,
Qt::WindowFlags f)
: QOpenGLWidget(parent, f),
m_textureStore(textureStore), m_properties{properties},
m_cubePlaneIntersection{m_properties->clippingPlane().plane()},
m_prevRotation{0}, m_verticalFlipped{false}, m_horizontalFlipped{false}
m_prevRotation{0}, m_verticalFlipped{false}, m_horizontalFlipped{false},
m_selectedPoint{0, 0}
{
m_viewMatrix.scale(1 / sqrt(3.0));
connect(&m_properties.get()->transferFunction(),
......@@ -50,19 +52,47 @@ void ObliqueSliceRenderWidget::initializeGL()
&tfn::TransferProperties::transferFunctionChanged,
[this]() { update(); });
updateObliqueSlice();
moveSelection(QPointF{width() / 2.f, height() / 2.f});
}
void ObliqueSliceRenderWidget::paintGL()
{
m_sliceProgram.bind();
glClearColor(0.1f, 0.1f, 0.1f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
if (m_textureStore->volume().loadingInProgress())
return;
Geometry::instance().allocateObliqueSlice(m_cubePlaneIntersection);
m_sliceProgram.bind();
paintSlice();
m_sliceProgram.release();
paintSelection();
}
bool ObliqueSliceRenderWidget::moveSelection(QPointF newSelection)
{
if (newSelection == m_selectedPoint)
return false;
m_selectedPoint = newSelection;
m_selectedBox = QRectF{m_selectedPoint - QPointF{5, 5},
m_selectedPoint + QPointF{5, 5}};
QVector3D normalizedPoint{
(static_cast<float>(m_selectedPoint.x() / width()) - 0.5f) * 2.f,
-(static_cast<float>(m_selectedPoint.y() / height()) - 0.5f) * 2.f, 0.f};
QMatrix4x4 modelViewMatrix =
m_aspectRatioMatrix * m_viewMatrix *
m_cubePlaneIntersection.getModelRotationMatrix() *
m_textureStore->volume().modelMatrix();
// QMatrix4x4 viewMatrix = m_aspectRatioMatrix * m_viewMatrix;
m_selectedVolumePoint = modelViewMatrix.inverted().map(normalizedPoint);
m_properties->clippingPlane().updateSelectedPoint(m_selectedVolumePoint);
qDebug() << m_selectedVolumePoint;
return true;
}
void ObliqueSliceRenderWidget::paintSlice()
{
QMatrix4x4 modelViewMatrix =
m_aspectRatioMatrix * m_viewMatrix *
m_cubePlaneIntersection.getModelRotationMatrix() *
......@@ -88,12 +118,20 @@ void ObliqueSliceRenderWidget::paintGL()
Geometry::instance().drawObliqueSlice();
Geometry::instance().releaseObliqueSliceIntersectionCoords();
glActiveTexture(GL_TEXTURE0);
m_textureStore->volume().release();
glActiveTexture(GL_TEXTURE1);
m_textureStore->transferFunction().release();
}
m_sliceProgram.release();
void ObliqueSliceRenderWidget::paintSelection()
{
QPainter painter{this};
painter.setPen(Qt::red);
painter.drawEllipse(m_selectedBox);
painter.drawLine(rect().topLeft(), rect().bottomRight());
}
void ObliqueSliceRenderWidget::resizeGL(int w, int h)
......
......@@ -18,7 +18,7 @@ class ObliqueSliceRenderWidget : public QOpenGLWidget,
public:
ObliqueSliceRenderWidget(
std::unique_ptr<ITextureStore>& textureStore,
const std::shared_ptr<const ISharedProperties> properties,
const std::shared_ptr<ISharedProperties> properties,
QWidget* parent = nullptr, Qt::WindowFlags f = Qt::WindowFlags());
public slots:
......@@ -32,11 +32,15 @@ class ObliqueSliceRenderWidget : public QOpenGLWidget,
virtual void paintGL();
virtual void resizeGL(int w, int h);
virtual void zoomCamera(float zoomFactor);
bool moveSelection(QPointF);
private:
void paintSlice();
void paintSelection();
void correctQuadForAspectRatio(int w, int h);
void updateTransferTexture(tfn::ColorMap cmap);
std::unique_ptr<ITextureStore>& m_textureStore;
const std::shared_ptr<const ISharedProperties> m_properties;
std::shared_ptr<ISharedProperties> m_properties;
QOpenGLShaderProgram m_sliceProgram;
CubePlaneIntersection m_cubePlaneIntersection;
QMatrix4x4 m_viewMatrix;
......@@ -44,6 +48,9 @@ class ObliqueSliceRenderWidget : public QOpenGLWidget,
float m_prevRotation;
bool m_horizontalFlipped;
bool m_verticalFlipped;
QPointF m_selectedPoint;
QRectF m_selectedBox;
QVector3D m_selectedVolumePoint;
};
#endif // OBLIQUESLICEWIDGET_H
......@@ -21,6 +21,20 @@ void ObliqueSliceInteractor::resizeEvent(QResizeEvent* event)
ObliqueSliceRenderWidget::resizeEvent(event);
}
void ObliqueSliceInteractor::mousePressEvent(QMouseEvent* event)
{
auto currentPosition = event->position();
if (moveSelection(currentPosition))
update();
}
void ObliqueSliceInteractor::mouseMoveEvent(QMouseEvent* event)
{
auto currentPosition = event->position();
if (event->buttons() & Qt::LeftButton && moveSelection(currentPosition))
update();
}
void ObliqueSliceInteractor::placeDial()
{
m_dial->setGeometry(geometry().width() - (DialSize + DialMargin),
......
......@@ -19,6 +19,8 @@ class ObliqueSliceInteractor : public ObliqueSliceRenderWidget
Qt::WindowFlags f = Qt::WindowFlags());
protected:
virtual void mousePressEvent(QMouseEvent*);
virtual void mouseMoveEvent(QMouseEvent*);
virtual void wheelEvent(QWheelEvent* event);
virtual void resizeEvent(QResizeEvent* event);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment