|
|
|
|
@@ -1,5 +1,6 @@
|
|
|
|
|
#include "PivotGui.h"
|
|
|
|
|
|
|
|
|
|
#include "Gauss.h"
|
|
|
|
|
#include "Matrix.h"
|
|
|
|
|
#include "Solver.h"
|
|
|
|
|
#include <imgui.h>
|
|
|
|
|
@@ -7,6 +8,38 @@
|
|
|
|
|
|
|
|
|
|
static std::string equationsResultImage;
|
|
|
|
|
|
|
|
|
|
struct GuiMatrix {
|
|
|
|
|
std::vector<std::vector<int>> matrixValues;
|
|
|
|
|
int matrixSizeX = 4;
|
|
|
|
|
int matrixSizeY = 4;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static void ResizeGuiMatrix(bool refresh, GuiMatrix& guiMatrix) {
|
|
|
|
|
if (refresh) {
|
|
|
|
|
guiMatrix.matrixValues.resize(guiMatrix.matrixSizeY);
|
|
|
|
|
for (auto& row : guiMatrix.matrixValues) {
|
|
|
|
|
row.resize(guiMatrix.matrixSizeX, 0);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void RenderMatrix(bool& refresh, GuiMatrix& guiMatrix) {
|
|
|
|
|
ResizeGuiMatrix(refresh, guiMatrix);
|
|
|
|
|
|
|
|
|
|
for (int y = 0; y < guiMatrix.matrixSizeY; y++) {
|
|
|
|
|
for (int x = 0; x < guiMatrix.matrixSizeX; x++) {
|
|
|
|
|
if (x > 0)
|
|
|
|
|
ImGui::SameLine();
|
|
|
|
|
ImGui::PushID((guiMatrix.matrixSizeX * 20 + guiMatrix.matrixSizeY * 50) + y * guiMatrix.matrixSizeX + x);
|
|
|
|
|
ImGui::PushItemWidth(60); // Adjust this value to change the cell size
|
|
|
|
|
if (ImGui::InputInt("", &guiMatrix.matrixValues[y][x], 0, 0, ImGuiInputTextFlags_CharsDecimal))
|
|
|
|
|
refresh = true;
|
|
|
|
|
ImGui::PopItemWidth();
|
|
|
|
|
ImGui::PopID();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static Matrix LoadMatrixFromStdVect(const std::vector<std::vector<int>>& data) {
|
|
|
|
|
Matrix result {data.size(), data.empty() ? 0 : data[0].size()};
|
|
|
|
|
for (std::size_t i = 0; i < result.GetRawCount(); i++) {
|
|
|
|
|
@@ -23,6 +56,19 @@ static std::string ElementToString(Matrix::Element e) {
|
|
|
|
|
return ss.str();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static std::string PrintRawMatrix(const Matrix& mat) {
|
|
|
|
|
if (mat.GetRawCount() == 0)
|
|
|
|
|
return "";
|
|
|
|
|
|
|
|
|
|
std::string result = " ( ";
|
|
|
|
|
for (std::size_t j = 0; j < mat.GetRawCount(); j++) {
|
|
|
|
|
result += ElementToString(mat.at(j, 0)) + ", ";
|
|
|
|
|
}
|
|
|
|
|
result = result.substr(0, result.size() - 2);
|
|
|
|
|
result += " )";
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static std::string PrintVect(const Vect& vect) {
|
|
|
|
|
if (vect.GetCardinal() == 0)
|
|
|
|
|
return "{0}";
|
|
|
|
|
@@ -30,12 +76,8 @@ static std::string PrintVect(const Vect& vect) {
|
|
|
|
|
std::string result = "Vect( ";
|
|
|
|
|
for (std::size_t i = 0; i < vect.GetCardinal(); i++) {
|
|
|
|
|
Matrix vector = vect.GetVector(i);
|
|
|
|
|
result += " (";
|
|
|
|
|
for (std::size_t j = 0; j < vect.GetDimension(); j++) {
|
|
|
|
|
result += ElementToString(vector.at(j, 0)) + ", ";
|
|
|
|
|
}
|
|
|
|
|
result = result.substr(0, result.size() - 2);
|
|
|
|
|
result += " ), ";
|
|
|
|
|
result += PrintRawMatrix(vector);
|
|
|
|
|
result += ", ";
|
|
|
|
|
}
|
|
|
|
|
result = result.substr(0, result.size() - 2);
|
|
|
|
|
result += " )";
|
|
|
|
|
@@ -44,104 +86,161 @@ static std::string PrintVect(const Vect& vect) {
|
|
|
|
|
|
|
|
|
|
void PivotGui::Init() {}
|
|
|
|
|
|
|
|
|
|
void PivotGui::Render() {
|
|
|
|
|
ImGuiIO& io = ImGui::GetIO();
|
|
|
|
|
static void RenderLeftSystemChild(bool& refresh, GuiMatrix& system, GuiMatrix& origin) {
|
|
|
|
|
ImVec2 topLeftWindowSize(ImGui::GetContentRegionAvail().x * 0.5f, 0);
|
|
|
|
|
|
|
|
|
|
ImGui::BeginChild("Left Child", topLeftWindowSize, ImGuiChildFlags_Border);
|
|
|
|
|
|
|
|
|
|
ImGui::Text("Système de la forme AX=B");
|
|
|
|
|
ImGui::Separator();
|
|
|
|
|
ImGui::Text("Taille matrice A :");
|
|
|
|
|
|
|
|
|
|
if (ImGui::InputInt("##RowsMatriceInitiale", &system.matrixSizeY))
|
|
|
|
|
refresh = true;
|
|
|
|
|
system.matrixSizeY = std::max(1, system.matrixSizeY);
|
|
|
|
|
ImGui::SameLine();
|
|
|
|
|
ImGui::Text("Lignes");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (ImGui::InputInt("##ColumnsMatriceInitiale", &system.matrixSizeX))
|
|
|
|
|
refresh = true;
|
|
|
|
|
system.matrixSizeX = std::max(1, system.matrixSizeX);
|
|
|
|
|
ImGui::SameLine();
|
|
|
|
|
ImGui::Text("Colonnes");
|
|
|
|
|
|
|
|
|
|
ImGui::NewLine();
|
|
|
|
|
|
|
|
|
|
RenderMatrix(refresh, system);
|
|
|
|
|
|
|
|
|
|
if (refresh) {
|
|
|
|
|
origin.matrixSizeX = 1;
|
|
|
|
|
origin.matrixSizeY = system.matrixSizeY;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ImGui::NewLine();
|
|
|
|
|
ImGui::Separator();
|
|
|
|
|
ImGui::Text("Matrice B :");
|
|
|
|
|
ImGui::NewLine();
|
|
|
|
|
|
|
|
|
|
RenderMatrix(refresh, origin);
|
|
|
|
|
|
|
|
|
|
ImGui::EndChild();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void RenderRightSystemChild(bool& refresh, GuiMatrix& system, GuiMatrix& origin) {
|
|
|
|
|
ImGui::BeginChild("Right Child", {0, 0}, ImGuiChildFlags_Border);
|
|
|
|
|
|
|
|
|
|
static std::string result = "";
|
|
|
|
|
|
|
|
|
|
static std::vector<std::vector<int>> matrixValues;
|
|
|
|
|
static int matrixSizeX = 4;
|
|
|
|
|
static int matrixSizeY = 4;
|
|
|
|
|
static Solver solver;
|
|
|
|
|
|
|
|
|
|
if (refresh) {
|
|
|
|
|
VectAffine solutions =
|
|
|
|
|
solver.RectangularSystem(LoadMatrixFromStdVect(system.matrixValues), LoadMatrixFromStdVect(origin.matrixValues));
|
|
|
|
|
|
|
|
|
|
result = "Solutions :\n";
|
|
|
|
|
result += PrintVect(solutions.GetBase());
|
|
|
|
|
result += "\n\n+\n\n";
|
|
|
|
|
result += PrintRawMatrix(solutions.GetOrigin());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ImGui::TextWrapped("%s", result.c_str());
|
|
|
|
|
|
|
|
|
|
ImGui::EndChild();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void RenderSystemTab() {
|
|
|
|
|
static GuiMatrix guiMatrix, originMatrix;
|
|
|
|
|
static bool refresh = true;
|
|
|
|
|
|
|
|
|
|
RenderLeftSystemChild(refresh, guiMatrix, originMatrix);
|
|
|
|
|
ImGui::SameLine();
|
|
|
|
|
RenderRightSystemChild(refresh, guiMatrix, originMatrix);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void RenderLeftGaussChild(bool& refresh, GuiMatrix& guiMatrix) {
|
|
|
|
|
// divisions des fenetres
|
|
|
|
|
ImVec2 topLeftWindowSize(io.DisplaySize.x * 0.5f, io.DisplaySize.y * 0.8f);
|
|
|
|
|
ImVec2 topRightWindowSize(io.DisplaySize.x * 0.5f, io.DisplaySize.y * 0.8f);
|
|
|
|
|
ImVec2 bottomWindowSize(io.DisplaySize.x, io.DisplaySize.y * 0.2f);
|
|
|
|
|
ImVec2 topLeftWindowSize(ImGui::GetContentRegionAvail().x * 0.5f, 0);
|
|
|
|
|
|
|
|
|
|
// Begin fenetre top left
|
|
|
|
|
ImGui::SetNextWindowSize(topLeftWindowSize);
|
|
|
|
|
ImGui::SetNextWindowPos(ImVec2(0, 0)); // Position at the top-left corner
|
|
|
|
|
ImGui::Begin("Left Top Window", nullptr,
|
|
|
|
|
// ImGui::SetNextWindowPos(ImVec2(0, 0)); // Position at the top-left corner
|
|
|
|
|
ImGui::BeginChild("Left Top Window", topLeftWindowSize, ImGuiChildFlags_Border);
|
|
|
|
|
/*ImGui::Begin(, nullptr,
|
|
|
|
|
ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoScrollbar);
|
|
|
|
|
*/
|
|
|
|
|
// ImGui::BeginTabBar("MainMenu");
|
|
|
|
|
|
|
|
|
|
// Get window position
|
|
|
|
|
ImVec2 windowPos = ImGui::GetWindowPos();
|
|
|
|
|
|
|
|
|
|
ImGui::Text("Matrice initiale:");
|
|
|
|
|
|
|
|
|
|
if (ImGui::InputInt("##RowsMatriceInitiale", &matrixSizeY))
|
|
|
|
|
if (ImGui::InputInt("##RowsMatriceInitiale", &guiMatrix.matrixSizeY))
|
|
|
|
|
refresh = true;
|
|
|
|
|
matrixSizeY = std::max(1, matrixSizeY);
|
|
|
|
|
guiMatrix.matrixSizeY = std::max(1, guiMatrix.matrixSizeY);
|
|
|
|
|
ImGui::SameLine();
|
|
|
|
|
ImGui::Text("Lignes");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (ImGui::InputInt("##ColumnsMatriceInitiale", &matrixSizeX))
|
|
|
|
|
if (ImGui::InputInt("##ColumnsMatriceInitiale", &guiMatrix.matrixSizeX))
|
|
|
|
|
refresh = true;
|
|
|
|
|
matrixSizeX = std::max(1, matrixSizeX);
|
|
|
|
|
guiMatrix.matrixSizeX = std::max(1, guiMatrix.matrixSizeX);
|
|
|
|
|
ImGui::SameLine();
|
|
|
|
|
ImGui::Text("Colonnes");
|
|
|
|
|
|
|
|
|
|
ImGui::NewLine();
|
|
|
|
|
|
|
|
|
|
ImGui::BeginChild("MatriceInitiale", ImVec2(topLeftWindowSize.x, io.DisplaySize.y * 0.7f), false);
|
|
|
|
|
// ImGui::BeginChild("MatriceInitiale", ImVec2(topLeftWindowSize.x, io.DisplaySize.y * 0.7f), false);
|
|
|
|
|
|
|
|
|
|
// Resize matrixValues and initialize new elements to 0
|
|
|
|
|
|
|
|
|
|
if (refresh) {
|
|
|
|
|
matrixValues.resize(matrixSizeY);
|
|
|
|
|
for (auto& row : matrixValues) {
|
|
|
|
|
row.resize(matrixSizeX, 0);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
RenderMatrix(refresh, guiMatrix);
|
|
|
|
|
|
|
|
|
|
for (int y = 0; y < matrixSizeY; y++) {
|
|
|
|
|
for (int x = 0; x < matrixSizeX; x++) {
|
|
|
|
|
if (x > 0)
|
|
|
|
|
ImGui::SameLine();
|
|
|
|
|
ImGui::PushID(y * matrixSizeX + x);
|
|
|
|
|
ImGui::PushItemWidth(30); // Adjust this value to change the cell size
|
|
|
|
|
if (ImGui::InputInt("", &matrixValues[y][x], 0, 0, ImGuiInputTextFlags_CharsDecimal))
|
|
|
|
|
refresh = true;
|
|
|
|
|
ImGui::PopItemWidth();
|
|
|
|
|
// ImGui::EndChild(); // End Matrice initiale
|
|
|
|
|
|
|
|
|
|
ImGui::NewLine();
|
|
|
|
|
|
|
|
|
|
ImGui::Text("Matrice échelonnée:");
|
|
|
|
|
|
|
|
|
|
// Convert the "result" string back to a matrix
|
|
|
|
|
Matrix resultMatrix = LoadMatrixFromStdVect(guiMatrix.matrixValues);
|
|
|
|
|
|
|
|
|
|
// Apply the Gauss-Jordan elimination to the matrix
|
|
|
|
|
Gauss::GaussJordan(resultMatrix, true, true); // Assuming you want to reduce and normalize the matrix
|
|
|
|
|
|
|
|
|
|
// Display the matrix
|
|
|
|
|
for (std::size_t i = 0; i < resultMatrix.GetRawCount(); i++) {
|
|
|
|
|
for (std::size_t j = 0; j < resultMatrix.GetColumnCount(); j++) {
|
|
|
|
|
ImGui::PushID(i * resultMatrix.GetColumnCount() + j);
|
|
|
|
|
if (ImGui::Button(ElementToString(resultMatrix.at(i, j)).c_str(), ImVec2(70, 70))) { // Adjust the size as needed
|
|
|
|
|
// Handle button click here if needed
|
|
|
|
|
}
|
|
|
|
|
ImGui::PopID();
|
|
|
|
|
if (j < resultMatrix.GetColumnCount() - 1)
|
|
|
|
|
ImGui::SameLine();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Display the equationsResult strings in the GUI if they are not empty
|
|
|
|
|
if (!equationsResultImage.empty()) {
|
|
|
|
|
ImGui::TextWrapped(equationsResultImage.c_str());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ImGui::EndChild(); // End Matrice initiale
|
|
|
|
|
|
|
|
|
|
ImGui::End(); // End fenetre top left
|
|
|
|
|
ImGui::EndChild();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void RenderRightGaussChild(bool& refresh, GuiMatrix& guiMatrix) {
|
|
|
|
|
static Solver solver;
|
|
|
|
|
// Begin fenetre top right
|
|
|
|
|
ImGui::SetNextWindowSize(topRightWindowSize);
|
|
|
|
|
ImGui::SetNextWindowPos(ImVec2(windowPos.x + topLeftWindowSize.x, 0)); // Position at the top-right corner
|
|
|
|
|
ImGui::Begin("Right Top Window", nullptr,
|
|
|
|
|
ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoScrollbar);
|
|
|
|
|
// ImGui::SetNextWindowSize(topRightWindowSize);
|
|
|
|
|
// ImGui::SetNextWindowPos(ImVec2(windowPos.x + topLeftWindowSize.x, 0)); // Position at the top-right corner
|
|
|
|
|
ImGui::BeginChild("Right Top Window", {0, 0}, ImGuiChildFlags_Border);
|
|
|
|
|
// ImGui::Begin("Right Top Window", nullptr,
|
|
|
|
|
// ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoScrollbar);
|
|
|
|
|
|
|
|
|
|
// rajouter le code pour la partie top right
|
|
|
|
|
|
|
|
|
|
static std::string result = "";
|
|
|
|
|
|
|
|
|
|
ImGui::TextWrapped(result.c_str());
|
|
|
|
|
|
|
|
|
|
ImGui::End(); // End fenetre top right
|
|
|
|
|
|
|
|
|
|
// Begin fenetre bas
|
|
|
|
|
ImGui::SetNextWindowSize(bottomWindowSize);
|
|
|
|
|
ImGui::SetNextWindowPos(ImVec2(0, io.DisplaySize.y * 0.8f)); // Position at the bottom-left corner
|
|
|
|
|
ImGui::Begin("Bottom Part", nullptr,
|
|
|
|
|
ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoScrollbar);
|
|
|
|
|
|
|
|
|
|
if (refresh) {
|
|
|
|
|
|
|
|
|
|
// Calculate the kernel and image
|
|
|
|
|
Vect image = solver.Image(LoadMatrixFromStdVect(matrixValues));
|
|
|
|
|
Vect image = solver.Image(LoadMatrixFromStdVect(guiMatrix.matrixValues));
|
|
|
|
|
Matrix linearSystem = image.GetLinearSystem();
|
|
|
|
|
|
|
|
|
|
// Store the equationsResult strings in the global variable
|
|
|
|
|
@@ -154,13 +253,59 @@ void PivotGui::Render() {
|
|
|
|
|
equationsResultImage = equationsResultImage.substr(0, equationsResultImage.size() - 3) + " = 0\n";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
result = std::string("Noyau: ") + "\n" + PrintVect(solver.Kernel(LoadMatrixFromStdVect(matrixValues))) + "\n" + "\n" +
|
|
|
|
|
"Rang: " + "\n" + std::to_string(solver.Rank(LoadMatrixFromStdVect(matrixValues))) + "\n" + "\n" + "Image: " + "\n" +
|
|
|
|
|
PrintVect(image);
|
|
|
|
|
result = "\nNoyau: \n" + PrintVect(solver.Kernel(LoadMatrixFromStdVect(guiMatrix.matrixValues))) + "\n" +
|
|
|
|
|
"\n" + "Rang: " + "\n" + std::to_string(solver.Rank(LoadMatrixFromStdVect(guiMatrix.matrixValues))) + "\n" + "\n" +
|
|
|
|
|
"Image: " + "\n" + PrintVect(image);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
refresh = false;
|
|
|
|
|
ImGui::End(); // End fenetre bas
|
|
|
|
|
|
|
|
|
|
// Display the equationsResult strings in the GUI if they are not empty
|
|
|
|
|
if (!equationsResultImage.empty()) {
|
|
|
|
|
ImGui::TextWrapped("%s", equationsResultImage.c_str());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ImGui::TextWrapped("%s", result.c_str());
|
|
|
|
|
|
|
|
|
|
ImGui::EndChild(); // End fenetre top right
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void RenderGaussTab() {
|
|
|
|
|
static GuiMatrix guiMatrix;
|
|
|
|
|
static bool refresh = true;
|
|
|
|
|
|
|
|
|
|
RenderLeftGaussChild(refresh, guiMatrix);
|
|
|
|
|
ImGui::SameLine();
|
|
|
|
|
RenderRightGaussChild(refresh, guiMatrix);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void RenderMainWindow() {
|
|
|
|
|
ImGuiIO& io = ImGui::GetIO();
|
|
|
|
|
|
|
|
|
|
ImGui::SetNextWindowSize(io.DisplaySize);
|
|
|
|
|
ImGui::SetNextWindowPos({0, 0});
|
|
|
|
|
ImGui::Begin("MainWindow", nullptr,
|
|
|
|
|
ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoScrollbar);
|
|
|
|
|
ImGui::BeginTabBar("MainBar");
|
|
|
|
|
if (ImGui::BeginTabItem("Noyau et Image")) {
|
|
|
|
|
RenderGaussTab();
|
|
|
|
|
ImGui::EndTabItem();
|
|
|
|
|
}
|
|
|
|
|
if (ImGui::BeginTabItem("Systèmes")) {
|
|
|
|
|
RenderSystemTab();
|
|
|
|
|
ImGui::EndTabItem();
|
|
|
|
|
}
|
|
|
|
|
ImGui::EndTabBar();
|
|
|
|
|
ImGui::End();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void PivotGui::Render() {
|
|
|
|
|
|
|
|
|
|
RenderMainWindow();
|
|
|
|
|
|
|
|
|
|
#ifndef NDEBUG
|
|
|
|
|
ImGui::ShowDemoWindow(nullptr);
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void PivotGui::Destroy() {}
|