}
/**
-* 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<int> 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;
}
/**