Back to index

salome-geom  6.5.0
GEOM_TestHealing.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 #  GEOM GEOM_SWIG : binding of C++ implementaion with Python
00025 #  File   : GEOM_TestHealing.py
00026 #  Author : Julia DOROVSKIKH
00027 #  Module : GEOM
00028 #  $Header: /home/server/cvs/GEOM/GEOM_SRC/src/GEOM_SWIG/GEOM_TestHealing.py,v 1.7.2.2.10.3.14.1 2012-04-13 05:48:08 vsr Exp $
00029 #
00030 def TestProcessShape (geompy):
00031 
00032   ##Load shape from BREP file
00033   #import os
00034   #datadir = os.getenv("GEOM_TEST")
00035   #if datadir != 0:
00036   #  datadir = datadir + "/Resources/"
00037   #else:
00038   #  "Please, define GEOM_TEST variable !"
00039   #
00040   #print "Import ", datadir + "aze2.brep"
00041   #Shape = batchmode_geompy.Import(datadir + "aze2.brep", "BREP")
00042 
00043   p1 = geompy.MakeVertex(0,0,0)
00044   p2 = geompy.MakeVertex(200,0,0)
00045   p3 = geompy.MakeVertex(100,150,0)
00046 
00047   edge = geompy.MakeEdge(p1,p2)
00048   arc  = geompy.MakeArc(p1,p3,p2)
00049   wire = geompy.MakeWire([edge,arc])
00050   face = geompy.MakeFace(wire, 1)
00051 
00052   theShape = geompy.MakePrismVecH(face, edge, 130)
00053 
00054   #Check shape
00055   print "Before ProcessShape:"
00056   isValid = geompy.CheckShape(theShape)
00057   if isValid == 0:
00058     print "The shape is not valid"
00059   else:
00060     print "The shape seems to be valid"
00061 
00062   #Process Shape
00063   Operators = ["FixShape"]
00064   Parameters = ["FixShape.Tolerance3d"]
00065   Values = ["1e-7"]
00066 
00067   PS = geompy.ProcessShape(theShape, Operators, Parameters, Values)
00068 
00069   #Check shape
00070   print "After ProcessShape:"
00071   isValid = geompy.CheckShape(PS)
00072   if isValid == 0:
00073     print "The shape is not valid"
00074     raise RuntimeError, "It seems, that the ProcessShape() has failed"
00075   else:
00076     print "The shape seems to be valid"
00077 
00078   #Add In Study
00079   Id_Shape = geompy.addToStudy(theShape, "Invalid Shape")
00080   Id_PS    = geompy.addToStudy(PS, "Processed Shape")
00081 
00082 def TestSuppressFaces (geompy):
00083 
00084   #Create base geometry 3D
00085   Box = geompy.MakeBoxDXDYDZ(200., 200., 200.)
00086 
00087   #IDList for SuppHole
00088   faces = []
00089   faces = geompy.SubShapeAllSortedCentres(Box, geompy.ShapeType["FACE"])
00090 
00091   f_glob_id = geompy.GetSubShapeID(Box, faces[5])
00092 
00093   #Transform objects
00094   SuppFace = geompy.SuppressFaces(Box, [f_glob_id])
00095 
00096   #Add In Study
00097   Id_SuppFace = geompy.addToStudy(SuppFace, "SuppFace")
00098 
00099 def TestSuppressInternalWires (geompy):
00100 
00101   #Create Face with hole
00102   p11 = geompy.MakeVertex( 0,  0, 0)
00103   p12 = geompy.MakeVertex(30,  0, 0)
00104   p13 = geompy.MakeVertex(30, 30, 0)
00105   p14 = geompy.MakeVertex( 0, 30, 0)
00106 
00107   p21 = geompy.MakeVertex(10, 10, 0)
00108   p22 = geompy.MakeVertex(20, 10, 0)
00109   p23 = geompy.MakeVertex(20, 20, 0)
00110   p24 = geompy.MakeVertex(10, 20, 0)
00111 
00112   e11 = geompy.MakeEdge(p11, p12)
00113   e12 = geompy.MakeEdge(p12, p13)
00114   e13 = geompy.MakeEdge(p13, p14)
00115   e14 = geompy.MakeEdge(p14, p11)
00116 
00117   e21 = geompy.MakeEdge(p21, p22)
00118   e22 = geompy.MakeEdge(p22, p23)
00119   e23 = geompy.MakeEdge(p23, p24)
00120   e24 = geompy.MakeEdge(p24, p21)
00121 
00122   w1 = geompy.MakeWire([e11, e12, e13, e14])
00123   w2 = geompy.MakeWire([e21, e22, e23, e24])
00124 
00125   id_w1 = geompy.addToStudy(w1, "Outside Wire")
00126   id_w2 = geompy.addToStudy(w2, "Inside Wire")
00127 
00128   f12 = geompy.MakeFaceWires([w1, w2], 0)
00129   id_f12 = geompy.addToStudy(f12, "Face WO + WI")
00130 
00131   #Get Free Boundary
00132   Res1 = geompy.GetFreeBoundary(f12)
00133   isSuccess1   = Res1[0]
00134   ClosedWires1 = Res1[1]
00135   OpenWires1   = Res1[2]
00136   nbw1 = 0
00137 
00138   for wire in ClosedWires1:
00139     nbw1 = nbw1 + 1
00140 
00141   if nbw1 != 2:
00142     raise RuntimeError, "GetFreeBoundary(f12) must return 2 closed wires, but returned ", nbw1
00143 
00144   #SuppressInternalWires
00145   face = geompy.SuppressInternalWires(f12, [])
00146 
00147   #Get Free Boundary
00148   Res2 = geompy.GetFreeBoundary(face)
00149   isSuccess2   = Res2[0]
00150   ClosedWires2 = Res2[1]
00151   OpenWires2   = Res2[2]
00152   nbw2 = 0
00153 
00154   for wire in ClosedWires2:
00155     nbw2 = nbw2 + 1
00156 
00157   if nbw2 != 1:
00158     print "GetFreeBoundary(face) must return 1 closed wires, but returned ", nbw2
00159     raise RuntimeError, "SuppressInternalWires() works not correctly"
00160 
00161   #Add In Study
00162   Id_face = geompy.addToStudy(face, "Face without internal wires")
00163 
00164 def TestCloseContour (geompy):
00165 
00166   ##Load shape from BREP file
00167   #import os
00168   #datadir = os.getenv("GEOM_TEST")
00169   #if datadir != 0:
00170   #  datadir = datadir + "/Resources/"
00171   #else:
00172   #  "Please, define GEOM_TEST variable !"
00173   #
00174   #print "Import ", datadir + "open_cont.brep"
00175   #Shape = geompy.Import(datadir + "open_cont.brep", "BREP")
00176 
00177   p0   = geompy.MakeVertex(0.  , 0.  , 0.  )
00178   py   = geompy.MakeVertex(0.  , 100., 0.  )
00179   pz   = geompy.MakeVertex(0.  , 0.  , 100.)
00180   p200 = geompy.MakeVertex(200., 200., 200.)
00181 
00182   Shape = geompy.MakePolyline([p0, pz, py, p200])
00183 
00184   #Check shape
00185   print "Before closing contour:"
00186   isValid = geompy.CheckShape(Shape)
00187   if isValid == 0:
00188     print "The shape is not valid"
00189   else:
00190     print "The shape seems to be valid"
00191 
00192   #Close Contour
00193   IsCommonVertex = 0 # false
00194 
00195   shape_wires = geompy.SubShapeAll(Shape, geompy.ShapeType["WIRE"])
00196   Wires = []
00197   wi = 0
00198 
00199   for wire in shape_wires:
00200     Wires.append(geompy.GetSubShapeID(Shape, shape_wires[wi]))
00201     wi = wi + 1
00202 
00203   CC = geompy.CloseContour(Shape, Wires, IsCommonVertex)
00204 
00205   #Check shape
00206   print "After closing contour:"
00207   isValid = geompy.CheckShape(CC)
00208   if isValid == 0:
00209     print "The shape is not valid"
00210     raise RuntimeError, "It seems, that the contour was not closed"
00211   else:
00212     print "The shape seems to be valid"
00213 
00214   #Add In Study
00215   Id_Shape = geompy.addToStudy(Shape, "Shape with open wire")
00216   Id_CC    = geompy.addToStudy(CC, "Shape with closed wire")
00217 
00218 def TestSuppressHoles (geompy):
00219 
00220   #Create base Variables
00221   radius = 50.
00222   height = 300.
00223 
00224   #Create base points
00225   p1 = geompy.MakeVertex(100., 100., 50.)
00226 
00227   #Create base directions
00228   vz = geompy.MakeVectorDXDYDZ(0., 0., 100.)
00229 
00230   #Create base geometry 3D
00231   Box      = geompy.MakeBoxDXDYDZ(200., 200., 200.)
00232   Cylinder = geompy.MakeCylinder(p1, vz, radius, height)
00233 
00234   #Boolean (Cut)
00235   Cut = geompy.MakeBoolean(Box, Cylinder, 2)
00236   idCut = geompy.addToStudy(Cut, "CUT")
00237 
00238   #IDList for SuppressFaces
00239   faces = []
00240   faces = geompy.SubShapeAllSortedCentres(Cut, geompy.ShapeType["FACE"])
00241   ind = 0
00242   for face in faces:
00243       f_name = "FACE %d"%(ind)
00244       f_id = geompy.addToStudyInFather(Cut, face, f_name)
00245 
00246       f_glob_id = geompy.GetSubShapeID(Cut, face)
00247       print "face ", ind, " global index = ", f_glob_id
00248       ind = ind + 1
00249 
00250   f_glob_id_0 = geompy.GetSubShapeID(Cut, faces[0])
00251   cut_without_f_0 = geompy.SuppressFaces(Cut, [f_glob_id_0])
00252   geompy.addToStudy(cut_without_f_0, "Cut without face 0")
00253 
00254   faces1 = []
00255   faces1 = geompy.SubShapeAllSortedCentres(cut_without_f_0, geompy.ShapeType["FACE"])
00256   ind = 0
00257   for face in faces1:
00258       f_name = "FACE %d"%(ind)
00259       f_id = geompy.addToStudyInFather(cut_without_f_0, face, f_name)
00260 
00261       f_glob_id = geompy.GetSubShapeID(cut_without_f_0, face)
00262       print "face ", ind, " global index = ", f_glob_id
00263       ind = ind + 1
00264 
00265   f_glob_id_3 = geompy.GetSubShapeID(cut_without_f_0, faces1[3])
00266   cut_without_f_0_3 = geompy.SuppressFaces(cut_without_f_0, [f_glob_id_3])
00267   cut_without_f_0_3_id = geompy.addToStudy(cut_without_f_0_3, "Cut without faces 0 and 3")
00268 
00269   #IDList for SuppHole
00270   wires = []
00271   wires = geompy.SubShapeAllSortedCentres(cut_without_f_0_3, geompy.ShapeType["WIRE"])
00272   ind = 0
00273   for wire in wires:
00274       w_name = "WIRE %d"%(ind)
00275       w_id = geompy.addToStudyInFather(cut_without_f_0_3, wire, w_name)
00276 
00277       w_glob_id = geompy.GetSubShapeID(cut_without_f_0_3, wire)
00278       print "wire ", ind, " global index = ", w_glob_id
00279       ind = ind + 1
00280 
00281   w_3 = geompy.GetSubShapeID(cut_without_f_0_3, wires[3])
00282 
00283   SuppHole3 = geompy.SuppressHoles(cut_without_f_0_3, [w_3])
00284   SuppHole3_id = geompy.addToStudy(SuppHole3, "Supp Hole 3")
00285 
00286 def TestMakeSewing (geompy, math):
00287 
00288   #Create base points
00289   px = geompy.MakeVertex(100., 0., 0.)
00290   py = geompy.MakeVertex(0., 100., 0.)
00291   pz = geompy.MakeVertex(0., 0., 100.)
00292 
00293   #Create base geometry 2D & 3D
00294   Vector = geompy.MakeVector(px, py)
00295   Arc    = geompy.MakeArc(py, pz, px)
00296 
00297   #Create base objects
00298   angle     = 45. * math.pi / 180
00299   WantPlanarFace = 1 #True
00300 
00301   Wire = geompy.MakeWire([Vector, Arc])
00302   Face = geompy.MakeFace(Wire, WantPlanarFace)
00303   S    = geompy.MakeRotation(Face, Vector, angle)
00304 
00305   #Make Sewing
00306   precision = 0.00001
00307   Sewing = geompy.MakeSewing([Face, S], precision)
00308 
00309   #Add In Study
00310   id_Sewing = geompy.addToStudy(Sewing, "Sewing")
00311 
00312 def TestDivideEdge (geompy):
00313 
00314   #Create Box
00315   Box = geompy.MakeBoxDXDYDZ(200., 200., 200.)
00316 
00317   #Divide Edge
00318   box_edges = geompy.SubShapeAllSortedCentres(Box, geompy.ShapeType["EDGE"])
00319   edge_ind = geompy.GetSubShapeID(Box, box_edges[1])
00320 
00321   Divide = geompy.DivideEdge(Box, edge_ind, 0.5, 1) # Obj, ind, param, is_curve_param
00322 
00323   #Add In Study
00324   Id_Box    = geompy.addToStudy(Box, "Box")
00325   Id_Divide = geompy.addToStudy(Divide, "Box with Divided Edge")
00326 
00327 def TestHealingOperations (geompy, math):
00328 
00329   TestMakeSewing(geompy, math)
00330   TestDivideEdge(geompy)
00331   TestSuppressHoles(geompy)
00332   TestSuppressInternalWires(geompy)
00333   TestCloseContour(geompy)
00334   TestSuppressFaces(geompy)
00335   TestProcessShape(geompy)