Back to index

salome-geom  6.5.0
GEOM_TestMeasures.py
Go to the documentation of this file.
00001 #  -*- coding: iso-8859-1 -*-
00002 # Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00003 #
00004 # Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00005 # CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00006 #
00007 # This library is free software; you can redistribute it and/or
00008 # modify it under the terms of the GNU Lesser General Public
00009 # License as published by the Free Software Foundation; either
00010 # version 2.1 of the License.
00011 #
00012 # This library is distributed in the hope that it will be useful,
00013 # but WITHOUT ANY WARRANTY; without even the implied warranty of
00014 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015 # Lesser General Public License for more details.
00016 #
00017 # You should have received a copy of the GNU Lesser General Public
00018 # License along with this library; if not, write to the Free Software
00019 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00020 #
00021 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00022 #
00023 
00024 def TestMeasureOperations (geompy, math):
00025 
00026   p0   = geompy.MakeVertex(0 ,  0,  0)
00027   p137 = geompy.MakeVertex(10, 30, 70)
00028 
00029   box = geompy.MakeBoxTwoPnt(p0, p137)
00030 
00031   p678 = geompy.MakeVertex(60, 70, 80)
00032   p789 = geompy.MakeVertex(70, 80, 90)
00033 
00034   cube = geompy.MakeBoxTwoPnt(p678, p789)
00035 
00036   ####### PointCoordinates #######
00037 
00038   Coords = geompy.PointCoordinates(p137)
00039   if Coords[0] != 10 or Coords[1] != 30 or Coords[2] != 70:
00040     print "Coordinates of p137 must be (10, 30, 70), but returned (", Coords[0], ", ", Coords[1], ", ", Coords[2], ")"
00041 
00042   ####### CheckShape #######
00043 
00044   IsValid = geompy.CheckShape(box)
00045   if IsValid == 0:
00046     raise RuntimeError, "Invalid box created"
00047   else:
00048     print "\nBox is valid"
00049 
00050   ####### Detect Self-intersections #######
00051 
00052   [Face_1,Face_2] = geompy.SubShapes(box, [33, 23])
00053   Translation_1 = geompy.MakeTranslation(Face_1, 5, -15, -40)
00054   Compound_1 = geompy.MakeCompound([Face_2, Translation_1])
00055   if geompy.CheckSelfIntersections(Compound_1) == True:
00056     raise RuntimeError, "Existing self-intersection is not detected"
00057 
00058   ####### WhatIs #######
00059 
00060   Descr = geompy.WhatIs(box)
00061   print "\nBox 10x30x70 description:"
00062   print Descr
00063 
00064   ####### NbShapes #######
00065 
00066   NbSolids = geompy.NbShapes(box, geompy.ShapeType["SOLID"])
00067   print "\nBox 10x30x70 quantity of solids:", NbSolids
00068 
00069   ####### ShapeInfo #######
00070 
00071   BoxInfo = geompy.ShapeInfo(box)
00072   print "\nBox 10x30x70 shapes:"
00073   print BoxInfo
00074 
00075   ####### BasicProperties #######
00076 
00077   Props = geompy.BasicProperties(box)
00078   print "\nBox 10x30x70 Basic Properties:"
00079   print " Wires length: ", Props[0]
00080   print " Surface area: ", Props[1]
00081   print " Volume      : ", Props[2]
00082 
00083   dl = math.sqrt((Props[0] -   880)*(Props[0] -   880))
00084   da = math.sqrt((Props[1] -  6200)*(Props[1] -  6200))
00085   dv = math.sqrt((Props[2] - 21000)*(Props[2] - 21000))
00086   #print "|Props[0] - 880| = ", dl
00087 
00088   if dl > 1e-7 or da > 1e-7 or dv > 1e-7:
00089     print "While must be:"
00090     print " Wires length: ", 880
00091     print " Surface area: ", 6200
00092     print " Volume      : ", 21000
00093 
00094   ####### BoundingBox #######
00095 
00096   BB = geompy.BoundingBox(box)
00097   print "\nBounding Box of box 10x30x70:"
00098   print " Xmin = ", BB[0], ", Xmax = ", BB[1]
00099   print " Ymin = ", BB[2], ", Ymax = ", BB[3]
00100   print " Zmin = ", BB[4], ", Zmax = ", BB[5]
00101 
00102   ####### Inertia #######
00103 
00104   In = geompy.Inertia(box)
00105   print "\nInertia matrix of box 10x30x70:"
00106   print " (", In[0], ", ", In[1], ", ", In[2], ")"
00107   print " (", In[3], ", ", In[4], ", ", In[5], ")"
00108   print " (", In[6], ", ", In[7], ", ", In[8], ")"
00109   print "Main moments of inertia of box 10x30x70:"
00110   print " Ix = ", In[9], ", Iy = ", In[10], ", Iz = ", In[11]
00111 
00112   ####### Tolerance #######
00113 
00114   Toler = geompy.Tolerance(box)
00115   print "\nBox 10x30x70 tolerance:"
00116   print " Face min. tolerance: ", Toler[0]
00117   print " Face max. tolerance: ", Toler[1]
00118   print " Edge min. tolerance: ", Toler[2]
00119   print " Edge max. tolerance: ", Toler[3]
00120   print " Vertex min. tolerance: ", Toler[4]
00121   print " Vertex max. tolerance: ", Toler[5]
00122 
00123   ####### MakeCDG #######
00124 
00125   pcdg = geompy.MakeCDG(box)
00126   if pcdg is None:
00127     raise RuntimeError, "MakeCDG(box) failed"
00128   else:
00129     print "\nCentre of gravity of box has been successfully obtained:"
00130     Coords = geompy.PointCoordinates(pcdg)
00131     print "(", Coords[0], ", ", Coords[1], ", ", Coords[2], ")"
00132     if Coords[0] != 5 or Coords[1] != 15 or Coords[2] != 35:
00133       print "But must be (5, 15, 35)"
00134 
00135   ####### GetNormal #######
00136 
00137   faces = geompy.SubShapeAllSortedCentres(box, geompy.ShapeType["FACE"])
00138   face0 = faces[0]
00139   vnorm = geompy.GetNormal(face0)
00140   if vnorm is None:
00141     raise RuntimeError, "GetNormal(face0) failed"
00142   else:
00143     geompy.addToStudy(face0, "Face0")
00144     geompy.addToStudy(vnorm, "Normale to Face0")
00145     print "\nNormale of face has been successfully obtained:"
00146     #Coords = geompy.PointCoordinates(pcdg)
00147     #print "(", Coords[0], ", ", Coords[1], ", ", Coords[2], ")"
00148     #if Coords[0] != 5 or Coords[1] != 15 or Coords[2] != 35:
00149     #  print "But must be (5, 15, 35)"
00150 
00151   ####### MinDistance #######
00152 
00153   MinDist = geompy.MinDistance(box, cube)
00154 
00155   #print "\nMinimal distance between Box and Cube = ", MinDist[0]
00156   #print "It is reached at points:"
00157   #print " On Box  (", MinDist[1], ", ", MinDist[2], ", ", MinDist[3], ")"
00158   #print " On Cube (", MinDist[4], ", ", MinDist[5], ", ", MinDist[6], ")"
00159 
00160   print "\nMinimal distance between Box and Cube = ", MinDist
00161 
00162   MinDistComps = geompy.MinDistanceComponents(box, cube)
00163   print "\nMinimal distance between Box and Cube = ", MinDistComps[0]
00164   print "Its components are  (", MinDistComps[1], ", ", MinDistComps[2], ", ", MinDistComps[3], ")"
00165 
00166   ####### Angle #######
00167 
00168   OX  = geompy.MakeVectorDXDYDZ(10, 0,0)
00169   OXY = geompy.MakeVectorDXDYDZ(10,10,0)
00170 
00171   # in one plane
00172   Angle = geompy.GetAngle(OX, OXY)
00173 
00174   print "\nAngle between OX and OXY = ", Angle
00175   if math.fabs(Angle - 45.0) > 1e-05:
00176     print "  Error: returned angle is", Angle, "while must be 45.0"
00177 
00178   Angle = geompy.GetAngleRadians(OX, OXY)
00179 
00180   print "\nAngle between OX and OXY in radians = ", Angle
00181   if math.fabs(Angle - math.pi/4) > 1e-05:
00182     print "  Error: returned angle is", Angle, "while must be pi/4"
00183     pass
00184 
00185   # not in one plane
00186   OXY_shift = geompy.MakeTranslation(OXY,10,-10,20)
00187   Angle = geompy.GetAngle(OX, OXY_shift)
00188 
00189   print "Angle between OX and OXY_shift = ", Angle
00190   if math.fabs(Angle - 45.0) > 1e-05:
00191     print "  Error: returned angle is", Angle, "while must be 45.0"
00192 
00193   ####### Position (LCS) #######
00194 
00195   Pos = geompy.GetPosition(box)
00196   print "\nPosition(LCS) of box 10x30x70:"
00197   print "Origin: (", Pos[0], ", ", Pos[1], ", ", Pos[2], ")"
00198   print "Z axis: (", Pos[3], ", ", Pos[4], ", ", Pos[5], ")"
00199   print "X axis: (", Pos[6], ", ", Pos[7], ", ", Pos[8], ")"
00200 
00201   ####### KindOfShape #######
00202 
00203   Kind = geompy.KindOfShape(box)
00204   print "\nKindOfShape(box 10x30x70):", Kind
00205   #if Kind[0] != geompy.kind.BOX:
00206   #  print "Error: returned type is", Kind[0], "while must be", geompy.kind.BOX
00207 
00208   Kind = geompy.KindOfShape(p137)
00209   print "\nKindOfShape(p137):", Kind
00210   if Kind[0] != geompy.kind.VERTEX:
00211     print "  Error: returned type is", Kind[0], "while must be", geompy.kind.VERTEX
00212   else:
00213     dx = math.fabs(Kind[1] - 10)
00214     dy = math.fabs(Kind[2] - 30)
00215     dz = math.fabs(Kind[3] - 70)
00216     if (dx + dy + dz) > 1e-5:
00217       print "  Error: coordinates are (", Kind[1], ",", Kind[2], ",", Kind[3], ") while must be (10, 20, 30)"
00218 
00219   pass