diff --git a/sourceCode/BQ_workpieceCornerExtraction.cpp b/sourceCode/BQ_workpieceCornerExtraction.cpp index 6aebc31..5aaa912 100644 --- a/sourceCode/BQ_workpieceCornerExtraction.cpp +++ b/sourceCode/BQ_workpieceCornerExtraction.cpp @@ -410,8 +410,18 @@ SSX_BQworkpieceResult sx_BQ_getWorkpieceCorners( SVzNL3DPoint firstPt = region[0].edge[0]; SVzNL3DPoint lastPt = region[0].edge.back(); int idx0 = _getPointClosestContour(v_trees, true, firstPt, scanLines, true); + if (idx0 < 0) + { + *errCode = SX_ERR_INVLD_CLOSES_PT; + return; + } _getEdgeLinkingContour(&v_trees[idx0], true, firstPt, region[0].edgeLink_1, scanLines, true, workpieceParam.lineLen); int idx1 = _getPointClosestContour(v_trees, true, lastPt, scanLines, true); + if (idx1 < 0) + { + *errCode = SX_ERR_INVLD_CLOSES_PT; + return; + } _getEdgeLinkingContour(&v_trees[idx1], true, lastPt, region[0].edgeLink_2, scanLines, true, workpieceParam.lineLen); if ((region[0].edgeLink_1.size() < 5) || (region[0].edgeLink_2.size() < 5)) { @@ -425,8 +435,18 @@ SSX_BQworkpieceResult sx_BQ_getWorkpieceCorners( firstPt = region[1].edge[0]; lastPt = region[1].edge.back(); idx0 = _getPointClosestContour(h_trees, false, firstPt, scanLines, true); + if (idx0 < 0) + { + *errCode = SX_ERR_INVLD_CLOSES_PT; + return; + } _getEdgeLinkingContour(&h_trees[idx0], false, firstPt, region[1].edgeLink_1, scanLines, true, workpieceParam.lineLen); idx1 = _getPointClosestContour(h_trees, false, lastPt, scanLines, true); + if (idx1 < 0) + { + *errCode = SX_ERR_INVLD_CLOSES_PT; + return; + } _getEdgeLinkingContour(&h_trees[idx1], false, lastPt, region[1].edgeLink_2, scanLines, true, workpieceParam.lineLen); if ((region[1].edgeLink_1.size() < 5) || (region[1].edgeLink_2.size() < 5)) { @@ -439,8 +459,18 @@ SSX_BQworkpieceResult sx_BQ_getWorkpieceCorners( firstPt = region[2].edge[0]; lastPt = region[2].edge.back(); idx0 = _getPointClosestContour(v_trees, true, firstPt, scanLines, false); + if (idx0 < 0) + { + *errCode = SX_ERR_INVLD_CLOSES_PT; + return; + } _getEdgeLinkingContour(&v_trees[idx0], true, firstPt, region[2].edgeLink_1, scanLines, false, workpieceParam.lineLen); idx1 = _getPointClosestContour(v_trees, true, lastPt, scanLines, false); + if (idx1 < 0) + { + *errCode = SX_ERR_INVLD_CLOSES_PT; + return; + } _getEdgeLinkingContour(&v_trees[idx1], true, lastPt, region[2].edgeLink_2, scanLines, false, workpieceParam.lineLen); if ((region[2].edgeLink_1.size() < 5) || (region[2].edgeLink_2.size() < 5)) { @@ -453,8 +483,18 @@ SSX_BQworkpieceResult sx_BQ_getWorkpieceCorners( firstPt = region[3].edge[0]; lastPt = region[3].edge.back(); idx0 = _getPointClosestContour(h_trees, false, firstPt, scanLines, true); + if (idx0 < 0) + { + *errCode = SX_ERR_INVLD_CLOSES_PT; + return; + } _getEdgeLinkingContour(&h_trees[idx0], false, firstPt, region[3].edgeLink_1, scanLines, false, workpieceParam.lineLen); idx1 = _getPointClosestContour(h_trees, false, lastPt, scanLines, true); + if (idx1 < 0) + { + *errCode = SX_ERR_INVLD_CLOSES_PT; + return; + } _getEdgeLinkingContour(&h_trees[idx1], false, lastPt, region[3].edgeLink_2, scanLines, false, workpieceParam.lineLen); if ((region[3].edgeLink_1.size() < 5) || (region[3].edgeLink_2.size() < 5)) { diff --git a/sourceCode/SG_errCode.h b/sourceCode/SG_errCode.h index e61d36e..a35b02a 100644 --- a/sourceCode/SG_errCode.h +++ b/sourceCode/SG_errCode.h @@ -10,4 +10,5 @@ //BQ_workpiece #define SX_ERR_INVLD_VTREE_NUM -2001 #define SX_ERR_INVLD_HTREE_NUM -2002 -#define SX_ERR_INVLD_EDGE_LINK_NUM -2003 \ No newline at end of file +#define SX_ERR_INVLD_EDGE_LINK_NUM -2003 +#define SX_ERR_INVLD_CLOSES_PT -2004 \ No newline at end of file