Commit c09078e2 authored by CHEVALIER Arthur's avatar CHEVALIER Arthur Committed by Mathieu Faverge
Browse files

feat(gl): Added zoom and dezoom into the gl widget in order to zoom on the...

feat(gl): Added zoom and dezoom into the gl widget in order to zoom on the trace multiple time without consumming much memory
parent 16d5aa5f
...@@ -45,6 +45,8 @@ void QuadTree::move(float xStart, float xEnd, float yStart, float yEnd) ...@@ -45,6 +45,8 @@ void QuadTree::move(float xStart, float xEnd, float yStart, float yEnd)
{ {
int i, j; int i, j;
std::cerr << "Moving from " << xStart << "," << yStart << " to " << xEnd << "," << yEnd << std::endl;
int startCblk = xStart * m_matrix->m_cblknbr; int startCblk = xStart * m_matrix->m_cblknbr;
int endCbkl = startCblk + (xEnd - xStart) * m_matrix->m_cblknbr; int endCbkl = startCblk + (xEnd - xStart) * m_matrix->m_cblknbr;
...@@ -66,15 +68,17 @@ void QuadTree::move(float xStart, float xEnd, float yStart, float yEnd) ...@@ -66,15 +68,17 @@ void QuadTree::move(float xStart, float xEnd, float yStart, float yEnd)
} }
} }
float xCoeff = 256.f / (float)diffCblk; float xCoeff = (float)DEFAULT_LEVEL_POWER_2 / (float)diffCblk;
float yCoeff = 256.f / (float)diffRow; float yCoeff = (float)DEFAULT_LEVEL_POWER_2 / (float)diffRow;
std::cerr << "xCoeff: " << xCoeff << ", " << "yCoeff: " << yCoeff << std::endl;
for (i = startCblk; i < endCbkl; ++i) for (i = startCblk; i < endCbkl; ++i)
{ {
int firstBlokNum = cblks[i].m_bloknum; int firstBlokNum = cblks[i].m_bloknum;
int nextBlokNum = (i + 1 != m_matrix->m_cblknbr ? cblks[i + 1].m_bloknum : m_matrix->m_cblknbr); int nextBlokNum = (i + 1 != m_matrix->m_cblknbr ? cblks[i + 1].m_bloknum : m_matrix->m_cblknbr);
int x = (float)i * xCoeff; int x = ((float)i - startCblk) * xCoeff;
for (j = firstBlokNum; j < nextBlokNum; ++j) for (j = firstBlokNum; j < nextBlokNum; ++j)
{ {
...@@ -82,7 +86,7 @@ void QuadTree::move(float xStart, float xEnd, float yStart, float yEnd) ...@@ -82,7 +86,7 @@ void QuadTree::move(float xStart, float xEnd, float yStart, float yEnd)
if (blok->m_frownum > startRow && blok->m_frownum <= endRow) if (blok->m_frownum > startRow && blok->m_frownum <= endRow)
{ {
int y = (float)blok->m_frownum * yCoeff; int y = ((float)blok->m_frownum - startRow) * yCoeff;
m_colors[x][y] = 1.0f; m_colors[x][y] = 1.0f;
} }
......
...@@ -22,8 +22,8 @@ typedef struct Node ...@@ -22,8 +22,8 @@ typedef struct Node
class QuadTree class QuadTree
{ {
public: public:
static const int DEFAULT_LEVEL = 8; static const int DEFAULT_LEVEL = 10;
static const int DEFAULT_LEVEL_POWER_2 = 256; static const int DEFAULT_LEVEL_POWER_2 = 1024;
public: public:
QuadTree(Node* root, symbol_matrix_t* matrix); QuadTree(Node* root, symbol_matrix_t* matrix);
......
...@@ -2,9 +2,9 @@ ...@@ -2,9 +2,9 @@
#include "MatrixWindow.hpp" #include "MatrixWindow.hpp"
#define BACKGROUND_COLOR_R 1.f #define BACKGROUND_COLOR_R 0.f
#define BACKGROUND_COLOR_G 1.f #define BACKGROUND_COLOR_G 0.f
#define BACKGROUND_COLOR_B 1.f #define BACKGROUND_COLOR_B 0.f
/* Helpers */ /* Helpers */
static void drawSquare(GLfloat x, GLfloat y, GLfloat dx, GLfloat dy, GLfloat r, GLfloat g, GLfloat b) static void drawSquare(GLfloat x, GLfloat y, GLfloat dx, GLfloat dy, GLfloat r, GLfloat g, GLfloat b)
...@@ -52,6 +52,17 @@ MatrixGLWidget::MatrixGLWidget(QWidget* parent, symbol_matrix_t* matrix, QLabel* ...@@ -52,6 +52,17 @@ MatrixGLWidget::MatrixGLWidget(QWidget* parent, symbol_matrix_t* matrix, QLabel*
#endif #endif
m_updateTimer.start(1000 / 60); m_updateTimer.start(1000 / 60);
m_qtToGLWidthCoeff = 1.f;
m_qtToGLHeightCoeff = 1.f;
m_camera.m_cameraX = 0.f;
m_camera.m_cameraY = 0.f;
m_camera.m_cameraDx = 1.f;
m_camera.m_cameraDy = 1.f;
m_mouseXClicked = -1;
m_mouseYClicked = -1;
} }
MatrixGLWidget::~MatrixGLWidget() MatrixGLWidget::~MatrixGLWidget()
...@@ -68,7 +79,7 @@ void MatrixGLWidget::initializeGL() ...@@ -68,7 +79,7 @@ void MatrixGLWidget::initializeGL()
glMatrixMode(GL_PROJECTION); glMatrixMode(GL_PROJECTION);
glLoadIdentity(); glLoadIdentity();
glOrtho(0, QuadTree::DEFAULT_LEVEL_POWER_2+2, 0, QuadTree::DEFAULT_LEVEL_POWER_2+2, -1, 1); glOrtho(0, QuadTree::DEFAULT_LEVEL_POWER_2, QuadTree::DEFAULT_LEVEL_POWER_2, 0, -1, 1);
glMatrixMode(GL_MODELVIEW); glMatrixMode(GL_MODELVIEW);
glLoadIdentity(); glLoadIdentity();
...@@ -79,10 +90,14 @@ void MatrixGLWidget::resizeGL(int w, int h) ...@@ -79,10 +90,14 @@ void MatrixGLWidget::resizeGL(int w, int h)
{ {
glMatrixMode(GL_PROJECTION); glMatrixMode(GL_PROJECTION);
glLoadIdentity(); glLoadIdentity();
glOrtho(0, QuadTree::DEFAULT_LEVEL_POWER_2, 0, QuadTree::DEFAULT_LEVEL_POWER_2, -1, 1); glOrtho(0, QuadTree::DEFAULT_LEVEL_POWER_2, QuadTree::DEFAULT_LEVEL_POWER_2, 0, -1, 1);
glMatrixMode(GL_MODELVIEW); glMatrixMode(GL_MODELVIEW);
glLoadIdentity(); glLoadIdentity();
glTranslatef(0, 2, 0);
m_qtToGLWidthCoeff = (double)QuadTree::DEFAULT_LEVEL_POWER_2 / (double)w;
m_qtToGLHeightCoeff = (double)QuadTree::DEFAULT_LEVEL_POWER_2 / (double)h;
} }
void MatrixGLWidget::paintGL() void MatrixGLWidget::paintGL()
...@@ -108,11 +123,13 @@ void MatrixGLWidget::paintGL() ...@@ -108,11 +123,13 @@ void MatrixGLWidget::paintGL()
for (j = 0; j < QuadTree::DEFAULT_LEVEL_POWER_2; ++j) for (j = 0; j < QuadTree::DEFAULT_LEVEL_POWER_2; ++j)
{ {
GLfloat grey = m_quadtree->getColor(i, j); GLfloat grey = m_quadtree->getColor(i, j);
drawSquare(i, j, 1, 1, grey, grey, grey);
if (grey != 0.f)
drawSquare(i, j, 1, 1, grey, grey, grey);
} }
} }
drawEmpty(); // drawEmpty();
m_frameCount++; m_frameCount++;
} }
...@@ -132,3 +149,74 @@ void MatrixGLWidget::keyPressEvent(QKeyEvent *keyEvent) ...@@ -132,3 +149,74 @@ void MatrixGLWidget::keyPressEvent(QKeyEvent *keyEvent)
break; break;
} }
} }
void MatrixGLWidget::mousePressEvent(QMouseEvent* mouseEvent)
{
if (mouseEvent->button() == Qt::RightButton)
{
if (m_savedPositions.size() > 0)
{
CameraPosition newCamera = m_savedPositions.top();
m_savedPositions.pop();
m_camera = newCamera;
refreshCamera();
}
}
else if (mouseEvent->button() == Qt::LeftButton)
{
m_mouseXClicked = mouseEvent->x() * m_qtToGLWidthCoeff;
m_mouseYClicked = mouseEvent->y() * m_qtToGLHeightCoeff;
}
}
void MatrixGLWidget::mouseMoveEvent(QMouseEvent* mouseEvent)
{
}
void MatrixGLWidget::mouseReleaseEvent(QMouseEvent* mouseEvent)
{
if (m_mouseXClicked != -1 && m_mouseYClicked != -1)
{
int glPosX = mouseEvent->x() * m_qtToGLWidthCoeff;
int glPosY = mouseEvent->y() * m_qtToGLHeightCoeff;
m_savedPositions.push(m_camera);
// Switch min max
if (m_mouseXClicked > glPosX)
{
int tmp = m_mouseXClicked;
m_mouseXClicked = glPosX;
glPosX = tmp;
}
if (m_mouseYClicked > glPosY)
{
int tmp = m_mouseXClicked;
m_mouseYClicked = glPosY;
glPosY = tmp;
}
int diffX = glPosX - m_mouseXClicked;
int diffY = glPosY - m_mouseYClicked;
m_camera.m_cameraX += ((float)m_mouseXClicked * m_camera.m_cameraDx) / (float)QuadTree::DEFAULT_LEVEL_POWER_2;
m_camera.m_cameraY += ((float)m_mouseYClicked * m_camera.m_cameraDy) / (float)QuadTree::DEFAULT_LEVEL_POWER_2;
m_camera.m_cameraDx = ((float)diffX * m_camera.m_cameraDx) / (float)QuadTree::DEFAULT_LEVEL_POWER_2;
m_camera.m_cameraDy = ((float)diffY * m_camera.m_cameraDy) / (float)QuadTree::DEFAULT_LEVEL_POWER_2;
refreshCamera();
m_mouseXClicked = -1;
m_mouseYClicked = -1;
}
}
void MatrixGLWidget::refreshCamera()
{
m_quadtree->move(m_camera.m_cameraX, m_camera.m_cameraX + m_camera.m_cameraDx,
m_camera.m_cameraY, m_camera.m_cameraY + m_camera.m_cameraDy);
}
\ No newline at end of file
...@@ -13,6 +13,8 @@ ...@@ -13,6 +13,8 @@
#endif #endif
#include <QKeyEvent> #include <QKeyEvent>
#include <stack>
#include "../Formats/SymbolMatrix.hpp" #include "../Formats/SymbolMatrix.hpp"
#include "../Common/QuadTree.hpp" #include "../Common/QuadTree.hpp"
...@@ -34,18 +36,45 @@ protected: ...@@ -34,18 +36,45 @@ protected:
void keyPressEvent(QKeyEvent *keyEvent); void keyPressEvent(QKeyEvent *keyEvent);
void mousePressEvent(QMouseEvent* mouseEvent);
void mouseReleaseEvent(QMouseEvent* mouseEvent);
void mouseMoveEvent(QMouseEvent* mouseEvent);
private:
typedef struct CameraPosition
{
float m_cameraX;
float m_cameraY;
float m_cameraDx;
float m_cameraDy;
} CameraPosition;
private:
void refreshCamera();
private slots: private slots:
/* Helpers */ /* Helpers */
void updateTimer(); void updateTimer();
private: private:
QuadTree* m_quadtree; QuadTree* m_quadtree;
uint32_t m_frameCount; uint32_t m_frameCount;
QTime m_time; QTime m_time;
QTimer m_updateTimer; QTimer m_updateTimer;
QLabel* m_label; QLabel* m_label;
char m_fpsString[256];
double m_qtToGLWidthCoeff;
double m_qtToGLHeightCoeff;
// Zoom
int m_mouseXClicked;
int m_mouseYClicked;
CameraPosition m_camera;
char m_fpsString[256]; // Zoom stack
std::stack<CameraPosition> m_savedPositions;
}; };
#endif #endif
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment