Skip to content
Snippets Groups Projects

ROI to full image and adjust to other ROI

Merged Schrödter, Tobias requested to merge 271-region-of-interest into master
All threads resolved!
Files
4
+ 45
2
@@ -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();
Loading