#include "ROIPoint.h" ROIPoint::ROIPoint() { using namespace HalconCpp; numHandles = 1; activeHandleIdx = 1; roiType = ROIType::Point; midRow = 0; midCol = 0; } void ROIPoint::createROI(double midX, double midY) { midRow = midY; midCol = midX; updateArrowHandle(); } void ROIPoint::drawROI(HTuple winID, double scaleFactor) { Q_UNUSED(scaleFactor); int width=handleWidth; HObject ho_Rectangle; //DispRectangle2(winID, HTuple(midRow), HTuple(midCol), 0, width, width); GenRectangle2ContourXld(&ho_Rectangle, HTuple(midRow), HTuple(midCol), 0, width, width); DispObj(ho_Rectangle, winID); // if (arrowHandleXLD.IsInitialized()==false) { updateArrowHandle(); } DispObj(arrowHandleXLD, winID); //window.DispRectangle2( row2, col2, 0, 5, 5); HObject ho_Cross; GenCrossContourXld(&ho_Cross, midRow, midCol, 40, 0); DispObj(ho_Cross, winID); //DispCircle(winID, midRow, midCol, 20); HObject ho_ContCircle; GenCircleContourXld(&ho_ContCircle, midRow, midCol, 20, 0, 6.28318, "positive", 1); DispObj(ho_ContCircle, winID); } double ROIPoint::distToClosestHandle(double x, double y) { double max = 10000; double val[3] = {0}; val[0] = HMisc::DistancePp(y, x, midRow, midCol); // upper left for (int i = 0; i < numHandles; i++) { if (val[i] < max) { max = val[i]; activeHandleIdx = i; } }// end of for return val[activeHandleIdx]; } void ROIPoint::displayActive(HTuple winID, double scaleFactor) { Q_UNUSED(scaleFactor); HObject ho_Rectangle; int width=handleWidth; switch (activeHandleIdx) { case 0: //DispRectangle2(winID, HTuple(midRow), HTuple(midCol), 0, width / 2, width / 2 ); GenRectangle2ContourXld(&ho_Rectangle, HTuple(midRow), HTuple(midCol), 0, width / 2, width / 2); DispObj(ho_Rectangle, winID); break; case 1: DispObj(arrowHandleXLD, winID); //window.DispRectangle2(row2, col2, 0, 5, 5); break; } } void ROIPoint::moveByHandle(double newX, double newY) { switch (activeHandleIdx) { case 0: // first end point midRow = newY; midCol = newX; break; } updateArrowHandle(); } QCursor ROIPoint::showByHandle() { QCursor cursor; cursor = Qt::SizeBDiagCursor; return cursor; } HRegion ROIPoint::getRegion() { HRegion region; region.GenRectangle2((midRow), (midCol),0.0 , (handleWidth), (handleWidth)); return region; } HTuple ROIPoint::getROIData() { HTuple dat; dat.Clear(); dat[0] = midRow; dat[1] = midCol; return dat; } void ROIPoint::setROIData(HTuple dat) { if (dat.TupleLength() == 2) { midRow = dat[0]; midCol = dat[1]; } } void ROIPoint::save(QDataStream& dataStream) { ROI::save(dataStream); int paranum;//参数数量 paranum = 3; dataStream << paranum;//先保存参数数量 dataStream << (int)1 << midRow; dataStream << (int)2 << midCol; dataStream << (int)3 << m_strTitle; } void ROIPoint::load(QDataStream& dataStream) { ROI::load(dataStream); int paranum;//参数数量 int para; dataStream >> paranum;//读取参数数量 for (int i = 0; i < paranum; i++) { dataStream >> para; switch (para) { case 1: dataStream >> midRow; break; case 2: dataStream >> midCol; break; case 3: dataStream >> m_strTitle; break; default: { qWarning() << "配置文档错误!"; } break; } } } void ROIPoint::updateArrowHandle() { using namespace HalconCpp; arrowHandleXLD.GenEmptyObj(); //GenRectangle2(&arrowHandleXLD, HTuple(midRow),HTuple(midCol), 0, handleWidth, handleWidth); GenCrossContourXld(&arrowHandleXLD, HTuple(midRow), HTuple(midCol), handleWidth * 2, 0); }