Skip to content
Snippets Groups Projects
Commit 6db431c3 authored by Vojtěch Tomas's avatar Vojtěch Tomas
Browse files

Refactoring the parameter loading

parent 3d502c48
No related branches found
No related tags found
No related merge requests found
......@@ -22,7 +22,8 @@ Výsledky jsou uloženy ve [složce monadic](./monadic) spolu s podrobnějším
Je přiložen Makefile, vše by mělo fungovat na všech platformách (snad), jiné závislosti nejsou třeba. Vyvíjím na Linuxu.
## Ovládání
command <parameter> (optional parameter)
Overview of available commands:
command <parameter> (optional parameter)
open <filename>
loads image from file onto image stack
......@@ -34,14 +35,15 @@ Je přiložen Makefile, vše by mělo fungovat na všech platformách (snad), ji
images
list all images loaded on image stack
save <stack index> <png|jpg> <output name>
save image into a file with chosen format
save <png|jpg> <output name>
save image on top of image stack
into a file with chosen format
histogram (filename)
draw histogram of the image on top of the stack
or save the histogram it into .png file
negative
negate
negate the image on top of the image stack
threshold <value from <0, 1>>
......@@ -71,6 +73,9 @@ Je přiložen Makefile, vše by mělo fungovat na všech platformách (snad), ji
quantize the image
on top of the image stack
exit
exit the application
equalize
eqalize the image
on top of the image stack
exit
exit the application
\ No newline at end of file
File deleted
#pragma once
#include "editor.hpp"
#include <unordered_map>
using namespace std;
class Interface;
typedef void (Interface::*imethod)(istringstream & iss);
class Interface {
public:
......@@ -11,11 +18,11 @@ protected:
void load_image(istringstream & iss);
void drop_image(istringstream & iss);
void save_image(istringstream & iss);
void print_help() const;
void print_image_stack() const;
void print_help(istringstream & iss);
void print_image_stack(istringstream & iss);
void histogram(istringstream & iss);
void negative();
void negative(istringstream & iss);
void threshold(istringstream & iss);
void brightness(istringstream & iss);
void contrast(istringstream & iss);
......@@ -23,7 +30,9 @@ protected:
void nonlincontrast(istringstream & iss);
void logscale(istringstream & iss);
void quantize(istringstream & iss);
void equalize();
void equalize(istringstream & iss);
Editor editor;
std::unordered_map<std::string, imethod> calls;
};
......@@ -2,6 +2,7 @@
#include <string>
#include <sstream>
#include <cstring>
#include "include/interface.hpp"
#include "include/editor.hpp"
......@@ -12,6 +13,22 @@ using namespace std;
Interface::Interface()
{
cout << "Initializing the application..." << endl;
calls["open"] = &Interface::load_image;
calls["drop"] = &Interface::drop_image;
calls["save"] = &Interface::save_image;
calls["help"] = &Interface::print_help;
calls["images"] = &Interface::print_image_stack;
calls["negate"] = &Interface::negative;
calls["threshold"] = &Interface::threshold;
calls["brightness"] = &Interface::brightness;
calls["contrast"] = &Interface::contrast;
calls["gamma"] = &Interface::gamma;
calls["nonlincontrast"] = &Interface::nonlincontrast;
calls["logscale"] = &Interface::logscale;
calls["equalize"] = &Interface::equalize;
calls["quantize"] = &Interface::quantize;
calls["histogram"] = &Interface::histogram;
}
void Interface::run()
......@@ -28,56 +45,16 @@ void Interface::run()
istringstream iss(line);
iss >> input;
if (input == "open")
load_image(iss);
if (input == "drop")
drop_image(iss);
if (input == "save")
save_image(iss);
if (input == "help")
print_help();
if (input == "negate")
negative();
if (input == "threshold")
threshold(iss);
if (input == "brightness")
brightness(iss);
if (input == "contrast")
contrast(iss);
if (input == "gamma")
gamma(iss);
if (input == "nonlincontrast")
nonlincontrast(iss);
if (input == "logscale")
logscale(iss);
if (input == "equlize")
equalize();
if (input == "quantize")
quantize(iss);
if (input == "images")
print_image_stack();
if (input == "histogram")
histogram(iss);
if (input == "exit")
{
iss.clear();
return;
}
auto it = calls.find(input);
if (it != calls.end())
(this->*(it->second))(iss);
}
if (cin.eof())
......@@ -148,7 +125,7 @@ void Interface::histogram(istringstream &iss)
cout << "there was some error creating the histogram" << endl;
}
void Interface::negative()
void Interface::negative(istringstream & iss)
{
int status = editor.negative();
......@@ -268,7 +245,7 @@ void Interface::quantize(istringstream &iss)
cout << "there was some error" << endl;
}
void Interface::equalize()
void Interface::equalize(istringstream & iss)
{
int status = editor.equalize();
......@@ -276,7 +253,7 @@ void Interface::equalize()
cout << "there was some error" << endl;
}
void Interface::print_help() const
void Interface::print_help(istringstream & iss)
{
cout << "Overview of available commands:\n"
" command <parameter> (optional parameter)\n\n"
......@@ -287,12 +264,13 @@ void Interface::print_help() const
" filename from image stack\n\n"
" images\n"
" list all images loaded on image stack\n\n"
" save <stack index> <png|jpg> <output name>\n"
" save image into a file with chosen format\n\n"
" save <png|jpg> <output name>\n"
" save image on top of image stack\n"
" into a file with chosen format\n\n"
" histogram (filename)\n"
" draw histogram of the image on top of the stack\n"
" or save the histogram it into .png file\n\n"
" negative\n"
" negate\n"
" negate the image on top of the image stack\n\n"
" threshold <value from <0, 1>>\n"
" threshold the image on top of the image stack\n\n"
......@@ -314,11 +292,14 @@ void Interface::print_help() const
" quantize <integer value from <1, inf>>\n"
" quantize the image\n"
" on top of the image stack\n\n"
" equalize\n"
" eqalize the image\n"
" on top of the image stack\n\n"
" exit\n"
" exit the application\n\n";
}
void Interface::print_image_stack() const{
void Interface::print_image_stack(istringstream & iss) {
for (size_t i = 0; i < STACKSIZE; i++)
{
const Image * image = editor.get_image(i);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment