diff --git a/app/CMakeLists.txt b/app/CMakeLists.txt index 82822c20ba7fc4e0acab67f977e8bc9f1ad97b1d..3b28d420b8f09de63a1bff5468606ebbd96e5088 100644 --- a/app/CMakeLists.txt +++ b/app/CMakeLists.txt @@ -140,8 +140,8 @@ set(imageinsa_SOURCES Operations/TranslateOp.h Operations/UCharConvertOp.cpp Operations/UCharConvertOp.h - Operations/ucharconvertdialog.cpp - Operations/ucharconvertdialog.h + Operations/UCharConvertDialog.cpp + Operations/UCharConvertDialog.h Operations/ZeroCrossingOp.cpp Operations/ZeroCrossingOp.h Services/ImageINSAService.cpp @@ -187,7 +187,6 @@ set(UIS Operations/DCTDialog.ui Operations/ColorDialog.ui Operations/MedianDialog.ui - Operations/ucharconvertdialog.ui ) qt5_wrap_ui(WRAPPED_UIS ${UIS}) diff --git a/app/Operations/UCharConvertDialog.cpp b/app/Operations/UCharConvertDialog.cpp new file mode 100644 index 0000000000000000000000000000000000000000..dd68b7511a00ab26182b99ade9e5139bbc179544 --- /dev/null +++ b/app/Operations/UCharConvertDialog.cpp @@ -0,0 +1,76 @@ +#include "UCharConvertDialog.h" +#include "ui_ucharconvertdialog.h" +#include <Converter.h> +#include <QDialog> +#include <QDialogButtonBox> +#include <QHBoxLayout> +#include <QFormLayout> +#include <QLabel> +#include <QSpinBox> +#include <QComboBox> +#include <QStringList> + + +UCharConvertDialog::UCharConvertDialog(QWidget *parent) : + QDialog(parent) +{ + this->setWindowTitle(qApp->translate("Operations","Convert to UChar")); + this->setMinimumWidth(180); + + QFormLayout* layout = new QFormLayout(this); + + QStringList text = (QStringList() << "crop" << "normalize" << "Add Offset" << "Scale" << "Add offset and scale"); + QLabel* label1 = new QLabel("Operation"); + _comboBox = new QComboBox(); + _comboBox->addItems(text); + + _label2 = new QLabel("Offset"); + _spinBox = new QSpinBox(); + _spinBox->setMaximum(255); + _spinBox->setMinimum(0); + _spinBox->setValue(127); + _spinBox->setEnabled(false); + _label2->setEnabled(false); + _spinBox->setVisible(false); + _label2->setVisible(false); + + layout->addRow(label1, _comboBox); + layout->addRow(_label2, _spinBox); + + QDialogButtonBox* buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok|QDialogButtonBox::Cancel, Qt::Horizontal, this); + layout->insertRow(3, buttonBox); + + QObject::connect(_comboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(enableOffset(int))); + QObject::connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept())); + QObject::connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject())); +} + + +void UCharConvertDialog::enableOffset(int n){ + std::cout << "which case it is ? -> " << n << "\n"; + if(n==2){ + _spinBox->setEnabled(true); + _label2->setEnabled(true); + _spinBox->setVisible(true); + _label2->setVisible(true); + }else if(n==4){ + _spinBox->setEnabled(false); + _label2->setEnabled(false); + _spinBox->setValue(127); + _spinBox->setVisible(true); + _label2->setVisible(true); + }else{ + _spinBox->setEnabled(false); + _label2->setEnabled(false); + _spinBox->setVisible(false); + _label2->setVisible(false); + } +} + +int UCharConvertDialog::getCombo(){ + return _comboBox->currentIndex(); +} + +int UCharConvertDialog::getOffset(){ + return _spinBox->value(); +} diff --git a/app/Operations/UCharConvertDialog.h b/app/Operations/UCharConvertDialog.h new file mode 100644 index 0000000000000000000000000000000000000000..fbcae6228de63565a5685ce3b8b3c92450281419 --- /dev/null +++ b/app/Operations/UCharConvertDialog.h @@ -0,0 +1,33 @@ +#ifndef UCHARCONVERTDIALOG_H +#define UCHARCONVERTDIALOG_H + +#include <QDialog> +#include <QSpinBox> +#include <QLabel> +#include <QComboBox> + +namespace Ui { +class UCharConvertDialog; +} + +class UCharConvertDialog : public QDialog +{ + Q_OBJECT + +public: + explicit UCharConvertDialog(QWidget *parent = 0); + int getCombo(); + int getOffset(); + + +public slots: + void enableOffset(int); + +protected: + QLabel* _label2; + QSpinBox* _spinBox; + QComboBox* _comboBox; + +}; + +#endif // UCHARCONVERTDIALOG_H diff --git a/app/Operations/UCharConvertOp.cpp b/app/Operations/UCharConvertOp.cpp index 45c4b47888d43f62493923bd876ae5d9fb6b8550..8c39c07c88d1a29dce7ef166e2de0493fe33e1e7 100644 --- a/app/Operations/UCharConvertOp.cpp +++ b/app/Operations/UCharConvertOp.cpp @@ -23,9 +23,17 @@ #include <QApplication> #include <QObject> #include "Operation.h" -#include "ucharconvertdialog.h" +#include "UCharConvertDialog.h" #include "Image.h" #include <Converter.h> +#include <QDialog> +#include <QDialogButtonBox> +#include <QHBoxLayout> +#include <QFormLayout> +#include <QLabel> +#include <QSpinBox> +#include <QComboBox> +#include <QStringList> using namespace imagein; @@ -38,46 +46,45 @@ bool UCharConvertOp::needCurrentImg() const{ } void UCharConvertOp::operator()(const imagein::Image_t<double>* from, const std::map<const imagein::Image_t<double>*, std::string>&){ + UCharConvertDialog* dialog = new UCharConvertDialog(QApplication::activeWindow()); - QDialog::DialogCode code = static_cast<QDialog::DialogCode>(dialog->exec()); + QDialog::DialogCode code = static_cast<QDialog::DialogCode>(dialog->exec()); if(code!=QDialog::Accepted) return; - - - - Image * resImg; std::string LogMessage = ""; Image_t<int> * tempIntImg; int offset; - switch(conversionTYPE) + + switch(dialog->getCombo()) { - case CROP : + case 0 : resImg = Converter<Image>::convertAndRound(*from); break; - case NORMALIZE : + case 1 : tempIntImg = Converter<Image_t<double>>::convertToInt(*from); tempIntImg->normalize(); resImg = Converter<Image>::convert(*tempIntImg); delete tempIntImg; break; - case OFFSET : + case 2 : + std::cout << "offset : " << dialog->getOffset() << " \n"; tempIntImg = Converter<Image_t<double>>::convertToInt(*from); - offset = 130; //getOffset() + offset = dialog->getOffset(); resImg = Converter<Image>::convertAndOffset(*tempIntImg, &LogMessage, offset); delete tempIntImg; break; - case OFFSETNSCALE : + case 4 : tempIntImg = Converter<Image_t<double>>::convertToInt(*from); resImg = Converter<Image>::convertScaleAndOffset(*tempIntImg, &LogMessage); delete tempIntImg; break; - case SCALE : + case 3 : tempIntImg = Converter<Image_t<double>>::convertToInt(*from); resImg = Converter<Image>::convertAndScale(*tempIntImg, &LogMessage); delete tempIntImg; @@ -91,3 +98,5 @@ void UCharConvertOp::operator()(const imagein::Image_t<double>* from, const std: outImage(resImg, "Title"); } + + diff --git a/app/Operations/UCharConvertOp.h b/app/Operations/UCharConvertOp.h index 1091d40b68bcc9c120686ffb88fb978eaa2b63bb..2301ad26642c16abc9fa7acd7c5b5f8a8c75113f 100644 --- a/app/Operations/UCharConvertOp.h +++ b/app/Operations/UCharConvertOp.h @@ -3,7 +3,10 @@ #include <QObject> #include "Operation.h" -#include "ucharconvertdialog.h" +#include "UCharConvertDialog.h" +#include <QLabel> +#include <QSpinBox> +#include <QComboBox> class UCharConvertOp : public DoubleOperation @@ -14,9 +17,7 @@ public: bool needCurrentImg() const; void operator()(const imagein::Image_t<double>*, const std::map<const imagein::Image_t<double>*, std::string>&); - private : - enum{CROP, NORMALIZE, OFFSET, OFFSETNSCALE, SCALE} conversionTYPE; };