Back to index

salome-geom  6.5.0
Functions
GEOM_TestMeasures Namespace Reference

Functions

def TestMeasureOperations

Function Documentation

def GEOM_TestMeasures.TestMeasureOperations (   geompy,
  math 
)

Definition at line 24 of file GEOM_TestMeasures.py.

00024 
00025 def TestMeasureOperations (geompy, math):
00026 
00027   p0   = geompy.MakeVertex(0 ,  0,  0)
00028   p137 = geompy.MakeVertex(10, 30, 70)
00029 
00030   box = geompy.MakeBoxTwoPnt(p0, p137)
00031 
00032   p678 = geompy.MakeVertex(60, 70, 80)
00033   p789 = geompy.MakeVertex(70, 80, 90)
00034 
00035   cube = geompy.MakeBoxTwoPnt(p678, p789)
00036 
00037   ####### PointCoordinates #######
00038 
00039   Coords = geompy.PointCoordinates(p137)
00040   if Coords[0] != 10 or Coords[1] != 30 or Coords[2] != 70:
00041     print "Coordinates of p137 must be (10, 30, 70), but returned (", Coords[0], ", ", Coords[1], ", ", Coords[2], ")"
00042 
00043   ####### CheckShape #######
00044 
00045   IsValid = geompy.CheckShape(box)
00046   if IsValid == 0:
00047     raise RuntimeError, "Invalid box created"
00048   else:
00049     print "\nBox is valid"
00050 
00051   ####### Detect Self-intersections #######
00052 
00053   [Face_1,Face_2] = geompy.SubShapes(box, [33, 23])
00054   Translation_1 = geompy.MakeTranslation(Face_1, 5, -15, -40)
00055   Compound_1 = geompy.MakeCompound([Face_2, Translation_1])
00056   if geompy.CheckSelfIntersections(Compound_1) == True:
00057     raise RuntimeError, "Existing self-intersection is not detected"
00058 
00059   ####### WhatIs #######
00060 
00061   Descr = geompy.WhatIs(box)
00062   print "\nBox 10x30x70 description:"
00063   print Descr
00064 
00065   ####### NbShapes #######
00066 
00067   NbSolids = geompy.NbShapes(box, geompy.ShapeType["SOLID"])
00068   print "\nBox 10x30x70 quantity of solids:", NbSolids
00069 
00070   ####### ShapeInfo #######
00071 
00072   BoxInfo = geompy.ShapeInfo(box)
00073   print "\nBox 10x30x70 shapes:"
00074   print BoxInfo
00075 
00076   ####### BasicProperties #######
00077 
00078   Props = geompy.BasicProperties(box)
00079   print "\nBox 10x30x70 Basic Properties:"
00080   print " Wires length: ", Props[0]
00081   print " Surface area: ", Props[1]
00082   print " Volume      : ", Props[2]
00083 
00084   dl = math.sqrt((Props[0] -   880)*(Props[0] -   880))
00085   da = math.sqrt((Props[1] -  6200)*(Props[1] -  6200))
00086   dv = math.sqrt((Props[2] - 21000)*(Props[2] - 21000))
00087   #print "|Props[0] - 880| = ", dl
00088 
00089   if dl > 1e-7 or da > 1e-7 or dv > 1e-7:
00090     print "While must be:"
00091     print " Wires length: ", 880
00092     print " Surface area: ", 6200
00093     print " Volume      : ", 21000
00094 
00095   ####### BoundingBox #######
00096 
00097   BB = geompy.BoundingBox(box)
00098   print "\nBounding Box of box 10x30x70:"
00099   print " Xmin = ", BB[0], ", Xmax = ", BB[1]
00100   print " Ymin = ", BB[2], ", Ymax = ", BB[3]
00101   print " Zmin = ", BB[4], ", Zmax = ", BB[5]
00102 
00103   ####### Inertia #######
00104 
00105   In = geompy.Inertia(box)
00106   print "\nInertia matrix of box 10x30x70:"
00107   print " (", In[0], ", ", In[1], ", ", In[2], ")"
00108   print " (", In[3], ", ", In[4], ", ", In[5], ")"
00109   print " (", In[6], ", ", In[7], ", ", In[8], ")"
00110   print "Main moments of inertia of box 10x30x70:"
00111   print " Ix = ", In[9], ", Iy = ", In[10], ", Iz = ", In[11]
00112 
00113   ####### Tolerance #######
00114 
00115   Toler = geompy.Tolerance(box)
00116   print "\nBox 10x30x70 tolerance:"
00117   print " Face min. tolerance: ", Toler[0]
00118   print " Face max. tolerance: ", Toler[1]
00119   print " Edge min. tolerance: ", Toler[2]
00120   print " Edge max. tolerance: ", Toler[3]
00121   print " Vertex min. tolerance: ", Toler[4]
00122   print " Vertex max. tolerance: ", Toler[5]
00123 
00124   ####### MakeCDG #######
00125 
00126   pcdg = geompy.MakeCDG(box)
00127   if pcdg is None:
00128     raise RuntimeError, "MakeCDG(box) failed"
00129   else:
00130     print "\nCentre of gravity of box has been successfully obtained:"
00131     Coords = geompy.PointCoordinates(pcdg)
00132     print "(", Coords[0], ", ", Coords[1], ", ", Coords[2], ")"
00133     if Coords[0] != 5 or Coords[1] != 15 or Coords[2] != 35:
00134       print "But must be (5, 15, 35)"
00135 
00136   ####### GetNormal #######
00137 
00138   faces = geompy.SubShapeAllSortedCentres(box, geompy.ShapeType["FACE"])
00139   face0 = faces[0]
00140   vnorm = geompy.GetNormal(face0)
00141   if vnorm is None:
00142     raise RuntimeError, "GetNormal(face0) failed"
00143   else:
00144     geompy.addToStudy(face0, "Face0")
00145     geompy.addToStudy(vnorm, "Normale to Face0")
00146     print "\nNormale of face has been successfully obtained:"
00147     #Coords = geompy.PointCoordinates(pcdg)
00148     #print "(", Coords[0], ", ", Coords[1], ", ", Coords[2], ")"
00149     #if Coords[0] != 5 or Coords[1] != 15 or Coords[2] != 35:
00150     #  print "But must be (5, 15, 35)"
00151 
00152   ####### MinDistance #######
00153 
00154   MinDist = geompy.MinDistance(box, cube)
00155 
00156   #print "\nMinimal distance between Box and Cube = ", MinDist[0]
00157   #print "It is reached at points:"
00158   #print " On Box  (", MinDist[1], ", ", MinDist[2], ", ", MinDist[3], ")"
00159   #print " On Cube (", MinDist[4], ", ", MinDist[5], ", ", MinDist[6], ")"
00160 
00161   print "\nMinimal distance between Box and Cube = ", MinDist
00162 
00163   MinDistComps = geompy.MinDistanceComponents(box, cube)
00164   print "\nMinimal distance between Box and Cube = ", MinDistComps[0]
00165   print "Its components are  (", MinDistComps[1], ", ", MinDistComps[2], ", ", MinDistComps[3], ")"
00166 
00167   ####### Angle #######
00168 
00169   OX  = geompy.MakeVectorDXDYDZ(10, 0,0)
00170   OXY = geompy.MakeVectorDXDYDZ(10,10,0)
00171 
00172   # in one plane
00173   Angle = geompy.GetAngle(OX, OXY)
00174 
00175   print "\nAngle between OX and OXY = ", Angle
00176   if math.fabs(Angle - 45.0) > 1e-05:
00177     print "  Error: returned angle is", Angle, "while must be 45.0"
00178 
00179   Angle = geompy.GetAngleRadians(OX, OXY)
00180 
00181   print "\nAngle between OX and OXY in radians = ", Angle
00182   if math.fabs(Angle - math.pi/4) > 1e-05:
00183     print "  Error: returned angle is", Angle, "while must be pi/4"
00184     pass
00185 
00186   # not in one plane
00187   OXY_shift = geompy.MakeTranslation(OXY,10,-10,20)
00188   Angle = geompy.GetAngle(OX, OXY_shift)
00189 
00190   print "Angle between OX and OXY_shift = ", Angle
00191   if math.fabs(Angle - 45.0) > 1e-05:
00192     print "  Error: returned angle is", Angle, "while must be 45.0"
00193 
00194   ####### Position (LCS) #######
00195 
00196   Pos = geompy.GetPosition(box)
00197   print "\nPosition(LCS) of box 10x30x70:"
00198   print "Origin: (", Pos[0], ", ", Pos[1], ", ", Pos[2], ")"
00199   print "Z axis: (", Pos[3], ", ", Pos[4], ", ", Pos[5], ")"
00200   print "X axis: (", Pos[6], ", ", Pos[7], ", ", Pos[8], ")"
00201 
00202   ####### KindOfShape #######
00203 
00204   Kind = geompy.KindOfShape(box)
00205   print "\nKindOfShape(box 10x30x70):", Kind
00206   #if Kind[0] != geompy.kind.BOX:
00207   #  print "Error: returned type is", Kind[0], "while must be", geompy.kind.BOX
00208 
00209   Kind = geompy.KindOfShape(p137)
00210   print "\nKindOfShape(p137):", Kind
00211   if Kind[0] != geompy.kind.VERTEX:
00212     print "  Error: returned type is", Kind[0], "while must be", geompy.kind.VERTEX
00213   else:
00214     dx = math.fabs(Kind[1] - 10)
00215     dy = math.fabs(Kind[2] - 30)
00216     dz = math.fabs(Kind[3] - 70)
00217     if (dx + dy + dz) > 1e-5:
00218       print "  Error: coordinates are (", Kind[1], ",", Kind[2], ",", Kind[3], ") while must be (10, 20, 30)"
00219 
00220   pass