Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- from OCC.Utils.Construct import make_closed_polygon, make_n_sided, make_vertex, make_face, make_wire
- from OCC.gp import *
- from OCC.BRepBuilderAPI import *
- from OCC.Utils.Topology import WireExplorer, Topo
- from OCC.BRepAdaptor import *
- from OCC.BRep import *
- from OCC.ShapeAnalysis import *
- from OCC.GeomLProp import *
- import types, sys, time, random
- from OCC.Display.SimpleGui import init_display
- from OCC.Utils.DataExchange.IGES import IGESImporter
- from OCC.BRepFill import *
- from OCC.GeomPlate import *
- display, start_display, add_menu, add_function_to_menu = init_display()
- def build_plate(polygon, points):
- '''
- build a surface from a constraining polygon(s) and point(s)
- @param polygon: list of polygons ( TopoDS_Shape)
- @param points: list of points ( gp_Pnt )
- '''
- # plate surface
- bpSrf = GeomPlate_BuildPlateSurface(3,15,2)
- # add curve constraints
- for poly in polygon:
- for edg in WireExplorer(poly).ordered_edges():
- c = BRepAdaptor_HCurve()
- c.ChangeCurve().Initialize(edg)
- constraint = BRepFill_CurveConstraint(c.GetHandle(), 0)
- bpSrf.Add(constraint.GetHandle())
- # add point constraint
- for pt in points:
- bpSrf.Add(GeomPlate_PointConstraint(pt, 0).GetHandle())
- bpSrf.Perform()
- maxSeg, maxDeg, critOrder = 9,8,0
- tol = 1e-4
- dmax = max([tol,10*bpSrf.G0Error()])
- srf = bpSrf.Surface()
- plate = GeomPlate_MakeApprox(srf, tol, maxSeg, maxDeg, dmax, critOrder)
- print type(plate.Surface())
- uMin, uMax, vMin, vMax = srf.GetObject().Bounds()
- return make_face(plate.Surface(), uMin, uMax, vMin, vMax)
- def geom_plate():
- # random number of random points in xy-plane at height z
- height = 0.5
- pmax = 50
- p = 0
- ub = 1.0
- pnts = []
- while p < pmax:
- pnts.append(gp_Pnt(random.uniform(0.0,ub), random.uniform(0.0,ub), height))
- p += 1
- poly = make_closed_polygon(pnts[0:-1])
- edges = [i for i in Topo(poly).edges()]
- face = make_n_sided(edges, [pnts[-1]])
- plate = build_plate([poly], [pnts[-1]])
- #display.DisplayShape(plate)
- display.DisplayShape(edges)
- display.DisplayShape(make_vertex(pnts[-1]))
- display.DisplayShape(face, update=True)
- if __name__ == "__main__":
- geom_plate()
- start_display()
Advertisement
Add Comment
Please, Sign In to add comment