def boundary_curve_from_2_points(p1, p2): # first create an edge e0 = BRepBuilderAPI_MakeEdge(p1, p2).Edge() w0 = BRepBuilderAPI_MakeWire(e0).Wire() # boundary for filling adap = BRepAdaptor_CompCurve(w0) p0_h = BRepAdaptor_HCompCurve(adap) boundary = GeomFill_SimpleBound(p0_h.GetHandle(), 1e-6, 1e-6) return boundary.GetHandle()
def wire_to_curve(wire, tolerance=TOLERANCE, order=GeomAbs_C2, max_segment=200, max_order=12): ''' a wire can consist of many edges. these edges are merged given a tolerance and a curve @param wire: ''' adap = BRepAdaptor_CompCurve(wire) hadap = BRepAdaptor_HCompCurve(adap) from OCC.Approx import Approx_Curve3d approx = Approx_Curve3d(hadap.GetHandle(), tolerance, order, max_segment, max_order) with assert_isdone(approx, 'not able to compute approximation from wire'): return approx.Curve().GetObject()
def wire_2_bsplinecurve_edge(occwire): """ This function covnerts an OCCwire to a bspline OCCedge. Parameters ---------- occwire : OCCwire The OCCwire to be converted. Returns ------- converted bspline edge : OCCedge The converted OCCedge. """ adaptor = BRepAdaptor_CompCurve(occwire) hadap = BRepAdaptor_HCompCurve(adaptor) from OCC.Core.Approx import Approx_Curve3d from OCC.Core.GeomAbs import GeomAbs_C2 approx = Approx_Curve3d(hadap, 1e-06, GeomAbs_C2, 10000, 12) bspline_handle = approx.Curve() occedge = BRepBuilderAPI_MakeEdge(bspline_handle) return occedge.Edge()
from OCC.Core.Approx import Approx_Curve3d from OCC.Core.GeomAbs import GeomAbs_C2 from OCC.Core.GeomAPI import GeomAPI_ProjectPointOnCurve # Read wire wire_filename = os.path.join('..', 'assets', 'models', 'wire.brep') shp = TopoDS_Shape() aBuilder = BRep_Builder() breptools.Read(shp, wire_filename, aBuilder) wire = topods.Wire(shp) if wire.IsNull(): raise AssertionError("Wire is Null") # discretize the wire and interpolate using a C2 wireAdaptor = BRepAdaptor_CompCurve(wire) curve = BRepAdaptor_HCompCurve(wireAdaptor) tol = 1e-7 max_segments = 200 max_degrees = 12 approx = Approx_Curve3d(curve, tol, GeomAbs_C2, max_segments, max_degrees) if (approx.IsDone() and approx.HasResult()): an_approximated_curve = approx.Curve() # there are two ways to project a point on this curve, # they both give the same restult # 1st solution: using GeomAPI_ProjectPointOnCurve point_to_project = gp_Pnt(1., 2., 3.) projection = GeomAPI_ProjectPointOnCurve(point_to_project, an_approximated_curve) # get the results of the projection