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