diff --git a/include/petrack.h b/include/petrack.h index dd74bc0feeeb1707868c830e56d78ea70013560d..c8e08ee701765e596e2f8105a6c1056787377df1 100644 --- a/include/petrack.h +++ b/include/petrack.h @@ -141,9 +141,9 @@ public slots: void saveView(QString dest = ""); void saveImage(QString dest = ""); void setStatusPosReal(); - void addManualTrackPointOnlyVisible(QPointF pos); + void addManualTrackPointOnlyVisible(const QPointF& pos); void splitTrackPerson(QPointF pos); - int addManualTrackPoint(QPointF pos); + int addOrMoveManualTrackPoint(const QPointF& pos); void editTrackPersonComment(QPointF pos); void setTrackPersonHeight(QPointF pos); void resetTrackPersonHeight(QPointF pos); diff --git a/include/tracker.h b/include/tracker.h index ae5ec285eaf6cdd1b9e63536bfad7b236fe32e25..c33e1f99d7d562ab13dfc64b00ab2e5a74bdbdfc 100644 --- a/include/tracker.h +++ b/include/tracker.h @@ -498,7 +498,7 @@ public: // true, if new traj is inserted with point p and initial frame frame // p in pixel coord // pers wird gesetzt, wenn existierender trackpoint einer person verschoben wird - bool addPoint(TrackPoint &p, int frame, QSet<int> onlyVisible, int *pers = NULL); + bool addPoint(TrackPoint &p, int frame, const QSet<int>& onlyVisible, int *pers = NULL); // hier sollte direkt die farbe mit uebergeben werden void addPoints(QList<TrackPoint> &pL, int frame); diff --git a/src/petrack.cpp b/src/petrack.cpp index 8ba1c066d922af6d7b131bb5876e6cedd8de3945..d0a4c74a58636f5dfba30ca337c602cf48b1b497 100644 --- a/src/petrack.cpp +++ b/src/petrack.cpp @@ -214,7 +214,7 @@ Petrack::Petrack() connect(mView, SIGNAL(mouseDoubleClick()), this, SLOT(openSequence())); connect(mView, SIGNAL(mouseShiftDoubleClick(QPointF)), this, SLOT(addManualTrackPointOnlyVisible(QPointF))); //const QPoint &pos funktionierte nicht connect(mView, SIGNAL(mouseShiftControlDoubleClick(QPointF)), this, SLOT(splitTrackPerson(QPointF))); //const QPoint &pos funktionierte nicht - connect(mView, SIGNAL(mouseControlDoubleClick(QPointF)), this, SLOT(addManualTrackPoint(QPointF))); //const QPoint &pos funktionierte nicht + connect(mView, SIGNAL(mouseControlDoubleClick(QPointF)), this, SLOT(addOrMoveManualTrackPoint(QPointF))); //const QPoint &pos funktionierte nicht connect(mView, SIGNAL(mouseRightDoubleClick(QPointF, int)), this, SLOT(deleteTrackPoint(QPointF, int))); //const QPoint &pos funktionierte nicht connect(mView, SIGNAL(mouseMiddleDoubleClick(int)), this, SLOT(deleteTrackPointAll(int))); //const QPoint &pos funktionierte nicht connect(mView, SIGNAL(mouseShiftWheel(int)), this, SLOT(skipToFrameWheel(int))); @@ -4106,9 +4106,9 @@ QSet<int> Petrack::getOnlyVisible() return QSet<int>(); } -void Petrack::addManualTrackPointOnlyVisible(QPointF pos) +void Petrack::addManualTrackPointOnlyVisible(const QPointF& pos) { - int pers = addManualTrackPoint(pos)+1; + int pers = addOrMoveManualTrackPoint(pos)+1; if (pers == 0) pers = mTracker->size()+1; pers = mControlWidget->trackShowOnlyNr->maximum(); @@ -4140,26 +4140,23 @@ void Petrack::splitTrackPerson(QPointF pos) } /** - * @brief Lets the user add a TrackPoint manually + * @brief Lets the user add or move a TrackPoint manually + * + * There is an check inside addPoint which inhibits adding a point, + * if only selected trajectories are visualized, since one wouldn't + * see the newly added TrackPoint. * * @param pos pixel position of mouse on image - * @return index of added person; -1 if failed + * @return index of person whose point was moved; -1 if failed or new trajectory is started */ -int Petrack::addManualTrackPoint(QPointF pos) //const QPoint &pos +int Petrack::addOrMoveManualTrackPoint(const QPointF& pos) { - if(getOnlyVisible().empty()){ - int pers = -1; - TrackPoint tP((Vec2F) pos, 110); // 110 ist ueber 100 (hoechste Qualitaetsstufe) und wird nach einfuegen auf 100 gesetzt - // so kann aber ein punkt immer angepasst werden - mTracker->addPoint(tP, mAnimation->getCurrentFrameNum(), getOnlyVisible(), &pers); - updateControlWidget(); - return pers; - }else{ - QMessageBox::warning(this, tr("PeTrack"), tr("Adding a manual TrackPoint is only possible, when \"show only people\" and \"show only people list\" are disabled!\n" - "You would not see the newly created TrackPoint otherwise.")); - return -1; - } - + int pers = -1; + TrackPoint tP(Vec2F{pos}, 110); // 110 is higher than 100 (max. quality) and gets clamped to 100 after insertion + // allows replacemet of every point (check for better quality always passes) + mTracker->addPoint(tP, mAnimation->getCurrentFrameNum(), getOnlyVisible(), &pers); + updateControlWidget(); + return pers; } // direction zeigt an, ob bis zum aktuellen (-1), ab dem aktuellen (1) oder ganzer trackpath (0) diff --git a/src/tracker.cpp b/src/tracker.cpp index db9f83ad3f6d8767a3fdece2085299d36407792e..704c6738f5386c0747cf0d886a3093196b4c082b 100644 --- a/src/tracker.cpp +++ b/src/tracker.cpp @@ -1087,10 +1087,28 @@ int Tracker::calcPosition(int /*frame*/) { return -1; } -// true, if new traj is inserted with point p and initial frame frame -// p in pixel coord -// used from recognition and manual -bool Tracker::addPoint(TrackPoint &p, int frame, QSet<int> onlyVisible, int *pers) +/** + * @brief Adds the point to the Tracker, either to exising person or creating a new one. + * + * This function find the nearest person to the given point and if the distance between point + * and trajectory is small enough, it gets added to this trajectory. If the point is not fitting to + * any trajectory, a new TrackPerson is created. + * + * It is possible for point to replace existing ones, if the quality is better. (Manual insertion, + * reverse tracking,...) + * + * For multicolor, the color gets added as well. For Aruco, the code of TrackPoint and TrackPerson + * gets synchronized. + * + * This function is used form manual insertions and from recognition. + * + * @param[in] p TrackPoint to add + * @param[in] frame current frame (frame in which p was detected) + * @param[in] onlyVisible set of selected persons, see Petrack::getOnlyVisible() + * @param[out] pers person the point was added to; undefined when new trajectory was created + * @return true if new trajectory was created; false otherwise + */ +bool Tracker::addPoint(TrackPoint &p, int frame, const QSet<int>& onlyVisible, int *pers) { bool found = false; int i, iNearest = 0.; @@ -1214,7 +1232,12 @@ bool Tracker::addPoint(TrackPoint &p, int frame, QSet<int> onlyVisible, int *per if ((z > 0) && ((onlyVisible.empty()) || found)) (*this)[iNearest].setHeight(z, mMainWindow->getControlWidget()->coordAltitude->value()); // , frame if ((!onlyVisible.empty()) && !found) + { + QMessageBox::warning(nullptr, "PeTrack", "Adding a manual TrackPoint is only possible, when \"show only people\" and \"show only people list\" are disabled!\n" + "You would not see the newly created TrackPoint otherwise."); debout << "Warning: No manual insertion, because not all trajectories are visible!" <<endl; + return false; + } return !found; } diff --git a/src/trackerItem.cpp b/src/trackerItem.cpp index b4ab504e878494c94a3593f94af5b9ffc43bacc4..c82424c6ec4e00dd65ec40b943d77bba766af74f 100644 --- a/src/trackerItem.cpp +++ b/src/trackerItem.cpp @@ -173,7 +173,7 @@ void TrackerItem::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) if( selectedAction == creTrj ) { //debout << "Create new trajectory..." << endl; - mMainWindow->addManualTrackPoint(event->scenePos()); + mMainWindow->addOrMoveManualTrackPoint(event->scenePos()); //debout << "addManuelTrackPoint: " << res << endl; }else if( selectedAction == delTrj ) {