From 9a9b99e668271e1546d2eced407deabae2cffa23 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sacha=20Percot-T=C3=A9tu?= <zakinster@zakinster.com> Date: Fri, 6 Jul 2012 15:48:24 +0200 Subject: [PATCH] Added ImageListBox, modified Operation::operator() --- app/Operations/ImageListBox.cpp | 44 +++++++++++++++++++++++++++++++ app/Operations/ImageListBox.h | 44 +++++++++++++++++++++++++++++++ app/Operations/PointOp.cpp | 20 +++++--------- app/Operations/PointOp.h | 2 +- app/Operations/ThresholdOp.cpp | 2 +- app/Operations/ThresholdOp.h | 2 +- app/Services/OperationService.cpp | 4 +-- core/Operation.h | 2 +- core/PlugOperation.cpp | 4 +-- core/PlugOperation.h | 2 +- 10 files changed, 104 insertions(+), 22 deletions(-) create mode 100644 app/Operations/ImageListBox.cpp create mode 100644 app/Operations/ImageListBox.h diff --git a/app/Operations/ImageListBox.cpp b/app/Operations/ImageListBox.cpp new file mode 100644 index 0000000..14426f7 --- /dev/null +++ b/app/Operations/ImageListBox.cpp @@ -0,0 +1,44 @@ +/* + * Copyright 2011-2012 INSA Rennes + * + * This file is part of EIImage. + * + * EIImage is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * EIImage is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with EIImage. If not, see <http://www.gnu.org/licenses/>. +*/ + +#include "ImageListBox.h" + +using namespace std; +using namespace imagein; + +ImageListBox::ImageListBox(QWidget *parent, const Image* img, const map<const Image*, string>& imgList) : + QComboBox(parent) +{ + int i = 0, index = 0; + for(map<const Image*, string>::const_iterator it = imgList.begin(); it != imgList.end(); ++it) { + _images.insert(pair<string, const Image*>(it->second, it->first)); + this->insertItem(i, QString(it->second.c_str())); + if(it->first == img) index = i; + } + this->setCurrentIndex(index); +} + +const Image* ImageListBox::currentImage() { + string name = this->currentText().toStdString(); + map<string, const Image*>::iterator it = _images.find(name); + if(it != _images.end()) { + return _images[name]; + } + return NULL; +} diff --git a/app/Operations/ImageListBox.h b/app/Operations/ImageListBox.h new file mode 100644 index 0000000..0dafb6e --- /dev/null +++ b/app/Operations/ImageListBox.h @@ -0,0 +1,44 @@ +/* + * Copyright 2011-2012 INSA Rennes + * + * This file is part of EIImage. + * + * EIImage is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * EIImage is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with EIImage. If not, see <http://www.gnu.org/licenses/>. +*/ + +#ifndef IMAGELISTBOX_H +#define IMAGELISTBOX_H + +#include <QComboBox> +#include <map> +#include <string> + +#include <Image.h> + +class ImageListBox : public QComboBox +{ + Q_OBJECT +public: + explicit ImageListBox(QWidget *parent, const imagein::Image*, const std::map<const imagein::Image*, std::string>&); + + const imagein::Image* currentImage(); +signals: + +public slots: + +protected: + std::map<std::string, const imagein::Image*> _images; +}; + +#endif // IMAGELISTBOX_H diff --git a/app/Operations/PointOp.cpp b/app/Operations/PointOp.cpp index 4883b99..cd6daac 100644 --- a/app/Operations/PointOp.cpp +++ b/app/Operations/PointOp.cpp @@ -31,6 +31,7 @@ #include "PointOp.h" #include "ImgWidget.h" +#include "ImageListBox.h" using namespace std; using namespace imagein; @@ -65,16 +66,11 @@ PointOp::ImageOp* PointOp::ImageOp::fromString(QString op) { return new ImgIdent(); } -vector<QWidget*> PointOp::operator()(const imagein::Image* image, const std::map<std::string, const imagein::Image*>& imgList) { +vector<QWidget*> PointOp::operator()(const imagein::Image* image, const std::map<const imagein::Image*, std::string>& imgList) { vector<QWidget*> result; QStringList pixOperators, imgOperators; pixOperators << "" << "+" << "-" << "*" << "/" << "&" << "|" << "^" << "<<" << ">>"; imgOperators << "" << "+" << "-" << "&" << "|" << "^"; - QStringList imageNames; - for(map<string, const Image*>::const_iterator it = imgList.begin(); it != imgList.end(); ++it) { - imageNames << it->first.c_str(); - } - QDialog* dialog = new QDialog(); dialog->setWindowTitle(dialog->tr("Parameter")); @@ -99,7 +95,7 @@ vector<QWidget*> PointOp::operator()(const imagein::Image* image, const std::map QComboBox** pixOperatorBoxes = new QComboBox*[nChannel+1]; QComboBox** imgOperatorBoxes = new QComboBox*[nChannel+1]; QLineEdit** exprEdits = new QLineEdit*[nChannel+1]; - QComboBox** imageBoxes = new QComboBox*[nChannel+1]; + ImageListBox** imageBoxes = new ImageListBox*[nChannel+1]; QWidget* pixelWidget = new QWidget(dialog); valueLayouts[0] = new QHBoxLayout(); @@ -109,8 +105,7 @@ vector<QWidget*> PointOp::operator()(const imagein::Image* image, const std::map imgOperatorBoxes[0]->addItems(imgOperators); exprEdits[0] = new QLineEdit(pixelWidget); exprEdits[0]->setFixedWidth(64); - imageBoxes[0] = new QComboBox(pixelWidget); - imageBoxes[0]->addItems(imageNames); + imageBoxes[0] = new ImageListBox(pixelWidget, image, imgList); valueLayouts[0]->addWidget(new QLabel("Image", pixelWidget)); valueLayouts[0]->addWidget(pixOperatorBoxes[0]); valueLayouts[0]->addWidget(imgOperatorBoxes[0]); @@ -131,8 +126,7 @@ vector<QWidget*> PointOp::operator()(const imagein::Image* image, const std::map imgOperatorBoxes[i]->addItems(imgOperators); exprEdits[i] = new QLineEdit(colorWidget); exprEdits[i]->setFixedWidth(64); - imageBoxes[i] = new QComboBox(colorWidget); - imageBoxes[i]->addItems(imageNames); + imageBoxes[i] = new ImageListBox(colorWidget, image, imgList); valueLayouts[i]->addWidget(new QLabel(colorName(i-1, nChannel), colorWidget)); valueLayouts[i]->addWidget(pixOperatorBoxes[i]); valueLayouts[i]->addWidget(imgOperatorBoxes[i]); @@ -177,7 +171,7 @@ vector<QWidget*> PointOp::operator()(const imagein::Image* image, const std::map QString expr = exprEdits[0]->text(); PixelOp* pixelOp = PixelOp::fromString(pixOperatorBoxes[0]->currentText(), expr); ImageOp* imageOp = ImageOp::fromString(imgOperatorBoxes[0]->currentText()); - const Image* imageImg = imgList.find(imageBoxes[0]->currentText().toStdString())->second; + const Image* imageImg = imageBoxes[0]->currentImage(); maxWidth = min(maxWidth, imageImg->getWidth()); maxHeight = min(maxHeight, imageImg->getHeight()); @@ -192,7 +186,7 @@ vector<QWidget*> PointOp::operator()(const imagein::Image* image, const std::map QString expr = exprEdits[i+1]->text(); pixelOps[i] = PixelOp::fromString(pixOperatorBoxes[i+1]->currentText(), expr); imageOps[i] = ImageOp::fromString(imgOperatorBoxes[i+1]->currentText()); - imageImgs[i] = imgList.find(imageBoxes[i+1]->currentText().toStdString())->second; + imageImgs[i] = imageBoxes[i+1]->currentImage(); maxWidth = min(maxWidth, imageImgs[i]->getWidth()); maxHeight = min(maxHeight, imageImgs[i]->getHeight()); } diff --git a/app/Operations/PointOp.h b/app/Operations/PointOp.h index 0c03986..cadebb1 100644 --- a/app/Operations/PointOp.h +++ b/app/Operations/PointOp.h @@ -36,7 +36,7 @@ class PointOp : public Operation { PointOp(); - std::vector<QWidget*> operator()(const imagein::Image*, const std::map<std::string, const imagein::Image*>&); + std::vector<QWidget*> operator()(const imagein::Image*, const std::map<const imagein::Image*, std::string>&); bool needCurrentImg(); diff --git a/app/Operations/ThresholdOp.cpp b/app/Operations/ThresholdOp.cpp index 1397784..a86c30f 100644 --- a/app/Operations/ThresholdOp.cpp +++ b/app/Operations/ThresholdOp.cpp @@ -17,7 +17,7 @@ bool ThresholdOp::needCurrentImg() { return true; } -std::vector<QWidget*> ThresholdOp::operator()(const imagein::Image* image, const std::map<std::string, const imagein::Image*>&) { +std::vector<QWidget*> ThresholdOp::operator()(const imagein::Image* image, const std::map<const imagein::Image*, std::string>&) { vector<QWidget*> result; const GrayscaleImage* img = dynamic_cast<const GrayscaleImage*>(image); diff --git a/app/Operations/ThresholdOp.h b/app/Operations/ThresholdOp.h index 98b639e..e682c12 100644 --- a/app/Operations/ThresholdOp.h +++ b/app/Operations/ThresholdOp.h @@ -42,7 +42,7 @@ class ThresholdOp : public Operation { ThresholdOp(); - std::vector<QWidget*> operator()(const imagein::Image*, const std::map<std::string, const imagein::Image*>&); + std::vector<QWidget*> operator()(const imagein::Image*, const std::map<const imagein::Image*, std::string>&); bool needCurrentImg(); diff --git a/app/Services/OperationService.cpp b/app/Services/OperationService.cpp index f843ad3..f2b8a20 100644 --- a/app/Services/OperationService.cpp +++ b/app/Services/OperationService.cpp @@ -65,10 +65,10 @@ void OperationService::operation() { } if(_operation->needCurrentImg() && image == NULL) return; - map<string,const Image*> imgList; + map<const Image*, string> imgList; vector<StandardImageWindow*> windows = ws->getImageWindows(); for(vector<StandardImageWindow*>::iterator it = windows.begin(); it < windows.end(); ++it) { - imgList.insert(pair<string,const Image*>((*it)->windowTitle().toStdString(), (*it)->getImage())); + imgList.insert(pair<const Image*, string>((*it)->getImage(), (*it)->windowTitle().toStdString())); } vector<QWidget*> result = _operation->operator()(image, imgList); diff --git a/core/Operation.h b/core/Operation.h index 967da43..fd39bb3 100644 --- a/core/Operation.h +++ b/core/Operation.h @@ -32,7 +32,7 @@ class Operation { public: Operation(std::string name) : _name(name) {} - virtual std::vector<QWidget*> operator()(const imagein::Image*, const std::map<std::string, const imagein::Image*>&) = 0; + virtual std::vector<QWidget*> operator()(const imagein::Image*, const std::map<const imagein::Image*, std::string>&) = 0; inline std::string getName() { return _name; } virtual bool needCurrentImg() = 0; diff --git a/core/PlugOperation.cpp b/core/PlugOperation.cpp index c17ad8b..0a8cf54 100644 --- a/core/PlugOperation.cpp +++ b/core/PlugOperation.cpp @@ -44,7 +44,7 @@ void PlugOperation::addOutput(const Output& output) { } -std::vector<QWidget*> PlugOperation::operator()(const Image* currentImg, const std::map<std::string, const Image*>&) { +std::vector<QWidget*> PlugOperation::operator()(const Image* currentImg, const std::map<const Image*, std::string>&) { vector<QWidget*> result; if(this->needCurrentImg()) { @@ -54,7 +54,7 @@ std::vector<QWidget*> PlugOperation::operator()(const Image* currentImg, const s if(_inputs.size()>0) { QDialog* dialog = new QDialog(); - dialog->setWindowTitle("Paramètres"); + dialog->setWindowTitle("Paramètres"); dialog->setMinimumWidth(160); QVBoxLayout* layout = new QVBoxLayout(); dialog->setLayout(layout); diff --git a/core/PlugOperation.h b/core/PlugOperation.h index b992296..f7ed94d 100644 --- a/core/PlugOperation.h +++ b/core/PlugOperation.h @@ -44,7 +44,7 @@ class PlugOperation : public Operation { public: PlugOperation(std::string name); - std::vector<QWidget*> operator()(const imagein::Image*, const std::map<std::string, const imagein::Image*>&); + std::vector<QWidget*> operator()(const imagein::Image*, const std::map<const imagein::Image*, std::string>&); inline bool needCurrentImg() { return _needCurrentImg; } -- GitLab