From b7fd733778c85aa49ed45e50e52d978820f25fd5 Mon Sep 17 00:00:00 2001 From: Anthony Geay Date: Thu, 4 Aug 2022 08:34:25 +0200 Subject: [PATCH] Integrate acceptance test --- doc/salome/examples/curvature_face.py | 78 +++++++++++++++++++++++++-- 1 file changed, 73 insertions(+), 5 deletions(-) diff --git a/doc/salome/examples/curvature_face.py b/doc/salome/examples/curvature_face.py index 262f51b3e..3c22b34c0 100644 --- a/doc/salome/examples/curvature_face.py +++ b/doc/salome/examples/curvature_face.py @@ -6,6 +6,70 @@ import GEOM from salome.geom import geomBuilder geompy = geomBuilder.New() import math +import numpy as np + +def test_acceptance(): + """ + Acceptance test [tuleap29472] + """ + Vector = [0,100,100] + O = geompy.MakeVertex(0, 0, 0) + OX = geompy.MakeVectorDXDYDZ(1, 0, 0) + OY = geompy.MakeVectorDXDYDZ(0, 1, 0) + OZ = geompy.MakeVectorDXDYDZ(0, 0, 1) + Cylinder_1 = geompy.MakeCylinderRH(100, 300) + Translation_1 = geompy.MakeTranslation(Cylinder_1, 0, 0, -150) + Vertex_1 = geompy.MakeVertex(100, 0, 0) + Vertex_2 = geompy.MakeVertex(100, -Vector[2], Vector[1]) + Line_1 = geompy.MakeLineTwoPnt(Vertex_1, Vertex_2) + Plane_1 = geompy.MakePlane(Vertex_1, Line_1, 2000) + Rotation_1 = geompy.MakeRotation(Translation_1, OZ, 90*math.pi/180.0)# avoid to have degenerated edge across Vertex_1 + + [Face_1,Face_2,Face_3] = geompy.ExtractShapes(Rotation_1, geompy.ShapeType["FACE"], True) + + curvature_29472 = np.array( geompy.VectorCoordinates( geompy.CurvatureOnFace(Face_2, Vertex_1, geompy.MakeVectorDXDYDZ(*Vector))) ).reshape(1,3) + expected_curvature = np.array( [-200.0,0.0,0.0] ).reshape(1,3) + assert( np.isclose( 0.0, np.linalg.norm( curvature_29472 - expected_curvature ) ,rtol=0,atol=1e-5 ) ) + + Intersection_1 = geompy.MakeSection(Face_2, Plane_1, True) + geompy.addToStudy( O, 'O' ) + geompy.addToStudy( OX, 'OX' ) + geompy.addToStudy( OY, 'OY' ) + geompy.addToStudy( OZ, 'OZ' ) + geompy.addToStudy( Vertex_1, 'Vertex_1' ) + geompy.addToStudy( Cylinder_1, 'Cylinder_1' ) + geompy.addToStudy( Translation_1, 'Translation_1' ) + geompy.addToStudy( Vertex_2, 'Vertex_2' ) + geompy.addToStudy( Line_1, 'Line_1' ) + geompy.addToStudy( Plane_1, 'Plane_1' ) + geompy.addToStudy( Rotation_1, 'Rotation_1' ) + geompy.addToStudyInFather( Rotation_1, Face_1, 'Face_1' ) + geompy.addToStudyInFather( Rotation_1, Face_2, 'Face_2' ) + geompy.addToStudyInFather( Rotation_1, Face_3, 'Face_3' ) + geompy.addToStudy( Intersection_1, 'Intersection_1' ) + angle = math.asin(Vector[2]/math.sqrt(Vector[1]*Vector[1]+Vector[2]*Vector[2])) + tmp = geompy.MakeTranslation(Intersection_1,*[-elt for elt in geompy.PointCoordinates(Vertex_1)]) + tmp = geompy.MakeRotation(tmp,OX,-angle) + Intersection_1_OXY = geompy.MakeTranslation(tmp,*geompy.PointCoordinates(Vertex_1)) + geompy.addToStudy( Intersection_1_OXY, 'Intersection_1_OXY' ) + + eps = 0.01 + offset = 0.75 + p0 = np.array( geompy.PointCoordinates( geompy.MakeVertexOnCurve(Intersection_1_OXY,offset-eps) ) ).reshape(1,3) + p1 = np.array( geompy.PointCoordinates( geompy.MakeVertexOnCurve(Intersection_1_OXY,offset) ) ).reshape(1,3) + p2 = np.array( geompy.PointCoordinates( geompy.MakeVertexOnCurve(Intersection_1_OXY,offset+eps) ) ).reshape(1,3) + assert( np.isclose(0.0,np.linalg.norm(p1- np.array(geompy.PointCoordinates(Vertex_1)).reshape(1,3) ),rtol=0,atol=1e-8) ) + p01=(p0+p1)/2 + p12=(p1+p2)/2 + v0 = (p1-p0)/np.linalg.norm(p1-p0) + v1 = (p2-p1)/np.linalg.norm(p2-p1) + computedRadius = 1/np.linalg.norm((v1-v0)/np.linalg.norm(p12-p01)) + # manual detection of radius : https://fr.wikipedia.org/wiki/Courbure_d%27un_arc + circle = geompy.MakeCircle(O,OZ,computedRadius) + circle = geompy.MakeTranslation(circle,100-computedRadius,0,0) + geompy.addToStudy(circle, "expectedCircle") + print("Radius expected is {}".format(computedRadius)) + print("Radius obtain by CurvatureOnFace is {}".format(np.linalg.norm(curvature_29472))) O = geompy.MakeVertex(0, 0, 0, 'O') OX = geompy.MakeVectorDXDYDZ(1, 0, 0, 'OX') @@ -119,11 +183,12 @@ Vertex_2 = geompy.MakeVertex(100, 0, 0, 'Vertex_2') curvature_Y = geompy.CurvatureOnFace(Filling_1, Vertex_2, OY, 'curvature_Y') curvature_Z = geompy.CurvatureOnFace(Filling_1, Vertex_2, OZ, 'curvature_Z') -cury = geompy.VectorCoordinates(curvature_Y) -curz = geompy.VectorCoordinates(curvature_Z) - -# Vectors should be opposite, scalar product should be negative -assert(cury[0]*curz[0] + cury[1]*curz[1] + cury[2]*curz[2] < -1e-07) +cury = np.array( geompy.VectorCoordinates(curvature_Y) ).reshape(1,3) +curz = np.array( geompy.VectorCoordinates(curvature_Z) ).reshape(1,3) +cury_expected = np.array( [50,0,0] ).reshape(1,3) +curz_expected = np.array( [-100,0,0] ).reshape(1,3) +assert( np.isclose( 0.0, np.linalg.norm( cury - cury_expected ) ,rtol=0,atol=1e-5 ) ) +assert( np.isclose( 0.0, np.linalg.norm( curz - curz_expected ) ,rtol=0,atol=1e-5 ) ) # Normal direction norm_1 = geompy.GetNormal(Filling_1, Vertex_2, "Normal_1") @@ -133,3 +198,6 @@ try: except: isExcept = True assert(isExcept) + +# acceptance case +test_acceptance() \ No newline at end of file