Commit f40719d7 authored by CHEVALIER Arthur's avatar CHEVALIER Arthur Committed by Mathieu Faverge

feat(matrix gl): Adding window for visualizing the matrix

parent 71227574
......@@ -58,6 +58,7 @@ build
# Generated files
src/common/ViteConfig.hpp
toto.trace
log.txt
# QT files
src/interface/vite.qrc.depends
......
......@@ -32,6 +32,9 @@ set (MATRIXVISUALIZER_hdrs
Formats/SymbolMatrix.hpp
Parsers/Readers/Pastix.hpp
Windows/MatrixWindow.hpp
Windows/MatrixGLWidget.hpp
)
set (MATRIXVISUALIZER_srcs
......@@ -42,16 +45,42 @@ set (MATRIXVISUALIZER_srcs
Parsers/SymbolParser.cpp
Parsers/Readers/Pastix.cpp
Windows/MatrixWindow.cpp
Windows/MatrixGLWidget.cpp
)
QT5_WRAP_UI(MATRIXVISUALIZER_forms
widget.ui
Plugin.ui
)
add_library(MatrixVisualizer SHARED ${MATRIXVISUALIZER_srcs} ${MATRIXVISUALIZER_forms})
#############################################
# QT5
#############################################
IF(USE_QT5)
qt5_use_modules(MatrixVisualizer Widgets Core)
qt5_use_modules(MatrixVisualizer Widgets Core Xml OpenGL UiTools)
ENDIF(USE_QT5)
TARGET_LINK_LIBRARIES(MatrixVisualizer
${QT_LIBRARIES}
${OPENGL_gl_LIBRARY}
${OPENGL_glu_LIBRARY}
${Boost_LIBRARIES}
)
IF(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
TARGET_LINK_LIBRARIES(MatrixVisualizer
rt
)
ADD_DEFINITIONS("-DBOOST_GZIP")
ENDIF(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
IF(VITE_ENABLE_VBO)
TARGET_LINK_LIBRARIES(MatrixVisualizer
${GLEW_LIBRARY}
)
ENDIF(VITE_ENABLE_VBO)
install(TARGETS MatrixVisualizer DESTINATION $ENV{HOME}/.vite)
......@@ -86,7 +86,7 @@ void symbol_matrix_print_stats(symbol_matrix_t* matrix)
cblk = matrix->m_cblktab;
blok = matrix->m_bloktab;
for (itercblk = 0; itercblk < cblknbr; ++itercblk, cblk++)
for (itercblk = 0; itercblk < cblknbr; ++itercblk, ++cblk)
{
int32_t iterblok = cblk[0].m_bloknum + 1;
int32_t lbloknum = cblk[1].m_bloknum;
......@@ -112,6 +112,13 @@ void symbol_matrix_print_stats(symbol_matrix_t* matrix)
}
dof = matrix->m_dof;
if (dof < 1)
{
Helper::log(LogStatus::WARNING, "DOF lower than 1 so statistics might be wrong !");
dof = 1;
}
blokmin *= dof;
blokmax *= dof;
cblkmin *= dof;
......@@ -139,7 +146,7 @@ void symbol_matrix_print_stats(symbol_matrix_t* matrix)
" Blok height max %10ld\n"
" Blok height avg %11.2lf\n"
" Blok height stdev %11.2lf\n"
" Memory space %11.2lf %s\n",
" Matrix structure space %11.2lf %s\n",
(long)cblknbr, (long)bloknbr,
(long)cblkmin, (long)cblkmax, cblkavg1, cblkavg2,
(long)blokmin, (long)blokmax, blokavg1, blokavg2,
......
......@@ -6,15 +6,18 @@ typedef struct symbol_cblk_s
int32_t m_fcolumn;
int32_t m_lcolnum;
int32_t m_bloknum;
int32_t m_brownum;
int32_t m_flags;
} symbol_cblk_t;
#define CBLK_FLAG_2D 1
#define CBLK_FLAG_1D CBLK_FLAG_2D << 1
typedef struct symbol_blok_s
{
int32_t m_frownum;
int32_t m_lrownum;
int32_t m_lcblknm;
int32_t m_fcblknm;
int32_t m_lcblknm; // local
int32_t m_fcblknm; // facing
} symbol_blok_t;
typedef struct symbol_matrix_s
......
......@@ -3,15 +3,21 @@
#include <cstdarg>
#include <QWidget>
#include <QMainWindow>
#include <QOpenGLWidget>
#include <QOpenGLFunctions>
#include "plugin/Plugin.hpp"
// Generated
#include "ui_widget.h"
#include "ui_Plugin.h"
#include "Parsers/Parser.hpp"
#include "Formats/SymbolMatrix.hpp"
#include "Parsers/SymbolParser.hpp"
#include "Windows/MatrixGLWidget.hpp"
#include "Windows/MatrixWindow.hpp"
#include "MatrixVisualizer.hpp"
namespace Helper
......
......@@ -5,16 +5,24 @@
#include <QFileDialog>
#include <QWidget>
#include <QString>
#include <QMainWindow>
#include <QOpenGLWidget>
#include <QOpenGLFunctions>
#include "Formats/SymbolMatrix.hpp"
#include "plugin/Plugin.hpp"
// Generated
#include "ui_widget.h"
#include "ui_Plugin.h"
#include "Parsers/Parser.hpp"
#include "Formats/SymbolMatrix.hpp"
#include "Parsers/SymbolParser.hpp"
#include "Windows/MatrixGLWidget.hpp"
#include "Windows/MatrixWindow.hpp"
#include "Helper.hpp"
#include "MatrixVisualizer.hpp"
......@@ -22,6 +30,7 @@ Plugin *create() { return Matrix_visualizer::Get(); }
Matrix_visualizer* Matrix_visualizer::s_plugin = nullptr;
SymbolParser Matrix_visualizer::s_symbol_parser;
Matrix_window* Matrix_visualizer::s_matrix_window = nullptr;
Matrix_visualizer::Matrix_visualizer() {
setupUi(this);
......@@ -57,8 +66,6 @@ void Matrix_visualizer::connect_widgets()
}
Matrix_visualizer::~Matrix_visualizer(){
std::cout << "Destroying..." << std::endl;
s_plugin = nullptr;
}
void Matrix_visualizer::init(){
......@@ -95,16 +102,19 @@ void Matrix_visualizer::execute(){
// Parse the symbol file
Helper::log(LogStatus::MESSAGE, "Parsing symbol file...");
symbol_matrix_t* symbol_matrix = s_symbol_parser.parse(symbol_filepath.toStdString());
symbol_matrix_t* matrix = s_symbol_parser.parse(symbol_filepath.toStdString());
if (symbol_matrix != nullptr)
if (matrix == nullptr)
{
Helper::log(LogStatus::MESSAGE, "Successfully readed symbol file");
symbol_matrix_print_stats(symbol_matrix);
symbol_matrix_deinit(symbol_matrix);
delete symbol_matrix;
return;
}
Helper::log(LogStatus::MESSAGE, "Successfully readed symbol file");
symbol_matrix_print_stats(matrix);
// Open window for opengl drawing
s_matrix_window = new Matrix_window(matrix);
s_matrix_window->show();
}
void Matrix_visualizer::log(LogStatus status, const char* format, va_list ap)
......
#ifndef MATRIX_VISUALIZER_HPP
#define MATRIX_VISUALIZER_HPP
class Matrix_visualizer : public Plugin, public Ui::Matrix_visualizer_widget_ui {
class Matrix_visualizer : public Plugin, public Ui::Matrix_visualizer_plugin_ui {
public:
static Matrix_visualizer* Get();
~Matrix_visualizer();
......@@ -32,6 +32,9 @@ private slots:
private:
static Matrix_visualizer* s_plugin;
static SymbolParser s_symbol_parser;
// Windows
static Matrix_window* s_matrix_window;
};
extern "C"
......
......@@ -55,17 +55,20 @@ int pastix_read_symbol(FILE* stream, symbol_matrix_t* matrix)
int32_t cblknbr = matrix->m_cblknbr;
for (cblknum = 0; cblknum < cblknbr; ++cblknum)
{
if ((pastix_read_int(stream, &matrix->m_cblktab[cblknum].m_fcolumn) +
pastix_read_int(stream, &matrix->m_cblktab[cblknum].m_lcolnum) +
pastix_read_int(stream, &matrix->m_cblktab[cblknum].m_bloknum) != 3) ||
if ((pastix_read_int(stream, &(matrix->m_cblktab[cblknum].m_fcolumn)) +
pastix_read_int(stream, &(matrix->m_cblktab[cblknum].m_lcolnum)) +
pastix_read_int(stream, &(matrix->m_cblktab[cblknum].m_bloknum)) != 3) ||
(matrix->m_cblktab[cblknum].m_fcolumn > matrix->m_cblktab[cblknum].m_lcolnum))
{
Helper::log(LogStatus::ERROR, "Bad input while reading cblk !");
return 1;
}
matrix->m_cblktab[cblknum].m_flags = 0;
}
matrix->m_cblktab[cblknbr].m_fcolumn = matrix->m_cblktab[cblknbr].m_lcolnum = matrix->m_nodenbr + matrix->m_baseval;
matrix->m_cblktab[cblknbr].m_bloknum = matrix->m_bloknbr + matrix->m_baseval;
int32_t bloknbr = matrix->m_bloknbr;
for (bloknum = 0; bloknum < bloknbr; ++bloknum)
......@@ -75,15 +78,24 @@ int pastix_read_symbol(FILE* stream, symbol_matrix_t* matrix)
pastix_read_int(stream, &matrix->m_bloktab[bloknum].m_fcblknm) != 3) ||
(matrix->m_bloktab[bloknum].m_frownum > matrix->m_bloktab[bloknum].m_lrownum))
{
Helper::log(LogStatus::ERROR, "Bad input while reading blok %d !", bloknum);
Helper::log(LogStatus::MESSAGE, "%d %d %d", matrix->m_bloktab[bloknum].m_frownum,
matrix->m_bloktab[bloknum].m_lrownum,
matrix->m_bloktab[bloknum].m_fcblknm);
Helper::log(LogStatus::ERROR, "Bad input while reading blok !", bloknum);
return 1;
}
// Compatibility block
{
int32_t tmp;
if ((versval == 0) && (pastix_read_int(stream, &tmp) != 1))
{
Helper::log(LogStatus::ERROR, "Bad input while reading lefval !");
return 1;
}
}
}
matrix->m_dof = 1;
return 0;
}
......
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Matrix_visualizer_widget_ui</class>
<widget class="QWidget" name="Matrix_visualizer_widget_ui">
<class>Matrix_visualizer_plugin_ui</class>
<widget class="QWidget" name="Matrix_visualizer_plugin_ui">
<property name="windowTitle">
Matrix visualizer
</property>
......
#include <QtOpenGL/QtOpenGL>
#include <QOpenGLFunctions>
#include <QOpenGLWidget>
#include <QWidget>
#include "../Formats/SymbolMatrix.hpp"
#include "MatrixGLWidget.hpp"
/* Helpers */
static void drawSquare(GLfloat x, GLfloat y, GLfloat dx, GLfloat dy)
{
}
MatrixGLWidget::MatrixGLWidget(QWidget* parent, symbol_matrix_t* matrix)
: QOpenGLWidget(parent)
, m_matrix(matrix)
{
}
MatrixGLWidget::~MatrixGLWidget()
{
symbol_matrix_deinit(m_matrix);
delete m_matrix;
}
void MatrixGLWidget::initializeGL()
{
initializeOpenGLFunctions();
glClearColor(0, 0, 0, 1);
}
void MatrixGLWidget::resizeGL(int w, int h)
{
glViewport(0, 0, w, h);
}
void MatrixGLWidget::paintGL()
{
initializeOpenGLFunctions();
glClear(GL_COLOR_BUFFER_BIT);
}
void MatrixGLWidget::keyPressEvent(QKeyEvent *keyEvent)
{
switch (keyEvent->key())
{
default:
break;
}
}
#ifndef MATRIX_GL_WIDGET_HPP
#define MATRIX_GL_WIDGET_HPP
class MatrixGLWidget : public QOpenGLWidget, protected QOpenGLFunctions
{
public:
MatrixGLWidget(QWidget* parent, symbol_matrix_t* matrix);
~MatrixGLWidget();
protected:
void initializeGL() override;
void resizeGL(int w, int h) override;
void paintGL() override;
void keyPressEvent(QKeyEvent *keyEvent);
private:
/* Helpers */
private:
symbol_matrix_t* m_matrix;
};
#endif
#include <QCloseEvent>
#include <iostream>
#include <QWidget>
#include <QOpenGLWidget>
#include <QOpenGLFunctions>
#include <QCloseEvent>
#include "../Formats/SymbolMatrix.hpp"
#include "MatrixGLWidget.hpp"
#include <QMainWindow>
#include "MatrixWindow.hpp"
Matrix_window::Matrix_window(symbol_matrix_t* matrix)
{
m_gl = new MatrixGLWidget(this, matrix);
m_gl->setObjectName(QStringLiteral("matrix_gl_visualizer"));
this->setCentralWidget(m_gl);
this->setFixedSize(1024, 768);
}
Matrix_window::~Matrix_window()
{
delete m_gl;
}
void Matrix_window::closeEvent(QCloseEvent* event)
{
// Dgueu
delete this;
}
#ifndef MATRIX_WINDOW_HPP
#define MATRIX_WINDOW_HPP
class Matrix_window : public QMainWindow
{
public:
Matrix_window(symbol_matrix_t* matrix);
~Matrix_window();
void closeEvent(QCloseEvent* event);
private:
MatrixGLWidget* m_gl;
};
#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