From cb49a70ef9a2e662637741a8bd5ab3545ac1c168 Mon Sep 17 00:00:00 2001 From: Pablo Garzon Date: Mon, 15 May 2023 11:27:16 +0200 Subject: [PATCH] #3502 Bug close surface in CreateMeshFromPoints --- .../src/bbcreaVtkCreateMeshFromPoints.cxx | 43 +++++++++++-------- 1 file changed, 24 insertions(+), 19 deletions(-) diff --git a/bbtk_creaVtk_PKG/src/bbcreaVtkCreateMeshFromPoints.cxx b/bbtk_creaVtk_PKG/src/bbcreaVtkCreateMeshFromPoints.cxx index 900de4e..58448a4 100644 --- a/bbtk_creaVtk_PKG/src/bbcreaVtkCreateMeshFromPoints.cxx +++ b/bbtk_creaVtk_PKG/src/bbcreaVtkCreateMeshFromPoints.cxx @@ -261,34 +261,39 @@ bool CreateMeshFromPoints::isPointingCorrectly( int firstPointId, int secPointId } /** -* Checks if points on each side of the shapes represent a curve. +* Checks if the order of the points represent a curved spline (U shape) or the points resemble a straight spline. +* Now it checks the angle between each point and the vector that goes from the last point to the first. +* +* Previous version checked the curvature between 3 points in the spline, but this created problems when the straight lines +* had curves in the middle, increasing the curvature although they are not in the U shape. */ bool CreateMeshFromPoints::CheckLinePointOrder(){ int sizePoints = bbGetInputLstX().size(); std::vector lstIndexs = bbGetInputLstIndexs(); double point1[3], point2[3], point3[3]; double center[3]; - double firstRadiusSum = 0; - double secondRadiusSum = 0; - for(int i = 0; i < lstIndexs[0] && lstIndexs[0] > 9; i+=5){ - if(i+10 < lstIndexs[0]){ - points->GetPoint(i, point1); - points->GetPoint(i+5, point2); - points->GetPoint(i+10, point3); - firstRadiusSum += vtkMath::Solve3PointCircle(point1, point2, point3, center); - } + double firstAngleSum = 0; + double secondAngleSum = 0; + + points->GetPoint(0, point1); + points->GetPoint((lstIndexs[0]-1), point3); + double firstVect[3]; + double secVect[3]; + vtkMath::Subtract(point3, point1, firstVect); + for(int i = 0; i < lstIndexs[0]; i++){ + points->GetPoint(i, point2); + vtkMath::Subtract(point2, point1, secVect); + firstAngleSum += vtkMath::SignedAngleBetweenVectors(firstVect, secVect, firstVect); } - - for(int i = 0; i < sizePoints && lstIndexs.size() > 9; i+=(lstIndexs.size()*5)){ - if(i+(10*lstIndexs.size()) < sizePoints){ - points->GetPoint(i, point1); - points->GetPoint(i+(5*lstIndexs.size()), point2); - points->GetPoint(i+(10*lstIndexs.size()), point3); - secondRadiusSum += vtkMath::Solve3PointCircle(point1, point2, point3, center); - } + points->GetPoint((sizePoints-lstIndexs[0]), point3); + vtkMath::Subtract(point3, point1, firstVect); + for(int i = 0; i < sizePoints; i+=lstIndexs.size()){ + points->GetPoint(i, point2); + vtkMath::Subtract(point2, point1, secVect); + secondAngleSum += vtkMath::SignedAngleBetweenVectors(firstVect, secVect, firstVect); } - return firstRadiusSum > secondRadiusSum; + return firstAngleSum < secondAngleSum; } /** -- 2.47.1