3 \page tui_measurement_tools_page Measurement Tools
5 <br><h2>Point Coordinates</h2>
12 point = geompy.MakeVertex(15., 23., 80.)
14 # get the coordinates of the point and check its values
15 coords = geompy.PointCoordinates(point)
17 # check the obtained coordinate values
19 def IsEqual(val1, val2): return (math.fabs(val1 - val2) < tolerance)
21 if IsEqual(coords[0], 15.) and IsEqual(coords[1], 23.) and IsEqual(coords[2], 80.):
22 print "All values are OK."
24 print "Coordinates of point must be (15, 23, 80), but returned (",
25 print coords[0], ", ", coords[1], ", ", coords[2], ")"
29 <br><h2>Basic Properties</h2>
36 box = geompy.MakeBoxDXDYDZ(100,30,100)
37 props = geompy.BasicProperties(box)
38 print "\nBox 100x30x100 Basic Properties:"
39 print " Wires length: ", props[0]
40 print " Surface area: ", props[1]
41 print " Volume : ", props[2]
42 length = math.sqrt((props[0] - 1840)*(props[0] - 1840))
43 area = math.sqrt((props[1] - 32000)*(props[1] - 32000))
44 volume = math.sqrt((props[2] - 300000)*(props[2] - 300000))
45 if length > 1e-7 or area > 1e-7 or volume > 1e-7:
46 print "While must be:"
47 print " Wires length: ", 1840
48 print " Surface area: ", 32000
49 print " Volume : ", 300000.
52 <br><h2>Center of masses</h2>
59 box = geompy.MakeBoxDXDYDZ(100,30,100)
60 cm = geompy.MakeCDG(box)
62 raise RuntimeError, "MakeCDG(box) failed"
64 print "\nCentre of gravity of box has been successfully obtained:"
65 coords = geompy.PointCoordinates(cm)
66 print "(", coords[0], ", ", coords[1], ", ", coords[2], ")"
67 dx = math.sqrt((coords[0] - 50)*(coords[0] - 50))
68 dy = math.sqrt((coords[1] - 15)*(coords[1] - 15))
69 dz = math.sqrt((coords[2] - 50)*(coords[2] - 50))
70 if dx > 1e-7 or dy > 1e-7 or dz > 1e-7:
71 print "But must be (50, 15, 50)"
81 box = geompy.MakeBoxDXDYDZ(100,30,100)
82 In = geompy.Inertia(box)
83 print "\nInertia matrix of box 100x30x100:"
84 print " (", In[0], ", ", In[1], ", ", In[2], ")"
85 print " (", In[3], ", ", In[4], ", ", In[5], ")"
86 print " (", In[6], ", ", In[7], ", ", In[8], ")"
87 print "Main moments of inertia of box 100x30x100:"
88 print " Ix = ", In[9], ", Iy = ", In[10], ", Iz = ", In[11]
91 <br><h2>Check Free Boundaries</h2>
97 gg = salome.ImportComponentGUI("GEOM")
100 box1 = geompy.MakeBox(0,0,0,100,50,100)
101 box2 = geompy.MakeBox(100,0,0,250,50,100)
104 compound = geompy.MakeCompound([box1, box2])
107 ImportFromBREP = geompy.ImportBREP(os.getenv("DATA_DIR")+"/Shapes/Brep/flight_solid.brep")
110 faces = geompy.SubShapeAllSorted(ImportFromBREP, geompy.ShapeType["FACE"])
112 # get the free boundary for face 32
113 Res = geompy.GetFreeBoundary(faces[32])
119 print "Checking free boudaries is OK."
121 print "Checking free boudaries is KO!"
122 print "len(ClosedWires) = ", len(ClosedWires)
125 for wire in ClosedWires :
126 wire_name = "Face 32 -> Close wires : WIRE %d"%(i+1)
127 geompy.addToStudy(ClosedWires[i], wire_name)
128 if i < len(ClosedWires) :
131 print "len(OpenWires) = ", len(OpenWires)
134 for wire in OpenWires :
135 wire_name = "Face 32 -> Open wires : WIRE %d"%(i+1)
136 geompy.addToStudy(OpenWires[i], wire_name)
137 if i < len(OpenWires) :
140 # get the free boundary for face 41
141 Res = geompy.GetFreeBoundary(faces[41])
147 print "Checking free boudaries is OK."
149 print "Checking free boudaries is KO!"
150 print "len(ClosedWires) = ", len(ClosedWires)
153 for wire in ClosedWires :
154 wire_name = "Face 41 -> Close wires : WIRE %d"%(i+1)
155 geompy.addToStudy(ClosedWires[i], wire_name)
156 if i < len(ClosedWires) :
159 print "len(OpenWires) = ", len(OpenWires)
162 for wire in OpenWires :
163 wire_name = "Face 41 -> Open wires : WIRE %d"%(i+1)
164 geompy.addToStudy(OpenWires[i], wire_name)
165 if i < len(OpenWires) :
168 # add the imported object to the study
169 id_ImportFromBREP = geompy.addToStudy(ImportFromBREP, "ImportFromBREP")
170 salome.sg.updateObjBrowser(1)
174 <br><h2>Check Free Faces</h2>
179 gg = salome.ImportComponentGUI("GEOM")
181 # create a vertex and a vector
182 p1 = geompy.MakeVertex(35, 35, 0)
183 p2 = geompy.MakeVertex(35, 35, 50)
184 v = geompy.MakeVector(p1, p2)
187 cylinder = geompy.MakeCone(p1, v, 30, 20, 20)
190 cone = geompy.MakeCone(p1, v, 70, 40, 60)
193 cut = geompy.MakeCut(cone, cylinder)
195 # get faces as sub-shapes
197 faces = geompy.SubShapeAllSorted(cut, geompy.ShapeType["FACE"])
198 f_2 = geompy.GetSubShapeID(cut, faces[0])
200 # remove one face from the shape
201 cut_without_f_2 = geompy.SuppressFaces(cut, [f_2])
203 # suppress the specified wire
204 result = geompy.GetFreeFacesIDs(cut_without_f_2)
205 print "A number of free faces is ", len(result)
207 # add objects in the study
208 all_faces = geompy.SubShapeAllSorted(cut_without_f_2, geompy.ShapeType["FACE"])
209 for face in all_faces :
210 sub_shape_id = geompy.GetSubShapeID(cut_without_f_2, face)
211 if result.count(sub_shape_id) > 0 :
212 face_name = "Free face %d"%(sub_shape_id)
213 geompy.addToStudy(face, face_name)
215 # in this example all faces from cut_without_f_2 are free
216 id_cut_without_f_2 = geompy.addToStudy(cut_without_f_2, "Cut without f_2")
218 # display the results
219 gg.createAndDisplayGO(id_cut_without_f_2)
220 gg.setDisplayMode(id_cut_without_f_2,1)
225 <br><h2>Bounding Box</h2>
231 box = geompy.MakeBoxDXDYDZ(100,30,100)
232 bb = geompy.BoundingBox(box)
233 print "\nBounding Box of box 100x30x100:"
234 print " Xmin = ", bb[0], ", Xmax = ", bb[1]
235 print " Ymin = ", bb[2], ", Ymax = ", bb[3]
236 print " Zmin = ", bb[4], ", Zmax = ", bb[5]
239 <br><h2>Minimal Distance</h2>
245 box1 = geompy.MakeBoxDXDYDZ(100,30,100)
246 box2 = geompy.MakeBox(105,0,0,200,30,100)
247 min_dist = geompy.MinDistance(box1,box2)
248 print "\nMinimal distance between box1 and box2 = ", min_dist
251 <br><h2>Tolerance</h2>
257 box = geompy.MakeBoxDXDYDZ(100,30,100)
258 Toler = geompy.Tolerance(box)
259 print "\nBox 100x30x100 tolerance:"
260 print " Face min. tolerance: ", Toler[0]
261 print " Face max. tolerance: ", Toler[1]
262 print " Edge min. tolerance: ", Toler[2]
263 print " Edge max. tolerance: ", Toler[3]
264 print " Vertex min. tolerance: ", Toler[4]
265 print " Vertex max. tolerance: ", Toler[5]
276 geompy.init_geom(salome.myStudy)
278 OX = geompy.MakeVectorDXDYDZ(10, 0,0)
279 OXY = geompy.MakeVectorDXDYDZ(10,10,0)
282 Angle = geompy.GetAngle(OX, OXY)
284 print "\nAngle between OX and OXY = ", Angle
285 if math.fabs(Angle - 45.0) > 1e-05:
286 print " Error: returned angle is", Angle, "while must be 45.0"
290 OXY_shift = geompy.MakeTranslation(OXY,10,-10,20)
291 Angle = geompy.GetAngle(OX, OXY_shift)
293 print "Angle between OX and OXY_shift = ", Angle
294 if math.fabs(Angle - 45.0) > 1e-05:
295 print " Error: returned angle is", Angle, "while must be 45.0"
299 pnt1 = geompy.MakeVertex(0, 0, 0)
300 pnt2 = geompy.MakeVertex(10, 0, 0)
301 pnt3 = geompy.MakeVertex(20, 10, 0)
302 arc = geompy.MakeArc(pnt1, pnt2, pnt3)
303 Angle = geompy.GetAngle(OX, arc)
305 if (math.fabs(Angle + 1.0) > 1e-6 or geompy.MeasuOp.IsDone()):
306 print "Error. Angle must not be computed on curvilinear edges"
319 box = geompy.MakeBoxDXDYDZ(100,30,100)
320 Descr = geompy.WhatIs(box)
321 print "\nBox 100x30x100 description:"
325 <br><h2>Check Shape</h2>
331 box = geompy.MakeBoxDXDYDZ(100,30,100)
332 IsValid = geompy.CheckShape(box)
334 raise RuntimeError, "Invalid box created"
336 print "\nBox is valid"
339 <br><h2>Check Compound of Blocks</h2>
344 gg = salome.ImportComponentGUI("GEOM")
347 box1 = geompy.MakeBox(0,0,0,100,50,100)
348 box2 = geompy.MakeBox(100,0,0,250,50,100)
351 compound = geompy.MakeCompound([box1, box2])
353 # glue the faces of the compound
355 glue = geompy.MakeGlueFaces(compound, tolerance)
356 IsValid = geompy.CheckCompoundOfBlocks(glue)
358 raise RuntimeError, "Invalid compound created"
360 print "\nCompound is valid"