def brep_feat_rib(event=None): mkw = BRepBuilderAPI_MakeWire() mkw.Add(BRepBuilderAPI_MakeEdge(gp_Pnt(0., 0., 0.), gp_Pnt(200., 0., 0.)).Edge()) mkw.Add(BRepBuilderAPI_MakeEdge(gp_Pnt(200., 0., 0.), gp_Pnt(200., 0., 50.)).Edge()) mkw.Add(BRepBuilderAPI_MakeEdge(gp_Pnt(200., 0., 50.), gp_Pnt(50., 0., 50.)).Edge()) mkw.Add(BRepBuilderAPI_MakeEdge(gp_Pnt(50., 0., 50.), gp_Pnt(50., 0., 200.)).Edge()) mkw.Add(BRepBuilderAPI_MakeEdge(gp_Pnt(50., 0., 200.), gp_Pnt(0., 0., 200.)).Edge()) mkw.Add(BRepBuilderAPI_MakeEdge(gp_Pnt(0., 0., 200.), gp_Pnt(0., 0., 0.)).Edge()) S = BRepPrimAPI_MakePrism(BRepBuilderAPI_MakeFace(mkw.Wire()).Face(), gp_Vec(gp_Pnt(0., 0., 0.), gp_Pnt(0., 100., 0.))) display.EraseAll() # display.DisplayShape(S.Shape()) W = BRepBuilderAPI_MakeWire(BRepBuilderAPI_MakeEdge(gp_Pnt(50., 45., 100.), gp_Pnt(100., 45., 50.)).Edge()) aplane = Geom_Plane(0., 1., 0., -45.) aform = BRepFeat_MakeLinearForm(S.Shape(), W.Wire(), aplane, gp_Vec(0., 10., 0.), gp_Vec(0., 0., 0.), 1, True) aform.Perform() display.DisplayShape(aform.Shape()) display.FitAll()
def thicken_spline(event=None): # Creation of points for the spine array = TColgp_Array1OfPnt(1, 5) array.SetValue(1, gp_Pnt(1, 4, 0)) array.SetValue(2, gp_Pnt(2, 2, 0)) array.SetValue(3, gp_Pnt(3, 3, 0)) array.SetValue(4, gp_Pnt(4, 3, 0)) array.SetValue(5, gp_Pnt(5, 5, 0)) # Creation of a Bezier Curve as the spine bz_curv = Geom_BezierCurve(array) bz_curv_edge = BRepBuilderAPI_MakeEdge(bz_curv).Edge() bz_curv_wire = BRepBuilderAPI_MakeWire(bz_curv_edge).Wire() display.DisplayShape(bz_curv_wire) # Creation of profile to sweep along the spine circle = gp_Circ(gp_ZOX(), 1) circle.SetLocation(array[0]) circle_edge = BRepBuilderAPI_MakeEdge(circle).Edge() circle_wire = BRepBuilderAPI_MakeWire(circle_edge).Wire() # Creation of the law to dictate the evolution of the profile brep1 = BRepOffsetAPI_MakePipeShell(bz_curv_wire) law_f = Law_Linear() law_f.Set(0, 0.5, 1, 1) brep1.SetLaw(circle_wire, law_f, False, True) return brep1.Shape()
def make_wire(*args): # if we get an iterable, than add all edges to wire builder if isinstance(args[0], list) or isinstance(args[0], tuple): wire = BRepBuilderAPI_MakeWire() for i in args[0]: wire.Add(i) wire.Build() return wire.Wire() wire = BRepBuilderAPI_MakeWire(*args) return wire.Wire()
def make_wire(*args): # if we get an iterable, than add all edges to wire builder if isinstance(args[0], (list, tuple)): wire = BRepBuilderAPI_MakeWire() for i in args[0]: wire.Add(i) wire.Build() return wire.Wire() wire = BRepBuilderAPI_MakeWire(*args) assert_isdone(wire, "failed to produce wire") return wire.Wire()
def display_path(lay, col, nozz_dia=0): wire = BRepBuilderAPI_MakeWire() for i in range(1, len(lay)): if lay[i - 1][0].Distance(lay[i][0]) < 8 and i < len(lay) - 1: ray = BRepBuilderAPI_MakeEdge(lay[i - 1][0], lay[i][0]).Edge() wire.Add(ray) else: display.DisplayShape(wire.Wire(), color=col, update=False) wire = BRepBuilderAPI_MakeWire() if i < len(lay) - 1: display.DisplayShape(ray, color=col, update=False) else: display.DisplayShape(ray, color=col, update=True)
def make_wire(*args): # if we get an iterable, than add all edges to wire builder if isinstance(args[0], list) or isinstance(args[0], tuple): wire = BRepBuilderAPI_MakeWire() for i in args[0]: wire.Add(i) wire.Build() return wire.Wire() wire = BRepBuilderAPI_MakeWire(*args) wire.Build() with assert_isdone(wire, 'failed to produce wire'): result = wire.Wire() return result
def main(): vertices = [gp_Pnt(p[0], p[1], p[2]) for p in mesh['vertices']] oFaces = [] builder = BRep_Builder() shell = TopoDS_Shell() builder.MakeShell(shell) for face in mesh['faces']: edges = [] face.reverse() for i in range(len(face)): cur = face[i] nxt = face[(i + 1) % len(face)] segment = GC_MakeSegment(vertices[cur], vertices[nxt]) edges.append(BRepBuilderAPI_MakeEdge(segment.Value())) wire = BRepBuilderAPI_MakeWire() for edge in edges: wire.Add(edge.Edge()) oFace = BRepBuilderAPI_MakeFace(wire.Wire()) builder.Add(shell, oFace.Shape()) write_stl_file(shell, "./cube_binding.stl")
def display_path(lay, col): wire = BRepBuilderAPI_MakeWire() for i in range(1, len(lay)): if lay[i - 1][0].Distance(lay[i][0]) < 50: ray = BRepBuilderAPI_MakeEdge(lay[i - 1][0], lay[i][0]).Edge() wire.Add(ray) display.DisplayShape(wire.Wire(), color=col, update=False)
def to_wire(self, stroking_interval=5.0): """convert IfcTransitionSegment2D to OCC wire :param stroking_interval: maximum curve length between points to be calculated :type stroking_interval: float :return: OCC wire containing interpolated points """ points = list() L = self.SegmentLength R = self.EndRadius ccw = self.IsStartRadiusCCW trans_type = self.TransitionCurveType.name num_intervals = math.ceil(L / stroking_interval) interval_dist = L / num_intervals lpt = 0.0 # length along the curve at the point to be calculated for _ in range(num_intervals): points.append(self._calc_transition_curve_point(lpt, L, R, ccw, trans_type)) lpt += interval_dist edges = list() for i in range(len(points) - 1): edges.append(BRepBuilderAPI_MakeEdge2d(points[i], points[i + 1])) wire = BRepBuilderAPI_MakeWire() for e in edges: wire.Add(e.Edge()) # return wire return points
def brep_feat_local_revolution(event=None): S = BRepPrimAPI_MakeBox(400., 250., 300.).Shape() faces = list(TopologyExplorer(S).faces()) F1 = faces[2] surf = BRep_Tool_Surface(F1) D = gp_OX() MW1 = BRepBuilderAPI_MakeWire() p1 = gp_Pnt2d(100., 100.) p2 = gp_Pnt2d(200., 100.) aline = GCE2d_MakeLine(p1, p2).Value() MW1.Add(BRepBuilderAPI_MakeEdge(aline, surf, 0., p1.Distance(p2)).Edge()) p1 = gp_Pnt2d(200., 100.) p2 = gp_Pnt2d(150., 200.) aline = GCE2d_MakeLine(p1, p2).Value() MW1.Add(BRepBuilderAPI_MakeEdge(aline, surf, 0., p1.Distance(p2)).Edge()) p1 = gp_Pnt2d(150., 200.) p2 = gp_Pnt2d(100., 100.) aline = GCE2d_MakeLine(p1, p2).Value() MW1.Add(BRepBuilderAPI_MakeEdge(aline, surf, 0., p1.Distance(p2)).Edge()) MKF1 = BRepBuilderAPI_MakeFace() MKF1.Init(surf, False, 1e-6) MKF1.Add(MW1.Wire()) FP = MKF1.Face() breplib_BuildCurves3d(FP) MKrev = BRepFeat_MakeRevol(S, FP, F1, D, 1, True) F2 = faces[4] MKrev.Perform(F2) display.EraseAll() display.DisplayShape(MKrev.Shape()) display.FitAll()
def extrude_polyline2d(polyline, frame, height): pol3d = polyline.to_frame(frame) lines = [] yb_point = Point([frame[0][i] for i in range(3)]) yb_vec = Vector([frame[1][0][i] for i in range(3)]).unit() print '*************' print yb_vec orig = gp_Pnt(frame[0][0], frame[0][1], frame[0][2]) vec = gp_Dir(yb_vec[0], yb_vec[1], yb_vec[2]) plane = gp_Pln(orig, vec) for i, p in enumerate(pol3d[:-1]): print p print 'zob' gp0 = gp_Pnt(p[0], p[1], p[2]) gp1 = gp_Pnt(pol3d[i + 1][0], pol3d[i + 1][1], pol3d[i + 1][2]) lines.append(BRepBuilderAPI_MakeEdge(gp0, gp1).Edge()) wire = BRepBuilderAPI_MakeWire(lines[0]) for l in lines[1:]: wire.Add(l) face = BRepBuilderAPI_MakeFace(wire.Wire()) print 'normal' print[vec.X(), vec.Y(), vec.Z()] extrude = BRepPrimAPI_MakePrism( face.Shape(), gp_Vec(height * vec.X(), height * vec.Y(), height * vec.Z())).Shape() return extrude
def pipe(): # the bspline path, must be a wire array2 = TColgp_Array1OfPnt(1, 3) array2.SetValue(1, gp_Pnt(0, 0, 0)) array2.SetValue(2, gp_Pnt(0, 1, 2)) array2.SetValue(3, gp_Pnt(0, 2, 3)) bspline2 = GeomAPI_PointsToBSpline(array2).Curve() path_edge = BRepBuilderAPI_MakeEdge(bspline2).Edge() path_wire = BRepBuilderAPI_MakeWire(path_edge).Wire() # the bspline profile. Profile mist be a wire array = TColgp_Array1OfPnt(1, 5) array.SetValue(1, gp_Pnt(0, 0, 0)) array.SetValue(2, gp_Pnt(1, 2, 0)) array.SetValue(3, gp_Pnt(2, 3, 0)) array.SetValue(4, gp_Pnt(4, 3, 0)) array.SetValue(5, gp_Pnt(5, 5, 0)) bspline = GeomAPI_PointsToBSpline(array).Curve() profile_edge = BRepBuilderAPI_MakeEdge(bspline).Edge() # pipe pipe = BRepOffsetAPI_MakePipe(path_wire, profile_edge).Shape() display.DisplayShape(profile_edge, update=False) display.DisplayShape(path_wire, update=False) display.DisplayShape(pipe, update=True)
def make_revolved_cylinder(pnt, height, revolve_angle, rotation, wall_thick): """ This method demonstrates how to create a revolved shape from a drawn closed edge. It currently creates a hollow cylinder adapted from algotopia.com's opencascade_basic tutorial: http://www.algotopia.com/contents/opencascade/opencascade_basic :param pnt: :param height: :param revolve_angle: :param rotation: :param wall_thick: :type pnt: dict :type height: float :type revolve_angle: float :type rotation: float :type wall_thick: float """ from OCC.Core.BRepBuilderAPI import ( BRepBuilderAPI_MakeEdge, BRepBuilderAPI_MakeFace, BRepBuilderAPI_MakeWire, ) from OCC.Core.BRepPrimAPI import BRepPrimAPI_MakeRevol from OCC.Core.gp import gp_Ax1, gp_Dir, gp_Pnt face_inner_radius = pnt["X"] + (17.0 - wall_thick / 2) * 1000 face_outer_radius = pnt["X"] + (17.0 + wall_thick / 2) * 1000 # point to create an edge from edg_points = [ gp_Pnt(face_inner_radius, pnt["Y"], pnt["Z"]), gp_Pnt(face_inner_radius, pnt["Y"], pnt["Z"] + height), gp_Pnt(face_outer_radius, pnt["Y"], pnt["Z"] + height), gp_Pnt(face_outer_radius, pnt["Y"], pnt["Z"]), gp_Pnt(face_inner_radius, pnt["Y"], pnt["Z"]), ] # aggregate edges in wire hexwire = BRepBuilderAPI_MakeWire() for i in range(len(edg_points) - 1): hexedge = BRepBuilderAPI_MakeEdge(edg_points[i], edg_points[i + 1]).Edge() hexwire.Add(hexedge) hexwire_wire = hexwire.Wire() # face from wire hexface = BRepBuilderAPI_MakeFace(hexwire_wire).Face() revolve_axis = gp_Ax1(gp_Pnt(pnt["X"], pnt["Y"], pnt["Z"]), gp_Dir(0, 0, 1)) # create revolved shape revolved_shape_ = BRepPrimAPI_MakeRevol(hexface, revolve_axis, np.radians( float(revolve_angle))).Shape() revolved_shape_ = rotate_shp_3_axis(revolved_shape_, revolve_axis, rotation) return revolved_shape_
def makeHalfWire(event=None): global aWire aWire = BRepBuilderAPI_MakeWire(aEdge1.Edge(), aEdge2.Edge(), aEdge3.Edge()).Wire() display.EraseAll() display.DisplayColoredShape(aWire, 'BLUE') display.Repaint() win.statusBar().showMessage('Make Half Wire complete')
def display_path(lay, col, nozz_dia=0): wire = BRepBuilderAPI_MakeWire() for i in range(1, len(lay)): ray = BRepBuilderAPI_MakeEdge(lay[i - 1][0], lay[i][0]).Edge() if i == len(lay) - 1: display.DisplayShape(ray, color=col, update=True) else: display.DisplayShape(ray, color=col, update=False)
def _generate_tip(self, maxDeg): """ Private method to generate the surface that closing the blade tip. :param int maxDeg: Define the maximal U degree of generated surface """ self._import_occ_libs() generator = BRepOffsetAPI_ThruSections(False, False, 1e-10) generator.SetMaxDegree(maxDeg) # npoints_up == npoints_down npoints = len(self.blade_coordinates_down[-1][0]) vertices_1 = TColgp_HArray1OfPnt(1, npoints) vertices_2 = TColgp_HArray1OfPnt(1, npoints) for j in range(npoints): vertices_1.SetValue( j + 1, gp_Pnt(1000 * self.blade_coordinates_down[-1][0][j], 1000 * self.blade_coordinates_down[-1][1][j], 1000 * self.blade_coordinates_down[-1][2][j])) vertices_2.SetValue( j + 1, gp_Pnt(1000 * self.blade_coordinates_up[-1][0][j], 1000 * self.blade_coordinates_up[-1][1][j], 1000 * self.blade_coordinates_up[-1][2][j])) # Initializes an algorithm for constructing a constrained # BSpline curve passing through the points of the blade last # section, with tolerance = 1e-9 bspline_1 = GeomAPI_Interpolate(vertices_1, False, 1e-9) bspline_1.Perform() bspline_2 = GeomAPI_Interpolate(vertices_2, False, 1e-9) bspline_2.Perform() edge_1 = BRepBuilderAPI_MakeEdge(bspline_1.Curve()).Edge() edge_2 = BRepBuilderAPI_MakeEdge(bspline_2.Curve()).Edge() # Add BSpline wire to the generator constructor generator.AddWire(BRepBuilderAPI_MakeWire(edge_1).Wire()) generator.AddWire(BRepBuilderAPI_MakeWire(edge_2).Wire()) # Returns the shape built by the shape construction algorithm generator.Build() # Returns the Face generated by each edge of the first section self.generated_tip = generator.GeneratedFace(edge_1)
def face_polygon(pnts): wire_maker = BRepBuilderAPI_MakeWire() verts = [BRepBuilderAPI_MakeVertex(as_occ(pnt, gp_Pnt)).Vertex() for pnt in pnts] for i in range(len(verts)): j = (i + 1) % len(verts) wire_maker.Add(BRepBuilderAPI_MakeEdge(verts[i], verts[j]).Edge()) return BRepBuilderAPI_MakeFace(wire_maker.Wire()).Face()
def extrusion(event=None): # Make a box Box = BRepPrimAPI_MakeBox(400., 250., 300.) S = Box.Shape() # Choose the first Face of the box F = next(TopologyExplorer(S).faces()) surf = BRep_Tool_Surface(F) # Make a plane from this face Pl = Handle_Geom_Plane_DownCast(surf) Pln = Pl.GetObject() # Get the normal of this plane. This will be the direction of extrusion. D = Pln.Axis().Direction() # Inverse normal D.Reverse() # Create the 2D planar sketch MW = BRepBuilderAPI_MakeWire() p1 = gp_Pnt2d(200., -100.) p2 = gp_Pnt2d(100., -100.) aline = GCE2d_MakeLine(p1, p2).Value() Edge1 = BRepBuilderAPI_MakeEdge(aline, surf, 0., p1.Distance(p2)) MW.Add(Edge1.Edge()) p1 = p2 p2 = gp_Pnt2d(100., -200.) aline = GCE2d_MakeLine(p1, p2).Value() Edge2 = BRepBuilderAPI_MakeEdge(aline, surf, 0., p1.Distance(p2)) MW.Add(Edge2.Edge()) p1 = p2 p2 = gp_Pnt2d(200., -200.) aline = GCE2d_MakeLine(p1, p2).Value() Edge3 = BRepBuilderAPI_MakeEdge(aline, surf, 0., p1.Distance(p2)) MW.Add(Edge3.Edge()) p1 = p2 p2 = gp_Pnt2d(200., -100.) aline = GCE2d_MakeLine(p1, p2).Value() Edge4 = BRepBuilderAPI_MakeEdge(aline, surf, 0., p1.Distance(p2)) MW.Add(Edge4.Edge()) # Build Face from Wire. NB: a face is required to generate a solid. MKF = BRepBuilderAPI_MakeFace() MKF.Init(surf, False, 1e-6) MKF.Add(MW.Wire()) FP = MKF.Face() breplib_BuildCurves3d(FP) MKP = BRepFeat_MakePrism(S, FP, F, D, False, True) MKP.Perform(200.) # TODO MKP completes, seeing a split operation but no extrusion assert MKP.IsDone() res1 = MKP.Shape() display.EraseAll() display.DisplayColoredShape(res1, 'BLUE') display.FitAll()
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 _renderWireObj(self, aWire, aWireRadius): startPoint, tangentDir = _getWireStartPointAndTangentDir(aWire) profileCircle = GC_MakeCircle(startPoint, tangentDir, aWireRadius).Value() profileEdge = BRepBuilderAPI_MakeEdge(profileCircle).Edge() profileWire = BRepBuilderAPI_MakeWire(profileEdge).Wire() shape = BRepOffsetAPI_MakePipe(aWire, profileWire).Shape() self._renderShapeObj(shape)
def __make_wire(lst): mk = BRepBuilderAPI_MakeWire() for ptr in lst: if ptr.Shape().ShapeType() == TopAbs_WIRE: mk.Add(ptr.Wire()) elif ptr.Shape().ShapeType() == TopAbs_EDGE: mk.Add(ptr.Edge()) return mk.Wire()
def by_edge(edge): """ Create a wire from an edge. :param afem.topology.entities.Edge edge: The edge. :return: The wire. :rtype: afem.topology.entities.Wire """ return Wire(BRepBuilderAPI_MakeWire(edge.object).Wire())
def __init__(self, *edges): # Build builder = BRepBuilderAPI_MakeWire() for e in edges: if e is not None and not e.is_null and e.is_edge: builder.Add(e.object) self._w = Wire(builder.Wire()) self._last_e = Edge(builder.Edge()) self._last_v = Vertex(builder.Vertex())
def _make_wire(arr): mk = BRepBuilderAPI_MakeWire() for ptr in arr: if (ptr.Shape().ShapeType() == TopAbs_WIRE): mk.Add(ptr.Wire()) elif (ptr.Shape().ShapeType() == TopAbs_EDGE): mk.Add(ptr.Edge()) return Shape(mk.Wire())
def holes_in_face(): aPlane = gp_Pln() print(type(gp_Pln())) print(type(gp_XOY())) aCircle1 = gp_Circ(gp_XOY(), 1.0) aCircle2 = gp_Circ(gp_XOY(), 1.0) aCircle3 = gp_Circ(gp_XOY(), 1.0) aCircle1.SetLocation(gp_Pnt(3.0, 3.0, 0.0)) aCircle2.SetLocation(gp_Pnt(7.0, 3.0, 0.0)) aCircle3.SetLocation(gp_Pnt(3.0, 7.0, 0.0)) anEdgeMaker1 = BRepBuilderAPI_MakeEdge(aCircle1) anEdgeMaker2 = BRepBuilderAPI_MakeEdge(aCircle2) anEdgeMaker3 = BRepBuilderAPI_MakeEdge(aCircle3) aWireMaker1 = BRepBuilderAPI_MakeWire(anEdgeMaker1.Edge()) aWireMaker2 = BRepBuilderAPI_MakeWire(anEdgeMaker2.Edge()) aWireMaker3 = BRepBuilderAPI_MakeWire(anEdgeMaker3.Edge()) aFaceMaker = BRepBuilderAPI_MakeFace(aPlane, 0.0, 10.0, 0.0, 10.0) if aWireMaker1.IsDone(): aWire1 = aWireMaker1.Wire() aWire1.Reverse() # Makes this a hole in outer profile aFaceMaker.Add(aWire1) if aWireMaker2.IsDone(): aWire2 = aWireMaker2.Wire() aWire2.Reverse() # Makes this a hole in outer profile aFaceMaker.Add(aWire2) if aWireMaker3.IsDone(): aWire3 = aWireMaker3.Wire() aWire3.Reverse() # Makes this a hole in outer profile aFaceMaker.Add(aWire3) if not aFaceMaker.IsDone(): raise AssertionError("shape not Done.") return aFaceMaker.Shape()
def wire_from_polyline(pol3d): lines = [] for i, p in enumerate(pol3d[:-1]): gp0 = gp_Pnt(p[0], p[1], p[2]) gp1 = gp_Pnt(pol3d[i + 1][0], pol3d[i + 1][1], pol3d[i + 1][2]) lines.append(BRepBuilderAPI_MakeEdge(gp0, gp1).Edge()) wire = BRepBuilderAPI_MakeWire(lines[0]) for l in lines[1:]: wire.Add(l) return wire
def renderTube(self, geometry, transforms, styleName, layerName): aWire, radius = geometry startPoint, tangentDir = getWireStartPointAndTangentDir(aWire) profileCircle = GC_MakeCircle(startPoint, tangentDir, radius).Value() profileEdge = BRepBuilderAPI_MakeEdge(profileCircle).Edge() profileWire = BRepBuilderAPI_MakeWire(profileEdge).Wire() pipeShell = BRepOffsetAPI_MakePipe(aWire, profileWire) pipeShape = pipeShell.Shape() self.renderShapeObj(pipeShape, transforms, styleName)
def generate_planar_slices(nozz_dia, sur_nozz_dia): xmin, ymin, zmin, xmax, ymax, zmax = get_boundingbox(part_shape) print(xmax - xmin, ",", ymax - ymin, ",", zmax - zmin) wires = [] slices = [] contours = [] for z in numpy.arange(zmin+(nozz_dia/2)+(sur_nozz_dia/2), \ zmax-(nozz_dia/2)-(sur_nozz_dia/2), nozz_dia): plane = gp_Pln(gp_Pnt(0., 0., z), gp_Dir(0., 0., 1.)) slices.append(Slicing.plane_shape_intersection(plane, part_shape)) for s in range(0, len(slices)): wire = [] wires.append([]) while len(slices[s]) != 0: for i in range(0, len(slices[s])): if len(wire) == 0: wire.append(slices[s][i]) slices[s].remove(slices[s][i]) break elif Slicing.do_edges_connect(slices[s][i], wire[-1]): wire.append(slices[s][i]) slices[s].remove(slices[s][i]) break if Slicing.do_edges_connect(wire[0], wire[-1]): if len(wire) > 2: wires[s].append(wire) wire = [] elif len(wire) == 2 and Slicing.do_edges_loop( wire[0], wire[-1]): wires[s].append(wire) wire = [] for k in range(0, len(wires)): contours.append([]) for l in range(0, len(wires[k])): make_wire = BRepBuilderAPI_MakeWire() for edge in wires[k][l]: make_wire.Add(edge) try: made_wire = make_wire.Wire() contours[k].append(made_wire) except: print("Skipped a contour!") continue contour_faces = [] for contour in contours: if len(contour) == 1: contour_faces.append( BRepBuilderAPI_MakeFace(contour[0]).Face()) else: contour_faces.extend(Slicing.get_layer_faces(contour)) # for l in range(0,len(contour_faces)): # display.DisplayShape(contour_faces[l], color=colour[l%5],\ # transparency=0.95, update=True) return contour_faces
def face_polyline3d(pol3d): from OCC.Core.TopoDS import topods lines = [] for i, p in enumerate(pol3d[:-1]): gp0 = gp_Pnt(p[0], p[1], p[2]) gp1 = gp_Pnt(pol3d[i + 1][0], pol3d[i + 1][1], pol3d[i + 1][2]) lines.append(BRepBuilderAPI_MakeEdge(gp0, gp1).Edge()) wire = BRepBuilderAPI_MakeWire(lines[0]) for l in lines[1:]: wire.Add(l) face = BRepBuilderAPI_MakeFace(wire.Wire()) return face
def spline_from_polyline(pol): from OCC.Extend.ShapeFactory import point_list_to_TColgp_Array1OfPnt, make_face from OCC.Core.GeomAPI import GeomAPI_PointsToBSpline array = [] for p in pol: array.append(gp_Pnt(p[0], p[1], p[2])) pt_list1 = point_list_to_TColgp_Array1OfPnt(array) SPL1 = GeomAPI_PointsToBSpline(pt_list1).Curve() SPL1 = GeomAPI_PointsToBSpline(pt_list1) edge = BRepBuilderAPI_MakeEdge(SPL1.Curve()) wire = BRepBuilderAPI_MakeWire(edge.Edge()) return edge.Shape(), wire