|
|
|
|
@ -3,12 +3,7 @@
|
|
|
|
|
#include "colossusbase.h"
|
|
|
|
|
#include "QPalette"
|
|
|
|
|
#pragma execution_character_set("utf-8")
|
|
|
|
|
/*
|
|
|
|
|
RECTANGLE = 0,
|
|
|
|
|
CIRCLE,
|
|
|
|
|
ELLIPSE,
|
|
|
|
|
POLY
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
bool subDevListSort(const Item_List &info1, const Item_List &info2)
|
|
|
|
|
{
|
|
|
|
|
if (info1.size() < 0 || info2.size() < 0)
|
|
|
|
|
@ -37,7 +32,6 @@ bool subDevListSort(const Item_List &info1, const Item_List &info2)
|
|
|
|
|
|
|
|
|
|
CDsgRoiDlg::CDsgRoiDlg(QWidget *parent) : QDialog(parent), ui(new Ui::RoiDlg)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
m_pDE = NULL;
|
|
|
|
|
m_pTask = NULL;
|
|
|
|
|
|
|
|
|
|
@ -46,36 +40,15 @@ CDsgRoiDlg::CDsgRoiDlg(QWidget *parent) : QDialog(parent), ui(new Ui::RoiDlg)
|
|
|
|
|
SystemStateInfo::rgb = QColor(255, 0, 0).rgb();
|
|
|
|
|
connect(ui->pushButton, SIGNAL(clicked()), this, SLOT(OnOk()));
|
|
|
|
|
connect(ui->pushButton_2, SIGNAL(clicked()), this, SLOT(OnCancel()));
|
|
|
|
|
//connect(ui->pushButton_3, SIGNAL(clicked()), this, SLOT(OnRectangle()));
|
|
|
|
|
connect(ui->pushButton_7, SIGNAL(clicked()), this, SLOT(OnCircle()));
|
|
|
|
|
//connect(ui->pushButton_4, SIGNAL(clicked()), this, SLOT(OnEllipse()));
|
|
|
|
|
connect(ui->pushButton_8, SIGNAL(clicked()), this, SLOT(OnShowColorDlg()));
|
|
|
|
|
ui->pushButton_8->setAutoDefault(false);
|
|
|
|
|
|
|
|
|
|
// connect(ui->pushButton_9, SIGNAL(clicked()), this, SLOT(OnSetItem()));
|
|
|
|
|
|
|
|
|
|
// connect(ui->pushButton_10, SIGNAL(clicked()), this, SLOT(OnMove()));
|
|
|
|
|
// connect(ui->pushButton_11, SIGNAL(clicked()), this, SLOT(OnMove()));
|
|
|
|
|
// connect(ui->pushButton_12, SIGNAL(clicked()), this, SLOT(OnMove()));
|
|
|
|
|
// connect(ui->pushButton_13, SIGNAL(clicked()), this, SLOT(OnMove()));
|
|
|
|
|
|
|
|
|
|
// connect(ui->pushButton_14, SIGNAL(clicked()), this, SLOT(OnSelectImage()));
|
|
|
|
|
// connect(ui->pushButton_15, SIGNAL(clicked()), this, SLOT(OnSnapCameraImage()));
|
|
|
|
|
// connect(ui->pushButton_16, SIGNAL(clicked()), this, SLOT(OnZoomOut()));
|
|
|
|
|
// connect(ui->pushButton_17, SIGNAL(clicked()), this, SLOT(OnZoomIn()));
|
|
|
|
|
|
|
|
|
|
connect(this, SIGNAL(sgShowCameraImage(QImage)), this, SLOT(OnShowCameraImage(QImage)));
|
|
|
|
|
|
|
|
|
|
connect(ui->pushButton_5, SIGNAL(clicked()), this, SLOT(OnShowTenFlag()));
|
|
|
|
|
ui->pushButton_5->setText(QObject::tr("显示定位线"));
|
|
|
|
|
m_pRoiScene = new RoiScene(this);
|
|
|
|
|
//m_pRoiScene->SetRoiDlg(this);
|
|
|
|
|
m_pRoiScene->SetGraphicsView(ui->graphicsView);
|
|
|
|
|
m_pRoiScene->SetInfoLable(ui->label_pixel_info);
|
|
|
|
|
// Qt::WindowFlags flags = Qt::Dialog;
|
|
|
|
|
// flags |= Qt::WindowMinMaxButtonsHint;
|
|
|
|
|
// flags |= Qt::WindowCloseButtonHint;
|
|
|
|
|
// setWindowFlags(flags);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CDsgRoiDlg::~CDsgRoiDlg()
|
|
|
|
|
@ -85,34 +58,36 @@ CDsgRoiDlg::~CDsgRoiDlg()
|
|
|
|
|
delete m_pRoiScene;
|
|
|
|
|
m_pRoiScene = nullptr;
|
|
|
|
|
}
|
|
|
|
|
if (ui)
|
|
|
|
|
{
|
|
|
|
|
delete ui;
|
|
|
|
|
ui = nullptr;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool CDsgRoiDlg::Initialize(IDetectorEngine* pDE, IDetectorAlgorithm* pAlgo, IDetectorTask* pTask)
|
|
|
|
|
{
|
|
|
|
|
if (!pDE || !pAlgo || !pTask)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
m_pDE = pDE;
|
|
|
|
|
m_pTask = pTask;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!InitGraphView())
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool CDsgRoiDlg::InitGraphView()
|
|
|
|
|
{
|
|
|
|
|
ui->pushButton_5->setText(QObject::tr("显示定位线"));
|
|
|
|
|
ui->graphicsView->setUserData(0, (QObjectUserData*)1);
|
|
|
|
|
ui->graphicsView->setScene(m_pRoiScene);
|
|
|
|
|
ui->pushButton_5->setText(QObject::tr("显示定位线"));
|
|
|
|
|
ui->graphicsView->setRenderHint(QPainter::Antialiasing);
|
|
|
|
|
|
|
|
|
|
ui->graphicsView->setResizeAnchor(QGraphicsView::AnchorUnderMouse);
|
|
|
|
|
ui->graphicsView->setTransformationAnchor(QGraphicsView::AnchorUnderMouse);
|
|
|
|
|
m_pRoiScene->updateTenItem(false);
|
|
|
|
|
m_pRoiScene->update();
|
|
|
|
|
if (m_pRoiScene)
|
|
|
|
|
{
|
|
|
|
|
ui->graphicsView->setScene(m_pRoiScene);
|
|
|
|
|
m_pRoiScene->updateTenItem(false);
|
|
|
|
|
m_pRoiScene->update();
|
|
|
|
|
}
|
|
|
|
|
ui->graphicsView->update();
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
@ -120,7 +95,8 @@ bool CDsgRoiDlg::InitGraphView()
|
|
|
|
|
|
|
|
|
|
bool CDsgRoiDlg::OnOk()
|
|
|
|
|
{
|
|
|
|
|
//TODO 检查绑定内容
|
|
|
|
|
if (!m_pRoiScene)
|
|
|
|
|
return false;
|
|
|
|
|
QList<QGraphicsItem *> items = m_pRoiScene->items();
|
|
|
|
|
QList<GraphicsItem *> temp;
|
|
|
|
|
int nSize = items.size();
|
|
|
|
|
@ -172,23 +148,16 @@ void CDsgRoiDlg::OnShowColorDlg()
|
|
|
|
|
return ;
|
|
|
|
|
QString strRGB = QString("(%1,%2,%3)").arg(QString::number(color.red()), QString::number(color.green()), QString::number(color.blue()));
|
|
|
|
|
ui->lineEdit_3->setText(strRGB);
|
|
|
|
|
ui->lineEdit_3->setUserData(0, (QObjectUserData*)color.rgb());
|
|
|
|
|
QString strStyle = QString("background-color:rgba(%1,%2,%3,255);").arg(color.red()).arg(color.green()).arg(color.blue());
|
|
|
|
|
ui->lineEdit_3->setStyleSheet(strStyle);
|
|
|
|
|
SystemStateInfo::rgb = color.rgb();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CDsgRoiDlg::OnShowCameraImage(QImage img)
|
|
|
|
|
{
|
|
|
|
|
m_tempRoiData.img = ColossusBase::QImage2cvMat(img).clone();
|
|
|
|
|
m_pRoiScene->Initialize(m_tempRoiData);
|
|
|
|
|
m_pRoiScene->DisableMenu(false);
|
|
|
|
|
//m_pRoiScene->updateTenItem(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CDsgRoiDlg::OnShowTenFlag()
|
|
|
|
|
{
|
|
|
|
|
if (!m_pRoiScene)
|
|
|
|
|
return;
|
|
|
|
|
QString strtext = ui->pushButton_5->text();
|
|
|
|
|
if (strtext == QObject::tr("显示定位线"))
|
|
|
|
|
{
|
|
|
|
|
@ -202,32 +171,15 @@ void CDsgRoiDlg::OnShowTenFlag()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void __stdcall RoiImageEventHandler(void * callBackOwner, QImage& img, int nDeviceID)
|
|
|
|
|
{
|
|
|
|
|
CDsgRoiDlg* p = (CDsgRoiDlg*)(callBackOwner);
|
|
|
|
|
emit p->sgShowCameraImage(img);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CDsgRoiDlg::OnSnapCameraImage()
|
|
|
|
|
{
|
|
|
|
|
// DeviceType type;
|
|
|
|
|
// IDetectorCameraDevice* pCamera = (IDetectorCameraDevice*)m_pDeviceMgr->GetDevice(m_pTask->GetTaskInfo()->nCameraID, type);
|
|
|
|
|
// if (!pCamera && type != CAMERA)
|
|
|
|
|
// return;
|
|
|
|
|
//
|
|
|
|
|
// pCamera->SnapImage(this, RoiImageEventHandler);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CDsgRoiDlg::OnSelectImage()
|
|
|
|
|
{
|
|
|
|
|
if (!m_pRoiScene)
|
|
|
|
|
return;
|
|
|
|
|
QString strFileName = QFileDialog::getOpenFileName(this, "open file", "", "Images (*.bmp *.png *.xpm *.jpg)");
|
|
|
|
|
if (strFileName.length() > 0)
|
|
|
|
|
{
|
|
|
|
|
std::string strpath = strFileName.toLocal8Bit().toStdString();
|
|
|
|
|
m_tempRoiData.img = cv::imread(strpath/*strFileName.toLocal8Bit().data()*/, CV_LOAD_IMAGE_UNCHANGED);
|
|
|
|
|
// m_tempRoiData.img = cv::imread(strFileName.toLatin1().data());
|
|
|
|
|
// m_pRoiScene->InitShowImage(m_tempRoiData.img);
|
|
|
|
|
|
|
|
|
|
m_tempRoiData.img = cv::imread(strpath, CV_LOAD_IMAGE_UNCHANGED);
|
|
|
|
|
m_pRoiScene->Initialize(m_tempRoiData);
|
|
|
|
|
m_pRoiScene->DisableMenu(false);
|
|
|
|
|
}
|
|
|
|
|
@ -243,34 +195,37 @@ LP_DETECTOR_ROI_DATA CDsgRoiDlg::ShowRoiDlg(LP_DETECTOR_ROI_DATA roiData)
|
|
|
|
|
QColor color(SystemStateInfo::rgb);
|
|
|
|
|
QString strRGB = QString("(%1,%2,%3)").arg(QString::number(color.red()), QString::number(color.green()), QString::number(color.blue()));
|
|
|
|
|
ui->lineEdit_3->setText(strRGB);
|
|
|
|
|
ui->lineEdit_3->setUserData(0, (QObjectUserData*)color.rgb());
|
|
|
|
|
|
|
|
|
|
QString strStyle = QString("background-color:rgba(%1,%2,%3,255);").arg(color.red()).arg(color.green()).arg(color.blue());
|
|
|
|
|
ui->lineEdit_3->setStyleSheet(strStyle);
|
|
|
|
|
|
|
|
|
|
QDesktopWidget* desktop = QApplication::desktop();//
|
|
|
|
|
QDesktopWidget* desktop = QApplication::desktop();
|
|
|
|
|
move((desktop->width() - this->width()) / 2, (desktop->height() - this->height()) / 2);
|
|
|
|
|
|
|
|
|
|
if (this->exec() == QDialog::Accepted)
|
|
|
|
|
{
|
|
|
|
|
FillRoi(m_tempRoiData);
|
|
|
|
|
m_pRoiScene->DisableMenu(true);
|
|
|
|
|
if (m_pRoiScene)
|
|
|
|
|
{
|
|
|
|
|
m_pRoiScene->DisableMenu(true);
|
|
|
|
|
}
|
|
|
|
|
SystemStateInfo::setIni.setValue(QStringLiteral("roi_color"), SystemStateInfo::rgb);
|
|
|
|
|
return m_tempRoiData;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
m_pRoiScene->DisableMenu(true);
|
|
|
|
|
if (m_pRoiScene)
|
|
|
|
|
{
|
|
|
|
|
m_pRoiScene->DisableMenu(true);
|
|
|
|
|
}
|
|
|
|
|
return roiData;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool CDsgRoiDlg::FillRoi(LP_DETECTOR_ROI_DATA& roiData)
|
|
|
|
|
{
|
|
|
|
|
if (!m_pRoiScene)
|
|
|
|
|
return false;
|
|
|
|
|
roiData.records.clear();
|
|
|
|
|
|
|
|
|
|
QList<QGraphicsItem *> items = m_pRoiScene->items();
|
|
|
|
|
|
|
|
|
|
QList<GraphicsItem *> temp;
|
|
|
|
|
|
|
|
|
|
int nSize = items.size();
|
|
|
|
|
for (int i = 0; i < nSize; i++)
|
|
|
|
|
{
|
|
|
|
|
@ -288,189 +243,179 @@ bool CDsgRoiDlg::FillRoi(LP_DETECTOR_ROI_DATA& roiData)
|
|
|
|
|
GraphicsItem *item = temp.at(j);
|
|
|
|
|
Item_List record;
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
Feature_List tItem;
|
|
|
|
|
ItemType type = item->GetType();
|
|
|
|
|
QRectF itemRect = item->mapRectToScene(item->boundingRect());;
|
|
|
|
|
QPointF itemPoint = item->pos() + m_pRoiScene->GetOffSet();
|
|
|
|
|
|
|
|
|
|
switch (type)
|
|
|
|
|
{
|
|
|
|
|
Feature_List tItem;
|
|
|
|
|
ItemType type = item->GetType();
|
|
|
|
|
QRectF itemRect = item->mapRectToScene(item->boundingRect());;
|
|
|
|
|
QPointF itemPoint = item->pos() + m_pRoiScene->GetOffSet();
|
|
|
|
|
|
|
|
|
|
switch (type)
|
|
|
|
|
{
|
|
|
|
|
case GraphicsRect:
|
|
|
|
|
{
|
|
|
|
|
tItem.first = RECTANGLE;
|
|
|
|
|
|
|
|
|
|
if (!roiData.img.empty()){
|
|
|
|
|
if (itemRect.x() < -(roiData.img.cols / 2))
|
|
|
|
|
{
|
|
|
|
|
itemRect.setX(-(roiData.img.cols / 2));
|
|
|
|
|
itemPoint.setX(itemPoint.x() + itemRect.width());
|
|
|
|
|
}
|
|
|
|
|
if (itemRect.y() < -(roiData.img.rows / 2))
|
|
|
|
|
{
|
|
|
|
|
itemRect.setY(-(roiData.img.rows / 2));
|
|
|
|
|
itemPoint.setY(itemPoint.y() + itemRect.width());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (itemRect.x() + itemRect.width() > roiData.img.cols / 2)
|
|
|
|
|
{
|
|
|
|
|
int width = itemRect.width();
|
|
|
|
|
itemRect.setX(roiData.img.cols / 2 - width);
|
|
|
|
|
itemRect.setWidth(width);
|
|
|
|
|
itemPoint.setX(itemPoint.x() - width / 2);
|
|
|
|
|
}
|
|
|
|
|
if (itemRect.y() + itemRect.height() > roiData.img.rows / 2)
|
|
|
|
|
{
|
|
|
|
|
int width = itemRect.height();
|
|
|
|
|
itemRect.setY(roiData.img.rows / 2 - width);
|
|
|
|
|
itemRect.setHeight(width);
|
|
|
|
|
itemPoint.setY(itemPoint.y() - width / 2);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (itemRect.width() > roiData.img.cols / 2 || itemRect.height() > roiData.img.rows / 2)
|
|
|
|
|
{
|
|
|
|
|
itemRect.setWidth(roiData.img.cols);
|
|
|
|
|
itemRect.setHeight(roiData.img.rows);
|
|
|
|
|
itemPoint.setY(roiData.img.rows / 2);
|
|
|
|
|
itemPoint.setX(roiData.img.cols / 2);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
case GraphicsRect:
|
|
|
|
|
{
|
|
|
|
|
tItem.first = RECTANGLE;
|
|
|
|
|
|
|
|
|
|
tItem.second.push_back(itemPoint.x());
|
|
|
|
|
tItem.second.push_back(itemPoint.y());
|
|
|
|
|
tItem.second.push_back(itemRect.width());
|
|
|
|
|
tItem.second.push_back(itemRect.height());
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case GraphicsCircle:
|
|
|
|
|
{
|
|
|
|
|
tItem.first = CIRCLE;
|
|
|
|
|
|
|
|
|
|
if (!roiData.img.empty()){
|
|
|
|
|
if (itemRect.x() < -(roiData.img.cols/2))
|
|
|
|
|
{
|
|
|
|
|
itemRect.setX(-(roiData.img.cols / 2));
|
|
|
|
|
itemPoint.setX(itemPoint.x() + itemRect.width());
|
|
|
|
|
}
|
|
|
|
|
if (itemRect.y() < -(roiData.img.rows / 2))
|
|
|
|
|
{
|
|
|
|
|
itemRect.setY(-(roiData.img.rows / 2));
|
|
|
|
|
itemPoint.setY(itemPoint.y() + itemRect.width());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (itemRect.x()+itemRect.width() > roiData.img.cols / 2)
|
|
|
|
|
{
|
|
|
|
|
int width = itemRect.width();
|
|
|
|
|
itemRect.setX(roiData.img.cols / 2-width);
|
|
|
|
|
itemRect.setWidth(width);
|
|
|
|
|
itemPoint.setX(itemPoint.x() - width / 2);
|
|
|
|
|
}
|
|
|
|
|
if (itemRect.y() + itemRect.width() > roiData.img.rows / 2)
|
|
|
|
|
{
|
|
|
|
|
int width = itemRect.width();
|
|
|
|
|
itemRect.setY(roiData.img.rows / 2-width);
|
|
|
|
|
itemRect.setWidth(width);
|
|
|
|
|
itemPoint.setY(itemPoint.y() - width / 2);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (itemRect.width() > roiData.img.rows/2||itemRect.height()>roiData.img.cols/2)
|
|
|
|
|
{
|
|
|
|
|
int minWidth = 100;
|
|
|
|
|
if (roiData.img.rows > roiData.img.cols)
|
|
|
|
|
minWidth = roiData.img.cols;
|
|
|
|
|
else
|
|
|
|
|
minWidth = roiData.img.rows;
|
|
|
|
|
itemRect.setWidth(minWidth);
|
|
|
|
|
itemRect.setHeight(minWidth);
|
|
|
|
|
itemPoint.setY(roiData.img.rows / 2);
|
|
|
|
|
itemPoint.setX(roiData.img.cols / 2);
|
|
|
|
|
}
|
|
|
|
|
if (!roiData.img.empty()) {
|
|
|
|
|
if (itemRect.x() < -(roiData.img.cols / 2))
|
|
|
|
|
{
|
|
|
|
|
itemRect.setX(-(roiData.img.cols / 2));
|
|
|
|
|
itemPoint.setX(itemPoint.x() + itemRect.width());
|
|
|
|
|
}
|
|
|
|
|
if (itemRect.y() < -(roiData.img.rows / 2))
|
|
|
|
|
{
|
|
|
|
|
itemRect.setY(-(roiData.img.rows / 2));
|
|
|
|
|
itemPoint.setY(itemPoint.y() + itemRect.width());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (itemRect.x() + itemRect.width() > roiData.img.cols / 2)
|
|
|
|
|
{
|
|
|
|
|
int width = itemRect.width();
|
|
|
|
|
itemRect.setX(roiData.img.cols / 2 - width);
|
|
|
|
|
itemRect.setWidth(width);
|
|
|
|
|
itemPoint.setX(itemPoint.x() - width / 2);
|
|
|
|
|
}
|
|
|
|
|
if (itemRect.y() + itemRect.height() > roiData.img.rows / 2)
|
|
|
|
|
{
|
|
|
|
|
int width = itemRect.height();
|
|
|
|
|
itemRect.setY(roiData.img.rows / 2 - width);
|
|
|
|
|
itemRect.setHeight(width);
|
|
|
|
|
itemPoint.setY(itemPoint.y() - width / 2);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
tItem.second.push_back(itemPoint.x());
|
|
|
|
|
tItem.second.push_back(itemPoint.y());
|
|
|
|
|
tItem.second.push_back(itemRect.width() / 2);
|
|
|
|
|
break;
|
|
|
|
|
if (itemRect.width() > roiData.img.cols / 2 || itemRect.height() > roiData.img.rows / 2)
|
|
|
|
|
{
|
|
|
|
|
itemRect.setWidth(roiData.img.cols);
|
|
|
|
|
itemRect.setHeight(roiData.img.rows);
|
|
|
|
|
itemPoint.setY(roiData.img.rows / 2);
|
|
|
|
|
itemPoint.setX(roiData.img.cols / 2);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
case GraphicsEllipse:
|
|
|
|
|
{
|
|
|
|
|
if (!roiData.img.empty()){
|
|
|
|
|
if (itemRect.x() < -(roiData.img.cols / 2))
|
|
|
|
|
{
|
|
|
|
|
itemRect.setX(-(roiData.img.cols / 2));
|
|
|
|
|
itemPoint.setX(itemPoint.x() + itemRect.width());
|
|
|
|
|
}
|
|
|
|
|
if (itemRect.y() < -(roiData.img.rows / 2))
|
|
|
|
|
{
|
|
|
|
|
itemRect.setY(-(roiData.img.rows / 2));
|
|
|
|
|
itemPoint.setY(itemPoint.y() + itemRect.width());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (itemRect.x() + itemRect.width() > roiData.img.cols / 2)
|
|
|
|
|
{
|
|
|
|
|
int width = itemRect.width();
|
|
|
|
|
itemRect.setX(roiData.img.cols / 2 - width);
|
|
|
|
|
itemRect.setWidth(width);
|
|
|
|
|
itemPoint.setX(itemPoint.x() - width / 2);
|
|
|
|
|
}
|
|
|
|
|
if (itemRect.y() + itemRect.height() > roiData.img.rows / 2)
|
|
|
|
|
{
|
|
|
|
|
int width = itemRect.height();
|
|
|
|
|
itemRect.setY(roiData.img.rows / 2 - width);
|
|
|
|
|
itemRect.setHeight(width);
|
|
|
|
|
itemPoint.setY(itemPoint.y() - width / 2);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (itemRect.width() > roiData.img.cols / 2 || itemRect.height() > roiData.img.rows / 2)
|
|
|
|
|
{
|
|
|
|
|
itemRect.setWidth(roiData.img.cols);
|
|
|
|
|
itemRect.setHeight(roiData.img.rows);
|
|
|
|
|
itemPoint.setY(roiData.img.rows / 2);
|
|
|
|
|
itemPoint.setX(roiData.img.cols / 2);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
tItem.second.push_back(itemPoint.x());
|
|
|
|
|
tItem.second.push_back(itemPoint.y());
|
|
|
|
|
tItem.second.push_back(itemRect.width());
|
|
|
|
|
tItem.second.push_back(itemRect.height());
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case GraphicsCircle:
|
|
|
|
|
{
|
|
|
|
|
tItem.first = CIRCLE;
|
|
|
|
|
|
|
|
|
|
if (!roiData.img.empty()) {
|
|
|
|
|
if (itemRect.x() < -(roiData.img.cols / 2))
|
|
|
|
|
{
|
|
|
|
|
itemRect.setX(-(roiData.img.cols / 2));
|
|
|
|
|
itemPoint.setX(itemPoint.x() + itemRect.width());
|
|
|
|
|
}
|
|
|
|
|
if (itemRect.y() < -(roiData.img.rows / 2))
|
|
|
|
|
{
|
|
|
|
|
itemRect.setY(-(roiData.img.rows / 2));
|
|
|
|
|
itemPoint.setY(itemPoint.y() + itemRect.width());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
tItem.first = ELLIPSE;
|
|
|
|
|
tItem.second.push_back(itemPoint.x());
|
|
|
|
|
tItem.second.push_back(itemPoint.y());
|
|
|
|
|
tItem.second.push_back(itemRect.width() / 2);
|
|
|
|
|
tItem.second.push_back(itemRect.height() / 2);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case GraphicsPoly:
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
if (itemRect.x() + itemRect.width() > roiData.img.cols / 2)
|
|
|
|
|
{
|
|
|
|
|
int width = itemRect.width();
|
|
|
|
|
itemRect.setX(roiData.img.cols / 2 - width);
|
|
|
|
|
itemRect.setWidth(width);
|
|
|
|
|
itemPoint.setX(itemPoint.x() - width / 2);
|
|
|
|
|
}
|
|
|
|
|
if (itemRect.y() + itemRect.width() > roiData.img.rows / 2)
|
|
|
|
|
{
|
|
|
|
|
int width = itemRect.width();
|
|
|
|
|
itemRect.setY(roiData.img.rows / 2 - width);
|
|
|
|
|
itemRect.setWidth(width);
|
|
|
|
|
itemPoint.setY(itemPoint.y() - width / 2);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (itemRect.width() > roiData.img.rows / 2 || itemRect.height() > roiData.img.cols / 2)
|
|
|
|
|
{
|
|
|
|
|
int minWidth = 100;
|
|
|
|
|
if (roiData.img.rows > roiData.img.cols)
|
|
|
|
|
minWidth = roiData.img.cols;
|
|
|
|
|
else
|
|
|
|
|
minWidth = roiData.img.rows;
|
|
|
|
|
itemRect.setWidth(minWidth);
|
|
|
|
|
itemRect.setHeight(minWidth);
|
|
|
|
|
itemPoint.setY(roiData.img.rows / 2);
|
|
|
|
|
itemPoint.setX(roiData.img.cols / 2);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
record.push_back(tItem);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tItem.second.push_back(itemPoint.x());
|
|
|
|
|
tItem.second.push_back(itemPoint.y());
|
|
|
|
|
tItem.second.push_back(itemRect.width() / 2);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case GraphicsEllipse:
|
|
|
|
|
{
|
|
|
|
|
if (!roiData.img.empty()) {
|
|
|
|
|
if (itemRect.x() < -(roiData.img.cols / 2))
|
|
|
|
|
{
|
|
|
|
|
itemRect.setX(-(roiData.img.cols / 2));
|
|
|
|
|
itemPoint.setX(itemPoint.x() + itemRect.width());
|
|
|
|
|
}
|
|
|
|
|
if (itemRect.y() < -(roiData.img.rows / 2))
|
|
|
|
|
{
|
|
|
|
|
itemRect.setY(-(roiData.img.rows / 2));
|
|
|
|
|
itemPoint.setY(itemPoint.y() + itemRect.width());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
records.push_back(record);
|
|
|
|
|
if (itemRect.x() + itemRect.width() > roiData.img.cols / 2)
|
|
|
|
|
{
|
|
|
|
|
int width = itemRect.width();
|
|
|
|
|
itemRect.setX(roiData.img.cols / 2 - width);
|
|
|
|
|
itemRect.setWidth(width);
|
|
|
|
|
itemPoint.setX(itemPoint.x() - width / 2);
|
|
|
|
|
}
|
|
|
|
|
if (itemRect.y() + itemRect.height() > roiData.img.rows / 2)
|
|
|
|
|
{
|
|
|
|
|
int width = itemRect.height();
|
|
|
|
|
itemRect.setY(roiData.img.rows / 2 - width);
|
|
|
|
|
itemRect.setHeight(width);
|
|
|
|
|
itemPoint.setY(itemPoint.y() - width / 2);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (itemRect.width() > roiData.img.cols / 2 || itemRect.height() > roiData.img.rows / 2)
|
|
|
|
|
{
|
|
|
|
|
itemRect.setWidth(roiData.img.cols);
|
|
|
|
|
itemRect.setHeight(roiData.img.rows);
|
|
|
|
|
itemPoint.setY(roiData.img.rows / 2);
|
|
|
|
|
itemPoint.setX(roiData.img.cols / 2);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//delete[] lppItem;
|
|
|
|
|
delete item;
|
|
|
|
|
tItem.first = ELLIPSE;
|
|
|
|
|
tItem.second.push_back(itemPoint.x());
|
|
|
|
|
tItem.second.push_back(itemPoint.y());
|
|
|
|
|
tItem.second.push_back(itemRect.width() / 2);
|
|
|
|
|
tItem.second.push_back(itemRect.height() / 2);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case GraphicsPoly:
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
record.push_back(tItem);
|
|
|
|
|
}
|
|
|
|
|
records.push_back(record);
|
|
|
|
|
delete item;
|
|
|
|
|
}
|
|
|
|
|
if (records.size() > 1){
|
|
|
|
|
//排序 ROI最小的放在前面
|
|
|
|
|
qSort(records.begin(), records.end(), subDevListSort);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
roiData.records=records;//
|
|
|
|
|
roiData.records = records;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CDsgRoiDlg::CleanUp()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CDsgRoiDlg::OnMove()
|
|
|
|
|
{
|
|
|
|
|
if (!m_pRoiScene)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (sender()->objectName() == "pushButton_10")
|
|
|
|
|
{
|
|
|
|
|
m_pRoiScene->MoveSelectedItem(LEFT);
|
|
|
|
|
@ -490,87 +435,24 @@ void CDsgRoiDlg::OnMove()
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CDsgRoiDlg::OnSetItem()
|
|
|
|
|
{
|
|
|
|
|
//QList<QGraphicsItem *> items = m_pTaskScene->items();
|
|
|
|
|
|
|
|
|
|
//GraphicsItem *item1;
|
|
|
|
|
//GraphicsItem *item2;
|
|
|
|
|
|
|
|
|
|
//int nSize = items.size();
|
|
|
|
|
//for (int i = 0; i < nSize; i++)
|
|
|
|
|
//{
|
|
|
|
|
// GraphicsItem *item = qgraphicsitem_cast<GraphicsItem*>(items.at(i));
|
|
|
|
|
// if (item && item->GetType() == GraphicsRect)
|
|
|
|
|
// {
|
|
|
|
|
//
|
|
|
|
|
// item1 = item;
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// if (item && item->GetType() == GraphicsCircle)
|
|
|
|
|
// {
|
|
|
|
|
// item2 = item;
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
//QList<QGraphicsItem *> temp1 = item1->collidingItems(Qt::ContainsItemShape);
|
|
|
|
|
// int b = temp1.size();
|
|
|
|
|
|
|
|
|
|
//for (int k = 0; k < b; k++)
|
|
|
|
|
//{
|
|
|
|
|
// int aa = temp1.at(k)->type();
|
|
|
|
|
// int bb = temp1.at(k)->Type;
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
//QList<QGraphicsItem *> temp2 = item2->collidingItems(Qt::ContainsItemShape);
|
|
|
|
|
//int c = temp2.size();
|
|
|
|
|
|
|
|
|
|
//bool bRet1 = item1->collidesWithItem(item2, Qt::ContainsItemShape);
|
|
|
|
|
//bool bRet2 = item2->collidesWithItem(item1, Qt::ContainsItemShape);
|
|
|
|
|
//QPointF pos1 = item1->pos();
|
|
|
|
|
//QPointF pos2 = item2->pos();
|
|
|
|
|
//int a = 0;
|
|
|
|
|
// QPoint pos;
|
|
|
|
|
// QRect size;
|
|
|
|
|
// pos.setX(ui->lineEdit_4->text().toInt() - m_pRoiScene->GetOffSet().x());
|
|
|
|
|
// pos.setY(ui->lineEdit_5->text().toInt() - m_pRoiScene->GetOffSet().y());
|
|
|
|
|
// size.setWidth(ui->lineEdit_6->text().toInt());
|
|
|
|
|
// size.setHeight(ui->lineEdit_7->text().toInt());
|
|
|
|
|
// m_pRoiScene->SetSelectedItem(pos, size);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CDsgRoiDlg::ResetItem(QPoint pos, QRect size)
|
|
|
|
|
{
|
|
|
|
|
// ui->lineEdit_4->clear();
|
|
|
|
|
// ui->lineEdit_5->clear();
|
|
|
|
|
// ui->lineEdit_6->clear();
|
|
|
|
|
// ui->lineEdit_7->clear();
|
|
|
|
|
//
|
|
|
|
|
// ui->lineEdit_4->setText(QString::number(pos.x()));
|
|
|
|
|
// ui->lineEdit_5->setText(QString::number(pos.y()));
|
|
|
|
|
//
|
|
|
|
|
// ui->lineEdit_6->setText(QString::number(size.width()));
|
|
|
|
|
// ui->lineEdit_7->setText(QString::number(size.height()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CDsgRoiDlg::showEvent(QShowEvent *evt)
|
|
|
|
|
{
|
|
|
|
|
if (!m_pRoiScene)
|
|
|
|
|
return;
|
|
|
|
|
m_pRoiScene->Initialize(m_tempRoiData);
|
|
|
|
|
m_pRoiScene->DisableMenu(false);
|
|
|
|
|
|
|
|
|
|
// ui->lineEdit_4->clear();
|
|
|
|
|
// ui->lineEdit_5->clear();
|
|
|
|
|
// ui->lineEdit_6->clear();
|
|
|
|
|
// ui->lineEdit_7->clear();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CDsgRoiDlg::OnZoomIn()
|
|
|
|
|
{
|
|
|
|
|
if (!m_pRoiScene)
|
|
|
|
|
return;
|
|
|
|
|
m_pRoiScene->zoomImage(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CDsgRoiDlg::OnZoomOut()
|
|
|
|
|
{
|
|
|
|
|
if (!m_pRoiScene)
|
|
|
|
|
return;
|
|
|
|
|
m_pRoiScene->zoomImage(false);
|
|
|
|
|
}
|
|
|
|
|
|