#include "stdafx.h" #include "CutDotProcess.h" #include "VisionRecipe.h" #include "VisionBufferPro.h" #include "FileRecipe.h" CCutDotProcess::CCutDotProcess(){ /* code */ m_poseType = 0; m_eDir = DIMENSION_NONE; m_id = 0; m_nUse = 0; m_strName.Format(_T("P%d"), m_id); m_nPosX = 0; m_nPosY = 0; m_nEdgeThres = 120; m_nInc = 0; m_nMin = 0; m_nMax = 0; m_distResult = 0.0f; } CCutDotProcess::CCutDotProcess(DimensionDir eDir, int id) { /* code */ m_poseType = 0; m_eDir = eDir; m_id = id; m_nUse = 0; switch (eDir) { case GLOBAL_DEFINE::DIMENSION_A: m_strName.Format(_T("TopA_L%d"), m_id); break; case GLOBAL_DEFINE::DIMENSION_B: m_strName.Format(_T("TopB_L%d"), m_id); break; case GLOBAL_DEFINE::DIMENSION_C: m_strName.Format(_T("TopC_L%d"), m_id); break; case GLOBAL_DEFINE::DIMENSION_D: m_strName.Format(_T("TopD_L%d"), m_id); break; case GLOBAL_DEFINE::DIMENSION_A_DN: m_strName.Format(_T("BotA_L%d"), m_id); break; case GLOBAL_DEFINE::DIMENSION_B_DN: m_strName.Format(_T("BotB_L%d"), m_id); break; case GLOBAL_DEFINE::DIMENSION_C_DN: m_strName.Format(_T("BotC_L%d"), m_id); break; case GLOBAL_DEFINE::DIMENSION_D_DN: m_strName.Format(_T("BotD_L%d"), m_id); break; case GLOBAL_DEFINE::DIMENSION_NONE: m_strName.Format(_T("P_L%d"), m_id); break; default: m_strName.Format(_T("P_Cut_Dot%d"), m_id); break; } m_nPosX = 0; m_nPosY = 0; m_nEdgeThres = 120; m_nInc = 0; m_nMin = 0; m_nMax = 0; m_distResult = 0.0f; } CCutDotProcess::~CCutDotProcess(){ /* code */ } int CCutDotProcess::Execute(DimensionDir eDir, Point2I offset) { /* code */ m_nNgInfo.clear(); m_ptNearResult.x = 0.0f; m_ptNearResult.y = 0.0f; m_ptMeasureResult.x = 0.0f; m_ptMeasureResult.y = 0.0f; m_distResult = 0.0f; if (1 != m_nUse) return 0; if (0 == m_nPosX && 0 == m_nPosY) return 0; //1. »ñÈ¡½âÊÍ¶È getMmvsp(eDir); //2. ²éÕÒleft if (!FindLeftLine(eDir, offset)) return -1; //3. ½á¹ûÅÐ¶Ï judgeResult(); return 0; } bool CCutDotProcess::FindLeftLine(DimensionDir eDir, Point2I offset) { /* code */ CBlSideData *pSideData = CVisionRecipe::getInstance()->getSideData(m_eDir); if (NULL == pSideData) return false; if (0 == m_poseType) { if (!pSideData->m_bTopMark_Find) return false; if (!pSideData->m_bBotMark_Find) return false; } else { if (!pSideData->m_bTopPoint_Find) return false; if (!pSideData->m_bBotPoint_Find) return false; } Point2I ptOffset; ptOffset.x = -1 * m_nPosX; ptOffset.y = m_nPosY; Point2I result; if (!CVisionBufferPro::TransformToReal(m_eDir, ptOffset, m_poseType, result)) return false; m_locPointResult = result; double fzSearchRange = 500.0f; int nSearchRange = (int)(fzSearchRange / pSideData->m_dPixelSizeX); Point2I cutResult; if (!CVisionBufferPro::findCutLine(m_eDir, result, nSearchRange, m_nEdgeThres, cutResult)) return false; m_ptMeasureResult.x = cutResult.x; m_ptMeasureResult.y = cutResult.y; m_ptNearResult = m_ptMeasureResult; Line2D line; line.pt0.x = 0.0f; // m_Points[0].x; line.pt0.y = 0.0f; // m_Points[0].y; line.pt1.x = m_xMmvsp * (m_Points[1].x - m_Points[0].x); line.pt1.y = m_yMmvsp * (m_Points[1].y - m_Points[0].y); Point2D ptEdge; ptEdge.x = m_xMmvsp * (m_ptMeasureResult.x - m_Points[0].x); ptEdge.y = m_yMmvsp * (m_ptMeasureResult.y - m_Points[0].y); Point2D pose = ClsVision::ProjectionPL(ptEdge, line); Point2D posProject; posProject.x = m_Points[0].x + pose.x / pSideData->m_dPixelSizeX; posProject.y = m_Points[0].y + pose.y / pSideData->m_dPixelSizeY; if (nullptr != pSideData) { //ÇøÓòµÄÏÔʾ½á¹û DispVisionResult inf; inf.nType = 3; inf.eDir = (int)(m_eDir); inf.strName = m_strName; inf.eVision = (int)(VISION_CUT); inf.rectX1 = (int)(cutResult.x); inf.rectY1 = (int)(cutResult.y); inf.rectX2 = (int)(posProject.x); inf.rectY2 = (int)(posProject.y); pSideData->m_vDispVisionResult.push_back(inf); } return true; } int CCutDotProcess::getID(void) { /* code */ return m_id; } void CCutDotProcess::getMmvsp(DimensionDir eDir) { /* code */ CBlSideData *pSideData = CVisionRecipe::getInstance()->getSideData(eDir); m_xMmvsp = pSideData->m_dPixelSizeX; m_yMmvsp = pSideData->m_dPixelSizeY; } void CCutDotProcess::judgeResult(void) { /* code */ m_nNgInfo.clear(); CBlSideData* pSideData = CVisionRecipe::getInstance()->getSideData(m_eDir); if (NULL == pSideData) return; if (NULL != pSideData) { DispVisionResult inf; inf.nType = 4; inf.eDir = (int)(m_eDir); inf.strName = m_strName; inf.eVision = (int)(VISION_CUT); inf.pointX = (int)(m_ptMeasureResult.x); inf.pointY = (int)(m_ptMeasureResult.y); pSideData->m_vDispVisionResult.push_back(inf); } NgDotInfo ng; ng.eDir = m_eDir; ng.id = m_id; ng.isRes = true; ng.minValue = m_nMin; ng.maxValue = m_nMax; ng.strName = m_strName; ng.ngType = DefectLoc_OK; //ȱÏÝÀàÐÍ ng.eVision = VISION_KDIST; ng.xPosPxl = m_locPointResult.x; ng.yPosPxl = m_locPointResult.y; ng.xResult = 0.0f; ng.yResult = 0.0f; ng.x1 = m_locPointResult.x - 40; ng.y1 = m_locPointResult.y - 20; ng.x2 = m_locPointResult.x + 40; ng.y2 = m_locPointResult.y + 20; ng.ngType = DefectLoc_Dist_Cut; Line2D line; line.pt0.x = 0.0f; // m_Points[0].x; line.pt0.y = 0.0f; // m_Points[0].y; line.pt1.x = m_xMmvsp * (m_Points[1].x - m_Points[0].x); line.pt1.y = m_yMmvsp * (m_Points[1].y - m_Points[0].y); Point2D ptEdge; ptEdge.x = m_xMmvsp * (m_ptMeasureResult.x - m_Points[0].x); ptEdge.y = m_yMmvsp * (m_ptMeasureResult.y - m_Points[0].y); Point2D pose = ClsVision::ProjectionPL(ptEdge, line); double dx = (ptEdge.x - pose.x); double dy = (ptEdge.y - pose.y); m_distResult = sqrt(dx * dx + dy * dy); m_distResult += m_nInc; ng.result = m_distResult; if (m_nMax < 0.5) { m_nNgInfo.push_back(ng); return; } double dDist = m_distResult - abs(m_nPosX); if (dDist < m_nMin || dDist > m_nMax) { ng.isRes = false; } m_nNgInfo.push_back(ng); } void CCutDotProcess::setPoint(Point2I pose, int nType) { /* code */ if (0 == nType) { m_Points[0] = pose; } else if (1 == nType) { m_Points[1] = pose; } } Json::Value CCutDotProcess::WriteToJson(void) { /* code */ std::string strName = CFileRecipe::toString(m_strName); Json::Value jsValue; jsValue["alg type"] = CUT_VISION_TYPE; jsValue["side"] = (int)(m_eDir); jsValue["id"] = m_id; jsValue["name"] = strName; jsValue["use"] = m_nUse; jsValue["pos x"] = m_nPosX; jsValue["pos y"] = m_nPosY; jsValue["inc"] = m_nInc; jsValue["min"] = m_nMin; jsValue["max"] = m_nMax; jsValue["pos type"] = m_poseType; jsValue["line thres"] = m_nEdgeThres; return jsValue; } void CCutDotProcess::DecodeJson(Json::Value &jsValue) { /* code */ int num = (int)(jsValue.size()); if (num < 1) return; //1. side std::string strName = "side"; if (jsValue.isMember(strName.c_str()) && jsValue[strName.c_str()].isInt()) { m_eDir = (DimensionDir)(jsValue[strName.c_str()].asInt()); } //2. id strName = "id"; if (jsValue.isMember(strName.c_str()) && jsValue[strName.c_str()].isInt()) { m_id = jsValue[strName.c_str()].asInt(); } //3. name strName = "name"; if (jsValue.isMember(strName.c_str()) && jsValue[strName.c_str()].isString()) { m_strName = CFileRecipe::toCString(jsValue[strName.c_str()].asString()); } //4. use strName = "use"; if (jsValue.isMember(strName.c_str()) && jsValue[strName.c_str()].isInt()) { m_nUse = jsValue[strName.c_str()].asInt(); } //5. pos x strName = "pos x"; if (jsValue.isMember(strName.c_str()) && jsValue[strName.c_str()].isInt()) { m_nPosX = jsValue[strName.c_str()].asInt(); } //6. pos y strName = "pos y"; if (jsValue.isMember(strName.c_str()) && jsValue[strName.c_str()].isInt()) { m_nPosY = jsValue[strName.c_str()].asInt(); } //7. inc strName = "inc"; if (jsValue.isMember(strName.c_str()) && jsValue[strName.c_str()].isInt()) { m_nInc = jsValue[strName.c_str()].asInt(); } //8. min strName = "min"; if (jsValue.isMember(strName.c_str()) && jsValue[strName.c_str()].isInt()) { m_nMin = jsValue[strName.c_str()].asInt(); } //9. max strName = "max"; if (jsValue.isMember(strName.c_str()) && jsValue[strName.c_str()].isInt()) { m_nMax = jsValue[strName.c_str()].asInt(); } //10. pos type strName = "pos type"; if (jsValue.isMember(strName.c_str()) && jsValue[strName.c_str()].isInt()) { m_poseType = jsValue[strName.c_str()].asInt(); } //11. line width strName = "line thres"; if (jsValue.isMember(strName.c_str()) && jsValue[strName.c_str()].isInt()) { m_nEdgeThres = jsValue[strName.c_str()].asInt(); } }