Skip to content

Commit

Permalink
progress
Browse files Browse the repository at this point in the history
  • Loading branch information
mattrussmill committed Mar 20, 2019
1 parent 8985a98 commit 58151eb
Show file tree
Hide file tree
Showing 11 changed files with 172 additions and 26 deletions.
2 changes: 1 addition & 1 deletion src/bufferwrappersqcv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
#include <QPixmap>
#include <QString>
#include <QDebug>
#include <opencv2/core/core.hpp>
#include <opencv2/core.hpp>

namespace qcv
{
Expand Down
2 changes: 1 addition & 1 deletion src/bufferwrappersqcv.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@

#include <QString>
#include <QDebug>
#include <opencv2/core/core.hpp>
#include <opencv2/core.hpp>
class QImage;
class QPixmap;

Expand Down
9 changes: 4 additions & 5 deletions src/filtermenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ FilterMenu::FilterMenu(QMutex *mutex, QWidget *parent) :
QScrollArea(parent),
ui(new Ui::FilterMenu)
{
ui->setupUi(this);
ui->setupUi(this);
masterImage_m = nullptr;
previewImage_m = nullptr;
Expand Down Expand Up @@ -140,7 +139,7 @@ FilterMenu::~FilterMenu()
{
worker_m.terminate();
worker_m.wait();
delete filterWorker_m; //safe? Different way to handle this?
delete filterWorker_m;
filterWorker_m = nullptr;
}
delete ui;
Expand Down Expand Up @@ -245,7 +244,7 @@ void FilterMenu::collectBlurParameters()
menuValues_m[KernelWeight] = ui->horizontalSlider_SmoothWeight->value();
menuValues_m[KernelOperation] = SmoothFilter;

emit workSignalSuppressor.receiveNewData(QByteArray(reinterpret_cast<char*>(&menuValues_m), sizeof(int) * 3));
workSignalSuppressor.receiveNewData(QByteArray(reinterpret_cast<char*>(&menuValues_m), sizeof(int) * 3));
}

//Populates the menuValues_m parameter and passes it to a worker slot for the Sharpen operation.
Expand All @@ -258,7 +257,7 @@ void FilterMenu::collectSharpenParameters()
menuValues_m[KernelWeight] = ui->horizontalSlider_SharpenWeight->value();
menuValues_m[KernelOperation] = SharpenFilter;

emit workSignalSuppressor.receiveNewData(QByteArray(reinterpret_cast<char*>(&menuValues_m), sizeof(int) * 3));
workSignalSuppressor.receiveNewData(QByteArray(reinterpret_cast<char*>(&menuValues_m), sizeof(int) * 3));
}

//Populates the menuValues_m parameter and passes it to a worker slot for the Edge Detect operation.
Expand All @@ -272,7 +271,7 @@ void FilterMenu::collectEdgeDetectParameters()
menuValues_m[KernelWeight] = ui->horizontalSlider_EdgeWeight->value() * 2 + 1;
menuValues_m[KernelOperation] = EdgeFilter;

emit workSignalSuppressor.receiveNewData(QByteArray(reinterpret_cast<char*>(&menuValues_m), sizeof(int) * 3));
workSignalSuppressor.receiveNewData(QByteArray(reinterpret_cast<char*>(&menuValues_m), sizeof(int) * 3));
}

//Sets the sample image based on the menu item selected.
Expand Down
6 changes: 3 additions & 3 deletions src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent),
// connect(imageWorker_m, SIGNAL(resultHistoUpdate()), this, SLOT(updateHistogram()));
// connect(imageWorker_m, SIGNAL(updateStatus(QString)), ui->statusBar, SLOT(showMessage(QString)));

//connect necessary worker thread - adjustmenu / ui slots
//connect necessary adjustmenu / ui slots
connect(ui->pushButtonCancel, SIGNAL(released()), adjustMenu_m, SLOT(initializeSliders()));
connect(ui->pushButtonApply, SIGNAL(released()), adjustMenu_m, SLOT(initializeSliders()));
connect(adjustMenu_m, SIGNAL(updateDisplayedImage()), this, SLOT(displayPreview()));
Expand All @@ -90,7 +90,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent),
connect(this, SIGNAL(distributeImageBufferAddresses(const cv::Mat*, cv::Mat*)), adjustMenu_m, SLOT(initializeSliders()));
connect(this, SIGNAL(distributeImageBufferAddresses(const cv::Mat*, cv::Mat*)), adjustMenu_m, SLOT(receiveImageAddresses(const cv::Mat*, cv::Mat*)));

//connect necessary worker thread - filtermenu / ui slots
//connect necessary filtermenu / ui slots
connect(ui->pushButtonCancel, SIGNAL(released()), filterMenu_m, SLOT(initializeSliders()));
connect(ui->pushButtonApply, SIGNAL(released()), filterMenu_m, SLOT(initializeSliders()));
connect(filterMenu_m, SIGNAL(updateDisplayedImage()), this, SLOT(displayPreview()));
Expand All @@ -99,7 +99,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent),
connect(this, SIGNAL(distributeImageBufferAddresses(const cv::Mat*, cv::Mat*)), filterMenu_m, SLOT(initializeSliders()));
connect(this, SIGNAL(distributeImageBufferAddresses(const cv::Mat*, cv::Mat*)), filterMenu_m, SLOT(receiveImageAddresses(const cv::Mat*, cv::Mat*)));

//connect necessary worker thread - temperaturemenu / ui slots
//connect necessary temperaturemenu / ui slots
connect(ui->pushButtonCancel, SIGNAL(released()), temperatureMenu_m, SLOT(initializeSliders()));
connect(ui->pushButtonApply, SIGNAL(released()), temperatureMenu_m, SLOT(initializeSliders()));
connect(temperatureMenu_m, SIGNAL(updateDisplayedImage()), this, SLOT(displayPreview()));
Expand Down
6 changes: 4 additions & 2 deletions src/qcvTouchUp.pro
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ SOURCES += \
colorselectionwidget.cpp \
adjustworker.cpp \
filterworker.cpp \
temperatureworker.cpp
temperatureworker.cpp \
transformworker.cpp

HEADERS += \
mainwindow.h \
Expand All @@ -66,7 +67,8 @@ HEADERS += \
colorselectionwidget.h \
adjustworker.h \
filterworker.h \
temperatureworker.h
temperatureworker.h \
transformworker.h

FORMS += \
mainwindow.ui \
Expand Down
6 changes: 3 additions & 3 deletions src/temperaturemenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ TemperatureMenu::TemperatureMenu(QMutex *mutex, QWidget *parent) :
connect(ui->horizontalSlider_Temperature, SIGNAL(sliderReleased()), this, SLOT(deselectRadioButtonFromSlider()));
connect(ui->horizontalSlider_Temperature, QSlider::valueChanged, &workSignalSuppressor, SignalSuppressor::receiveNewData);

initializeMenu();
initializeSliders();
}

//autogenerated destructor
Expand Down Expand Up @@ -126,7 +126,7 @@ void TemperatureMenu::setMenuTracking(bool enable)
}

// Function initializes the necessary widget values to their starting values.
void TemperatureMenu::initializeMenu()
void TemperatureMenu::initializeSliders()
{
ui->horizontalSlider_Temperature->blockSignals(true);
int middle = (ui->horizontalSlider_Temperature->minimum() + ui->horizontalSlider_Temperature->maximum()) / 2;
Expand Down Expand Up @@ -175,7 +175,7 @@ void TemperatureMenu::setVisible(bool visible)
//overloads show event to initialize the visible menu widgets before being seen
void TemperatureMenu::showEvent(QShowEvent *event)
{
initializeMenu();
initializeSliders();
QWidget::showEvent(event);
}

Expand Down
2 changes: 1 addition & 1 deletion src/temperaturemenu.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class TemperatureMenu : public QScrollArea
~TemperatureMenu();

public slots:
void initializeMenu();
void initializeSliders();
void receiveImageAddresses(const cv::Mat *masterImage, cv::Mat *previewImage);
void setMenuTracking(bool enable);
void setVisible(bool visible) override;
Expand Down
119 changes: 112 additions & 7 deletions src/transformmenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
#include "focusindetectoreventfilter.h"
#include "transformmenu.h"
#include "imagewidget.h"
#include "transformworker.h"
#include "ui_transformmenu.h"
#include <cmath>
#include <QButtonGroup>
Expand All @@ -58,11 +59,16 @@

/* Constructor installs the necessary filters for different objects, groups the buttons together
* to easily search for the selected button, and establishes all signals/slots necessary.*/
TransformMenu::TransformMenu(QWidget *parent) :
TransformMenu::TransformMenu(QMutex *mutex, QWidget *parent) :
QScrollArea(parent),
ui(new Ui::TransformMenu)
{
ui->setupUi(this);
masterImage_m = nullptr;
previewImage_m = nullptr;
workerMutex_m = mutex;
filterWorker_m = nullptr;

MouseWheelEaterEventFilter *wheelFilter = new MouseWheelEaterEventFilter(this);
FocusInDetectorEventFilter *cropFocusFilter = new FocusInDetectorEventFilter(this);
FocusInDetectorEventFilter *rotateFocusFilter = new FocusInDetectorEventFilter(this);
Expand Down Expand Up @@ -93,7 +99,7 @@ TransformMenu::TransformMenu(QWidget *parent) :
connect(rotateFocusFilter, SIGNAL(focusDetected(bool)), ui->radioButton_RotateEnable, SLOT(setChecked(bool)));
connect(ui->spinBox_RotateDegrees, SIGNAL(valueChanged(int)), ui->horizontalSlider_Rotate, SLOT(setValue(int)));
connect(ui->horizontalSlider_Rotate, SIGNAL(valueChanged(int)), ui->spinBox_RotateDegrees, SLOT(setValue(int)));
connect(ui->spinBox_RotateDegrees, SIGNAL(valueChanged(int)), this, SIGNAL(performImageRotate(int)));
connect(ui->spinBox_RotateDegrees, QSlider::valueChanged, &workSignalSuppressor, SignalSuppressor::receiveNewData);
connect(ui->checkBox_rotateAutoCrop, SIGNAL(toggled(bool)), this, SIGNAL(setAutoCropOnRotate(bool)));
connect(ui->checkBox_rotateAutoCrop, SIGNAL(toggled(bool)), this, SLOT(resendImageRotateSignal()));
connect(ui->radioButton_RotateEnable, SIGNAL(toggled(bool)), this, SLOT(changeSampleImage(bool)));
Expand Down Expand Up @@ -123,13 +129,44 @@ TransformMenu::TransformMenu(QWidget *parent) :
//autogenerated destructor
TransformMenu::~TransformMenu()
{
if(transformWorker_m)
{
worker_m.terminate();
worker_m.wait();
delete filterWorker_m;
filterWorker_m = nullptr;
}
delete ui;
}

/* This slot is used to update the member addresses for the master and preview images stored
* in the parent object. If the Mat's become empty in the parent object this slot
* should be signaled with nullptrs to signify they are empty. */
void TransformMenu::receiveImageAddresses(const cv::Mat *masterImage, cv::Mat *previewImage)
{
masterImage_m = masterImage;
previewImage_m = previewImage;
qDebug() << "Filter Menu Images:" << masterImage_m << previewImage_m;
emit distributeImageBufferAddresses(masterImage, previewImage);
}

// Enables or disables tracking for the appropriate menu widgets
void TransformMenu::setMenuTracking(bool enable)
{
ui->horizontalSlider_Rotate->setTracking(enable);
}

// Function initializes the necessary widget values to their starting values.
void TransformMenu::initializeMenu()
void TransformMenu::initializeSliders()
{
blockSignals(true);
ui->lineEdit_CropRoiStart->blockSignals(true);
ui->lineEdit_CropRoiEnd->blockSignals(true);
ui->spinBox_ScaleHeight->blockSignals(true);
ui->spinBox_ScaleWidth->blockSignals(true);
ui->horizontalSlider_Rotate->blockSignals(true);
ui->spinBox_RotateDegrees->blockSignals(true);
ui->checkBox_rotateAutoCrop->blockSignals(true);
ui->checkBox_ScaleLinked->blockSignals(true);

//reinitialize buttons to unchecked
QAbstractButton *checkedButton = buttonGroup_m->checkedButton();
Expand Down Expand Up @@ -183,6 +220,15 @@ void TransformMenu::initializeMenu()
//signal must be emitted on reset
ui->checkBox_rotateAutoCrop->setChecked(false);

ui->lineEdit_CropRoiStart->blockSignals(false);
ui->lineEdit_CropRoiEnd->blockSignals(false);
ui->spinBox_ScaleHeight->blockSignals(false);
ui->spinBox_ScaleWidth->blockSignals(false);
ui->horizontalSlider_Rotate->blockSignals(false);
ui->spinBox_RotateDegrees->blockSignals(false);
ui->checkBox_rotateAutoCrop->blockSignals(false);
ui->checkBox_ScaleLinked->blockSignals(false);

ui->label_SampleImage->setPixmap(QPixmap::fromImage(QImage(":/img/icons/masterIcons/rgb.png")));
emit setGetCoordinateMode(ImageWidget::CoordinateMode::NoClick);
}
Expand Down Expand Up @@ -260,11 +306,17 @@ void TransformMenu::setImageInternalROI()
//overloads setVisible to signal the worker thread to cancel any adjustments that weren't applied when minimized
void TransformMenu::setVisible(bool visible)
{
if(!visible)
initializeMenu();
manageWorker(visible);
QWidget::setVisible(visible);
}

//overloads show event to initialize the visible menu widgets before being seen
void FilterMenu::showEvent(QShowEvent *event)
{
initializeSliders();
QWidget::showEvent(event);
}

/* setSelectInImage is an internal method used to emit the appropriate signals to enable and disable region selection
* through emitting the proper signals to the ImageWidget object*/
void TransformMenu::setSelectInImage(bool checked)
Expand All @@ -285,7 +337,8 @@ void TransformMenu::setSelectInImage(bool checked)
//sends a signal to perform the image rotate operation. Intended to send value again to kick off operation @ toggle event
void TransformMenu::resendImageRotateSignal()
{
emit performImageRotate(ui->spinBox_RotateDegrees->value());
//emit performImageRotate(int); //only operation to use this object in this menu so far
workSignalSuppressor.receiveNewData(ui->spinBox_RotateDegrees->value());
}

/* setImageInternalSizeHeight sets the member storing the desired Scaled Image Size according to the new value in
Expand Down Expand Up @@ -372,3 +425,55 @@ void TransformMenu::changeSampleImage(bool detected)

}

/* This method determines when the worker thread should be created or destroyed so
* that the worker thread (with event loop) is only running if it is required (in
* this case if the menu is visible). This thread manages the creation, destruction,
* connection, and disconnection of the thread and its signals / slots.*/
void FilterMenu::manageWorker(bool life)
{
if(life)
{
if(!transformWorker_m)
{
//If worker is still trying to exit, wait and process other events until its done
if(worker_m.isRunning())
{
QApplication::setOverrideCursor(Qt::WaitCursor);
qDebug() << "Waiting for thread to exit";
while(!worker_m.isFinished())
{
QApplication::processEvents(QEventLoop::AllEvents, 100);
}
QApplication::restoreOverrideCursor();
}

transformWorker_m = new TransformWorker(masterImage_m, previewImage_m, workerMutex_m);
transformWorker_m->moveToThread(&worker_m);
//signal slot connections (might be able to do them in constructor?)
connect(this, SIGNAL(distributeImageBufferAddresses(const cv::Mat*,cv::Mat*)), filterWorker_m, SLOT(receiveImageAddresses(const cv::Mat*, cv::Mat*)));
connect(&workSignalSuppressor, SIGNAL(suppressedSignal(SignalSuppressor*)), filterWorker_m, SLOT(receiveSuppressedSignal(SignalSuppressor*)));
//other worker signals slots
connect(filterWorker_m, SIGNAL(updateDisplayedImage()), this, SIGNAL(updateDisplayedImage()));
connect(filterWorker_m, SIGNAL(updateStatus(QString)), this, SIGNAL(updateStatus(QString)));
worker_m.start();
}
}
else
{
//while the worker event loop is running, tell it to delete itself once loop is empty.
if(transformWorker_m)
{
/* All signals to and from the object are automatically disconnected (string based, not functor),
* and any pending posted events for the object are removed from the event queue. This is done incase functor signal/slots used later*/
disconnect(this, SIGNAL(distributeImageBufferAddresses(const cv::Mat*,cv::Mat*)), transformWorker_m, SLOT(receiveImageAddresses(const cv::Mat*, cv::Mat*)));
disconnect((&workSignalSuppressor, SIGNAL(suppressedSignal(SignalSuppressor*)), transformWorker_m, SLOT(receiveSuppressedSignal(SignalSuppressor*))));
//other worker signals slots
disconnect(transformWorker_m, SIGNAL(updateDisplayedImage()), this, SIGNAL(updateDisplayedImage()));
disconnect(transformWorker_m, SIGNAL(updateStatus(QString)), this, SIGNAL(updateStatus(QString)));
filterWorker_m->deleteLater();
filterWorker_m = nullptr;
worker_m.quit();
}
}
}

23 changes: 20 additions & 3 deletions src/transformmenu.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
class QString;
class QButtonGroup;
class QRect;
class TransformWorker;

namespace Ui {
class TransformMenu;
Expand All @@ -61,7 +62,7 @@ class TransformMenu : public QScrollArea
Q_OBJECT

public:
explicit TransformMenu(QWidget *parent = 0);
explicit TransformMenu(QMutex *mutex, QWidget *parent = 0);
~TransformMenu();
enum ParameterIndex
{
Expand All @@ -71,28 +72,44 @@ class TransformMenu : public QScrollArea
QRect getSizeOfScale() const;

public slots:
void initializeMenu();
void initializeSliders();
void receiveImageAddresses(const cv::Mat *masterImage, cv::Mat *previewImage);
void setMenuTracking(bool enable);
void setImageResolution(QRect imageSize);
void setImageROI(QRect ROI);
void setVisible(bool visible) override;
void showEvent(QShowEvent *event) override;

signals:
void updateDisplayedImage();
void distributeImageBufferAddresses(const cv::Mat*, cv::Mat*);
void updateStatus(QString);
void enableCropImage(bool); //mainwindow sends ROI to here, when performImageCrop is emitted, then sends the ROI value to worker when apply is selected.
void performImageCrop(QRect ROI); //if same size as image nothing happens. -> after apply is hit this is released
void giveImageROI(QRect ROI);
void setGetCoordinateMode(uint);
void cancelRoiSelection();
void performImageRotate(int);
void setAutoCropOnRotate(bool);
void performImageScale(QRect size);

protected:
const cv::Mat *masterImage_m;
cv::Mat *previewImage_m;
QMutex *workerMutex_m;
QThread worker_m;
TransformWorker *transformWorker_m;

protected slots:
void manageWorker(bool life);

private:
bool boundCheck(const QRect &ROI);
Ui::TransformMenu *ui;
QButtonGroup *buttonGroup_m;
QRect imageSize_m;
QRect croppedROI_m;
QVector<int> menuValues_m;
SignalSuppressor workSignalSuppressor;

private slots:
void setSelectInImage(bool checked);
Expand Down
6 changes: 6 additions & 0 deletions src/transformworker.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include "transformworker.h"

TransformWorker::TransformWorker(QObject *parent) : QObject(parent)
{

}
Loading

0 comments on commit 58151eb

Please sign in to comment.