PageRenderTime 20ms CodeModel.GetById 1ms app.highlight 13ms RepoModel.GetById 2ms app.codeStats 0ms

/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
 1# This is a simple port of Fotis'code to python
 2# see: http://www.opencascade.org/org/forum/thread_14890/
 3
 4from OCC.BRepPrimAPI import *
 5from OCC.TopAbs import *
 6from OCC.TopExp import *
 7from OCC.TopoDS import *
 8from OCC.SMESH import *
 9from OCC.StdMeshers import *
10from OCC.MeshVS import *
11
12from OCC.Display.SimpleGui import *
13display, start_display, add_menu, add_function_to_menu = init_display()
14#Create the shape to mesh
15#aShape = BRepPrimAPI_MakeSphere(40).Shape()
16aShape = BRepPrimAPI_MakeBox(10,20,30).Shape()
17#aShape = BRepPrimAPI_MakeTorus(400,40).Shape()
18
19aMeshGen = SMESH_Gen()
20aMesh = aMeshGen.CreateMesh(0,True)
21
22an1DHypothesis = StdMeshers_Arithmetic1D(0,0,aMeshGen)
23an1DHypothesis.SetLength(1.,False)
24an1DHypothesis.SetLength(5.,True)
25an1DAlgo = StdMeshers_Regular_1D(1,0,aMeshGen)
26
27a2dHypothseis = StdMeshers_QuadranglePreference(2,0,aMeshGen)
28a2dAlgo = StdMeshers_Quadrangle_2D(3,0,aMeshGen)
29
30#Calculate mesh
31aMesh.ShapeToMesh(aShape)
32
33#Assign hyptothesis to mesh
34aMesh.AddHypothesis(aShape,0)
35aMesh.AddHypothesis(aShape,1)
36aMesh.AddHypothesis(aShape,2)
37aMesh.AddHypothesis(aShape,3)
38
39#Compute the data
40aMeshGen.Compute(aMesh,aMesh.GetShapeToMesh())
41
42# Export the data
43print "Export to DAT"
44aMesh.ExportDAT("_TEST.DAT")
45
46print "Export to STL"
47aMesh.ExportSTL("_TEST.STL",True) #True if ascii
48
49print "Export to UNV"
50aMesh.ExportUNV("_TEST.UNV") #True if ascii
51
52# Export to MED fails
53#print "Export to MED"
54#aMesh.ExportMED("_TEST.MED")
55
56# Display the data
57aDS = SMESH_MeshVSLink(aMesh)
58aMeshVS = MeshVS_Mesh(True)
59DMF = 1 # to wrap!
60MeshVS_BP_Mesh       =  5 # To wrap!
61
62aPrsBuilder = MeshVS_MeshPrsBuilder(aMeshVS.GetHandle(),DMF,aDS.GetHandle(),0,MeshVS_BP_Mesh)
63aMeshVS.SetDataSource(aDS.GetHandle())
64aMeshVS.AddBuilder(aPrsBuilder.GetHandle(),True)
65
66
67context = display.Context
68context.Display(aMeshVS.GetHandle())
69context.Deactivate(aMeshVS.GetHandle())
70display.DisplayShape(aShape)
71start_display()
72
73
74