[TASK] Finish prepare the filter gui part.

This commit is contained in:
Jan Philipp Timme 2015-11-27 14:17:54 +01:00
parent a8365ea1f5
commit ae501ec6be
3 changed files with 63 additions and 9 deletions

View File

@ -16,27 +16,54 @@ class FilterGui {
private: private:
QTableWidget* widget; QTableWidget* widget;
int filter_size; int size;
int* data;
void recreateDataStorage() {
if(data != NULL) {
delete data;
data = NULL;
}
int fields = this->size * this->size;
data = (int*) malloc(sizeof(int) * fields);
for(int i=0; i<fields; i++) data[i] = 0;
}
void updateGui() { void updateGui() {
this->widget->setRowCount(this->filter_size); this->widget->setRowCount(this->size);
this->widget->setColumnCount(this->filter_size); this->widget->setColumnCount(this->size);
for(int i=0; i<this->filter_size; i++) { for(int i=0; i<this->size; i++) {
for(int j=0; j<this->filter_size; j++) { for(int j=0; j<this->size; j++) {
this->widget->setItem(i, j, new QTableWidgetItem("0")); this->widget->setItem(i, j, new QTableWidgetItem("0"));
} }
} }
}; };
void fetchData() {
for(int i=0; i<this->size; i++) {
for(int j=0; j<this->size; j++) {
QString temp = this->widget->item(i, j)->text();
this->data[i*this->size + j] = temp.toInt();
}
}
};
public: public:
FilterGui(int filter_size = 3) { FilterGui(int filter_size = 3) {
this->data = NULL;
this->widget = new QTableWidget(); this->widget = new QTableWidget();
this->setSize(filter_size); this->setSize(filter_size);
}; };
~FilterGui() { ~FilterGui() {
delete this->widget; if(this->widget != NULL) {
this->widget = NULL; delete this->widget;
this->widget = NULL;
}
if(this->data != NULL) {
delete this->data;
this->data = NULL;
}
}; };
QTableWidget* getWidget() { QTableWidget* getWidget() {
@ -44,13 +71,19 @@ class FilterGui {
}; };
void setSize(int size) { void setSize(int size) {
this->filter_size = size; this->size = size;
this->updateGui(); this->updateGui();
}; };
int getSize() { int getSize() {
return this->filter_size; return this->size;
}; };
int* getData() {
this->recreateDataStorage();
this->fetchData();
return this->data;
}
}; };

View File

@ -472,6 +472,21 @@ void ImageViewer::succeedingHistogrammAdaption() {
updateImageDisplay(); updateImageDisplay();
} }
void ImageViewer::applyFilter() {
logFile << "Applying filter ...";
int* data = filter_gui->getData();
for(int i=0; i<filter_gui->getSize(); i++) {
for(int j=0; j<filter_gui->getSize(); j++) {
logFile << "@" << i << "," << j << " -> " << data[i*filter_gui->getSize() + j] << std::endl;
}
}
logFile << "done." << std::endl;
renewLogging();
//updateImageDisplay();
}
/**************************************************************************************** /****************************************************************************************
@ -700,8 +715,12 @@ void ImageViewer::generateControlPanels() {
filter_gui = new FilterGui(); filter_gui = new FilterGui();
apply_filter = new QPushButton("Apply filter");
QObject::connect(apply_filter, SIGNAL(clicked()), this, SLOT(applyFilter()));
task_tab4_scrolllayout->addWidget(filter_size_slider); task_tab4_scrolllayout->addWidget(filter_size_slider);
task_tab4_scrolllayout->addWidget(filter_gui->getWidget()); task_tab4_scrolllayout->addWidget(filter_gui->getWidget());
task_tab4_scrolllayout->addWidget(apply_filter);
tabWidget->addTab(task_tab4_widget, "Task #4"); tabWidget->addTab(task_tab4_widget, "Task #4");

View File

@ -134,6 +134,7 @@ class ImageViewer : public QMainWindow {
QSlider* filter_size_slider; QSlider* filter_size_slider;
FilterGui* filter_gui; FilterGui* filter_gui;
QPushButton* apply_filter;
// "My" space for storing data/results // "My" space for storing data/results
LazyImage* original; LazyImage* original;
@ -156,6 +157,7 @@ class ImageViewer : public QMainWindow {
void partialLinearHistogrammAdaption(); void partialLinearHistogrammAdaption();
void succeedingHistogrammAdaption(); void succeedingHistogrammAdaption();
void changeFilterSize(int s); void changeFilterSize(int s);
void applyFilter();
void open(); void open();
void openReference(); void openReference();