From ae501ec6bedddffa57deebf3ca582ee79020a774 Mon Sep 17 00:00:00 2001 From: Jan Philipp Timme Date: Fri, 27 Nov 2015 14:17:54 +0100 Subject: [PATCH] [TASK] Finish prepare the filter gui part. --- filter_gui.cpp | 51 +++++++++++++++++++++++++++++++++++++-------- imageviewer-qt4.cpp | 19 +++++++++++++++++ imageviewer-qt4.h | 2 ++ 3 files changed, 63 insertions(+), 9 deletions(-) diff --git a/filter_gui.cpp b/filter_gui.cpp index e2e0d52..ee1e7fe 100644 --- a/filter_gui.cpp +++ b/filter_gui.cpp @@ -16,27 +16,54 @@ class FilterGui { private: 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; iwidget->setRowCount(this->filter_size); - this->widget->setColumnCount(this->filter_size); - for(int i=0; ifilter_size; i++) { - for(int j=0; jfilter_size; j++) { + this->widget->setRowCount(this->size); + this->widget->setColumnCount(this->size); + for(int i=0; isize; i++) { + for(int j=0; jsize; j++) { this->widget->setItem(i, j, new QTableWidgetItem("0")); } } }; + + void fetchData() { + for(int i=0; isize; i++) { + for(int j=0; jsize; j++) { + QString temp = this->widget->item(i, j)->text(); + this->data[i*this->size + j] = temp.toInt(); + } + } + }; public: FilterGui(int filter_size = 3) { + this->data = NULL; this->widget = new QTableWidget(); this->setSize(filter_size); }; ~FilterGui() { - delete this->widget; - this->widget = NULL; + if(this->widget != NULL) { + delete this->widget; + this->widget = NULL; + } + if(this->data != NULL) { + delete this->data; + this->data = NULL; + } }; QTableWidget* getWidget() { @@ -44,13 +71,19 @@ class FilterGui { }; void setSize(int size) { - this->filter_size = size; + this->size = size; this->updateGui(); }; int getSize() { - return this->filter_size; + return this->size; }; + + int* getData() { + this->recreateDataStorage(); + this->fetchData(); + return this->data; + } }; diff --git a/imageviewer-qt4.cpp b/imageviewer-qt4.cpp index b98cca0..b9307ca 100644 --- a/imageviewer-qt4.cpp +++ b/imageviewer-qt4.cpp @@ -472,6 +472,21 @@ void ImageViewer::succeedingHistogrammAdaption() { updateImageDisplay(); } +void ImageViewer::applyFilter() { + logFile << "Applying filter ..."; + + int* data = filter_gui->getData(); + + for(int i=0; igetSize(); i++) { + for(int j=0; jgetSize(); 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(); + 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_gui->getWidget()); + task_tab4_scrolllayout->addWidget(apply_filter); tabWidget->addTab(task_tab4_widget, "Task #4"); diff --git a/imageviewer-qt4.h b/imageviewer-qt4.h index 829b1a3..a524d87 100644 --- a/imageviewer-qt4.h +++ b/imageviewer-qt4.h @@ -134,6 +134,7 @@ class ImageViewer : public QMainWindow { QSlider* filter_size_slider; FilterGui* filter_gui; + QPushButton* apply_filter; // "My" space for storing data/results LazyImage* original; @@ -156,6 +157,7 @@ class ImageViewer : public QMainWindow { void partialLinearHistogrammAdaption(); void succeedingHistogrammAdaption(); void changeFilterSize(int s); + void applyFilter(); void open(); void openReference();