This commit is contained in:
2024-05-11 19:44:32 +02:00
parent 0d071b1cf9
commit 2975006972
10 changed files with 201 additions and 32 deletions

View File

@@ -17,7 +17,7 @@ static Matrix LoadMatrixFromStdVect(const std::vector<std::vector<int>>& data) {
}
static std::string PrintVect(const Vect& vect) {
if (vect.GetCardinal() == 0)
if (vect.GetCardinal() == 0)
return "{0}";
std::string result = "Vect( ";
@@ -25,7 +25,7 @@ static std::string PrintVect(const Vect& vect) {
Matrix vector = vect.GetVector(i);
result += " (";
for (std::size_t j = 0; j < vect.GetDimension(); j++) {
result += std::to_string(static_cast<int>((vector.at(j, 0)))) + ", ";
result += vector.at(j, 0).ToString() + ", ";
}
result += " ), ";
}
@@ -60,14 +60,18 @@ void PivotGui::Render() {
ImGui::Text("Matrice initiale:");
ImGui::InputInt("##RowsMatriceInitiale", &matrixSizeY);
matrixSizeY = std::max(1, matrixSizeY);
ImGui::SameLine();
ImGui::Text("Lignes");
ImGui::InputInt("##ColumnsMatriceInitiale", &matrixSizeX);
matrixSizeX = std::max(1, matrixSizeX);
ImGui::SameLine();
ImGui::Text("Colonnes");
ImGui::NewLine();
ImGui::BeginChild("MatriceInitiale", ImVec2(topLeftWindowSize.x, io.DisplaySize.y * 0.7f), false);
// Resize matrixValues and initialize new elements to 0
@@ -77,13 +81,16 @@ void PivotGui::Render() {
row.resize(matrixSizeX, 0);
}
bool refresh = false;
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
ImGui::InputInt("", &matrixValues[y][x], 0, 0, ImGuiInputTextFlags_CharsDecimal);
if (ImGui::InputInt("", &matrixValues[y][x], 0, 0, ImGuiInputTextFlags_CharsDecimal))
refresh = true;
ImGui::PopItemWidth();
ImGui::PopID();
}
@@ -106,7 +113,7 @@ void PivotGui::Render() {
// rajouter le code pour la partie top right
static std::string result = "RIEN";
static std::string result = "";
ImGui::TextWrapped(result.c_str());
@@ -118,36 +125,25 @@ void PivotGui::Render() {
ImGui::Begin("Bottom Part", nullptr,
ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoScrollbar);
if (ImGui::Button("Calcul")) {
if (refresh) {
// Calculate the kernel and image
Vect image = solver.Image(LoadMatrixFromStdVect(matrixValues));
Matrix linearSystem = image.GetLinearSystem();
// Create a column matrix with as many elements as the number of columns in the linear system
std::vector<std::string> columnMatrix(linearSystem.GetColumnCount());
for (size_t i = 0; i < linearSystem.GetColumnCount(); ++i) {
columnMatrix[i] = std::string(1, 'a' + static_cast<char>(i));
}
// Multiply the linear system matrix by the column matrix
std::vector<std::string> resultMatrix(linearSystem.GetRawCount());
for (size_t i = 0; i < linearSystem.GetRawCount(); ++i) {
for (size_t j = 0; j < linearSystem.GetColumnCount(); ++j) {
resultMatrix[i] += std::to_string(static_cast<int>(linearSystem.at(i, j))) + "*" + columnMatrix[j] + " + ";
}
resultMatrix[i] = resultMatrix[i].substr(0, resultMatrix[i].length() - 3) + " = 0";
}
// Store the equationsResult strings in the global variable
equationsResultImage = "Equations cartesiennes de l'espace vectoriel (Image):\n";
for (const auto& equation : resultMatrix) {
equationsResultImage += equation + "\n";
for (size_t i = 0; i < linearSystem.GetRawCount(); ++i) {
for (size_t j = 0; j < linearSystem.GetColumnCount(); ++j) {
equationsResultImage +=
linearSystem.at(i, j).ToString() + "*" + std::string {static_cast<char>('a' + j)} + " + ";
}
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);
"Rang: " + "\n" + std::to_string(solver.Rank(LoadMatrixFromStdVect(matrixValues))) + "\n" + "\n" + "Image: " + "\n" +
PrintVect(image);
}
ImGui::End(); // End fenetre bas