Skip to content
Snippets Groups Projects
Commit c8b847a2 authored by Provot Bertrand's avatar Provot Bertrand
Browse files

UCharConverter dialog and op almost operationnal

parent a94aa2cb
No related branches found
No related tags found
No related merge requests found
......@@ -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})
......
#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();
}
#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
......@@ -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");
}
......@@ -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;
};
......
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