1 # Test XYZtoUV and UVtoXYZ methods
4 salome.salome_init_without_session()
6 from salome.geom import geomBuilder
7 geompy = geomBuilder.New()
13 # Create "Horse saddle"
14 OX = geompy.MakeVectorDXDYDZ(1, 0, 0, 'OX')
15 OY = geompy.MakeVectorDXDYDZ(0, 1, 0, 'OY')
16 Sphere_1 = geompy.MakeSphereR(100, 'Sphere_1')
17 [Edge_1,Edge_2,Edge_3] = geompy.ExtractShapes(Sphere_1, geompy.ShapeType["EDGE"], True)
18 geompy.addToStudyInFather( Sphere_1, Edge_1, 'Edge_1' )
19 geompy.addToStudyInFather( Sphere_1, Edge_2, 'Edge_2' )
20 geompy.addToStudyInFather( Sphere_1, Edge_3, 'Edge_3' )
22 Rotation_1 = geompy.MakeRotation(Edge_3, OX, 90*math.pi/180.0, 'Rotation_1')
23 Rotation_2 = geompy.MakeRotation(Rotation_1, OY, 180*math.pi/180.0, 'Rotation_2')
24 Translation_1 = geompy.MakeTranslation(Rotation_2, 200, 0, 0, 'Translation_1')
25 Translation_2 = geompy.MakeTranslation(Edge_3, 100, 100, 0, 'Translation_2')
26 Translation_3 = geompy.MakeTranslation(Translation_2, 0, -200, 0, 'Translation_3')
28 Filling_1 = geompy.MakeFilling([Translation_2, Edge_3, Translation_3])
29 geompy.addToStudy(Filling_1, 'Filling_1')
31 HorseSaddle = geompy.LimitTolerance(Filling_1, toler, 'HorseSaddle')
33 # Get 100 equidistant points on the "Horse saddle"
34 CompoundOfVertices = geompy.MakeVertexInsideFace(HorseSaddle, 100, "CompoundOfVertices")
35 assert(geompy.NumberOfSubShapes(CompoundOfVertices, geompy.ShapeType["VERTEX"]) == 100)
37 # Extract the vertices
38 listOfVertices = geompy.ExtractShapes(CompoundOfVertices, geompy.ShapeType["VERTEX"], True)
40 # Get list of coordinates of all 100 vertices
42 for aV in listOfVertices:
43 listOfCoords += geompy.PointCoordinates(aV)
46 # Test 1: with normalization of parameters
49 listOfParams_norm = geompy.XYZtoUV(HorseSaddle, listOfCoords, True)
50 assert(len(listOfParams_norm) == 200)
53 listOfCoords_new1 = geompy.UVtoXYZ(HorseSaddle, listOfParams_norm, True)
54 assert(len(listOfCoords_new1) == 300)
56 # Compare listOfCoords_new with listOfCoords
57 for (c1, c2) in zip(listOfCoords, listOfCoords_new1):
58 assert(abs(c1 - c2) < toler)
61 # Test 2: without normalization of parameters
64 listOfParams = geompy.XYZtoUV(HorseSaddle, listOfCoords, False)
65 assert(len(listOfParams) == 200)
68 listOfCoords_new2 = geompy.UVtoXYZ(HorseSaddle, listOfParams, False)
69 assert(len(listOfCoords_new2) == 300)
71 # Compare listOfCoords_new with listOfCoords
72 for (c1, c2) in zip(listOfCoords, listOfCoords_new2):
73 assert(abs(c1 - c2) < toler)
76 # Test 3: Check exceptions throwing if point (XYZ or UV) is out of face
77 listXYZ_3 = listOfCoords[:3]
78 listXYZ_3[2] = listXYZ_3[2] + 1.0 # move along OZ
80 geompy.XYZtoUV(HorseSaddle, listXYZ_3, True)
82 print(geompy.MeasuOp.GetErrorCode(), ", it's OK")
85 assert False, 'Unexpected exception raised'
87 assert False, 'XYZtoUV should raise an exception if input point is out of face'
89 listUV_2 = [2, 2] # each parameter value should be in [0,1] range (for normalized case)
91 geompy.UVtoXYZ(HorseSaddle, listUV_2, True)
93 print(geompy.MeasuOp.GetErrorCode(), ", it's OK")
96 assert False, 'Unexpected exception raised'
98 assert False, 'UVtoXYZ should raise an exception if input parameters are out of face'
100 # parameter U should be in [4.71239, 7.85398] range (on this face, for not normalized case)
101 # parameter V should be in [0, 1] range (on this face, for not normalized case)
104 geompy.UVtoXYZ(HorseSaddle, listUV_2, True)
106 print(geompy.MeasuOp.GetErrorCode(), ", it's OK")
109 assert False, 'Unexpected exception raised'
111 assert False, 'UVtoXYZ should raise an exception if input parameters are out of face'
113 # Test 4: Check exceptions in case of invalid data type (wrong length of array or type of elements)
115 # 1. Length of input array is not divisible by 3 (for XYZtoUV) or by 2 (for UVtoXYZ)
116 listXYZ_4 = listOfCoords[:4]
117 assert(len(listXYZ_4) == 4)
119 geompy.XYZtoUV(HorseSaddle, listXYZ_4, True)
121 print(geompy.MeasuOp.GetErrorCode(), ", it's OK")
124 assert False, 'Unexpected exception raised'
126 assert False, 'XYZtoUV should raise an exception if input list length is not divisible by 3'
128 listUV_3 = listOfParams[:3]
129 assert(len(listUV_3) == 3)
131 geompy.UVtoXYZ(HorseSaddle, listUV_3, True)
133 print(geompy.MeasuOp.GetErrorCode(), ", it's OK")
136 assert False, 'Unexpected exception raised'
138 assert False, 'UVtoXYZ should raise an exception if input list length is not divisible by 2'
140 # 2. Input array contains data of wrong type
141 listXYZ_w = ['a', 'b', 'c']
143 geompy.XYZtoUV(HorseSaddle, listXYZ_w, True)
147 assert False, 'XYZtoUV should raise TypeError if input list contains not numerical data'
149 listXYZ_w = [10.0, '10.0', 10.0]
151 geompy.XYZtoUV(HorseSaddle, listXYZ_w, True)
155 assert False, 'XYZtoUV should raise TypeError if input list contains not numerical data'
157 listUV_w = ['a', 'b']
159 geompy.UVtoXYZ(HorseSaddle, listUV_w, True)
163 assert False, 'UVtoXYZ should raise TypeError if input list contains not numerical data'
165 listUV_w = [10.0, '10.0']
167 geompy.UVtoXYZ(HorseSaddle, listUV_w, True)
171 assert False, 'UVtoXYZ should raise TypeError if input list contains not numerical data'
173 # Test 5: a. Translate each of the 100 points by toler*2.0 along the face normal
174 # and check that the XYZtoUV method fails by raising an exception.
175 # b. Translate each of the 100 points by toler*0.7 along the face normal
176 # and check that we obtain a result.
177 for ii in range(100):
178 # cc - coordinates of point #ii
179 cc = listOfCoords[ii*3 : ii*3 + 3]
181 pnt = geompy.MakeVertex(cc[0], cc[1], cc[2])
182 normal = geompy.GetNormal(HorseSaddle, pnt)
183 vv = geompy.VectorCoordinates(normal)
184 norm = np.linalg.norm(vv)
187 # a. Move cc by toler*2.0 (XYZtoUV should fail)
188 pp_2tol = [cc[0] + vec[0]*toler*2.0,
189 cc[1] + vec[1]*toler*2.0,
190 cc[2] + vec[2]*toler*2.0]
192 geompy.XYZtoUV(HorseSaddle, pp_2tol)
196 assert False, 'Unexpected exception raised'
198 assert False, 'XYZtoUV should raise an exception if input point is out of face'
201 # b. Move cc by toler*0.7 (XYZtoUV should not fail)
202 pp_07tol = [cc[0] + vec[0]*toler*0.7,
203 cc[1] + vec[1]*toler*0.7,
204 cc[2] + vec[2]*toler*0.7]
205 UV_pp = geompy.XYZtoUV(HorseSaddle, pp_07tol, False)
206 # compare with value from listOfParams (computed above)
207 UV_cc = listOfParams[ii*2 : ii*2 + 2]
208 for (c1, c2) in zip(UV_pp, UV_cc):
209 assert(abs(c1 - c2) < toler)