From e70526625f7c801a6876e6acc9598c626294282b Mon Sep 17 00:00:00 2001 From: Alexander Alekhin Date: Wed, 5 Sep 2018 16:16:53 +0300 Subject: [PATCH] imgproc: fix Subdiv2D::getTriangleList() --- modules/imgproc/src/subdivision2d.cpp | 30 ++++++++++++++++----------- 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/modules/imgproc/src/subdivision2d.cpp b/modules/imgproc/src/subdivision2d.cpp index 596806c3ea..6014774722 100644 --- a/modules/imgproc/src/subdivision2d.cpp +++ b/modules/imgproc/src/subdivision2d.cpp @@ -758,24 +758,30 @@ void Subdiv2D::getTriangleList(std::vector& triangleList) const triangleList.clear(); int i, total = (int)(qedges.size()*4); std::vector edgemask(total, false); - Rect2f rect(topLeft.x, topLeft.y, bottomRight.x, bottomRight.y); + const bool filterPoints = true; + Rect2f rect(topLeft.x, topLeft.y, bottomRight.x - topLeft.x, bottomRight.y - topLeft.y); for( i = 4; i < total; i += 2 ) { if( edgemask[i] ) continue; Point2f a, b, c; - int edge = i; - edgeOrg(edge, &a); - edgemask[edge] = true; - edge = getEdge(edge, NEXT_AROUND_LEFT); - edgeOrg(edge, &b); - edgemask[edge] = true; - edge = getEdge(edge, NEXT_AROUND_LEFT); - edgeOrg(edge, &c); - edgemask[edge] = true; - if( rect.contains(a) && rect.contains(b) && rect.contains(c) ) - triangleList.push_back(Vec6f(a.x, a.y, b.x, b.y, c.x, c.y)); + int edge_a = i; + edgeOrg(edge_a, &a); + if (filterPoints && !rect.contains(a)) + continue; + int edge_b = getEdge(edge_a, NEXT_AROUND_LEFT); + edgeOrg(edge_b, &b); + if (filterPoints && !rect.contains(b)) + continue; + int edge_c = getEdge(edge_b, NEXT_AROUND_LEFT); + edgeOrg(edge_c, &c); + if (filterPoints && !rect.contains(c)) + continue; + edgemask[edge_a] = true; + edgemask[edge_b] = true; + edgemask[edge_c] = true; + triangleList.push_back(Vec6f(a.x, a.y, b.x, b.y, c.x, c.y)); } }