Commit 5fad6c35 authored by Andreas Kempe's avatar Andreas Kempe

Added user inputed settings and corrected a calculation error.

The image height was incorrectly being multiplied by the number of
processes at image assembly. Since the network sending of data was
implemented the width given in the settings is the actual width and not
the divided one.
parent 58dd708a
#include "main_window.h"
#include "mandelbrot.h"
#include <QPixmap>
#include <QPushButton>
#include <QDebug>
#include <QVBoxLayout>
#include <QFormLayout>
#include <QDialogButtonBox>
#include <Magick++.h>
#include <string>
......@@ -37,6 +38,55 @@ main_window::main_window(unsigned int port, QWidget* parent) :
connect(exit_btn, &QPushButton::clicked, this, &main_window::handle_kill_renderer);
layout->addWidget(exit_btn);
/************ Dialog for entering rendering options *****************************/
settings_dialog = new QDialog(this);
QFormLayout* form = new QFormLayout(settings_dialog);
settings_dialog->setLayout(form);
QLineEdit* line_edit = new QLineEdit("1", settings_dialog);
form->addRow("Real max", line_edit);
field_list.push_back(line_edit);
line_edit = new QLineEdit("-2", settings_dialog);
form->addRow("Real min", line_edit);
field_list.push_back(line_edit);
line_edit = new QLineEdit("1.4", settings_dialog);
form->addRow("Imaginary max", line_edit);
field_list.push_back(line_edit);
line_edit = new QLineEdit("-1.3", settings_dialog);
form->addRow("Imaginary min", line_edit);
field_list.push_back(line_edit);
line_edit = new QLineEdit("1064", settings_dialog);
form->addRow("Image width", line_edit);
field_list.push_back(line_edit);
line_edit = new QLineEdit("800", settings_dialog);
form->addRow("Image height", line_edit);
field_list.push_back(line_edit);
line_edit = new QLineEdit("1000", settings_dialog);
form->addRow("Iterations", line_edit);
field_list.push_back(line_edit);
QDialogButtonBox* diag_btns = new QDialogButtonBox(QDialogButtonBox::Ok, Qt::Horizontal,
settings_dialog);
form->addRow(diag_btns);
connect(diag_btns, &QDialogButtonBox::accepted, this, &main_window::handle_update_settings);
QPushButton* settings_btn = new QPushButton("Settings", this);
layout->addWidget(settings_btn);
connect(settings_btn, &QPushButton::clicked, this, &main_window::show_settings_diag);
/******************** End dialog ************************************************/
server = new mandel_tcp_server(this);
connect(server, &QTcpServer::newConnection, this, &main_window::handle_new_connection);
server->listen(QHostAddress::Any, port);
......@@ -63,16 +113,7 @@ void main_window::send_img_render()
QByteArray settings;
QDataStream stream(&settings, QIODevice::ReadWrite);
mandel_settings new_settings = { .re_max = 0.5,
.re_min = -1,
.im_max = 0.7,
.im_min = -0.625,
.img_width = 1064,
.img_height = 800,
.iterations = 1000};
stream << new_settings;
stream << render_settings;
char* payload = new char[settings.size()];
QDataStream read_stream(&settings, QIODevice::ReadOnly);
......@@ -92,6 +133,11 @@ void main_window::handle_kill_renderer()
socket->send_data_packet(kill_packet);
}
void main_window::show_settings_diag()
{
settings_dialog->exec();
}
void main_window::handle_new_connection()
{
socket = server->nextPendingConnection();
......@@ -137,3 +183,40 @@ void main_window::handle_recv_data()
delete packet;
}
void main_window::handle_update_settings()
{
settings_dialog->hide();
for (short i = 0; i < 7; ++i)
{
double value = field_list[i]->text().toDouble();
switch (i)
{
case 0:
render_settings.re_max = value;
break;
case 1:
render_settings.re_min = value;
break;
case 2:
render_settings.im_max = value;
break;
case 3:
render_settings.im_min = value;
break;
case 4:
render_settings.img_width = value;
break;
case 5:
render_settings.img_height = value;
break;
case 6:
render_settings.iterations = value;
break;
}
}
delete mandel_image;
mandel_image = new QImage(render_settings.img_width, render_settings.img_height, QImage::Format_RGB32);
}
......@@ -5,8 +5,12 @@
#include <QGraphicsScene>
#include <QGraphicsView>
#include <QGraphicsPixmapItem>
#include <QLineEdit>
#include <QDialog>
#include <vector>
#include "mandel_tcp_server.h"
#include "mandel_socket.h"
#include "mandelbrot.h"
class main_window : public QWidget
{
......@@ -27,15 +31,22 @@ class main_window : public QWidget
const unsigned int port;
QDialog* settings_dialog;
// Contains user set settings.
std::vector<QLineEdit*> field_list;
mandel_settings render_settings;
public slots:
void show_image();
void send_img_render();
void handle_kill_renderer();
void show_settings_diag();
private slots:
void handle_new_connection();
void handle_socket_close();
void handle_recv_data();
void handle_update_settings();
};
......
......@@ -2,15 +2,6 @@
#include <mpi.h>
#include <QCoreApplication>
#define IMG_WIDTH 1064lu
#define IMG_HEIGHT 800lu
#define ITERATIONS 200lu
#define RE_MAX 1
#define RE_MIN -2
#define IM_MAX 1.4
#define IM_MIN -1.3
using namespace std;
int main(int argc, char** argv)
......@@ -27,18 +18,7 @@ int main(int argc, char** argv)
// For the Qt event loop.
QCoreApplication app(argc, argv);
unsigned long effective_height = IMG_HEIGHT / procs;
mandel_settings settings = { .re_max = RE_MAX,
.re_min = RE_MIN,
.im_max = get_max_im(IM_MAX, IM_MIN, id, procs),
.im_min = get_min_im(IM_MAX, IM_MIN, id, procs),
.img_width = IMG_WIDTH,
.img_height = effective_height,
.iterations = ITERATIONS };
mandel_render_srv srv(settings, "192.168.1.2", PORT, id, procs, nullptr);
mandel_render_srv srv("192.168.1.2", PORT, id, procs, nullptr);
int exit_code = app.exec();
MPI_Finalize();
......
......@@ -9,7 +9,7 @@
using namespace std;
using namespace Magick;
mandel_render_srv::mandel_render_srv(mandel_settings settings, std::string host, unsigned int port,
mandel_render_srv::mandel_render_srv(std::string host, unsigned int port,
int id, int procs, QObject* parent) :
QObject(parent), settings(settings), id(id), procs(procs)
{
......@@ -57,17 +57,17 @@ void mandel_render_srv::start_drawing()
void mandel_render_srv::root_process_handling(unsigned long *receive_buffer)
{
Image my_image(Geometry(settings.img_width, settings.img_width * procs), "white");
Image my_image(Geometry(settings.img_width, settings.img_height), "white");
my_image.modifyImage();
Pixels pixel_cache(my_image);
PixelPacket *pixels = pixel_cache.get(0, 0, settings.img_width, settings.img_width * procs);
PixelPacket *pixels = pixel_cache.get(0, 0, settings.img_width, settings.img_height);
cout << "Assembling image!" << endl;
for (unsigned long y = 0; y < settings.img_width * procs; ++y)
for (unsigned long y = 0; y < settings.img_height; ++y)
{
cout << "Progress: " << setprecision(3) <<
static_cast<float>(y * 100) / settings.img_width * procs << " % \r" << flush;
static_cast<float>(y * 100) / (settings.img_height) << " % \r" << flush;
for (unsigned long x = 0; x < settings.img_width; ++x)
{
......@@ -107,7 +107,6 @@ void mandel_render_srv::mpi_event_loop()
// Sending the opcode as a double as well to only have to use one transmission.
MPI_Recv(&recv_buf, 8, MPI_DOUBLE, 0, 0, MPI_COMM_WORLD, &status);
mpi_opcodes op_code = static_cast<mpi_opcodes>(recv_buf[0]);
switch (op_code)
{
......
......@@ -13,7 +13,7 @@ enum class mpi_opcodes : int
class mandel_render_srv : public QObject
{
public:
mandel_render_srv(mandel_settings settings, std::string host, unsigned int port,
mandel_render_srv(std::string host, unsigned int port,
int id, int procs, QObject* parent);
void start_drawing();
......
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