/src/examples/Level1/SMESH/test_smesh.py
http://pythonocc.googlecode.com/ · Python · 74 lines · 42 code · 19 blank · 13 comment · 0 complexity · 160aa3e85efcdbbda303cb745c1a5102 MD5 · raw file
- # This is a simple port of Fotis'code to python
- # see: http://www.opencascade.org/org/forum/thread_14890/
- from OCC.BRepPrimAPI import *
- from OCC.TopAbs import *
- from OCC.TopExp import *
- from OCC.TopoDS import *
- from OCC.SMESH import *
- from OCC.StdMeshers import *
- from OCC.MeshVS import *
- from OCC.Display.SimpleGui import *
- display, start_display, add_menu, add_function_to_menu = init_display()
- #Create the shape to mesh
- #aShape = BRepPrimAPI_MakeSphere(40).Shape()
- aShape = BRepPrimAPI_MakeBox(10,20,30).Shape()
- #aShape = BRepPrimAPI_MakeTorus(400,40).Shape()
- aMeshGen = SMESH_Gen()
- aMesh = aMeshGen.CreateMesh(0,True)
- an1DHypothesis = StdMeshers_Arithmetic1D(0,0,aMeshGen)
- an1DHypothesis.SetLength(1.,False)
- an1DHypothesis.SetLength(5.,True)
- an1DAlgo = StdMeshers_Regular_1D(1,0,aMeshGen)
- a2dHypothseis = StdMeshers_QuadranglePreference(2,0,aMeshGen)
- a2dAlgo = StdMeshers_Quadrangle_2D(3,0,aMeshGen)
- #Calculate mesh
- aMesh.ShapeToMesh(aShape)
- #Assign hyptothesis to mesh
- aMesh.AddHypothesis(aShape,0)
- aMesh.AddHypothesis(aShape,1)
- aMesh.AddHypothesis(aShape,2)
- aMesh.AddHypothesis(aShape,3)
- #Compute the data
- aMeshGen.Compute(aMesh,aMesh.GetShapeToMesh())
- # Export the data
- print "Export to DAT"
- aMesh.ExportDAT("_TEST.DAT")
- print "Export to STL"
- aMesh.ExportSTL("_TEST.STL",True) #True if ascii
- print "Export to UNV"
- aMesh.ExportUNV("_TEST.UNV") #True if ascii
- # Export to MED fails
- #print "Export to MED"
- #aMesh.ExportMED("_TEST.MED")
- # Display the data
- aDS = SMESH_MeshVSLink(aMesh)
- aMeshVS = MeshVS_Mesh(True)
- DMF = 1 # to wrap!
- MeshVS_BP_Mesh = 5 # To wrap!
- aPrsBuilder = MeshVS_MeshPrsBuilder(aMeshVS.GetHandle(),DMF,aDS.GetHandle(),0,MeshVS_BP_Mesh)
- aMeshVS.SetDataSource(aDS.GetHandle())
- aMeshVS.AddBuilder(aPrsBuilder.GetHandle(),True)
- context = display.Context
- context.Display(aMeshVS.GetHandle())
- context.Deactivate(aMeshVS.GetHandle())
- display.DisplayShape(aShape)
- start_display()