Skip to content
Snippets Groups Projects
Commit 9a9b99e6 authored by Sacha Percot-Tétu's avatar Sacha Percot-Tétu
Browse files

Added ImageListBox, modified Operation::operator()

parent 673408fc
No related branches found
No related tags found
No related merge requests found
/*
* 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;
}
/*
* 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
......@@ -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());
}
......
......@@ -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();
......
......@@ -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);
......
......@@ -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();
......
......@@ -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);
......
......@@ -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;
......
......@@ -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("Paramtres");
dialog->setWindowTitle("Paramètres");
dialog->setMinimumWidth(160);
QVBoxLayout* layout = new QVBoxLayout();
dialog->setLayout(layout);
......
......@@ -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; }
......
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