|
|
|
|
@ -1,13 +1,9 @@
|
|
|
|
|
#include "RoiImgViewer.h"
|
|
|
|
|
#include <QDebug>
|
|
|
|
|
//#include "qtUtils.h"
|
|
|
|
|
#include <algorithm>
|
|
|
|
|
#include <QDateTime>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//#define DEBUG_PRINT
|
|
|
|
|
|
|
|
|
|
RoiImgViewer::RoiImgViewer(QWidget* parent /*= 0*/)
|
|
|
|
|
RoiImgViewer::RoiImgViewer(QWidget* parent /*= 0*/)
|
|
|
|
|
: lpImgViewer(parent)
|
|
|
|
|
, mMouseCaptureStatus(MouseCaptureNone)
|
|
|
|
|
, mDrawStatus(DrawNone)
|
|
|
|
|
@ -15,12 +11,12 @@
|
|
|
|
|
, mpDrawingLineItem(NULL)
|
|
|
|
|
, mpDrawingRectItem(NULL)
|
|
|
|
|
, mpSelectedRoiNode(NULL)
|
|
|
|
|
{
|
|
|
|
|
{
|
|
|
|
|
connect(scene(), SIGNAL(selectionChanged()), this, SLOT(updateSelectedRoiNode()));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QGraphicsPixmapItem* RoiImgViewer::setImg(QImage& img)
|
|
|
|
|
{
|
|
|
|
|
QGraphicsPixmapItem* RoiImgViewer::setImg(QImage& img)
|
|
|
|
|
{
|
|
|
|
|
if (lpImgViewer::setImg(img))
|
|
|
|
|
{
|
|
|
|
|
mpImgItem->setFlag(QGraphicsItem::ItemIsMovable, false);
|
|
|
|
|
@ -30,10 +26,10 @@
|
|
|
|
|
{
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QGraphicsItem* RoiImgViewer::firstSelectedItem()
|
|
|
|
|
{
|
|
|
|
|
QGraphicsItem* RoiImgViewer::firstSelectedItem()
|
|
|
|
|
{
|
|
|
|
|
auto selectedItemList = scene()->selectedItems();
|
|
|
|
|
if (selectedItemList.size())
|
|
|
|
|
{
|
|
|
|
|
@ -43,10 +39,10 @@
|
|
|
|
|
{
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void RoiImgViewer::setDrawStatus(DrawStatus s)
|
|
|
|
|
{
|
|
|
|
|
void RoiImgViewer::setDrawStatus(DrawStatus s)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
mDrawStatus = s;
|
|
|
|
|
// if(mpImgItem){
|
|
|
|
|
@ -59,10 +55,10 @@
|
|
|
|
|
// printf("RoiImgViewer::setDrawStatus false\n");
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void RoiImgViewer::clearRois(int type /*= -1*/)
|
|
|
|
|
{
|
|
|
|
|
void RoiImgViewer::clearRois(int type /*= -1*/)
|
|
|
|
|
{
|
|
|
|
|
QGraphicsScene* pScene = scene();
|
|
|
|
|
if (type < 0)
|
|
|
|
|
{
|
|
|
|
|
@ -97,10 +93,10 @@
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
rejectDrawingItem();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void RoiImgViewer::clearExistRois()
|
|
|
|
|
{
|
|
|
|
|
void RoiImgViewer::clearExistRois()
|
|
|
|
|
{
|
|
|
|
|
QGraphicsScene* pScene = scene();
|
|
|
|
|
|
|
|
|
|
foreach(auto itemList, mRoiItemMap)
|
|
|
|
|
@ -114,10 +110,10 @@
|
|
|
|
|
mRoiItemMap.clear();
|
|
|
|
|
mRoiNodeList.clear();
|
|
|
|
|
mpSelectedRoiNode = NULL;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void RoiImgViewer::addRoiRect(QRectF rect, qreal scale, QString channelName, QString id, bool isTemplate /*= true*/, QColor nonTmplColor /*= Qt::yellow*/)
|
|
|
|
|
{
|
|
|
|
|
void RoiImgViewer::addRoiRect(QRectF rect, qreal scale, QString channelName, QString id, bool isTemplate /*= true*/, QColor nonTmplColor /*= Qt::yellow*/)
|
|
|
|
|
{
|
|
|
|
|
DrawStatus backupDrawStatus = mDrawStatus;
|
|
|
|
|
QString backupChannelName = getChannel();
|
|
|
|
|
|
|
|
|
|
@ -142,10 +138,10 @@
|
|
|
|
|
|
|
|
|
|
mDrawStatus = backupDrawStatus;
|
|
|
|
|
setChannel(backupChannelName);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void RoiImgViewer::addRoiRect(QRectF rect, qreal scale, QString id)
|
|
|
|
|
{
|
|
|
|
|
void RoiImgViewer::addRoiRect(QRectF rect, qreal scale, QString id)
|
|
|
|
|
{
|
|
|
|
|
setDrawStatus(DrawRect);
|
|
|
|
|
// QPolygonF qrect = mapToScene(rect.toRect());
|
|
|
|
|
// mDrawingRect = qrect.boundingRect();
|
|
|
|
|
@ -155,10 +151,10 @@
|
|
|
|
|
//setFixedSizeScale(scale);
|
|
|
|
|
acceptDrawingItem();
|
|
|
|
|
lastRectRoi()->id = id;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void RoiImgViewer::addRoiLine(QLineF line, QString id)
|
|
|
|
|
{
|
|
|
|
|
void RoiImgViewer::addRoiLine(QLineF line, QString id)
|
|
|
|
|
{
|
|
|
|
|
setDrawStatus(DrawLine);
|
|
|
|
|
mDrawingLine = line;
|
|
|
|
|
createDrawingItem();
|
|
|
|
|
@ -166,10 +162,10 @@
|
|
|
|
|
acceptDrawingItem();
|
|
|
|
|
//lastRectRoi()->id = id;
|
|
|
|
|
setDrawStatus(DrawNone);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LP_ROI_NODE* RoiImgViewer::lastRectRoi()
|
|
|
|
|
{
|
|
|
|
|
LP_ROI_NODE* RoiImgViewer::lastRectRoi()
|
|
|
|
|
{
|
|
|
|
|
if (mRoiNodeList.size())
|
|
|
|
|
{
|
|
|
|
|
return &mRoiNodeList.last();
|
|
|
|
|
@ -178,10 +174,10 @@
|
|
|
|
|
{
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void RoiImgViewer::mousePressEvent(QMouseEvent *event)
|
|
|
|
|
{
|
|
|
|
|
void RoiImgViewer::mousePressEvent(QMouseEvent *event)
|
|
|
|
|
{
|
|
|
|
|
QGraphicsItem* pItem = firstSelectedItem();
|
|
|
|
|
if (!pItem)
|
|
|
|
|
{
|
|
|
|
|
@ -257,10 +253,10 @@
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
lpImgViewer::mousePressEvent(event);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void RoiImgViewer::mouseMoveEvent(QMouseEvent *evt)
|
|
|
|
|
{
|
|
|
|
|
void RoiImgViewer::mouseMoveEvent(QMouseEvent *evt)
|
|
|
|
|
{
|
|
|
|
|
lpImgViewer::mouseMoveEvent(evt);
|
|
|
|
|
|
|
|
|
|
QGraphicsItem* pItem = dynamic_cast<QGraphicsItem*>(
|
|
|
|
|
@ -356,10 +352,10 @@
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void RoiImgViewer::mouseReleaseEvent(QMouseEvent *event)
|
|
|
|
|
{
|
|
|
|
|
void RoiImgViewer::mouseReleaseEvent(QMouseEvent *event)
|
|
|
|
|
{
|
|
|
|
|
if (event->button() == Qt::LeftButton)
|
|
|
|
|
{
|
|
|
|
|
mMouseCaptureStatus = MouseCaptureNone;
|
|
|
|
|
@ -406,10 +402,10 @@
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
lpImgViewer::mouseReleaseEvent(event);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void RoiImgViewer::wheelEvent(QWheelEvent *evt)
|
|
|
|
|
{
|
|
|
|
|
void RoiImgViewer::wheelEvent(QWheelEvent *evt)
|
|
|
|
|
{
|
|
|
|
|
lpImgViewer::wheelEvent(evt);
|
|
|
|
|
|
|
|
|
|
if (!mpSelectedRoiNode)
|
|
|
|
|
@ -418,10 +414,10 @@
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
mpSelectedRoiNode->fScale = mFixedSizeScale;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void RoiImgViewer::keyPressEvent(QKeyEvent *event)
|
|
|
|
|
{
|
|
|
|
|
void RoiImgViewer::keyPressEvent(QKeyEvent *event)
|
|
|
|
|
{
|
|
|
|
|
if (mpSelectedRoiNode && Qt::Key_Delete == event->key()) {
|
|
|
|
|
QGraphicsScene* pScene = scene();
|
|
|
|
|
|
|
|
|
|
@ -451,15 +447,15 @@
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QRectF extRect(const QRectF& r, float w)
|
|
|
|
|
{
|
|
|
|
|
QRectF extRect(const QRectF& r, float w)
|
|
|
|
|
{
|
|
|
|
|
return QRectF(r.x() - w, r.y() - w, r.width() + 2.0 * w, r.height() + 2.0*w);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
RoiImgViewer::MouseCaptureStatus RoiImgViewer::decideMouseCaptureStatus(const QRectF r, QPointF p, float capDis /*= 10*/)
|
|
|
|
|
{
|
|
|
|
|
RoiImgViewer::MouseCaptureStatus RoiImgViewer::decideMouseCaptureStatus(const QRectF r, QPointF p, float capDis /*= 10*/)
|
|
|
|
|
{
|
|
|
|
|
MouseCaptureStatus ret = MouseCaptureNone;
|
|
|
|
|
|
|
|
|
|
QRectF validRect = extRect(r, capDis);
|
|
|
|
|
@ -486,15 +482,15 @@
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
RoiImgViewer::MouseCaptureStatus RoiImgViewer::decideMouseCaptureStatus(const QLineF l, QPointF p, float capDis /*= 10*/)
|
|
|
|
|
{
|
|
|
|
|
RoiImgViewer::MouseCaptureStatus RoiImgViewer::decideMouseCaptureStatus(const QLineF l, QPointF p, float capDis /*= 10*/)
|
|
|
|
|
{
|
|
|
|
|
return MouseCaptureNone;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void RoiImgViewer::updateSelectedRoiNode()
|
|
|
|
|
{
|
|
|
|
|
void RoiImgViewer::updateSelectedRoiNode()
|
|
|
|
|
{
|
|
|
|
|
QGraphicsItem* pItem = firstSelectedItem();
|
|
|
|
|
|
|
|
|
|
LP_ROI_NODE *pRoiNode = findRoiNode(pItem);
|
|
|
|
|
@ -503,10 +499,10 @@
|
|
|
|
|
mpSelectedRoiNode = pRoiNode;
|
|
|
|
|
emit roiSelectionChanged(mpSelectedRoiNode);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void RoiImgViewer::updateDrawingItem()
|
|
|
|
|
{
|
|
|
|
|
void RoiImgViewer::updateDrawingItem()
|
|
|
|
|
{
|
|
|
|
|
switch (mDrawStatus)
|
|
|
|
|
{
|
|
|
|
|
case DrawLine:
|
|
|
|
|
@ -540,10 +536,10 @@
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void RoiImgViewer::createDrawingItem()
|
|
|
|
|
{
|
|
|
|
|
void RoiImgViewer::createDrawingItem()
|
|
|
|
|
{
|
|
|
|
|
switch (mDrawStatus)
|
|
|
|
|
{
|
|
|
|
|
case DrawLine:
|
|
|
|
|
@ -571,10 +567,10 @@
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void RoiImgViewer::acceptDrawingItem()
|
|
|
|
|
{
|
|
|
|
|
void RoiImgViewer::acceptDrawingItem()
|
|
|
|
|
{
|
|
|
|
|
//clearExistRois();
|
|
|
|
|
switch (mDrawStatus)
|
|
|
|
|
{
|
|
|
|
|
@ -595,10 +591,10 @@
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void RoiImgViewer::rejectDrawingItem()
|
|
|
|
|
{
|
|
|
|
|
void RoiImgViewer::rejectDrawingItem()
|
|
|
|
|
{
|
|
|
|
|
switch (mDrawStatus)
|
|
|
|
|
{
|
|
|
|
|
case DrawLine:
|
|
|
|
|
@ -612,16 +608,16 @@
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void RoiImgViewer::resetAllDrawingItems()
|
|
|
|
|
{
|
|
|
|
|
void RoiImgViewer::resetAllDrawingItems()
|
|
|
|
|
{
|
|
|
|
|
mpDrawingLineItem = NULL;
|
|
|
|
|
mpDrawingRectItem = NULL;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void RoiImgViewer::acceptRoiItem(QGraphicsItem* pItem)
|
|
|
|
|
{
|
|
|
|
|
void RoiImgViewer::acceptRoiItem(QGraphicsItem* pItem)
|
|
|
|
|
{
|
|
|
|
|
int type = pItem->type();
|
|
|
|
|
if (mRoiItemMap.contains(type))
|
|
|
|
|
{
|
|
|
|
|
@ -649,10 +645,10 @@
|
|
|
|
|
mRoiNodeList.append(roi_node);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LP_ROI_NODE* RoiImgViewer::findRoiNode(QGraphicsItem* pItem)
|
|
|
|
|
{
|
|
|
|
|
LP_ROI_NODE* RoiImgViewer::findRoiNode(QGraphicsItem* pItem)
|
|
|
|
|
{
|
|
|
|
|
auto i = std::find_if(mRoiNodeList.begin(), mRoiNodeList.end(), [&](LP_ROI_NODE& roiNode)
|
|
|
|
|
{
|
|
|
|
|
return roiNode.pItem == pItem;
|
|
|
|
|
@ -665,6 +661,6 @@
|
|
|
|
|
{
|
|
|
|
|
return &(*i);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|