diff --git a/include/control.h b/include/control.h index 781960607807fa272a0a254a8971a041b2dd0c80..6e57ddbb1b5ec37bc7cc925cb2691a8b253bc3b5 100644 --- a/include/control.h +++ b/include/control.h @@ -580,6 +580,8 @@ private slots: void setMoCapShow(bool visibility); void setMoCapColor(QColor col); void setMoCapSize(int size); + void toggleRecoROIButtons(); + void toggleTrackROIButtons(); signals: void userChangedRecoMethod(reco::RecognitionMethod method); diff --git a/include/roiItem.h b/include/roiItem.h index 5ad0847100bff90243b10584307aa8b0d6f9f4ef..6d24deb07b2a90777f62fe08c22f755009a8ac68 100644 --- a/include/roiItem.h +++ b/include/roiItem.h @@ -21,11 +21,12 @@ #ifndef ROIITEM_H #define ROIITEM_H +#include "imageItem.h" +#include "petrack.h" + #include <QGraphicsRectItem> #include <QObject> -class Petrack; - class RoiItem : public QObject, public QGraphicsRectItem { Q_OBJECT @@ -61,6 +62,48 @@ public: void hoverMoveEvent(QGraphicsSceneHoverEvent *event) override; void restoreSize(); void setFixed(bool fixed) { mIsFixed = fixed; } + void setToFullImageSize(); + + /** + * @brief Sets the size and position of the rect relative to other. + * + * @tparam BinaryFunction + * @param other other ROI which is used as source for new position and size + * @param defaultHeight default height to determine the cm per pixel + * @param f binary function: in this case should be plus or minus + */ + template <typename BinaryFunction> + void adjustToOtherROI(const RoiItem &other, BinaryFunction f) + { + // Compute head sizes at the four corners to get the offset + auto otherTopLeft = other.rect().topLeft(); + auto headSizeTopLeft = mMainWindow->getHeadSize(&otherTopLeft); + + auto otherBottomLeft = other.rect().bottomLeft(); + auto headSizeBottomLeft = mMainWindow->getHeadSize(&otherBottomLeft); + + auto otherTopRight = other.rect().topRight(); + auto headSizeTopRight = mMainWindow->getHeadSize(&otherTopRight); + + auto otherBottomRight = other.rect().bottomRight(); + auto headSizeBottomRight = mMainWindow->getHeadSize(&otherBottomRight); + + constexpr auto headFactor = 2.; + auto offset = + headFactor * std::max({headSizeTopLeft, headSizeBottomLeft, headSizeTopRight, headSizeBottomRight}); + + auto borderSize = static_cast<double>(mMainWindow->getImageBorderSize()); + auto topLeftX = std::clamp( + f(otherTopLeft.x(), -offset), -borderSize, static_cast<double>(mMainWindow->getImage()->width())); + auto topLeftY = std::clamp( + f(otherTopLeft.y(), -offset), -borderSize, static_cast<double>(mMainWindow->getImage()->height())); + auto width = std::clamp( + f(other.rect().width(), 2 * offset), 0., mMainWindow->getImage()->width() - topLeftX - borderSize); + auto height = std::clamp( + f(other.rect().height(), 2 * offset), 0., mMainWindow->getImage()->height() - topLeftY - borderSize); + setRect(topLeftX, topLeftY, width, height); + emit changed(); + } signals: void changed(); diff --git a/src/control.cpp b/src/control.cpp index 3303457c732b6d2e67e11e3ffed2a3a392c42a01..995a0c0523424fb181ddfc802fc7612f4e733d61 100644 --- a/src/control.cpp +++ b/src/control.cpp @@ -222,7 +222,26 @@ Control::Control( scrollAreaWidgetContents_4->layout()->spacing() * 2); connect(trackRoiFix, &QCheckBox::stateChanged, &trackRoiItem, &RoiItem::setFixed); + connect(recoRoiToFullImageSize, &QPushButton::clicked, &recoRoiItem, &RoiItem::setToFullImageSize); + connect( + recoRoiAdjustAutomatically, + &QPushButton::clicked, + this, + [&recoRoiItem, &trackRoiItem]() { recoRoiItem.adjustToOtherROI(trackRoiItem, std::minus<>()); }); + connect(roiFix, &QCheckBox::stateChanged, &recoRoiItem, &RoiItem::setFixed); + connect(trackRoiToFullImageSize, &QPushButton::clicked, &trackRoiItem, &RoiItem::setToFullImageSize); + connect( + trackRoiAdjustAutomatically, + &QPushButton::clicked, + this, + [&recoRoiItem, &trackRoiItem]() { trackRoiItem.adjustToOtherROI(recoRoiItem, std::plus<>()); }); + + connect(roiFix, &QCheckBox::stateChanged, this, &Control::toggleRecoROIButtons); + connect(roiShow, &QCheckBox::stateChanged, this, &Control::toggleRecoROIButtons); + + connect(trackRoiFix, &QCheckBox::stateChanged, this, &Control::toggleTrackROIButtons); + connect(trackRoiShow, &QCheckBox::stateChanged, this, &Control::toggleTrackROIButtons); // "Hide" analysis tab until it is fixed tabs->removeTab(3); @@ -2785,8 +2804,9 @@ void Control::on_coordShow_stateChanged(int /*i*/) { mMainWindow->updateCoord(); mScene->update(); - setMeasuredAltitude(); // da measured nicht aktualisiert wird, waehrend scale verschoben und show deaktiviert - // und beim aktivieren sonst ein falscher wert zum angezeigten koord waere + setMeasuredAltitude(); // da measured nicht aktualisiert wird, waehrend scale verschoben und show + // deaktiviert und beim aktivieren sonst ein falscher wert zum angezeigten koord + // waere } // mScene->update(); //mScene->sceneRect() // ging auch, aber dann wurde zu oft matrix berechnet etc // mMainWindow->getImageWidget()->update(); // repaint() zeichnet sofort - schneller aber mgl flicker @@ -4000,8 +4020,8 @@ void Control::getXml(QDomElement &elem) } mapNr->setMaximum(colorPlot->getMapItem()->mapNum() - 1); - if(subSubElem.hasAttribute( - "MAP_NUMBER")) // hiermit werden aus map-datenstruktur richtige map angezeigt, daher am ende + if(subSubElem.hasAttribute("MAP_NUMBER")) // hiermit werden aus map-datenstruktur richtige map + // angezeigt, daher am ende { mapNr->setValue(subSubElem.attribute("MAP_NUMBER").toInt()); on_mapNr_valueChanged( @@ -4319,8 +4339,8 @@ void Control::getXml(QDomElement &elem) subSubElem.attribute("ONLY_PEOPLE_LIST").toInt() ? Qt::Checked : Qt::Unchecked); } - // IMPORTANT: reading ONLY_PEOPLE_NR is done in petrack.cpp, as the trajectories need to be loaded - // before! + // IMPORTANT: reading ONLY_PEOPLE_NR is done in petrack.cpp, as the trajectories need to be + // loaded before! if(subSubElem.hasAttribute("SHOW_CURRENT_POINT")) { trackShowCurrentPoint->setCheckState( @@ -4797,4 +4817,18 @@ void Control::expandRange(QColor &fromColor, QColor &toColor, const QColor &clic fromColor.setHsv(fromColorArr[0], fromColorArr[1], fromColorArr[2]); } +void Control::toggleRecoROIButtons() +{ + bool enabled = (!roiFix->isChecked()) && roiShow->isChecked(); + recoRoiAdjustAutomatically->setEnabled(enabled); + recoRoiToFullImageSize->setEnabled(enabled); +} + +void Control::toggleTrackROIButtons() +{ + bool enabled = (!trackRoiFix->isChecked()) && trackRoiShow->isChecked(); + trackRoiAdjustAutomatically->setEnabled(enabled); + trackRoiToFullImageSize->setEnabled(enabled); +} + #include "moc_control.cpp" diff --git a/src/roiItem.cpp b/src/roiItem.cpp index 362db0dbe53ab8c00987d442df25afe9f5815687..92953efd568ce28d193d67b60b1e79b81da2fbf8 100644 --- a/src/roiItem.cpp +++ b/src/roiItem.cpp @@ -340,3 +340,17 @@ void RoiItem::restoreSize() setRect(0, 0, 0, 0); } } + +/** + * @brief Sets the rect to the top left corner of the image and width/height such that it includes the full image. + */ +void RoiItem::setToFullImageSize() +{ + setRect( + -mMainWindow->getImageBorderSize(), + -mMainWindow->getImageBorderSize(), + mMainWindow->getImage()->width(), + mMainWindow->getImage()->height()); + + emit changed(); +} diff --git a/ui/control.ui b/ui/control.ui index a9084034e3cfad9b435c6199e7d45fe9b73491f8..16725d9e54c1202e56f3b4b8e705aef6c14689e3 100644 --- a/ui/control.ui +++ b/ui/control.ui @@ -3675,6 +3675,32 @@ </property> </widget> </item> + <item> + <widget class="QPushButton" name="recoRoiToFullImageSize"> + <property name="enabled"> + <bool>false</bool> + </property> + <property name="toolTip"> + <string>sets the recognition ROI such that it includes the full image</string> + </property> + <property name="text"> + <string>full image</string> + </property> + </widget> + </item> + <item> + <widget class="QPushButton" name="recoRoiAdjustAutomatically"> + <property name="enabled"> + <bool>false</bool> + </property> + <property name="toolTip"> + <string>sets the size of the recognition ROI to: tracking ROI - head size </string> + </property> + <property name="text"> + <string>adjust automatically</string> + </property> + </widget> + </item> </layout> </widget> </item> @@ -5090,6 +5116,32 @@ </property> </widget> </item> + <item> + <widget class="QPushButton" name="trackRoiToFullImageSize"> + <property name="enabled"> + <bool>false</bool> + </property> + <property name="toolTip"> + <string>sets the tracking ROI such that it includes the full image</string> + </property> + <property name="text"> + <string>full image</string> + </property> + </widget> + </item> + <item> + <widget class="QPushButton" name="trackRoiAdjustAutomatically"> + <property name="enabled"> + <bool>false</bool> + </property> + <property name="toolTip"> + <string>sets the size of the tracking ROI to: recogniton ROI + head size </string> + </property> + <property name="text"> + <string>adjust automatically</string> + </property> + </widget> + </item> </layout> </widget> </item>