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

Commit

Permalink
Fixed boundaries
Browse files Browse the repository at this point in the history
  • Loading branch information
MPIBR-kretschmerf committed Apr 26, 2017
1 parent e5d19a0 commit 2c28164
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 25 deletions.
7 changes: 2 additions & 5 deletions ResizeHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ QFlags<Qt::Edge> edgesAt(const QPointF & p, const QRectF & r, qreal w) {

ResizeHelper::ResizeHelper(QObject *parent) {
setAcceptedMouseButtons(Qt::LeftButton);
m_pen.setColor(QColor(255, 0, 0, 128));
m_pen.setStyle(Qt::SolidLine);
}

QRectF ResizeHelper::boundingRect() const {
Expand All @@ -28,6 +26,7 @@ void ResizeHelper::selectionChanged() {
if (sel.isEmpty() || sel.size() > 1) { setVisible(false); return; }
auto item = sel.at(0);
if (! traits.isGraphicsItemResizeable(item)) { setVisible(false); return; }
m_pen = traits.penFor(item);
setParentItem(item);
newGeometry();
setVisible(true);
Expand Down Expand Up @@ -67,7 +66,7 @@ void ResizeHelper::mouseMoveEvent(QGraphicsSceneMouseEvent * ev) {
}

/*Make sure that rectangle is within predefined boundaries (if given)*/
if ((!boundaries.isEmpty() & (boundaries.contains(rect))) | boundaries.isEmpty()){
if ((rect.width()>0 & rect.height()>0) & ((!boundsRect.isEmpty() & (boundsRect.contains(rect))) | boundsRect.isEmpty())){
traits.setRectOn(parentItem(), rect);
newGeometry();
emit(itemChanged(parentItem()));
Expand All @@ -80,6 +79,4 @@ void ResizeHelper::newGeometry() {
auto parentRect = traits.rectFor(parentItem());
m_rect.setTopLeft(mapFromParent(parentRect.topLeft()));
m_rect.setBottomRight(mapFromParent(parentRect.bottomRight()));
m_pen.setWidthF(std::min(m_rect.width(), m_rect.height()) * 0.1);
m_pen.setJoinStyle(Qt::MiterJoin);
}
2 changes: 1 addition & 1 deletion ResizeHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class ResizeHelper : public QGraphicsObject
public:
ResizeTraits traits;
QRectF m_rect;
QRectF boundaries;
QRectF boundsRect;
QPen m_pen;
QPointF clickPos;
QFlags<Qt::Edge> m_edges;
Expand Down
17 changes: 17 additions & 0 deletions ResizeTraits.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,20 @@ void ResizeTraits::setRectOn(QGraphicsItem * item, const QRectF & rect) {
return resizeableItem2->setRect(rect);
}
}

QPen ResizeTraits::penFor(QGraphicsItem *item)
{
auto resizeableItem = dynamic_cast<QGraphicsRectItem*>(item);
if (resizeableItem){
/*Use the same Pen as the parent for the bounding rectangle*/
QPen pen = resizeableItem->pen();
QColor color = pen.color();
color.setAlpha(100);
pen.setColor(color);
pen.setWidth(pen.width()*10);
pen.setJoinStyle(Qt::MiterJoin);
return pen;
}else{
return QPen(QColor(255, 0, 0, 128), Qt::SolidLine);
}
}
7 changes: 5 additions & 2 deletions ResizeTraits.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@
#define ResizeTraits_H
#include <QGraphicsItem>
#include <QRectF>
#include <QPen>
#include <QDebug>

class ResizeTraits
{
public:
static bool isGraphicsItemResizeable(QGraphicsItem * item);
static QRectF rectFor(QGraphicsItem * item);
static void setRectOn(QGraphicsItem * item, const QRectF & rect);
static QRectF rectFor(QGraphicsItem* item);
static void setRectOn(QGraphicsItem* item, const QRectF & rect);
static QPen penFor(QGraphicsItem* item);

};

Expand Down
14 changes: 1 addition & 13 deletions TrackerPlugin_EyeTracker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,6 @@ TrackerPlugin_EyeTracker::TrackerPlugin_EyeTracker(QObject *parent)
uiPlots.at(3)->setAxisTitle(0, "CR y [px]");
uiPlots.at(4)->setAxisTitle(0, "Pupil Ø [px]");

// pLineH.setLine(0,0,100,100);
// pLineV.setLine(0,0,0,0);
// cLineH.setLine(0,0,0,0);
// cLineV.setLine(0,0,0,0);

// cameraScene->addLine(pLineH);
// cameraScene->addLine(pLineV);
// cameraScene->addLine(cLineH);
// cameraScene->addLine(cLineV);

/*Prepare rects*/
for(int i=0;i<2;i++){
rectItems.push_back(new QGraphicsRectItem());
Expand All @@ -75,7 +65,6 @@ TrackerPlugin_EyeTracker::TrackerPlugin_EyeTracker(QObject *parent)
rectItems.at(i)->setFlag(QGraphicsItem::ItemIsSelectable, true);
}


/*Prepare curves*/
for(int i=0;i<plotPens.size();i++){
curves.push_back(new QwtPlotCurve("Curve"));
Expand Down Expand Up @@ -152,7 +141,7 @@ void TrackerPlugin_EyeTracker::initializeUI(QLayout *layout, QGraphicsScene *cam
this->cameraScene = cameraScene;

/*Make objects resizeable and moveable*/
resizeHelper->boundaries = QRectF(0,0,cameraResolution.width(),cameraResolution.height());
resizeHelper->boundsRect = QRectF(0,0,cameraResolution.width(),cameraResolution.height());
cameraScene->addItem(resizeHelper);
connect(cameraScene, SIGNAL(selectionChanged()), resizeHelper, SLOT(selectionChanged()));

Expand Down Expand Up @@ -209,7 +198,6 @@ void TrackerPlugin_EyeTracker::onCheckBoxClicked(int index)
break;
}


uiPlots.at(index)->setVisible(isVisible);
}

Expand Down
3 changes: 1 addition & 2 deletions TrackerPlugin_EyeTracker.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
#include <QDebug>
#include "ResizeHelper.h"


namespace Ui {
class TrackerPlugin_EyeTracker;
}
Expand Down Expand Up @@ -71,7 +70,7 @@ class TrackerPlugin_EyeTracker : public QWidget, public TrackerInterface
QSignalMapper* signalMapperSliders;
QSignalMapper* signalMapperLineEdit;

ResizeHelper* resizeHelper;
ResizeHelper* resizeHelper; //Manages resizing of items in scene

private slots:
void onTrackingResult(std::vector<double>);
Expand Down
2 changes: 0 additions & 2 deletions TrackerWorker.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,10 @@ public slots:
void onShowBinary(bool showBinary);
void onBrightPupil(bool isInverted);


signals:
void trackingPreview(Mat);
void trackingRois(QVector<Mat>);
void trackingResult(std::vector<double> data);

};

#endif // TRACKERWORKER_H

0 comments on commit 2c28164

Please sign in to comment.