Skip to content
This repository has been archived by the owner. It is now read-only.

Commit

Permalink
changed roi to integer
Browse files Browse the repository at this point in the history
  • Loading branch information
MPIBR-kretschmerf committed Apr 25, 2017
1 parent a5c0898 commit 2c420a5
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 65 deletions.
2 changes: 1 addition & 1 deletion ResizeTraits.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ QRectF ResizeTraits::rectFor(QGraphicsItem * item) {
if(resizeableItem2){
return resizeableItem2->rect();
}
return QRectF();
return QRect();
}

/// Sets a new rectangle on the item
Expand Down
8 changes: 4 additions & 4 deletions ResizeTraits.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#ifndef SIMPLETRAITS_H
#define SIMPLETRAITS_H
#ifndef ResizeTraits_H
#define ResizeTraits_H
#include <QGraphicsItem>
#include <QRectF>

class SimpleTraits
class ResizeTraits
{
public:
static bool isGraphicsItemResizeable(QGraphicsItem * item);
Expand All @@ -12,4 +12,4 @@ class SimpleTraits

};

#endif // SIMPLETRAITS_H
#endif // ResizeTraits_H
99 changes: 47 additions & 52 deletions TrackerPlugin_EyeTracker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ TrackerPlugin_EyeTracker::TrackerPlugin_EyeTracker(QObject *parent)
trackerWorker = new TrackerWorker();
ui->setupUi(this);

resizeHelper = new ResizeHelper(this);

ui->label_cornea->setStyleSheet("QLabel { color : magenta; }");
ui->label_pupil->setStyleSheet("QLabel { color : green; }");

Expand Down Expand Up @@ -38,9 +40,6 @@ TrackerPlugin_EyeTracker::TrackerPlugin_EyeTracker(QObject *parent)
uiSliders.push_back(ui->horizontalSlider_1);
uiSliders.push_back(ui->horizontalSlider_2);

uiSliders_Size.push_back(ui->horizontalSlider_Size_1);
uiSliders_Size.push_back(ui->horizontalSlider_Size_2);

uiLabels.push_back(ui->label_threshold_1);
uiLabels.push_back(ui->label_threshold_2);

Expand Down Expand Up @@ -70,16 +69,12 @@ TrackerPlugin_EyeTracker::TrackerPlugin_EyeTracker(QObject *parent)

/*Prepare rects*/
for(int i=0;i<2;i++){
rectItems.push_back(new NotifyingQGraphicsRectItem());
rectItems.push_back(new QGraphicsRectItem());
rectItems.at(i)->setRect(QRect(0,0,maxRectWidth,maxRectWidth));
rectItems.at(i)->setPen(*rectPens.at(i));
rectItems.at(i)->setFlag(QGraphicsItem::ItemIsMovable, true);
rectItems.at(i)->setFlag(QGraphicsItem::ItemSendsGeometryChanges, true);
/*Signalmapper position*/
connect(rectItems.at(i), SIGNAL(itemMoved()), signalMapperPosition, SLOT(map()));
signalMapperPosition->setMapping(rectItems.at(i), i);
rectItems.at(i)->setFlag(QGraphicsItem::ItemIsSelectable, true);
}
connect(signalMapperPosition, SIGNAL(mapped(int)), this, SLOT(onItemPositionChanged(int)));


/*Prepare curves*/
for(int i=0;i<plotPens.size();i++){
Expand Down Expand Up @@ -115,15 +110,6 @@ TrackerPlugin_EyeTracker::TrackerPlugin_EyeTracker(QObject *parent)
signalMapperSliders->setMapping(ui->horizontalSlider_2, 1);
connect(signalMapperSliders, SIGNAL(mapped(int)), this, SLOT(onThreshSliderMoved(int)));

/*Sliders Size signalmapper*/
signalMapperSliders_Size = new QSignalMapper(this);
/*Connect checkboxes and sliders*/
connect(ui->horizontalSlider_Size_1, SIGNAL(valueChanged(int)), signalMapperSliders_Size, SLOT(map()));
connect(ui->horizontalSlider_Size_2, SIGNAL(valueChanged(int)), signalMapperSliders_Size, SLOT(map()));
signalMapperSliders_Size->setMapping(ui->horizontalSlider_Size_1, 0);
signalMapperSliders_Size->setMapping(ui->horizontalSlider_Size_2, 1);
connect(signalMapperSliders_Size, SIGNAL(mapped(int)), this, SLOT(onSizeSliderMoved(int)));

/*LineEdit signalmapper*/
/*The signalmapper is an overkill at this point but since we used them for everything else, we'll stick to them for now*/
signalMapperLineEdit = new QSignalMapper(this);
Expand All @@ -142,16 +128,14 @@ TrackerPlugin_EyeTracker::TrackerPlugin_EyeTracker(QObject *parent)

/*Connection TrackingGui - TrackingWorker*/
connect(this, SIGNAL(thresholdChanged(int, int)), trackerWorker, SLOT(onThresholdChanged(int, int)));
// //connect(ui->widget_trackingGui, SIGNAL(roiChanged(int, QRectF)), trackingWorker, SLOT(onRoisChanged(int, QRectF)));
connect(this, SIGNAL(posChanged(int, QPoint)), trackerWorker, SLOT(onPosChanged(int, QPoint)));
connect(this, SIGNAL(sizeChanged(int, QSize)), trackerWorker, SLOT(onSizeChanged(int, QSize)));
connect(this, SIGNAL(roiChanged(int,QRect)), trackerWorker, SLOT(onRoiChanged(int,QRect)));
connect(this, SIGNAL(areaContraintsChanged(int,int)), trackerWorker, SLOT(onAreaConstraintsChanged(int,int)));
connect(ui->checkBox_showBinary, SIGNAL(clicked(bool)), trackerWorker, SLOT(onShowBinary(bool)));
connect(ui->checkBox_brightPupil, SIGNAL(clicked(bool)), trackerWorker, SLOT(onBrightPupil(bool)));
connect(trackerWorker, SIGNAL(trackingResult(std::vector<double>)), this, SLOT(onTrackingResult(std::vector<double>)));
// connect(trackerWorker, SIGNAL(trackingResult(TrackingResults)), this, SLOT(onTrackingResult(TrackingResults)));


connect(resizeHelper, SIGNAL(itemChanged(QGraphicsItem*)),this, SLOT(onItemChanged(QGraphicsItem*)));
}

QObject *TrackerPlugin_EyeTracker::worker()
Expand All @@ -167,6 +151,10 @@ void TrackerPlugin_EyeTracker::initializeUI(QLayout *layout, QGraphicsScene *cam
layout->addWidget(this);
this->cameraScene = cameraScene;

/*Make objects resizeable and moveable*/
cameraScene->addItem(resizeHelper);
connect(cameraScene, SIGNAL(selectionChanged()), resizeHelper, SLOT(selectionChanged()));

for(int i=0;i<rectItems.size();i++){
this->cameraScene->addItem(rectItems.at(i));
}
Expand All @@ -180,8 +168,7 @@ void TrackerPlugin_EyeTracker::initializeUI(QLayout *layout, QGraphicsScene *cam
for(int i=0;i<rectItems.size();i++){
rectItems.at(i)->setRect(QRect(0,0,maxRectWidth,maxRectWidth));
emit(thresholdChanged(i, uiSliders.at(i)->value()));
emit(sizeChanged(i, QSize(rectItems.at(i)->rect().width(), rectItems.at(i)->rect().height())));
emit(posChanged(i, QPoint(rectItems.at(i)->pos().rx(),rectItems.at(i)->pos().ry())));
emit(roiChanged(i, rectItems.at(i)->rect().toRect()));
}
}
}
Expand Down Expand Up @@ -214,12 +201,10 @@ void TrackerPlugin_EyeTracker::onCheckBoxClicked(int index)
case 0:
rectItems.at(index)->setVisible(isVisible);
uiSliders.at(index)->setVisible(isVisible);
uiSliders_Size.at(index)->setVisible(isVisible);
break;
case 2:
rectItems.at(1)->setVisible(isVisible);
uiSliders.at(1)->setVisible(isVisible);
uiSliders_Size.at(1)->setVisible(isVisible);
break;
}

Expand All @@ -234,18 +219,46 @@ void TrackerPlugin_EyeTracker::onThreshSliderMoved(int index)
emit(thresholdChanged(index, value));
}

void TrackerPlugin_EyeTracker::onSizeSliderMoved(int index)
void TrackerPlugin_EyeTracker::onItemChanged(QGraphicsItem *item)
{
float value = uiSliders_Size.at(index)->value();
value = value /100.0;
if((rectItems.at(index)->pos().x() + maxRectWidth*value < cameraScene->width()) &
(rectItems.at(index)->pos().y() + maxRectWidth*value < cameraScene->height())) {
int rectIdx = -1;
/*Determine which rectangle was changed*/
for(int i = 0; i<rectItems.size(); i++){
if(dynamic_cast<QGraphicsRectItem*>(item) == rectItems.at(i)){
rectIdx = i;
}
}
/*If the resized object is a ROI rectangle created by this plugin*/
/*Send message*/
if(rectIdx >= 0){

/*Make sure that roi is within camera window*/
QRectF rect = rectItems.at(rectIdx)->rect();
if(rect.x() < 0){
rect.setRight(rect.right() - rect.x());
rect.setLeft(0);
rectItems.at(rectIdx)->setRect(rect); }
if(rect.y() < 0){
rect.setBottom(rect.bottom() - rect.y());
rect.setTop(0);
rectItems.at(rectIdx)->setRect(rect);
}
if (rect.right() >= cameraResolution.width()){
rect.setLeft(rect.left() + (cameraResolution.width() - rect.right()));
rect.setRight(cameraResolution.width());
rectItems.at(rectIdx)->setRect(rect);
}
if (rect.bottom() >= cameraResolution.height()){
rect.setTop(rect.top() + (cameraResolution.height() - rect.bottom()));
rect.setBottom(cameraResolution.height());
rectItems.at(rectIdx)->setRect(rect);
}

rectItems.at(index)->setRect(QRect(0,0,maxRectWidth*value,maxRectWidth*value));
emit(sizeChanged(index, QSize(rectItems.at(index)->rect().width(),rectItems.at(index)->rect().height())));
emit(roiChanged(rectIdx, rect.toRect()));
}
}


void TrackerPlugin_EyeTracker::on_lineEdit_editingFinished()
{
wndLength = ui->lineEdit->text().toDouble();
Expand All @@ -259,21 +272,3 @@ void TrackerPlugin_EyeTracker::onAreaConstraintsEditingFinished(int index)
{
emit(areaContraintsChanged(index, uiLineEdits.at(index)->text().toInt()));
}

void TrackerPlugin_EyeTracker::onItemPositionChanged(int index)
{
if(rectItems.at(index)->pos().x() < 0){
rectItems.at(index)->setX(0);
}
if(rectItems.at(index)->pos().y() < 0){
rectItems.at(index)->setY(0);
}
if ((rectItems.at(index)->pos().x() + rectItems.at(index)->rect().width()) >= cameraResolution.width()){
rectItems.at(index)->setX(cameraResolution.width()-rectItems.at(index)->rect().width());
}
if ((rectItems.at(index)->pos().y() + rectItems.at(index)->rect().height()) >= cameraResolution.height()){
rectItems.at(index)->setY(cameraResolution.height()-rectItems.at(index)->rect().height());
}

emit(posChanged(index, QPoint(rectItems.at(index)->pos().x(),rectItems.at(index)->pos().y())));
}
14 changes: 6 additions & 8 deletions TrackerPlugin_EyeTracker.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
#include <QDebug>
#include <QSignalMapper>
#include <qwt_slider.h>
#include <NotifyingQGraphicsRectItem.h>
#include <QPoint>
#include <QSize>
#include <opencv2/core/core.hpp>
Expand All @@ -21,6 +20,7 @@
#include <opencv2/objdetect/objdetect.hpp>
#include <QObject>
#include <QDebug>
#include "ResizeHelper.h"


namespace Ui {
Expand All @@ -44,7 +44,7 @@ class TrackerPlugin_EyeTracker : public QWidget, public TrackerInterface
Ui::TrackerPlugin_EyeTracker *ui;
QGraphicsScene* cameraScene;
QGraphicsPixmapItem* pixmapItem;
QVector<NotifyingQGraphicsRectItem*> rectItems;
QVector<QGraphicsRectItem*> rectItems;
QVector<QPen*> plotPens;
QVector<QPen*> rectPens;

Expand All @@ -56,7 +56,6 @@ class TrackerPlugin_EyeTracker : public QWidget, public TrackerInterface
QVector<QwtPlot*> uiPlots;
QVector<QSlider*> uiSliders;
QVector<QLabel*> uiLabels;
QVector<QSlider*> uiSliders_Size;
QVector<QCheckBox*> uiCheckboxes;
QVector<QLineEdit*> uiLineEdits;

Expand All @@ -70,21 +69,20 @@ class TrackerPlugin_EyeTracker : public QWidget, public TrackerInterface
QSignalMapper* signalMapperPosition;
QSignalMapper* signalMapperCheckBoxes;
QSignalMapper* signalMapperSliders;
QSignalMapper* signalMapperSliders_Size;
QSignalMapper* signalMapperLineEdit;

ResizeHelper* resizeHelper;

private slots:
void onTrackingResult(std::vector<double>);
void onCheckBoxClicked(int);
void onThreshSliderMoved(int);
void onSizeSliderMoved(int);
void onItemChanged(QGraphicsItem* item);
void on_lineEdit_editingFinished();
void onAreaConstraintsEditingFinished(int);
void onItemPositionChanged(int);

signals:
void sizeChanged(int index, QSize size);
void posChanged(int index, QPoint pos);
void roiChanged(int index, QRect roi);
void thresholdChanged(int index, int value);
void areaContraintsChanged(int index, int value);

Expand Down
5 changes: 5 additions & 0 deletions TrackerWorker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,11 @@ void TrackerWorker::onSizeChanged(int index, QSize size)
rois.replace(index, QRect(rois.at(index).x(), rois.at(index).y(), size.width(), size.height()));
}

void TrackerWorker::onRoiChanged(int index, QRect roi)
{
rois.replace(index, roi);
}

void TrackerWorker::onShowBinary(bool showBinary)
{
this->showBinary = showBinary;
Expand Down
1 change: 1 addition & 0 deletions TrackerWorker.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public slots:
void onAreaConstraintsChanged(int minSize, int maxSize);
void onPosChanged(int index, QPoint pos);
void onSizeChanged(int index, QSize size);
void onRoiChanged(int index, QRect roi);
void onShowBinary(bool showBinary);
void onBrightPupil(bool isInverted);

Expand Down

0 comments on commit 2c420a5

Please sign in to comment.