365tuwe

faceFromPoints.py

May 7th, 2013
291
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.78 KB | None | 0 0
  1. #!/usr/bin/env python                                                                                    
  2.                                                                                                          
  3. from OCC.Utils.Construct import make_closed_polygon, make_n_sided, make_vertex, make_face, make_wire
  4.  
  5. from OCC.gp import *
  6. from OCC.BRepBuilderAPI import *
  7.  
  8. from OCC.Utils.Topology import WireExplorer, Topo
  9. from OCC.BRepAdaptor import *
  10. from OCC.BRep import *
  11. from OCC.ShapeAnalysis import *
  12. from OCC.GeomLProp import *
  13.  
  14. import types, sys, time, random
  15.  
  16. from OCC.Display.SimpleGui import init_display
  17. from OCC.Utils.DataExchange.IGES import IGESImporter
  18. from OCC.BRepFill import *
  19. from OCC.GeomPlate import *
  20.  
  21. display, start_display, add_menu, add_function_to_menu = init_display()
  22.  
  23. def build_plate(polygon, points):
  24.         '''
  25.        build a surface from a constraining polygon(s) and point(s)
  26.        @param polygon:  list of polygons ( TopoDS_Shape)
  27.        @param points:    list of points ( gp_Pnt )
  28.        '''
  29.         # plate surface
  30.         bpSrf = GeomPlate_BuildPlateSurface(3,15,2)
  31.  
  32.         # add curve constraints
  33.         for poly in polygon:
  34.                 for edg in WireExplorer(poly).ordered_edges():
  35.                         c = BRepAdaptor_HCurve()
  36.                         c.ChangeCurve().Initialize(edg)
  37.                         constraint = BRepFill_CurveConstraint(c.GetHandle(), 0)
  38.                         bpSrf.Add(constraint.GetHandle())
  39.  
  40.         # add point constraint
  41.         for pt in points:
  42.                 bpSrf.Add(GeomPlate_PointConstraint(pt, 0).GetHandle())
  43.                 bpSrf.Perform()
  44.  
  45.         maxSeg, maxDeg, critOrder = 9,8,0
  46.         tol  = 1e-4
  47.         dmax = max([tol,10*bpSrf.G0Error()])
  48.  
  49.         srf = bpSrf.Surface()
  50.         plate = GeomPlate_MakeApprox(srf, tol, maxSeg, maxDeg, dmax, critOrder)
  51.  
  52.         print type(plate.Surface())
  53.         uMin, uMax, vMin, vMax = srf.GetObject().Bounds()
  54.  
  55.         return make_face(plate.Surface(), uMin, uMax, vMin, vMax)
  56.  
  57. def geom_plate():
  58.         # random number of random points in xy-plane at height z
  59.         height = 0.5
  60.         pmax = 50
  61.         p = 0
  62.         ub = 1.0
  63.         pnts = []
  64.         while p < pmax:
  65.                 pnts.append(gp_Pnt(random.uniform(0.0,ub), random.uniform(0.0,ub), height))
  66.                 p += 1
  67.  
  68.         poly = make_closed_polygon(pnts[0:-1])
  69.         edges = [i for i in Topo(poly).edges()]
  70.         face = make_n_sided(edges, [pnts[-1]])
  71.  
  72.         plate = build_plate([poly], [pnts[-1]])
  73.  
  74.         #display.DisplayShape(plate)
  75.         display.DisplayShape(edges)
  76.         display.DisplayShape(make_vertex(pnts[-1]))
  77.         display.DisplayShape(face, update=True)
  78.  
  79. if __name__ == "__main__":
  80.         geom_plate()
  81.         start_display()
Advertisement
Add Comment
Please, Sign In to add comment