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)"
74 <br><h2>Get vertex by index</h2>
79 # Create auxiliary objects
80 Vertex_1 = geompy.MakeVertex(0, 0, 0)
81 Vertex_2 = geompy.MakeVertex(10, 20, 0)
82 Vertex_3 = geompy.MakeVertex(0, 40, 0)
83 Vertex_4 = geompy.MakeVertex(-10, 60, 0)
84 Vertex_5 = geompy.MakeVertex(0, 80, 0)
85 Curve_1 = geompy.MakeInterpol([Vertex_1, Vertex_2, Vertex_3])
86 Curve_2 = geompy.MakeInterpol([Vertex_5, Vertex_4, Vertex_3])
87 Wire_1 = geompy.MakeWire([Curve_1, Curve_2])
88 Reversed_Wire = geompy.ChangeOrientationShellCopy(Wire_1)
90 # Get The vertexes from Reversed Wire by different functions
91 vertex_0 = geompy.GetFirstVertex(Reversed_Wire)
92 vertex_1 = geompy.GetVertexByIndex(Reversed_Wire, 1)
93 vertex_2 = geompy.GetLastVertex(Reversed_Wire)
95 # Publish objects in study
96 geompy.addToStudy( Wire_1, "Wire_1" )
97 geompy.addToStudy( Reversed_Wire, "Reversed_Wire" )
98 geompy.addToStudy( vertex_0, "vertex_0" )
99 geompy.addToStudy( vertex_1, "vertex_1" )
100 geompy.addToStudy( vertex_2, "vertex_2" )
110 box = geompy.MakeBoxDXDYDZ(100,30,100)
111 In = geompy.Inertia(box)
112 print "\nInertia matrix of box 100x30x100:"
113 print " (", In[0], ", ", In[1], ", ", In[2], ")"
114 print " (", In[3], ", ", In[4], ", ", In[5], ")"
115 print " (", In[6], ", ", In[7], ", ", In[8], ")"
116 print "Main moments of inertia of box 100x30x100:"
117 print " Ix = ", In[9], ", Iy = ", In[10], ", Iz = ", In[11]
120 <br><h2>Check Free Boundaries</h2>
126 gg = salome.ImportComponentGUI("GEOM")
129 box1 = geompy.MakeBox(0,0,0,100,50,100)
130 box2 = geompy.MakeBox(100,0,0,250,50,100)
133 compound = geompy.MakeCompound([box1, box2])
136 ImportFromBREP = geompy.ImportBREP(os.getenv("DATA_DIR")+"/Shapes/Brep/flight_solid.brep")
139 faces = geompy.SubShapeAllSortedCentres(ImportFromBREP, geompy.ShapeType["FACE"])
141 # get the free boundary for face 32
142 Res = geompy.GetFreeBoundary(faces[32])
148 print "Checking free boudaries is OK."
150 print "Checking free boudaries is KO!"
151 print "len(ClosedWires) = ", len(ClosedWires)
154 for wire in ClosedWires :
155 wire_name = "Face 32 -> Close wires : WIRE %d"%(i+1)
156 geompy.addToStudy(ClosedWires[i], wire_name)
157 if i < len(ClosedWires) :
160 print "len(OpenWires) = ", len(OpenWires)
163 for wire in OpenWires :
164 wire_name = "Face 32 -> Open wires : WIRE %d"%(i+1)
165 geompy.addToStudy(OpenWires[i], wire_name)
166 if i < len(OpenWires) :
169 # get the free boundary for face 41
170 Res = geompy.GetFreeBoundary(faces[41])
176 print "Checking free boudaries is OK."
178 print "Checking free boudaries is KO!"
179 print "len(ClosedWires) = ", len(ClosedWires)
182 for wire in ClosedWires :
183 wire_name = "Face 41 -> Close wires : WIRE %d"%(i+1)
184 geompy.addToStudy(ClosedWires[i], wire_name)
185 if i < len(ClosedWires) :
188 print "len(OpenWires) = ", len(OpenWires)
191 for wire in OpenWires :
192 wire_name = "Face 41 -> Open wires : WIRE %d"%(i+1)
193 geompy.addToStudy(OpenWires[i], wire_name)
194 if i < len(OpenWires) :
197 # add the imported object to the study
198 id_ImportFromBREP = geompy.addToStudy(ImportFromBREP, "ImportFromBREP")
199 salome.sg.updateObjBrowser(1)
203 <br><h2>Check Free Faces</h2>
208 gg = salome.ImportComponentGUI("GEOM")
210 # create a vertex and a vector
211 p1 = geompy.MakeVertex(35, 35, 0)
212 p2 = geompy.MakeVertex(35, 35, 50)
213 v = geompy.MakeVector(p1, p2)
216 cylinder = geompy.MakeCone(p1, v, 30, 20, 20)
219 cone = geompy.MakeCone(p1, v, 70, 40, 60)
222 cut = geompy.MakeCut(cone, cylinder)
224 # get faces as sub-shapes
226 faces = geompy.SubShapeAllSortedCentres(cut, geompy.ShapeType["FACE"])
227 f_2 = geompy.GetSubShapeID(cut, faces[0])
229 # remove one face from the shape
230 cut_without_f_2 = geompy.SuppressFaces(cut, [f_2])
232 # suppress the specified wire
233 result = geompy.GetFreeFacesIDs(cut_without_f_2)
234 print "A number of free faces is ", len(result)
236 # add objects in the study
237 all_faces = geompy.SubShapeAllSortedCentres(cut_without_f_2, geompy.ShapeType["FACE"])
238 for face in all_faces :
239 sub_shape_id = geompy.GetSubShapeID(cut_without_f_2, face)
240 if result.count(sub_shape_id) > 0 :
241 face_name = "Free face %d"%(sub_shape_id)
242 geompy.addToStudy(face, face_name)
244 # in this example all faces from cut_without_f_2 are free
245 id_cut_without_f_2 = geompy.addToStudy(cut_without_f_2, "Cut without f_2")
247 # display the results
248 gg.createAndDisplayGO(id_cut_without_f_2)
249 gg.setDisplayMode(id_cut_without_f_2,1)
254 <br><h2>Bounding Box</h2>
260 box = geompy.MakeBoxDXDYDZ(100,30,100)
261 bb = geompy.BoundingBox(box)
262 print "\nBounding Box of box 100x30x100:"
263 print " Xmin = ", bb[0], ", Xmax = ", bb[1]
264 print " Ymin = ", bb[2], ", Ymax = ", bb[3]
265 print " Zmin = ", bb[4], ", Zmax = ", bb[5]
268 <br><h2>Minimal Distance</h2>
274 box1 = geompy.MakeBoxDXDYDZ(100,30,100)
275 box2 = geompy.MakeBox(105,0,0,200,30,100)
276 min_dist = geompy.MinDistance(box1,box2)
277 print "\nMinimal distance between box1 and box2 = ", min_dist
280 <br><h2>Tolerance</h2>
286 box = geompy.MakeBoxDXDYDZ(100,30,100)
287 Toler = geompy.Tolerance(box)
288 print "\nBox 100x30x100 tolerance:"
289 print " Face min. tolerance: ", Toler[0]
290 print " Face max. tolerance: ", Toler[1]
291 print " Edge min. tolerance: ", Toler[2]
292 print " Edge max. tolerance: ", Toler[3]
293 print " Vertex min. tolerance: ", Toler[4]
294 print " Vertex max. tolerance: ", Toler[5]
305 geompy.init_geom(salome.myStudy)
307 OX = geompy.MakeVectorDXDYDZ(10, 0,0)
308 OXY = geompy.MakeVectorDXDYDZ(10,10,0)
311 Angle = geompy.GetAngle(OX, OXY)
313 print "\nAngle between OX and OXY = ", Angle
314 if math.fabs(Angle - 45.0) > 1e-05:
315 print " Error: returned angle is", Angle, "while must be 45.0"
318 Angle = geompy.GetAngleRadians(OX, OXY)
320 print "\nAngle between OX and OXY in radians = ", Angle
321 if math.fabs(Angle - math.pi/4) > 1e-05:
322 print " Error: returned angle is", Angle, "while must be pi/4"
326 OXY_shift = geompy.MakeTranslation(OXY,10,-10,20)
327 Angle = geompy.GetAngle(OX, OXY_shift)
329 print "Angle between OX and OXY_shift = ", Angle
330 if math.fabs(Angle - 45.0) > 1e-05:
331 print " Error: returned angle is", Angle, "while must be 45.0"
335 pnt1 = geompy.MakeVertex(0, 0, 0)
336 pnt2 = geompy.MakeVertex(10, 0, 0)
337 pnt3 = geompy.MakeVertex(20, 10, 0)
338 arc = geompy.MakeArc(pnt1, pnt2, pnt3)
339 Angle = geompy.GetAngle(OX, arc)
341 if (math.fabs(Angle + 1.0) > 1e-6 or geompy.MeasuOp.IsDone()):
342 print "Error. Angle must not be computed on curvilinear edges"
354 box = geompy.MakeBoxDXDYDZ(100,30,100)
355 Descr = geompy.WhatIs(box)
356 print "\nBox 100x30x100 description:"
360 <br><h2>NbShapes and ShapeInfo</h2>
366 box = geompy.MakeBoxDXDYDZ(100,30,100)
367 nbSolids = geompy.NbShapes(box, geompy.ShapeType["SOLID"])
368 print "\nBox 100x30x100 quantity of solids:", nbSolids
369 boxInfo = geompy.ShapeInfo(box)
370 print "\nBox 100x30x100 shapes:"
374 <br><h2>Check Shape</h2>
380 box = geompy.MakeBoxDXDYDZ(100,30,100)
381 IsValid = geompy.CheckShape(box)
383 raise RuntimeError, "Invalid box created"
385 print "\nBox is valid"
388 <br><h2>Detect Self-intersections</h2>
394 box = geompy.MakeBoxDXDYDZ(100,30,100)
395 IsValid = geompy.CheckSelfIntersections(box)
397 raise RuntimeError, "Box with self-intersections created"
399 print "\nBox is valid"
402 <br><h2>Check Compound of Blocks</h2>
407 gg = salome.ImportComponentGUI("GEOM")
410 box1 = geompy.MakeBox(0,0,0,100,50,100)
411 box2 = geompy.MakeBox(100,0,0,250,50,100)
414 compound = geompy.MakeCompound([box1, box2])
416 # glue the faces of the compound
418 glue = geompy.MakeGlueFaces(compound, tolerance)
419 IsValid = geompy.CheckCompoundOfBlocks(glue)
421 raise RuntimeError, "Invalid compound created"
423 print "\nCompound is valid"