Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • trauffle/imageinsa_tanguy
1 result
Show changes
Commits on Source (2)
...@@ -206,9 +206,9 @@ qt5_add_resources(RCC_FILES "imageinsa_app_res.qrc") ...@@ -206,9 +206,9 @@ qt5_add_resources(RCC_FILES "imageinsa_app_res.qrc")
set(TS_FILES imageinsa_en.ts imageinsa_fr.ts) set(TS_FILES imageinsa_en.ts imageinsa_fr.ts)
# Uncomment only 1 of the 2 folowing commands, depending on your needs # Uncomment only 1 of the 2 folowing commands, depending on your needs
# -1- Use current translations files # -1- Use current translations files
#qt5_add_translation(QM_FILES ${TS_FILES}) qt5_add_translation(QM_FILES ${TS_FILES})
# -2- Update translations files with changes from c++ sources # -2- Update translations files with changes from c++ sources
qt5_create_translation(QM_FILES ${imageinsa_SOURCES} ${UIS} ${TS_FILES}) #qt5_create_translation(QM_FILES ${imageinsa_SOURCES} ${UIS} ${TS_FILES})
# -3- Update translations files with changes from c++ sources AND drop useless translations # -3- Update translations files with changes from c++ sources AND drop useless translations
#qt5_create_translation(QM_FILES ${imageinsa_SOURCES} ${UIS} ${TS_FILES} OPTIONS -no-obsolete) #qt5_create_translation(QM_FILES ${imageinsa_SOURCES} ${UIS} ${TS_FILES} OPTIONS -no-obsolete)
......
...@@ -31,7 +31,7 @@ class ColorDialog; ...@@ -31,7 +31,7 @@ class ColorDialog;
class ColorDialog : public QDialog class ColorDialog : public QDialog
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit ColorDialog(QWidget *parent = 0); explicit ColorDialog(QWidget *parent = 0);
~ColorDialog(); ~ColorDialog();
......
...@@ -18,8 +18,6 @@ ...@@ -18,8 +18,6 @@
*/ */
#include <GrayscaleImage.h> #include <GrayscaleImage.h>
#include <QColor>
#include "SplitHsvOp.h" #include "SplitHsvOp.h"
#include "../Tools.h" #include "../Tools.h"
#include <QMessageBox> #include <QMessageBox>
......
...@@ -35,12 +35,13 @@ using namespace imagein::MorphoMat; ...@@ -35,12 +35,13 @@ using namespace imagein::MorphoMat;
MorphoMatService::MorphoMatService() { MorphoMatService::MorphoMatService() {
//!Création de l'élément structurant de base (= une croix)
bool elem[] = { bool elem[] = {
false, true, false, false, true, false,
true, true, true, true, true, true,
false, true, false false, true, false
}; };
//! L'ES initial est une image binaire de taille 3*3 avec le motif dessiné ci-dessus et son centre en (1,1)
_structElem = new StructElem(GrayscaleImage_t<bool>(3, 3, elem), 1, 1); _structElem = new StructElem(GrayscaleImage_t<bool>(3, 3, elem), 1, 1);
} }
...@@ -48,12 +49,8 @@ MorphoMatService::MorphoMatService() { ...@@ -48,12 +49,8 @@ MorphoMatService::MorphoMatService() {
void MorphoMatService::display(GenericInterface* gi) void MorphoMatService::display(GenericInterface* gi)
{ {
AlgorithmService::display(gi); AlgorithmService::display(gi);
// _editStructElem = _toolBar->addAction("&Structuring element"); //! Ajout des différentes opérateurs dans le menu Morpho. math.
// _erosion = _toolBar->addAction("&Erosion");
// _dilatation = _toolBar->addAction("&Dilatation");
QMenu* menu = gi->menu("&Morpho. math."); QMenu* menu = gi->menu("&Morpho. math.");
_erosion2 = menu->addAction(tr("&Erosion")); _erosion2 = menu->addAction(tr("&Erosion"));
...@@ -66,9 +63,7 @@ void MorphoMatService::display(GenericInterface* gi) ...@@ -66,9 +63,7 @@ void MorphoMatService::display(GenericInterface* gi)
menu->addSeparator(); menu->addSeparator();
_editStructElem = menu->addAction(tr("&Structuring element")); _editStructElem = menu->addAction(tr("&Structuring element"));
//!Les opérateurs sont désactivés car il faut s'assurer qu'une image uchar est sélectionnée
// _erosion->setEnabled(false);
// _dilatation->setEnabled(false);
_gradient->setEnabled(false); _gradient->setEnabled(false);
_erosion2->setEnabled(false); _erosion2->setEnabled(false);
_dilatation2->setEnabled(false); _dilatation2->setEnabled(false);
...@@ -77,37 +72,29 @@ void MorphoMatService::display(GenericInterface* gi) ...@@ -77,37 +72,29 @@ void MorphoMatService::display(GenericInterface* gi)
_gradient->setEnabled(false); _gradient->setEnabled(false);
_wtophat->setEnabled(false); _wtophat->setEnabled(false);
_btophat->setEnabled(false); _btophat->setEnabled(false);
// QMdiArea* area = (QMdiArea*)gi->centralWidget();
// _structElemWindow = new StructElemWindow(_structElem, _editStructElem);
// area->addSubWindow(_structElemWindow);
// _structElemWindow->setWindowTitle(tr("Editing structuring element"));
// _structElemWindow->hide();
} }
void MorphoMatService::connect(GenericInterface* gi) void MorphoMatService::connect(GenericInterface* gi)
{ {
AlgorithmService::connect(gi); AlgorithmService::connect(gi);
//! Réalisation des connections sur chacun des éléments du menu Morpho. Math.
QObject::connect(_editStructElem, SIGNAL(triggered()), this, SLOT(editStructElem())); QObject::connect(_editStructElem, SIGNAL(triggered()), this, SLOT(editStructElem()));
// QObject::connect(_erosion, SIGNAL(triggered()), this, SLOT(applyErosion()));
QObject::connect(_erosion2, SIGNAL(triggered()), this, SLOT(applyErosion())); QObject::connect(_erosion2, SIGNAL(triggered()), this, SLOT(applyErosion()));
// QObject::connect(_dilatation, SIGNAL(triggered()), this, SLOT(applyDilatation()));
QObject::connect(_dilatation2, SIGNAL(triggered()), this, SLOT(applyDilatation())); QObject::connect(_dilatation2, SIGNAL(triggered()), this, SLOT(applyDilatation()));
QObject::connect(_opening, SIGNAL(triggered()), this, SLOT(applyOpening())); QObject::connect(_opening, SIGNAL(triggered()), this, SLOT(applyOpening()));
QObject::connect(_closing, SIGNAL(triggered()), this, SLOT(applyClosing())); QObject::connect(_closing, SIGNAL(triggered()), this, SLOT(applyClosing()));
QObject::connect(_gradient, SIGNAL(triggered()), this, SLOT(applyGradient())); QObject::connect(_gradient, SIGNAL(triggered()), this, SLOT(applyGradient()));
QObject::connect(_wtophat, SIGNAL(triggered()), this, SLOT(applyWhiteTopHat())); QObject::connect(_wtophat, SIGNAL(triggered()), this, SLOT(applyWhiteTopHat()));
QObject::connect(_btophat, SIGNAL(triggered()), this, SLOT(applyBlackTopHat())); QObject::connect(_btophat, SIGNAL(triggered()), this, SLOT(applyBlackTopHat()));
//connexion des changements d'images //!connexion des changements d'images
QObject::connect(_ws, SIGNAL(activeWidgetChanged(const QWidget*)), this, SLOT(checkActionsValid(const QWidget*))); QObject::connect(_ws, SIGNAL(activeWidgetChanged(const QWidget*)), this, SLOT(checkActionsValid(const QWidget*)));
} }
void MorphoMatService::checkActionsValid(const QWidget* activeWidget) { void MorphoMatService::checkActionsValid(const QWidget* activeWidget) {
const StandardImageWindow* window = (activeWidget) ? dynamic_cast<const StandardImageWindow*>(activeWidget) : NULL; const StandardImageWindow* window = (activeWidget) ? dynamic_cast<const StandardImageWindow*>(activeWidget) : NULL;
//! On active les boutons du menu Morpho. Math. ssi l'image sélectionnée est de type uchar
if(window) { if(window) {
// _erosion->setEnabled(true);
// _dilatation->setEnabled(true);
_gradient->setEnabled(true); _gradient->setEnabled(true);
_erosion2->setEnabled(true); _erosion2->setEnabled(true);
_dilatation2->setEnabled(true); _dilatation2->setEnabled(true);
...@@ -118,8 +105,6 @@ void MorphoMatService::checkActionsValid(const QWidget* activeWidget) { ...@@ -118,8 +105,6 @@ void MorphoMatService::checkActionsValid(const QWidget* activeWidget) {
_btophat->setEnabled(true); _btophat->setEnabled(true);
} }
else { else {
// _erosion->setEnabled(false);
// _dilatation->setEnabled(false);
_gradient->setEnabled(false); _gradient->setEnabled(false);
_erosion2->setEnabled(false); _erosion2->setEnabled(false);
_dilatation2->setEnabled(false); _dilatation2->setEnabled(false);
...@@ -134,15 +119,12 @@ void MorphoMatService::checkActionsValid(const QWidget* activeWidget) { ...@@ -134,15 +119,12 @@ void MorphoMatService::checkActionsValid(const QWidget* activeWidget) {
void MorphoMatService::editStructElem() void MorphoMatService::editStructElem()
{ {
// _editStructElem->setEnabled(false); //! Création de la fenêtre d'édition de l'élément structurant
QDialog* structElemWindow = new StructElemWindow(_structElem, _editStructElem); QDialog* structElemWindow = new StructElemWindow(_structElem, _editStructElem);
//! Connection Qt pour appliquer l'Op. Morph. sélectionné dans le sous menu "Structuring Element" lorsque l'on clique sur "OK"
QObject::connect(structElemWindow, SIGNAL(sendOpMorph(OpMorpho)),this,SLOT(applyOpMorph(OpMorpho)));
//! Affichage de la fenêtre liée au menu "Structuring Element"
structElemWindow->exec(); structElemWindow->exec();
//WindowService* ws = dynamic_cast<WindowService*>(_gi->getService(GenericInterface::WINDOW_SERVICE));
//StandardImageWindow* current_siw = dynamic_cast<StandardImageWindow*>(ws->getCurrentImageWindow());
//ws->addWidget(ws->getWidgetId(current_siw), structElemWindow);
// _structElemWindow->show();
} }
void MorphoMatService::applyOperator(MorphoMat::Operator<depth_default_t>& op) void MorphoMatService::applyOperator(MorphoMat::Operator<depth_default_t>& op)
...@@ -185,3 +167,46 @@ void MorphoMatService::applyBlackTopHat() { ...@@ -185,3 +167,46 @@ void MorphoMatService::applyBlackTopHat() {
MorphoMat::BlackTopHat<depth8_t> op(*_structElem); MorphoMat::BlackTopHat<depth8_t> op(*_structElem);
this->applyOperator(op); this->applyOperator(op);
} }
void MorphoMatService::applyOpMorph(OpMorpho op){
//! Switch case qui permet d'identifier quel opérateur a été sélectionné par l'utilisateur dans le menu déroulant
switch(op){
case ErosionOp:
{
applyErosion();
break;
}
case DilatationOp:
{
applyDilatation();
break;
}
case OpeningOp:
{
applyOpening();
break;
}
case ClosingOp:
{
applyClosing();
break;
}
case GradientOp:
{
applyGradient();
break;
}
case WtophatOp:
{
applyWhiteTopHat();
break;
}
case BtophatOp:
{
applyBlackTopHat();
break;
}
default:
break;
}
}
...@@ -49,6 +49,7 @@ namespace genericinterface ...@@ -49,6 +49,7 @@ namespace genericinterface
void applyWhiteTopHat(); void applyWhiteTopHat();
void applyBlackTopHat(); void applyBlackTopHat();
void checkActionsValid(const QWidget* activeWidget); void checkActionsValid(const QWidget* activeWidget);
void applyOpMorph(OpMorpho);
private: private:
imagein::MorphoMat::StructElem* _structElem; imagein::MorphoMat::StructElem* _structElem;
......
...@@ -91,17 +91,17 @@ void StructElemViewer::mousePressEvent (QGraphicsSceneMouseEvent* event) ...@@ -91,17 +91,17 @@ void StructElemViewer::mousePressEvent (QGraphicsSceneMouseEvent* event)
view.elem->setCenter(px - view.x, py - view.y); view.elem->setCenter(px - view.x, py - view.y);
} }
} }
this->draw(0,0); this->draw(0,0);
} }
void StructElemViewer::draw(int x, int y) { void StructElemViewer::draw(int x, int y) {
QColor high(255, 255, 255, 0); QColor high(255, 255, 255, 0);
QColor red(255, 0, 0); QColor red(255, 0, 0);
for(int i = _views.size()-1; i >= 0; --i) { for(int k = _views.size()-1; k >= 0; --k) {
QColor low = i <= 1 ? QColor(50,50,50) : QColor::fromHsv(((i-2)*60)%360, 255, 230); QColor low = k <= 1 ? QColor(50,50,50) : QColor::fromHsv(((k-2)*60)%360, 255, 230);
ElemView view = _views.at(i); ElemView view = _views.at(k);
for(unsigned int j = 0; j < _col; j++) { for(unsigned int j = 0; j < _col; j++) {
for(unsigned int i = 0; i < _row; i++) { for(unsigned int i = 0; i < _row; i++) {
......
...@@ -19,10 +19,12 @@ ...@@ -19,10 +19,12 @@
#include "StructElemWindow.h" #include "StructElemWindow.h"
#include "StructElemViewer.h" #include "StructElemViewer.h"
#include "Services/MorphoMatService.h"
#include <Image.h> #include <Image.h>
#include <QDialogButtonBox> #include <QDialogButtonBox>
#include <QGroupBox>
using namespace genericinterface; using namespace genericinterface;
using namespace imagein; using namespace imagein;
...@@ -31,83 +33,178 @@ using namespace imagein::MorphoMat; ...@@ -31,83 +33,178 @@ using namespace imagein::MorphoMat;
StructElemWindow::StructElemWindow(StructElem*& elem, QAction* tbButton) : _structElem(elem), _serviceStructElem(elem), _tbButton(tbButton) StructElemWindow::StructElemWindow(StructElem*& elem, QAction* tbButton) : _structElem(elem), _serviceStructElem(elem), _tbButton(tbButton)
{ {
//! Taille de la fenêtre d'édition de l'élément structurant
setMinimumSize(600,400);
_realSize = *elem; _realSize = *elem;
QVBoxLayout* layout = new QVBoxLayout(); auto* layout = new QVBoxLayout();
QHBoxLayout* hlayout = new QHBoxLayout();
_openFileButton = new QPushButton(tr("&Open file"));
_saveFileButton = new QPushButton(tr("&Save as..."));
hlayout->addWidget(_openFileButton);
hlayout->addWidget(_saveFileButton);
layout->addLayout(hlayout);
this->setLayout(layout);
std::cout << "checked :" << _openFileButton->isChecked() << "\n"; //! sélection de la forme de l'élément à générer
std::cout << "checked2 : " << _saveFileButton->isChecked() << "\n"; auto* layout1 = new QHBoxLayout();
QFormLayout* formLayout = new QFormLayout(); layout->addLayout(layout1);
layout->addLayout(formLayout); layout1->addWidget(new QLabel(tr("Basic shapes :")));
QHBoxLayout* layout2 = new QHBoxLayout();
layout->addLayout(layout2);
layout2->addWidget(new QLabel(tr("Basic shapes :")));
_shapeToGen = new QComboBox; _shapeToGen = new QComboBox;
_shapeToGen->setEditable(false); _shapeToGen->setEditable(false);
_shapeToGen->insertItem(0, tr("Diamond")); _shapeToGen->insertItem(0, tr("Diamond"));
_shapeToGen->insertItem(1, tr("Disc")); _shapeToGen->insertItem(1, tr("Disc"));
_shapeToGen->insertItem(2, tr("Empty")); _shapeToGen->insertItem(2, tr("Empty"));
layout2->addWidget(_shapeToGen); layout1->addWidget(_shapeToGen);
//! menu déroulant sélection op. morph.
auto* layout2 = new QHBoxLayout();
layout->addLayout(layout2);
layout2->addWidget(new QLabel(tr("Opération :")));
_opMorphSelection = new QComboBox;
_opMorphSelection->setEditable(false);
_opMorphSelection->insertItem(EditES, tr("Edit structuring element"));
_opMorphSelection->insertItem(ErosionOp, tr("Erosion"));
_opMorphSelection->insertItem(DilatationOp, tr("Dilatation"));
_opMorphSelection->insertItem(OpeningOp, tr("Opening"));
_opMorphSelection->insertItem(ClosingOp, tr("Closing"));
_opMorphSelection->insertItem(GradientOp, tr("Gradient"));
_opMorphSelection->insertItem(WtophatOp, tr("White top hat"));
_opMorphSelection->insertItem(BtophatOp, tr("Black top hat"));
layout2->addWidget(_opMorphSelection);
//! sélection de la taille de l'élément structurant à générer
_shapeSize = new QSpinBox(); _shapeSize = new QSpinBox();
_shapeSize->setRange(1,64); _shapeSize->setRange(1,64);
_shapeSize->setSingleStep(1); _shapeSize->setSingleStep(1);
_shapeSize->setValue(3); _shapeSize->setValue(_structElem->getShapeSizeMemory());
layout2->addWidget(_shapeSize); layout1->addWidget(_shapeSize);
_shapeToGenvalue = _structElem->getShapeSizeMemory();
//! générer un nouvel élément structurant à partir de la forme et la taille sélectionnée
_genButton = new QPushButton(tr("Generate")); _genButton = new QPushButton(tr("Generate"));
layout2->addWidget(_genButton); layout1->addWidget(_genButton);
auto* structElemLayout = new QHBoxLayout();
//! Affichage de l'élément structurant
_viewer = new StructElemViewer(_structElem, true); _viewer = new StructElemViewer(_structElem, true);
_view = new QGraphicsView; _view = new QGraphicsView;
_view->setScene(_viewer); _view->setScene(_viewer);
layout->addWidget(_view);
_viewer->draw(0,0); _viewer->draw(0,0);
QHBoxLayout* layout3 = new QHBoxLayout(); //! Création des outils de modification de l'ES (boutons fléchés)
layout->addLayout(layout3); auto* rightPanelLayout = new QVBoxLayout();
layout3->addWidget(new QLabel(tr("Scale :"))); rightPanelLayout->setAlignment(Qt::AlignTop); // Alignement en haut
auto* dilatButtonWidget = new QWidget();
dilatButtonWidget->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
auto* dilatButtonLayout = new QGridLayout(dilatButtonWidget);
dilatButtonWidget->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
auto* dilatLeftButton = new QPushButton(QIcon(":/img/arrow-left.png"), "");
auto* dilatTopLeftButton = new QPushButton(QIcon(":/img/arrow-top-left.png"), "");
auto* dilatTopButton = new QPushButton(QIcon(":/img/arrow-top.png"), "");
auto* dilatTopRightButton = new QPushButton(QIcon(":/img/arrow-top-right.png"), "");
auto* dilatRightButton = new QPushButton(QIcon(":/img/arrow-right.png"), "");
auto* dilatBottomRightButton = new QPushButton(QIcon(":/img/arrow-bottom-right.png"), "");
auto* dilatBottomButton = new QPushButton(QIcon(":/img/arrow-bottom.png"), "");
auto* dilatBottomLeftButton = new QPushButton(QIcon(":/img/arrow-bottom-left.png"), "");
dilatLeftButton->setFixedSize(32, 32);
dilatTopLeftButton->setFixedSize(32, 32);
dilatTopButton->setFixedSize(32, 32);
dilatTopRightButton->setFixedSize(32, 32);
dilatRightButton->setFixedSize(32, 32);
dilatBottomRightButton->setFixedSize(32, 32);
dilatBottomButton->setFixedSize(32, 32);
dilatBottomLeftButton->setFixedSize(32, 32);
dilatButtonLayout->addWidget(dilatLeftButton, 1, 0);
dilatButtonLayout->addWidget(dilatTopLeftButton, 0, 0);
dilatButtonLayout->addWidget(dilatTopButton, 0, 1);
dilatButtonLayout->addWidget(dilatTopRightButton, 0, 2);
dilatButtonLayout->addWidget(dilatRightButton, 1, 2);
dilatButtonLayout->addWidget(dilatBottomRightButton, 2, 2);
dilatButtonLayout->addWidget(dilatBottomButton, 2, 1);
dilatButtonLayout->addWidget(dilatBottomLeftButton, 2, 0);
rightPanelLayout->addWidget(dilatButtonWidget);
rightPanelLayout->addWidget(dilatButtonWidget);
//! Ajout de _view et du widget contenant les boutons à la vue structElemBox
auto* structElemBox = new QGroupBox(tr("Structuring element"));
auto* hLayout = new QHBoxLayout();
hLayout->addWidget(_view);
hLayout->addLayout(rightPanelLayout);
structElemBox->setLayout(hLayout);
layout->addWidget(structElemBox);
//!bouton ouverture d'un ES sauvegardé
_openFileButton = new QToolButton();
_openFileButton->setToolTip(tr("Open file"));
_openFileButton->setIcon(this->style()->standardIcon(QStyle::SP_DialogOpenButton));
_openFileButton->setCheckable(true);
_openFileButton->setIconSize (QSize(18, 18));
//!bouton sauvegarde d'un ES
_saveFileButton = new QToolButton();
_saveFileButton->setToolTip(tr("Save as..."));
_saveFileButton->setIcon(this->style()->standardIcon(QStyle::SP_DialogSaveButton));
_saveFileButton->setCheckable(true);
_saveFileButton->setIconSize (QSize(18, 18));
//! Création layout horizontaux pour les boutons (sauvegarde et ouverture)
auto* layout3 = new QHBoxLayout();
auto* hlayout = new QHBoxLayout();
layout3->addStretch(); // Ajout d'un espace flexible pour pousser les boutons vers la droite
layout3->addWidget(_openFileButton);
layout3->addWidget(_saveFileButton);
hlayout->addLayout(layout3); // Ajouter le layout vertical au layout horizontal (ie en dessous de l'ES)
layout->addLayout(hlayout); //Ajouter le layout horizontal au layout principal
this->setLayout(layout);
auto* formLayout = new QFormLayout();
layout->addLayout(formLayout);
//! modification de l'échelle de l'élément structurant
auto* layout4 = new QHBoxLayout();
layout->addLayout(layout4);
layout4->addWidget(new QLabel(tr("Scale :")));
_scale = new QSpinBox(); _scale = new QSpinBox();
_scale->setRange(1,32); _scale->setRange(1,32);
_scale->setSingleStep(1); _scale->setSingleStep(1);
_scale->setSuffix(""); _scale->setSuffix("");
_scale->setValue(_structElem->getScale()); _scale->setValue(_structElem->getScaleMemory());
layout3->addWidget(_scale); _previousScale = _structElem->getScaleMemory();
layout4->addWidget(_scale);
// QPushButton* button = new QPushButton("OK");
// layout->addWidget(button); auto* buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok|QDialogButtonBox::Cancel, Qt::Horizontal, this);
QDialogButtonBox* buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok|QDialogButtonBox::Cancel, Qt::Horizontal, this);
layout->addWidget(buttonBox); layout->addWidget(buttonBox);
QObject::connect(buttonBox, SIGNAL(accepted()), this, SLOT(ok())); QObject::connect(buttonBox, SIGNAL(accepted()), this, SLOT(ok()));
QObject::connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject())); QObject::connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
QObject::connect(_openFileButton, SIGNAL(clicked(bool)), this, SLOT(openFile())); QObject::connect(_openFileButton, SIGNAL(clicked()), this, SLOT(openFile()));
QObject::connect(_saveFileButton, SIGNAL(clicked(bool)), this, SLOT(saveFile())); QObject::connect(_saveFileButton, SIGNAL(clicked()), this, SLOT(saveFile()));
QObject::connect(_scale, SIGNAL(valueChanged(int)), this, SLOT(resize(int))); QObject::connect(_scale, SIGNAL(valueChanged(int)), this, SLOT(resize(int)));
QObject::connect(_genButton, SIGNAL(clicked(bool)), this, SLOT(generate())); QObject::connect(_genButton, SIGNAL(clicked(bool)), this, SLOT(generate()));
//! Connections Qt pour la modification de l'ES avec les flèches
connect(dilatLeftButton, SIGNAL(clicked()), this, SLOT(dilateLeft()));
connect(dilatTopLeftButton, SIGNAL(clicked()), this, SLOT(dilateTopLeft()));
connect(dilatTopButton, SIGNAL(clicked()), this, SLOT(dilateTop()));
connect(dilatTopRightButton, SIGNAL(clicked()), this, SLOT(dilateTopRight()));
connect(dilatRightButton, SIGNAL(clicked()), this, SLOT(dilateRight()));
connect(dilatBottomRightButton, SIGNAL(clicked()), this, SLOT(dilateBottomRight()));
connect(dilatBottomButton, SIGNAL(clicked()), this, SLOT(dilateBottom()));
connect(dilatBottomLeftButton, SIGNAL(clicked()), this, SLOT(dilateBottomLeft()));
} }
void StructElemWindow::ok() { void StructElemWindow::ok() {
_serviceStructElem = _structElem; _serviceStructElem = _structElem;
// _tbButton->setEnabled(true); //! Envoi du signal pour l'application de l'Op. Morpho. sur l'image
//this->close(); emit sendOpMorph(OpMorpho(_opMorphSelection->currentIndex()));
// this->hide(); _structElem->setScaleMemory(_scale->value());
_structElem->setShapeSizeMemory(_shapeToGenvalue);
this->accept(); this->accept();
} }
//void StructElemWindow::closeEvent ( QCloseEvent * event) {
// _tbButton->setEnabled(true);
// event->ignore();
// this->hide();
//}
void rasterCircle(GrayscaleImage_t<bool>& img, int x0, int y0, int radius) void rasterCircle(GrayscaleImage_t<bool>& img, int x0, int y0, int radius)
{ {
int f = 1 - radius; int f = 1 - radius;
...@@ -160,11 +257,12 @@ void closing(GrayscaleImage_t<bool>& img) { ...@@ -160,11 +257,12 @@ void closing(GrayscaleImage_t<bool>& img) {
} }
void StructElemWindow::generate() { void StructElemWindow::generate() {
//! Récupération de la taille de la forme à générer (choix de l'utilisateur)
unsigned int size = _shapeSize->value(); unsigned int size = _shapeSize->value();
_scale->setValue(1); //! Création d'une nouvelle image en niveau de gris avec les nouvelles dimensions de l'ES
GrayscaleImage_t<bool> elem(size, size); GrayscaleImage_t<bool> elem(size, size);
//if(size%2==0) --size;
//! Initialisation de l'image de l'ES avec des 0 partout
for(unsigned int j = 0; j < elem.getHeight(); ++j) { for(unsigned int j = 0; j < elem.getHeight(); ++j) {
for(unsigned int i = 0; i < elem.getWidth(); ++i) { for(unsigned int i = 0; i < elem.getWidth(); ++i) {
elem.setPixel(i, j, false); elem.setPixel(i, j, false);
...@@ -212,29 +310,42 @@ void StructElemWindow::generate() { ...@@ -212,29 +310,42 @@ void StructElemWindow::generate() {
} }
//! Création de l'ES à partir de l'image de celui-ci et de la position de son centre
//closing(elem);
StructElem* structElem = new StructElem(elem, elem.getWidth()/2, elem.getHeight()/2); StructElem* structElem = new StructElem(elem, elem.getWidth()/2, elem.getHeight()/2);
//! Reset du facteur d'échelle
structElem->setScale(1);
_scale->setValue(1);
//! Sauvegarde du facteur d'échelle et de la taille de l'ES demandée
_structElem->setScaleMemory(1);
_structElem->setShapeSizeMemory(_shapeSize->value());
//! Remplacement de l'ES par celui que l'on vient de générer
changeStructElem(structElem); changeStructElem(structElem);
//! _shapeToGenvalue mis à jour avec le contenu de la box _shapeSize
_shapeToGenvalue = _shapeSize->value();
} }
void StructElemWindow::resize(int size) { void StructElemWindow::resize(int size) {
/*unsigned int size = std::abs(size_); //! On propage avec le plus proche voisin (imparfait pour les nombres pairs)
GrayscaleImage_t<bool> elem(_realSize.getWidth()*size, _realSize.getHeight()*size); GrayscaleImage_t<bool> elem(_structElem->getWidth()/_previousScale * size, _structElem->getHeight()/_previousScale * size);
_previousScale=size;
for(unsigned int j = 0; j < elem.getHeight(); ++j) { for(unsigned int j = 0; j < elem.getHeight(); ++j) {
for(unsigned int i = 0; i < elem.getWidth(); ++i) { for(unsigned int i = 0; i < elem.getWidth(); ++i) {
elem.setPixel(i, j, _realSize.getPixel(i/size, j/size)); //! Calcul des coordonnées correspondantes dans l'image source
} int srcX = floor(i / (double)elem.getWidth() * _structElem->getWidth());
}*/ int srcY = floor(j / (double)elem.getHeight() * _structElem->getHeight());
//StructElem<depth_default_t>* structElem = new StructElem<depth_default_t>(elem, elem.getWidth()/2, elem.getHeight()/2); //! Récupération de la valeur du pixel de l'image source (plus proche voisin)
_structElem->setScale(std::abs(size)); bool pixelValue = _structElem->getPixel(srcX, srcY);
elem.setPixel(i, j, pixelValue);
changeStructElem(_structElem); }
}
auto* structElem = new StructElem(elem, elem.getWidth() / 2, elem.getHeight() / 2);
changeStructElem(structElem);
} }
void StructElemWindow::changeStructElem(imagein::MorphoMat::StructElem* elem) { void StructElemWindow::changeStructElem(imagein::MorphoMat::StructElem* elem) {
//! changement d'ES
_structElem = elem; _structElem = elem;
StructElemViewer* newViewer = new StructElemViewer(_structElem,true); StructElemViewer* newViewer = new StructElemViewer(_structElem,true);
_view->setScene(newViewer); _view->setScene(newViewer);
...@@ -251,6 +362,7 @@ void StructElemWindow::openFile() { ...@@ -251,6 +362,7 @@ void StructElemWindow::openFile() {
changeStructElem(structElem); changeStructElem(structElem);
_realSize = *structElem; _realSize = *structElem;
_scale->setValue(1); _scale->setValue(1);
setShapeSizeScaling(structElem->getWidth());
} }
void StructElemWindow::saveFile() { void StructElemWindow::saveFile() {
...@@ -265,3 +377,66 @@ void StructElemWindow::saveFile() { ...@@ -265,3 +377,66 @@ void StructElemWindow::saveFile() {
} }
_structElem->save(file.toStdString()); _structElem->save(file.toStdString());
} }
void StructElemWindow::dilateLeft() {
StructElem::Dir dir;
dir = StructElem::Left;
_structElem->dilate(dir);
changeStructElem(_structElem);
}
void StructElemWindow::dilateTopLeft() {
StructElem::Dir dir;
dir = StructElem::BottomRight;
_structElem->dilate(dir);
changeStructElem(_structElem);
}
void StructElemWindow::dilateTop() {
StructElem::Dir dir;
dir = StructElem::Bottom;
_structElem->dilate(dir);
changeStructElem(_structElem);
}
void StructElemWindow::dilateTopRight() {
StructElem::Dir dir;
dir = StructElem::BottomLeft;
_structElem->dilate(dir);
changeStructElem(_structElem);
}
void StructElemWindow::dilateRight() {
StructElem::Dir dir;
dir = StructElem::Left;
_structElem->dilate(dir);
changeStructElem(_structElem);
}
void StructElemWindow::dilateBottomRight() {
StructElem::Dir dir;
dir = StructElem::TopLeft;
_structElem->dilate(dir);
changeStructElem(_structElem);
}
void StructElemWindow::dilateBottom() {
StructElem::Dir dir;
dir = StructElem::Top;
_structElem->dilate(dir);
changeStructElem(_structElem);
}
void StructElemWindow::dilateBottomLeft() {
StructElem::Dir dir;
dir = StructElem::TopRight;
_structElem->dilate(dir);
changeStructElem(_structElem);
}
\ No newline at end of file
...@@ -42,12 +42,15 @@ ...@@ -42,12 +42,15 @@
#include <QPushButton> #include <QPushButton>
#include <QDebug> #include <QDebug>
enum OpMorpho {EditES ,ErosionOp, DilatationOp, OpeningOp, ClosingOp, GradientOp, WtophatOp, BtophatOp};
class StructElemWindow : public QDialog class StructElemWindow : public QDialog
{ {
Q_OBJECT Q_OBJECT
public: public:
StructElemWindow(imagein::MorphoMat::StructElem*& elemi, QAction* button); StructElemWindow(imagein::MorphoMat::StructElem*& elemi, QAction* button);
void changeStructElem(imagein::MorphoMat::StructElem* elem); void changeStructElem(imagein::MorphoMat::StructElem* elem);
inline int getShapeSizeGenerate() const{ return _shapeToGenvalue;};
public slots: public slots:
void openFile(); void openFile();
...@@ -56,13 +59,32 @@ class StructElemWindow : public QDialog ...@@ -56,13 +59,32 @@ class StructElemWindow : public QDialog
void resize(int size); void resize(int size);
void generate(); void generate();
public slots:
void dilateLeft();
void dilateTopLeft();
void dilateTop();
void dilateTopRight();
void dilateRight();
void dilateBottomRight();
void dilateBottom();
void dilateBottomLeft();
//! _shapeToGenvalue mis à jour avec le contenu de la box _shapeSize
inline void setShapeSizeScaling(){ _shapeToGenvalue = _shapeSize->value();};
inline void setShapeSizeScaling(int shapeToGenvalue){ _shapeToGenvalue = shapeToGenvalue;};
signals:
void sendOpMorph(OpMorpho);
protected: protected:
// void closeEvent ( QCloseEvent * event ); // void closeEvent ( QCloseEvent * event );
private: private:
QWidget* _widget; QWidget* _widget;
QPushButton* _openFileButton; QToolButton* _openFileButton;
QPushButton* _saveFileButton; QToolButton* _saveFileButton;
QAction* _ok; QAction* _ok;
genericinterface::HistogramWindow* _histo; genericinterface::HistogramWindow* _histo;
QLabel* _labelThreshold; QLabel* _labelThreshold;
...@@ -74,9 +96,11 @@ class StructElemWindow : public QDialog ...@@ -74,9 +96,11 @@ class StructElemWindow : public QDialog
QAction* _tbButton; QAction* _tbButton;
QPushButton* _genButton; QPushButton* _genButton;
QComboBox* _shapeToGen; QComboBox* _shapeToGen;
QComboBox* _opMorphSelection;
QSpinBox* _shapeSize; QSpinBox* _shapeSize;
QSpinBox* _scale; QSpinBox* _scale;
int _shapeToGenvalue; //! Equivalent de _shapeToGen.value mais mis à jour uniquement à l'appuis sur le bouton "generate"
int _previousScale;
}; };
#endif #endif
Subproject commit 70788339b966c2ee63b2fd19215ff41eaa9fafd5 Subproject commit e61833c97707f2b45f11042e1a7ee4b7aa87f483