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
+ 48
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,51 @@ 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, float defaultHeight, BinaryFunction f)
{
if(mIsFixed)
{
return;
}
auto otherTopLeft = other.rect().topLeft();
// Compute head sizes at the four corners to get the offset
auto headSizeTopLeft =
mMainWindow->getImageItem()->getCmPerPixel(otherTopLeft.x(), otherTopLeft.y(), defaultHeight);
auto cmPerPixelTopLeft = (headSizeTopLeft.x() + headSizeTopLeft.y()) / 2.;
auto headSizeBottomLeft = mMainWindow->getImageItem()->getCmPerPixel(
other.rect().bottomLeft().x(), other.rect().bottomLeft().y(), defaultHeight);
auto cmPerPixelBottomLeft = (headSizeBottomLeft.x() + headSizeBottomLeft.y()) / 2.;
auto headSizeTopRight = mMainWindow->getImageItem()->getCmPerPixel(
other.rect().topRight().x(), other.rect().topRight().y(), defaultHeight);
auto cmPerPixelTopRight = (headSizeTopRight.x() + headSizeTopRight.y()) / 2.;
auto headSizeBottomRight = mMainWindow->getImageItem()->getCmPerPixel(
other.rect().bottomRight().x(), other.rect().bottomRight().y(), defaultHeight);
auto cmPerPixelBottomRight = (headSizeBottomRight.x() + headSizeBottomRight.y()) / 2.;
auto offset =
HEAD_SIZE / std::max({cmPerPixelTopLeft, cmPerPixelBottomLeft, cmPerPixelTopRight, cmPerPixelBottomRight});
auto topLeftX = f(otherTopLeft.x(), -offset);
auto topLeftY = f(otherTopLeft.y(), -offset);
setRect(topLeftX, topLeftY, f(other.rect().width(), 2 * offset), f(other.rect().height(), 2 * offset));
emit changed();
}
signals:
void changed();
Loading