diff --git a/CMakeLists.txt b/CMakeLists.txt index 1491e11f2592cd3b27ce54b6c68b0690fdba51ae..96dae512922c2b7d6d85db1b9a947a44b1af0408 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -328,7 +328,6 @@ target_sources(petrack_core PRIVATE include/colorMarkerWidget.h include/codeMarkerWidget.h include/multiColorMarkerWidget.h - include/recognitionRoiItem.h include/imageItem.h include/logoItem.h include/gridItem.h @@ -364,7 +363,7 @@ target_sources(petrack_core PRIVATE include/qtColorTriangle.h include/swapFilter.h include/extrCalibration.h - include/trackingRoiItem.h + include/roiItem.h include/analysePlot.h include/IO.h include/skeletonTree.h @@ -389,7 +388,6 @@ target_sources(petrack_core PRIVATE src/colorMarkerWidget.cpp src/codeMarkerWidget.cpp src/multiColorMarkerWidget.cpp - src/recognitionRoiItem.cpp src/imageItem.cpp src/logoItem.cpp src/gridItem.cpp @@ -425,7 +423,7 @@ target_sources(petrack_core PRIVATE src/qtColorTriangle.cpp src/swapFilter.cpp src/extrCalibration.cpp - src/trackingRoiItem.cpp + src/roiItem.cpp src/IO.cpp src/skeletonTree.cpp src/skeletonTreeFactory.cpp diff --git a/include/control.h b/include/control.h index f7623b9d68ddea971a24064e5579f77bea9e65b3..781960607807fa272a0a254a8971a041b2dd0c80 100644 --- a/include/control.h +++ b/include/control.h @@ -36,7 +36,12 @@ class Control : public QWidget, public Ui::Control Q_OBJECT public: - Control(QWidget &parent, QGraphicsScene &scene, reco::Recognizer &recognizer); + Control( + QWidget &parent, + QGraphicsScene &scene, + reco::Recognizer &recognizer, + RoiItem &trackRoiItem, + RoiItem &recoRoiItem); void setScene(QGraphicsScene *sc); diff --git a/include/petrack.h b/include/petrack.h index 187b268fb1099b9c75ea61929d4b938fcb9f88ba..1596a093e93eacc7744d9c7ef4686384528549de 100644 --- a/include/petrack.h +++ b/include/petrack.h @@ -46,7 +46,7 @@ class CalibFilter; class Animation; -class TrackingRoiItem; +class RoiItem; class RecognitionRoiItem; class GridItem; @@ -240,8 +240,8 @@ public: inline MultiColorMarkerItem *getMultiColorMarkerItem() { return mMultiColorMarkerItem; } inline BackgroundItem *getBackgroundItem() { return mBackgroundItem; } inline MoCapItem *getMoCapItem() { return mMoCapItem; } - inline RecognitionRoiItem *getRecoRoiItem() { return mRecognitionRoiItem; } - inline TrackingRoiItem *getTrackRoiItem() { return mTrackingRoiItem; } + inline RoiItem *getRecoRoiItem() { return mRecognitionRoiItem; } + inline RoiItem *getTrackRoiItem() { return mTrackingRoiItem; } inline TrackerItem *getTrackerItem() { return mTrackerItem; } inline Animation *getAnimation() { return mAnimation; } @@ -429,8 +429,8 @@ private: LogoItem *mLogoItem; CoordItem *mCoordItem; GridItem *mGridItem; - RecognitionRoiItem *mRecognitionRoiItem; - TrackingRoiItem *mTrackingRoiItem; + RoiItem *mRecognitionRoiItem; + RoiItem *mTrackingRoiItem; TrackerItem *mTrackerItem; StereoItem *mStereoItem; ColorMarkerItem *mColorMarkerItem; diff --git a/include/recognitionRoiItem.h b/include/roiItem.h similarity index 62% rename from include/recognitionRoiItem.h rename to include/roiItem.h index d942d6d90846290903a59c53a1de092e838e105a..5ad0847100bff90243b10584307aa8b0d6f9f4ef 100644 --- a/include/recognitionRoiItem.h +++ b/include/roiItem.h @@ -18,20 +18,22 @@ * along with this program. If not, see <https://www.gnu.org/licenses/>. */ -#ifndef RECOGNITIONROIITEM_H -#define RECOGNITIONROIITEM_H +#ifndef ROIITEM_H +#define ROIITEM_H #include <QGraphicsRectItem> +#include <QObject> class Petrack; -class Control; - -class RecognitionRoiItem : public QGraphicsRectItem +class RoiItem : public QObject, public QGraphicsRectItem { + Q_OBJECT + inline static constexpr int DISTANCE_TO_BORDER = 5; inline static constexpr int MIN_SIZE = 10; - enum pressLocation + + enum class PressLocation { inside, top, @@ -45,19 +47,23 @@ class RecognitionRoiItem : public QGraphicsRectItem }; private: - Petrack *mMainWindow; - Control *mControlWidget; - QRect mPressRect; - QPointF mPressPos; - enum pressLocation mPressLocation; + Petrack *mMainWindow; + QRect mPressRect; + QPointF mPressPos; + PressLocation mPressLocation{PressLocation::inside}; + bool mIsFixed{false}; public: - RecognitionRoiItem(QWidget *wParent, QGraphicsItem *parent = nullptr); - void mousePressEvent(QGraphicsSceneMouseEvent *event); - void mouseReleaseEvent(QGraphicsSceneMouseEvent *event); - void mouseMoveEvent(QGraphicsSceneMouseEvent *event); - void hoverMoveEvent(QGraphicsSceneHoverEvent *event); - void checkRect(); + RoiItem(QWidget *wParent, const QColor &color); + void mousePressEvent(QGraphicsSceneMouseEvent *event) override; + void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override; + void mouseMoveEvent(QGraphicsSceneMouseEvent *event) override; + void hoverMoveEvent(QGraphicsSceneHoverEvent *event) override; + void restoreSize(); + void setFixed(bool fixed) { mIsFixed = fixed; } + +signals: + void changed(); }; -#endif +#endif // ROIITEM_H diff --git a/include/trackingRoiItem.h b/include/trackingRoiItem.h deleted file mode 100644 index 36512d1e2fcea0c6b862252c14ce8ee276418c23..0000000000000000000000000000000000000000 --- a/include/trackingRoiItem.h +++ /dev/null @@ -1,63 +0,0 @@ -/* - * PeTrack - Software for tracking pedestrians movement in videos - * Copyright (C) 2010-2022 Forschungszentrum Jülich GmbH, - * Maik Boltes, Juliane Adrian, Ricardo Martin Brualla, Arne Graf, Paul Häger, Daniel Hillebrand, - * Deniz Kilic, Paul Lieberenz, Daniel Salden, Tobias Schrödter, Ann Katrin Seemann - * - * This program 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. - * - * This program 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 this program. If not, see <https://www.gnu.org/licenses/>. - */ - -#ifndef TRACKINGROIITEM_H -#define TRACKINGROIITEM_H - -#include <QGraphicsRectItem> - -class Petrack; -class Control; - -class TrackingRoiItem : public QGraphicsRectItem -{ - inline static constexpr int DISTANCE_TO_BORDER = 5; - inline static constexpr int MIN_SIZE = 10; - - enum pressLocation - { - inside, - top, - bottom, - left, - right, - topLeft, - topRight, - bottomLeft, - bottomRight - }; - -private: - Petrack *mMainWindow; - Control *mControlWidget; - QRect mPressRect; - QPointF mPressPos; - enum pressLocation mPressLocation; - -public: - TrackingRoiItem(QWidget *wParent, QGraphicsItem *parent = nullptr); - void mousePressEvent(QGraphicsSceneMouseEvent *event); - void mouseReleaseEvent(QGraphicsSceneMouseEvent *event); - void mouseMoveEvent(QGraphicsSceneMouseEvent *event); - void hoverMoveEvent(QGraphicsSceneHoverEvent *event); - void checkRect(); -}; - -#endif // TRACKINGROIITEM_H diff --git a/src/control.cpp b/src/control.cpp index e2fac371306b9ed4d28509d57a95e113ac71d326..a7abaa840100d007fd9ecba7755d786675578249 100644 --- a/src/control.cpp +++ b/src/control.cpp @@ -34,11 +34,10 @@ #include "pMessageBox.h" #include "petrack.h" #include "player.h" -#include "recognitionRoiItem.h" +#include "roiItem.h" #include "stereoWidget.h" #include "tracker.h" #include "trackerItem.h" -#include "trackingRoiItem.h" #include "view.h" #include <QDomElement> @@ -46,7 +45,13 @@ #define DEFAULT_HEIGHT 180.0 -Control::Control(QWidget &parent, QGraphicsScene &scene, reco::Recognizer &recognizer) : QWidget(&parent) +Control::Control( + QWidget &parent, + QGraphicsScene &scene, + reco::Recognizer &recognizer, + RoiItem &trackRoiItem, + RoiItem &recoRoiItem) : + QWidget(&parent) { setAccessibleName("Control"); mMainWindow = (class Petrack *) &parent; @@ -215,6 +220,9 @@ Control::Control(QWidget &parent, QGraphicsScene &scene, reco::Recognizer &recog scrollAreaWidgetContents_4->sizeHint().width() + 2 * scrollArea_4->frameWidth() + scrollArea_4->verticalScrollBar()->sizeHint().width() + scrollAreaWidgetContents_4->layout()->margin() * 2 + scrollAreaWidgetContents_4->layout()->spacing() * 2); + + connect(trackRoiFix, &QCheckBox::stateChanged, &trackRoiItem, &RoiItem::setFixed); + connect(roiFix, &QCheckBox::stateChanged, &recoRoiItem, &RoiItem::setFixed); } void Control::setScene(QGraphicsScene *sc) diff --git a/src/personStorage.cpp b/src/personStorage.cpp index 11ab1c3cabbac09a732d107ac6da36ae12d35b2d..a3a4b465ad30d266e92fb115ae2a86620244dfc1 100644 --- a/src/personStorage.cpp +++ b/src/personStorage.cpp @@ -25,7 +25,7 @@ #include "multiColorMarkerWidget.h" #include "pMessageBox.h" #include "petrack.h" -#include "recognitionRoiItem.h" +#include "roiItem.h" /** * @brief split trajectorie pers before frame frame diff --git a/src/petrack.cpp b/src/petrack.cpp index ceb25c1cf0ab4f8e3ffa3bc60a688e79b7c881a1..ab7c718a2d614d7ec751c272cda02f0fdd700544 100644 --- a/src/petrack.cpp +++ b/src/petrack.cpp @@ -43,13 +43,12 @@ #include "pMessageBox.h" #include "petrack.h" #include "player.h" -#include "recognitionRoiItem.h" +#include "roiItem.h" #include "stereoItem.h" #include "stereoWidget.h" #include "tracker.h" #include "trackerItem.h" #include "trackerReal.h" -#include "trackingRoiItem.h" #include "view.h" #include <QtPrintSupport/QPrintDialog> @@ -113,7 +112,15 @@ Petrack::Petrack() : mScene = new QGraphicsScene(this); - mControlWidget = new Control(*this, *mScene, mReco); + mTrackingRoiItem = new RoiItem(this, Qt::blue); + connect(mTrackingRoiItem, &RoiItem::changed, this, [=]() { this->setTrackChanged(true); }); + mTrackingRoiItem->setZValue(4); // groesser heisst weiter oben + + mRecognitionRoiItem = new RoiItem(this, Qt::green); + connect(mRecognitionRoiItem, &RoiItem::changed, this, [=]() { this->setRecognitionChanged(true); }); + mRecognitionRoiItem->setZValue(5); // groesser heisst weiter oben + + mControlWidget = new Control(*this, *mScene, mReco, *mTrackingRoiItem, *mRecognitionRoiItem); cw = mControlWidget; // muss spaeter geloescht werden mStereoWidget = new StereoWidget(this); @@ -154,13 +161,6 @@ Petrack::Petrack() : mCoordItem->setZValue(3); // groesser heisst weiter oben mImageItem->setCoordItem(mCoordItem); - mTrackingRoiItem = new TrackingRoiItem(this); - mTrackingRoiItem->setZValue(4); // groesser heisst weiter oben - - mRecognitionRoiItem = new RecognitionRoiItem(this); - mRecognitionRoiItem->setZValue(5); // groesser heisst weiter oben - - mViewWidget = new ViewWidget(this); mView = mViewWidget->view(); mView->setScene(mScene); @@ -3671,7 +3671,7 @@ void Petrack::updateImage(bool imageChanged) // default = false (only true for n size.height = mImgFiltered.rows; mTracker->resize(size); - mTrackingRoiItem->checkRect(); + mTrackingRoiItem->restoreSize(); } #ifndef STEREO_DISABLED // buildt disparity picture if it should be used for height detection @@ -3727,7 +3727,7 @@ void Petrack::updateImage(bool imageChanged) // default = false (only true for n #endif if(borderChanged) { - mRecognitionRoiItem->checkRect(); + mRecognitionRoiItem->restoreSize(); } if(mControlWidget->performRecognition->checkState() == Qt::Checked) diff --git a/src/recognition.cpp b/src/recognition.cpp index e8eb6186c226d221fdc2eb3d5625979e7ee45663..ef5125f563888c69dc1b1a0ab4365dea2fffd3ed 100644 --- a/src/recognition.cpp +++ b/src/recognition.cpp @@ -32,7 +32,7 @@ #include "multiColorMarkerItem.h" #include "multiColorMarkerWidget.h" #include "pMessageBox.h" -#include "recognitionRoiItem.h" +#include "roiItem.h" #include "tracker.h" #include <QPointF> diff --git a/src/recognitionRoiItem.cpp b/src/roiItem.cpp similarity index 61% rename from src/recognitionRoiItem.cpp rename to src/roiItem.cpp index a9782312278d6555bef59e8d726d73319b28a5c3..362db0dbe53ab8c00987d442df25afe9f5815687 100644 --- a/src/recognitionRoiItem.cpp +++ b/src/roiItem.cpp @@ -18,29 +18,25 @@ * along with this program. If not, see <https://www.gnu.org/licenses/>. */ -#include "recognitionRoiItem.h" +#include "roiItem.h" -#include "control.h" #include "petrack.h" -#include "view.h" -#include <QtWidgets> -RecognitionRoiItem::RecognitionRoiItem(QWidget *wParent, QGraphicsItem *parent) : QGraphicsRectItem(parent) +RoiItem::RoiItem(QWidget *wParent, const QColor &color) : QObject(wParent) { - mMainWindow = (class Petrack *) wParent; - mControlWidget = mMainWindow->getControlWidget(); - setRect(0, 0, 0, 0); // qreal x, qreal y, qreal width, qreal height - QPen pen(Qt::green); + mMainWindow = dynamic_cast<class Petrack *>(wParent); + setRect(0, 0, 0, 0); + QPen pen(color); setPen(pen); setAcceptHoverEvents(true); setFlags(ItemIsMovable); // default in control hide(); // default in control } -void RecognitionRoiItem::mousePressEvent(QGraphicsSceneMouseEvent *event) +void RoiItem::mousePressEvent(QGraphicsSceneMouseEvent *event) { - if(!mControlWidget->getRecoRoiFix()) + if(!mIsFixed) { mPressRect = QRect(myRound(rect().left()), myRound(rect().top()), myRound(rect().width()), myRound(rect().height())); @@ -49,17 +45,17 @@ void RecognitionRoiItem::mousePressEvent(QGraphicsSceneMouseEvent *event) { if((event->pos()).y() < DISTANCE_TO_BORDER + mPressRect.y()) { - mPressLocation = topLeft; + mPressLocation = PressLocation::topLeft; setCursor(Qt::SizeFDiagCursor); } else if((event->pos()).y() > mPressRect.height() + mPressRect.y() - DISTANCE_TO_BORDER) { - mPressLocation = bottomLeft; + mPressLocation = PressLocation::bottomLeft; setCursor(Qt::SizeBDiagCursor); } else { - mPressLocation = left; + mPressLocation = PressLocation::left; setCursor(Qt::SizeHorCursor); } } @@ -67,33 +63,33 @@ void RecognitionRoiItem::mousePressEvent(QGraphicsSceneMouseEvent *event) { if((event->pos()).y() < DISTANCE_TO_BORDER + mPressRect.y()) { - mPressLocation = topRight; + mPressLocation = PressLocation::topRight; setCursor(Qt::SizeBDiagCursor); } else if((event->pos()).y() > mPressRect.height() + mPressRect.y() - DISTANCE_TO_BORDER) { - mPressLocation = bottomRight; + mPressLocation = PressLocation::bottomRight; setCursor(Qt::SizeFDiagCursor); } else { - mPressLocation = right; + mPressLocation = PressLocation::right; setCursor(Qt::SizeHorCursor); } } else if((event->pos()).y() < DISTANCE_TO_BORDER + mPressRect.y()) { - mPressLocation = top; + mPressLocation = PressLocation::top; setCursor(Qt::SizeVerCursor); } else if((event->pos()).y() > mPressRect.height() + mPressRect.y() - DISTANCE_TO_BORDER) { - mPressLocation = bottom; + mPressLocation = PressLocation::bottom; setCursor(Qt::SizeVerCursor); } else { - mPressLocation = inside; + mPressLocation = PressLocation::inside; setCursor(Qt::ClosedHandCursor); } } @@ -101,9 +97,10 @@ void RecognitionRoiItem::mousePressEvent(QGraphicsSceneMouseEvent *event) QGraphicsRectItem::mousePressEvent(event); } -void RecognitionRoiItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) +void RoiItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) { - mMainWindow->setRecognitionChanged(true); + emit changed(); + if(!mMainWindow->isLoading()) { mMainWindow->updateImage(); @@ -112,136 +109,131 @@ void RecognitionRoiItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) QGraphicsRectItem::mouseReleaseEvent(event); } -// event, of moving mouse while mouse button is pressed -void RecognitionRoiItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event) +void RoiItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event) { - if(!mControlWidget->getRecoRoiFix()) + // event, of moving mouse while mouse button is pressed + if(!mIsFixed) { QImage *img = mMainWindow->getImage(); QPoint diff = QPoint(myRound((event->pos() - mPressPos).x()), myRound((event->pos() - mPressPos).y())); - // raender des bildes nicht ueberscheiten - // swappen des rechtecks vermeiden, damit keine negativen width... + // do not extend over the border of the image + // do not swap the rectangle, to avoid negative width if(img != nullptr) { - if(mPressLocation == inside || mPressLocation == topLeft || mPressLocation == left || - mPressLocation == bottomLeft) + if(mPressLocation == PressLocation::inside || mPressLocation == PressLocation::topLeft || + mPressLocation == PressLocation::left || mPressLocation == PressLocation::bottomLeft) { if(mPressRect.x() + diff.x() < -mMainWindow->getImageBorderSize()) { diff.setX(-mPressRect.x() - mMainWindow->getImageBorderSize()); } - if(mPressLocation != inside && mPressRect.width() - diff.x() < MIN_SIZE) + if(mPressLocation != PressLocation::inside && mPressRect.width() - diff.x() < MIN_SIZE) { diff.setX(mPressRect.width() - MIN_SIZE); } } - if(mPressLocation == inside || mPressLocation == topLeft || mPressLocation == top || - mPressLocation == topRight) + if(mPressLocation == PressLocation::inside || mPressLocation == PressLocation::topLeft || + mPressLocation == PressLocation::top || mPressLocation == PressLocation::topRight) { if(mPressRect.y() + diff.y() < -mMainWindow->getImageBorderSize()) { diff.setY(-mPressRect.y() - mMainWindow->getImageBorderSize()); } - if(mPressLocation != inside && mPressRect.height() - diff.y() < MIN_SIZE) + if(mPressLocation != PressLocation::inside && mPressRect.height() - diff.y() < MIN_SIZE) { diff.setY(mPressRect.height() - MIN_SIZE); } } - if(mPressLocation == inside || mPressLocation == topRight || mPressLocation == right || - mPressLocation == bottomRight) + if(mPressLocation == PressLocation::inside || mPressLocation == PressLocation::topRight || + mPressLocation == PressLocation::right || mPressLocation == PressLocation::bottomRight) { if(mPressRect.x() + diff.x() + mPressRect.width() > img->width() - mMainWindow->getImageBorderSize()) { diff.setX(img->width() - mPressRect.x() - mPressRect.width() - mMainWindow->getImageBorderSize()); } - if(mPressLocation != inside && mPressRect.width() + diff.x() < MIN_SIZE) + if(mPressLocation != PressLocation::inside && mPressRect.width() + diff.x() < MIN_SIZE) { diff.setX(-mPressRect.width() + MIN_SIZE); } } - if(mPressLocation == inside || mPressLocation == bottomLeft || mPressLocation == bottom || - mPressLocation == bottomRight) + if(mPressLocation == PressLocation::inside || mPressLocation == PressLocation::bottomLeft || + mPressLocation == PressLocation::bottom || mPressLocation == PressLocation::bottomRight) { if(mPressRect.y() + diff.y() + mPressRect.height() > img->height() - mMainWindow->getImageBorderSize()) { diff.setY(img->height() - mPressRect.y() - mPressRect.height() - mMainWindow->getImageBorderSize()); } - if(mPressLocation != inside && mPressRect.height() + diff.y() < MIN_SIZE) + if(mPressLocation != PressLocation::inside && mPressRect.height() + diff.y() < MIN_SIZE) { diff.setY(-mPressRect.height() + MIN_SIZE); } } } - if(mPressLocation == topLeft) - { - setRect( - mPressRect.x() + diff.x(), - mPressRect.y() + diff.y(), - mPressRect.width() - diff.x(), - mPressRect.height() - diff.y()); - } - else if(mPressLocation == topRight) - { - setRect( - mPressRect.x(), - mPressRect.y() + diff.y(), - mPressRect.width() + diff.x(), - mPressRect.height() - diff.y()); - } - else if(mPressLocation == bottomLeft) - { - setRect( - mPressRect.x() + diff.x(), - mPressRect.y(), - mPressRect.width() - diff.x(), - mPressRect.height() + diff.y()); - } - else if(mPressLocation == bottomRight) - { - setRect(mPressRect.x(), mPressRect.y(), mPressRect.width() + diff.x(), mPressRect.height() + diff.y()); - } - else if(mPressLocation == left) - { - setRect(mPressRect.x() + diff.x(), mPressRect.y(), mPressRect.width() - diff.x(), mPressRect.height()); - } - else if(mPressLocation == right) - { - setRect(mPressRect.x(), mPressRect.y(), mPressRect.width() + diff.x(), mPressRect.height()); - } - else if(mPressLocation == top) - { - setRect(mPressRect.x(), mPressRect.y() + diff.y(), mPressRect.width(), mPressRect.height() - diff.y()); - } - else if(mPressLocation == bottom) - { - setRect(mPressRect.x(), mPressRect.y(), mPressRect.width(), mPressRect.height() + diff.y()); - } - else // entspricht: if (mPressLocation == inside) + + switch(mPressLocation) { - setRect(mPressRect.x() + diff.x(), mPressRect.y() + diff.y(), mPressRect.width(), mPressRect.height()); + case PressLocation::topLeft: + setRect( + mPressRect.x() + diff.x(), + mPressRect.y() + diff.y(), + mPressRect.width() - diff.x(), + mPressRect.height() - diff.y()); + break; + case PressLocation::topRight: + setRect( + mPressRect.x(), + mPressRect.y() + diff.y(), + mPressRect.width() + diff.x(), + mPressRect.height() - diff.y()); + break; + case PressLocation::bottomLeft: + setRect( + mPressRect.x() + diff.x(), + mPressRect.y(), + mPressRect.width() - diff.x(), + mPressRect.height() + diff.y()); + break; + case PressLocation::bottomRight: + setRect(mPressRect.x(), mPressRect.y(), mPressRect.width() + diff.x(), mPressRect.height() + diff.y()); + break; + case PressLocation::left: + setRect(mPressRect.x() + diff.x(), mPressRect.y(), mPressRect.width() - diff.x(), mPressRect.height()); + break; + case PressLocation::right: + setRect(mPressRect.x(), mPressRect.y(), mPressRect.width() + diff.x(), mPressRect.height()); + break; + case PressLocation::top: + setRect(mPressRect.x(), mPressRect.y() + diff.y(), mPressRect.width(), mPressRect.height() - diff.y()); + break; + case PressLocation::bottom: + setRect(mPressRect.x(), mPressRect.y(), mPressRect.width(), mPressRect.height() + diff.y()); + break; + case PressLocation::inside: + setRect(mPressRect.x() + diff.x(), mPressRect.y() + diff.y(), mPressRect.width(), mPressRect.height()); + break; + // do not use QGraphicsRectItem::mouseMoveEvent(event) as it also moves the coordinate system } - // nicht, da sonst koordinatensystem verschoben wird: QGraphicsRectItem::mouseMoveEvent(event); // drag } - else // drag mach ich selber + else { QGraphicsRectItem::mouseMoveEvent(event); } } -// event, of moving mouse -void RecognitionRoiItem::hoverMoveEvent(QGraphicsSceneHoverEvent *event) +void RoiItem::hoverMoveEvent(QGraphicsSceneHoverEvent *event) { QPointF pos = event->scenePos(); pos.setX(pos.x() + mMainWindow->getImageBorderSize()); pos.setY(pos.y() + mMainWindow->getImageBorderSize()); - // abfrage auf width() ..., da durch rectLinie die recoBox etwas groesser ist als das Bild und - // es bei mMainWindow->setMousePosOnImage(pos); zum fehler beim bildzugriff kommen kann!!! - if(mMainWindow->getImage() && //(pos.x() > 0) && (pos.y() > 0) && - (pos.x() < mMainWindow->getImage()->width()) && (pos.y() < mMainWindow->getImage()->height())) + + // due to the line width of the QRect, the QRect might get slightly larger than the image. To avoid errors then + // accessing the image mMainWindow->setMousePosOnImage(pos) also width() is checked here + if((mMainWindow->getImage() != nullptr) && (pos.x() < mMainWindow->getImage()->width()) && + (pos.y() < mMainWindow->getImage()->height())) { mMainWindow->setMousePosOnImage(pos); - if(!mControlWidget->getRecoRoiFix()) + if(!mIsFixed) { QRect r = QRect(myRound(rect().left()), myRound(rect().top()), myRound(rect().width()), myRound(rect().height())); @@ -286,10 +278,10 @@ void RecognitionRoiItem::hoverMoveEvent(QGraphicsSceneHoverEvent *event) setCursor(Qt::OpenHandCursor); } } - else // wird nur einmal durchaufen - ruecksetzen in control.cpp + else // will only be executed once - reset in control.cpp { - setAcceptHoverEvents(false); // verhoindert nicht, dass wenn objekt darunter liegt, was andereen cursor - // haette - cursor wird weiterhin beim drueberfahren auf cross gesetzt + // if an object underneath would have a different cursor, the cursor will still be set to cross + setAcceptHoverEvents(false); setCursor(Qt::CrossCursor); } } @@ -297,13 +289,15 @@ void RecognitionRoiItem::hoverMoveEvent(QGraphicsSceneHoverEvent *event) QGraphicsRectItem::hoverMoveEvent(event); } -// check rect because bordersize changes and without mouse event nothing changes the rect -void RecognitionRoiItem::checkRect() +/** + * @brief Restores the size of the ROI if the image size changed + */ +void RoiItem::restoreSize() { cv::Mat img = mMainWindow->getImageFiltered(); + if(!img.empty()) { - // not QImage *img = mMainWindow->getImage(); as size is not adapted yet QRect r = QRect(myRound(rect().left()), myRound(rect().top()), myRound(rect().width()), myRound(rect().height())); if(r.x() > img.cols - mMainWindow->getImageBorderSize() - MIN_SIZE || diff --git a/src/tracker.cpp b/src/tracker.cpp index 4eb1ff784b03ca87f7285878c3b9b8cd58665fe7..062373e7f1b62f26a3102d270c74ff57d557f00f 100644 --- a/src/tracker.cpp +++ b/src/tracker.cpp @@ -26,7 +26,7 @@ #include "multiColorMarkerWidget.h" #include "pMessageBox.h" #include "petrack.h" -#include "recognitionRoiItem.h" +#include "roiItem.h" #include "stereoWidget.h" #include <ctime> diff --git a/src/trackerItem.cpp b/src/trackerItem.cpp index 85cbb63373870afc56f5d8dd6c582fb59192b153..8dca56c621e9bdec9ec3e5e7781bfc952c704d30 100644 --- a/src/trackerItem.cpp +++ b/src/trackerItem.cpp @@ -24,9 +24,8 @@ #include "control.h" #include "personStorage.h" #include "petrack.h" -#include "recognitionRoiItem.h" +#include "roiItem.h" #include "tracker.h" -#include "trackingRoiItem.h" #include "view.h" #include <QInputDialog> diff --git a/src/trackingRoiItem.cpp b/src/trackingRoiItem.cpp deleted file mode 100644 index 6b961c0b59f56eea6e950e562cebb2ccde11c32d..0000000000000000000000000000000000000000 --- a/src/trackingRoiItem.cpp +++ /dev/null @@ -1,350 +0,0 @@ -/* - * PeTrack - Software for tracking pedestrians movement in videos - * Copyright (C) 2010-2022 Forschungszentrum Jülich GmbH, - * Maik Boltes, Juliane Adrian, Ricardo Martin Brualla, Arne Graf, Paul Häger, Daniel Hillebrand, - * Deniz Kilic, Paul Lieberenz, Daniel Salden, Tobias Schrödter, Ann Katrin Seemann - * - * This program 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. - * - * This program 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 this program. If not, see <https://www.gnu.org/licenses/>. - */ - -#include "trackingRoiItem.h" - -#include "control.h" -#include "petrack.h" -#include "view.h" - -#include <QtWidgets> - -TrackingRoiItem::TrackingRoiItem(QWidget *wParent, QGraphicsItem *parent) : QGraphicsRectItem(parent) -{ - mMainWindow = (class Petrack *) wParent; - mControlWidget = mMainWindow->getControlWidget(); - setRect(0, 0, 0, 0); // qreal x, qreal y, qreal width, qreal height - QPen pen(Qt::blue); - setPen(pen); - setAcceptHoverEvents(true); - setFlags(ItemIsMovable); // default in control - hide(); // default in control -} - -void TrackingRoiItem::mousePressEvent(QGraphicsSceneMouseEvent *event) -{ - if(!mControlWidget->getTrackRoiFix()) - { - mPressRect = - QRect(myRound(rect().left()), myRound(rect().top()), myRound(rect().width()), myRound(rect().height())); - mPressPos = event->pos(); - if((event->pos()).x() < DISTANCE_TO_BORDER + mPressRect.x()) - { - if((event->pos()).y() < DISTANCE_TO_BORDER + mPressRect.y()) - { - mPressLocation = topLeft; - setCursor(Qt::SizeFDiagCursor); - } - else if((event->pos()).y() > mPressRect.height() + mPressRect.y() - DISTANCE_TO_BORDER) - { - mPressLocation = bottomLeft; - setCursor(Qt::SizeBDiagCursor); - } - else - { - mPressLocation = left; - setCursor(Qt::SizeHorCursor); - } - } - else if((event->pos()).x() > mPressRect.width() + mPressRect.x() - DISTANCE_TO_BORDER) - { - if((event->pos()).y() < DISTANCE_TO_BORDER + mPressRect.y()) - { - mPressLocation = topRight; - setCursor(Qt::SizeBDiagCursor); - } - else if((event->pos()).y() > mPressRect.height() + mPressRect.y() - DISTANCE_TO_BORDER) - { - mPressLocation = bottomRight; - setCursor(Qt::SizeFDiagCursor); - } - else - { - mPressLocation = right; - setCursor(Qt::SizeHorCursor); - } - } - else if((event->pos()).y() < DISTANCE_TO_BORDER + mPressRect.y()) - { - mPressLocation = top; - setCursor(Qt::SizeVerCursor); - } - else if((event->pos()).y() > mPressRect.height() + mPressRect.y() - DISTANCE_TO_BORDER) - { - mPressLocation = bottom; - setCursor(Qt::SizeVerCursor); - } - else - { - mPressLocation = inside; - setCursor(Qt::ClosedHandCursor); - } - } - - QGraphicsRectItem::mousePressEvent(event); -} - -void TrackingRoiItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) -{ - mMainWindow->setTrackChanged(true); - // mMainWindow->setRecognitionChanged(true); - if(!mMainWindow->isLoading()) - { - mMainWindow->updateImage(); - } - - QGraphicsRectItem::mouseReleaseEvent(event); -} - -// event, of moving mouse while mouse button is pressed -void TrackingRoiItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event) -{ - if(!mControlWidget->getTrackRoiFix()) - { - QImage *img = mMainWindow->getImage(); - QPoint diff = QPoint(myRound((event->pos() - mPressPos).x()), myRound((event->pos() - mPressPos).y())); - // raender des bildes nicht ueberscheiten - // swappen des rechtecks vermeiden, damit keine negativen width... - if(img != nullptr) - { - if(mPressLocation == inside || mPressLocation == topLeft || mPressLocation == left || - mPressLocation == bottomLeft) - { - if(mPressRect.x() + diff.x() < -mMainWindow->getImageBorderSize()) - { - diff.setX(-mPressRect.x() - mMainWindow->getImageBorderSize()); - } - if(mPressLocation != inside && mPressRect.width() - diff.x() < MIN_SIZE) - { - diff.setX(mPressRect.width() - MIN_SIZE); - } - } - if(mPressLocation == inside || mPressLocation == topLeft || mPressLocation == top || - mPressLocation == topRight) - { - if(mPressRect.y() + diff.y() < -mMainWindow->getImageBorderSize()) - { - diff.setY(-mPressRect.y() - mMainWindow->getImageBorderSize()); - } - if(mPressLocation != inside && mPressRect.height() - diff.y() < MIN_SIZE) - { - diff.setY(mPressRect.height() - MIN_SIZE); - } - } - if(mPressLocation == inside || mPressLocation == topRight || mPressLocation == right || - mPressLocation == bottomRight) - { - if(mPressRect.x() + diff.x() + mPressRect.width() > img->width() - mMainWindow->getImageBorderSize()) - { - diff.setX(img->width() - mPressRect.x() - mPressRect.width() - mMainWindow->getImageBorderSize()); - } - if(mPressLocation != inside && mPressRect.width() + diff.x() < MIN_SIZE) - { - diff.setX(-mPressRect.width() + MIN_SIZE); - } - } - if(mPressLocation == inside || mPressLocation == bottomLeft || mPressLocation == bottom || - mPressLocation == bottomRight) - { - if(mPressRect.y() + diff.y() + mPressRect.height() > img->height() - mMainWindow->getImageBorderSize()) - { - diff.setY(img->height() - mPressRect.y() - mPressRect.height() - mMainWindow->getImageBorderSize()); - } - if(mPressLocation != inside && mPressRect.height() + diff.y() < MIN_SIZE) - { - diff.setY(-mPressRect.height() + MIN_SIZE); - } - } - } - if(mPressLocation == topLeft) - { - setRect( - mPressRect.x() + diff.x(), - mPressRect.y() + diff.y(), - mPressRect.width() - diff.x(), - mPressRect.height() - diff.y()); - } - else if(mPressLocation == topRight) - { - setRect( - mPressRect.x(), - mPressRect.y() + diff.y(), - mPressRect.width() + diff.x(), - mPressRect.height() - diff.y()); - } - else if(mPressLocation == bottomLeft) - { - setRect( - mPressRect.x() + diff.x(), - mPressRect.y(), - mPressRect.width() - diff.x(), - mPressRect.height() + diff.y()); - } - else if(mPressLocation == bottomRight) - { - setRect(mPressRect.x(), mPressRect.y(), mPressRect.width() + diff.x(), mPressRect.height() + diff.y()); - } - else if(mPressLocation == left) - { - setRect(mPressRect.x() + diff.x(), mPressRect.y(), mPressRect.width() - diff.x(), mPressRect.height()); - } - else if(mPressLocation == right) - { - setRect(mPressRect.x(), mPressRect.y(), mPressRect.width() + diff.x(), mPressRect.height()); - } - else if(mPressLocation == top) - { - setRect(mPressRect.x(), mPressRect.y() + diff.y(), mPressRect.width(), mPressRect.height() - diff.y()); - } - else if(mPressLocation == bottom) - { - setRect(mPressRect.x(), mPressRect.y(), mPressRect.width(), mPressRect.height() + diff.y()); - } - else // entspricht: if (mPressLocation == inside) - { - setRect(mPressRect.x() + diff.x(), mPressRect.y() + diff.y(), mPressRect.width(), mPressRect.height()); - } - // nicht, da sonst koordinatensystem verschoben wird: QGraphicsRectItem::mouseMoveEvent(event); // drag - } - else // drag mach ich selber - { - QGraphicsRectItem::mouseMoveEvent(event); - } -} - -// event, of moving mouse -void TrackingRoiItem::hoverMoveEvent(QGraphicsSceneHoverEvent *event) -{ - QPointF pos = event->scenePos(); - pos.setX(pos.x() + mMainWindow->getImageBorderSize()); - pos.setY(pos.y() + mMainWindow->getImageBorderSize()); - // abfrage auf width() ..., da durch rectLinie die recoBox etwas groesser ist als das Bild und - // es bei mMainWindow->setMousePosOnImage(pos); zum fehler beim bildzugriff kommen kann!!! - if(mMainWindow->getImage() && //(pos.x() > 0) && (pos.y() > 0) && - (pos.x() < mMainWindow->getImage()->width()) && (pos.y() < mMainWindow->getImage()->height())) - { - mMainWindow->setMousePosOnImage(pos); - - if(!mControlWidget->getTrackRoiFix()) - { - QRect r = - QRect(myRound(rect().left()), myRound(rect().top()), myRound(rect().width()), myRound(rect().height())); - if((event->pos()).x() < DISTANCE_TO_BORDER + r.x()) - { - if((event->pos()).y() < DISTANCE_TO_BORDER + r.y()) - { - setCursor(Qt::SizeFDiagCursor); - } - else if((event->pos()).y() > r.height() + r.y() - DISTANCE_TO_BORDER) - { - setCursor(Qt::SizeBDiagCursor); - } - else - { - setCursor(Qt::SizeHorCursor); - } - } - else if((event->pos()).x() > r.width() + r.x() - DISTANCE_TO_BORDER) - { - if((event->pos()).y() < DISTANCE_TO_BORDER + r.y()) - { - setCursor(Qt::SizeBDiagCursor); - } - else if((event->pos()).y() > r.height() + r.y() - DISTANCE_TO_BORDER) - { - setCursor(Qt::SizeFDiagCursor); - } - else - { - setCursor(Qt::SizeHorCursor); - } - } - else if( - ((event->pos()).y() < DISTANCE_TO_BORDER + r.y()) || - ((event->pos()).y() > r.height() + r.y() - DISTANCE_TO_BORDER)) - { - setCursor(Qt::SizeVerCursor); - } - else - { - setCursor(Qt::OpenHandCursor); - } - } - else // wird nur einmal durchaufen - ruecksetzen in control.cpp - { - setAcceptHoverEvents(false); // verhoindert nicht, dass wenn objekt darunter liegt, was andereen cursor - // haette - cursor wird weiterhin beim drueberfahren auf cross gesetzt - setCursor(Qt::CrossCursor); - } - } - - QGraphicsRectItem::hoverMoveEvent(event); -} - -// check rect because bordersize changes and without mouse event nothing changes the rect -void TrackingRoiItem::checkRect() -{ - // not QImage *img = mMainWindow->getImage(); as size is not adapted yet - cv::Mat img = mMainWindow->getImageFiltered(); - - if(!img.empty()) - { - QRect r = - QRect(myRound(rect().left()), myRound(rect().top()), myRound(rect().width()), myRound(rect().height())); - if(r.x() > img.cols - mMainWindow->getImageBorderSize() - MIN_SIZE || - r.y() > img.rows - mMainWindow->getImageBorderSize() - MIN_SIZE || - r.x() + r.width() < -mMainWindow->getImageBorderSize() + MIN_SIZE || - r.y() + r.height() < -mMainWindow->getImageBorderSize() + MIN_SIZE) - { - setRect(-mMainWindow->getImageBorderSize(), -mMainWindow->getImageBorderSize(), img.cols, img.rows); - } - else - { - if(r.x() < -mMainWindow->getImageBorderSize()) - { - setRect( - -mMainWindow->getImageBorderSize(), - r.y(), - r.width() + (mMainWindow->getImageBorderSize() + r.x()), - r.height()); - } - if(r.y() < -mMainWindow->getImageBorderSize()) - { - setRect( - r.x(), - -mMainWindow->getImageBorderSize(), - r.width(), - r.height() + (mMainWindow->getImageBorderSize() + r.y())); - } - if(r.x() + mMainWindow->getImageBorderSize() + r.width() > img.cols) - { - setRect(r.x(), r.y(), img.cols - r.x() - mMainWindow->getImageBorderSize(), r.height()); - } - if(r.y() + mMainWindow->getImageBorderSize() + r.height() > img.rows) - { - setRect(r.x(), r.y(), r.width(), img.rows - r.y() - mMainWindow->getImageBorderSize()); - } - } - } - else - { - setRect(0, 0, 0, 0); - } -}