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 Compute(self): self.myGeometry = Geom_SurfaceOfRevolution(self.myCurve, self.myRevolveAxis) face = BRepBuilderAPI_MakeFace() face.Init(self.myGeometry, True, 1.0e-6) face.Build() self.myAIS_InteractiveObject = AIS_Shape(face.Shape()) self.myContext.Display(self.myAIS_InteractiveObject, True)
def Compute(self): if len(self.myCurves) == 2: self.myGeometry = GeomFill_BezierCurves(self.myCurves[0], self.myCurves[1], self.myStyle) elif len(self.myCurves) == 3: self.myGeometry = GeomFill_BezierCurves(self.myCurves[0], self.myCurves[1], self.myCurves[2], self.myStyle) elif len(self.myCurves) == 4: self.myGeometry = GeomFill_BezierCurves(self.myCurves[0], self.myCurves[1], self.myCurves[2], self.myCurves[3], self.myStyle) self.myGeometry = self.myGeometry.Surface() face = BRepBuilderAPI_MakeFace() face.Init(self.myGeometry, True, 1.0e-6) face.Build() face = face.Shape() self.myAIS_InteractiveObject = AIS_Shape(face) self.myContext.Display(self.myAIS_InteractiveObject, True) self.SetCenter(face) self.InitClippingPlane()
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 Compute(self): self.myGeometry = GeomFill_Pipe(self.myPath, self.myProfile, self.myProfile) self.myGeometry.Perform() face = BRepBuilderAPI_MakeFace() face.Init(self.myGeometry.Surface(), True, 1.0e-6) face.Build() self.myAIS_InteractiveObject = AIS_Shape(face.Shape()) self.myContext.Display(self.myAIS_InteractiveObject, True)
def heightmap_from_image(event=None): """ takes the heightmap from a jpeg file and apply a texture this example requires numpy/matplotlib """ print("opening image") heightmap = Image.open('../assets/images/mountain_heightmap.jpg') heightmap.show() width = heightmap.size[0] height = heightmap.size[1] # create the gp_Pnt array print("image size: ", width, height) print("parse image and fill in point array") for i in range(1, width): for j in range(1, height): # all 3 RGB values are equal, just take the first one # vertex 1 height_value = heightmap.getpixel((i - 1, j - 1))[0] v1 = gp_Pnt(i, j, float(height_value) / 10) # vertex 2 height_value = heightmap.getpixel((i, j - 1))[0] v2 = gp_Pnt(i + 1, j, float(height_value) / 10) # vertex 3 height_value = heightmap.getpixel((i, j))[0] v3 = gp_Pnt(i + 1, j + 1, float(height_value) / 10) # vertex 4 height_value = heightmap.getpixel((i - 1, j))[0] v4 = gp_Pnt(i, j + 1, float(height_value) / 10) # boundaries b1 = boundary_curve_from_2_points(v1, v2) b2 = boundary_curve_from_2_points(v2, v3) b3 = boundary_curve_from_2_points(v3, v4) b4 = boundary_curve_from_2_points(v4, v1) # bConstrainedFilling = GeomFill_ConstrainedFilling(8, 2) bConstrainedFilling.Init(b1, b2, b3, b4, False) srf1 = bConstrainedFilling.Surface() # make a face from this srf patch = BRepBuilderAPI_MakeFace() bounds = True toldegen = 1e-6 patch.Init(srf1, bounds, toldegen) patch.Build() display.DisplayShape(patch.Face()) # then create faces print("%s%%" % int(float(i) / width * 100)) #display.process_events() display.FitAll() # finally display image heightmap.show()
def beziercurve(): # the first bezier curve array = TColgp_Array1OfPnt(1, 5) array.SetValue(1, gp_Pnt(0, 0,-5)) array.SetValue(2, gp_Pnt(1, 2,1)) array.SetValue(3, gp_Pnt(2, 3,2)) array.SetValue(4, gp_Pnt(4, 3,-2)) array.SetValue(5, gp_Pnt(10, 5,-2)) beziercurve = Geom_BezierCurve(array) # the first bezier curve array1 = TColgp_Array1OfPnt(1, 5) array1.SetValue(1, gp_Pnt(0, 0, -5)) array1.SetValue(2, gp_Pnt(2, -2, 1)) array1.SetValue(3, gp_Pnt(2, -3, 2)) array1.SetValue(4, gp_Pnt(-4, 1, -2)) array1.SetValue(5, gp_Pnt(1, 5, -2)) beziercurve1 = Geom_BezierCurve(array1) array2 = TColgp_Array1OfPnt(1, 5) array2.SetValue(1, gp_Pnt(0, 0, -5)) array2.SetValue(2, gp_Pnt(-2, 2, 1)) array2.SetValue(3, gp_Pnt(2, -2, 2)) array2.SetValue(4, gp_Pnt(-4, 8, -2)) array2.SetValue(5, gp_Pnt(1, 5, -9)) beziercurve2 = Geom_BezierCurve(array2) plane = Geom_Plane(gp_Pnt(0.0, 0.0, 0.0), gp_Dir(0, 1, 1)) display.DisplayShape(plane, color='RED') surface1=GeomFill_BezierCurves(beziercurve,beziercurve1,beziercurve2,GeomFill_CurvedStyle) surface2 = GeomFill_BezierCurves(beziercurve, beziercurve1, GeomFill_StretchStyle) surface3 = GeomFill_BezierCurves(beziercurve, beziercurve1, GeomFill_CoonsStyle) bounds = True toldegen = 1e-6 face = BRepBuilderAPI_MakeFace() face.Init(surface1.Surface(), bounds, toldegen) face.Build() shapes = face.Shape() fix=AIS_FixRelation(shapes,plane) display.Context.Display(fix, True) display.DisplayShape(shapes, color="RED")
def Compute(self): if self.myConstructionMethod == SweepConstructionMethod.Radius: myGeometry = GeomFill_Pipe(self.myPath, self.myRadius) elif self.myConstructionMethod == SweepConstructionMethod.ConstantSection: myGeometry = GeomFill_Pipe(self.myPath, self.mySections[0]) elif self.myConstructionMethod == SweepConstructionMethod.EvolvingSection: myGeometry = GeomFill_Pipe(self.myPath, self.mySections[0], self.mySections[1]) myGeometry.Perform() self.myGeometry = myGeometry.Surface() face = BRepBuilderAPI_MakeFace() face.Init(self.myGeometry, True, 1.0e-6) face.Build() face = face.Shape() self.myAIS_InteractiveObject = AIS_Shape(face) self.myContext.Display(self.myAIS_InteractiveObject, True) self.SetCenter(face) self.InitClippingPlane()
def brepfeat_prism(event=None): box = BRepPrimAPI_MakeBox(400, 250, 300).Shape() faces = TopologyExplorer(box).faces() for i in range(5): face = next(faces) srf = BRep_Tool_Surface(face) c = gp_Circ2d(gp_Ax2d(gp_Pnt2d(200, 130), gp_Dir2d(1, 0)), 75) circle = Geom2d_Circle(c) wire = BRepBuilderAPI_MakeWire() wire.Add(BRepBuilderAPI_MakeEdge(circle, srf, 0., pi).Edge()) wire.Add(BRepBuilderAPI_MakeEdge(circle, srf, pi, 2. * pi).Edge()) wire.Build() display.DisplayShape(wire.Wire()) mkf = BRepBuilderAPI_MakeFace() mkf.Init(srf, False, 1e-6) mkf.Add(wire.Wire()) mkf.Build() new_face = mkf.Face() breplib_BuildCurves3d(new_face) display.DisplayShape(new_face) prism = BRepFeat_MakeDPrism(box, mkf.Face(), face, 100, True, True) prism.Perform(400) assert prism.IsDone() display.EraseAll() display.DisplayShape(prism.Shape()) display.DisplayColoredShape(wire.Wire(), 'RED') display.FitAll()
def DisplayShape(self, shapes, material=None, texture=None, color=None, transparency=None, update=False): """ display one or a set of displayable objects """ ais_shapes = [] # the list of all displayed shapes if issubclass(shapes.__class__, gp_Pnt): # if a gp_Pnt is passed, first convert to vertex vertex = BRepBuilderAPI_MakeVertex(shapes) shapes = [vertex.Shape()] elif isinstance(shapes, gp_Pnt2d): vertex = BRepBuilderAPI_MakeVertex( gp_Pnt(shapes.X(), shapes.Y(), 0)) shapes = [vertex.Shape()] elif isinstance(shapes, Geom_Surface): bounds = True toldegen = 1e-6 face = BRepBuilderAPI_MakeFace() face.Init(shapes, bounds, toldegen) face.Build() shapes = [face.Shape()] elif isinstance(shapes, Geom_Curve): edge = BRepBuilderAPI_MakeEdge(shapes) shapes = [edge.Shape()] elif isinstance(shapes, Geom2d_Curve): edge2d = BRepBuilderAPI_MakeEdge2d(shapes) shapes = [edge2d.Shape()] # if only one shapes, create a list with a single shape if not isinstance(shapes, list): shapes = [shapes] # build AIS_Shapes list for shape in shapes: if material or texture: if texture: shape_to_display = AIS_TexturedShape(shape) filename, toScaleU, toScaleV, toRepeatU, toRepeatV, originU, originV = texture.GetProperties( ) shape_to_display.SetTextureFileName( TCollection_AsciiString(filename)) shape_to_display.SetTextureMapOn() shape_to_display.SetTextureScale(True, toScaleU, toScaleV) shape_to_display.SetTextureRepeat(True, toRepeatU, toRepeatV) shape_to_display.SetTextureOrigin(True, originU, originV) shape_to_display.SetDisplayMode(3) elif material: shape_to_display = AIS_Shape(shape) shape_to_display.SetMaterial( Graphic3d_MaterialAspect(material)) else: # TODO: can we use .Set to attach all TopoDS_Shapes # to this AIS_Shape instance? shape_to_display = AIS_Shape(shape) ais_shapes.append(shape_to_display) # if not SOLO: # # computing graphic properties is expensive # # if an iterable is found, so cluster all TopoDS_Shape under # # an AIS_MultipleConnectedInteractive # #shape_to_display = AIS_MultipleConnectedInteractive() # for ais_shp in ais_shapes: # # TODO : following line crashes with oce-0.18 # # why ? fix ? # #shape_to_display.Connect(i) # self.Context.Display(ais_shp, False) # set the graphic properties if material is None: #The default material is too shiny to show the object #color well, so I set it to something less reflective for shape_to_display in ais_shapes: shape_to_display.SetMaterial( Graphic3d_MaterialAspect(Graphic3d_NOM_NEON_GNC)) if color: if isinstance(color, str): color = get_color_from_name(color) elif isinstance(color, int): color = Quantity_Color(color) for shp in ais_shapes: self.Context.SetColor(shp, color, False) if transparency: for shape_to_display in ais_shapes: shape_to_display.SetTransparency(transparency) # display the shapes for shape_to_display in ais_shapes: self.Context.Display(shape_to_display, False) if update: # especially this call takes up a lot of time... self.FitAll() self.Repaint() return ais_shapes
def brep_feat_extrusion_protrusion(event=None): # Extrusion S = BRepPrimAPI_MakeBox(400., 250., 300.).Shape() faces = TopologyExplorer(S).faces() F = next(faces) surf1 = BRep_Tool_Surface(F) Pl1 = Geom_Plane.DownCast(surf1) D1 = Pl1.Pln().Axis().Direction().Reversed() MW = BRepBuilderAPI_MakeWire() p1, p2 = gp_Pnt2d(200., -100.), gp_Pnt2d(100., -100.) aline = GCE2d_MakeLine(p1, p2).Value() MW.Add(BRepBuilderAPI_MakeEdge(aline, surf1, 0., p1.Distance(p2)).Edge()) p1, p2 = gp_Pnt2d(100., -100.), gp_Pnt2d(100., -200.) aline = GCE2d_MakeLine(p1, p2).Value() MW.Add(BRepBuilderAPI_MakeEdge(aline, surf1, 0., p1.Distance(p2)).Edge()) p1, p2 = gp_Pnt2d(100., -200.), gp_Pnt2d(200., -200.) aline = GCE2d_MakeLine(p1, p2).Value() MW.Add(BRepBuilderAPI_MakeEdge(aline, surf1, 0., p1.Distance(p2)).Edge()) p1, p2 = gp_Pnt2d(200., -200.), gp_Pnt2d(200., -100.) aline = GCE2d_MakeLine(p1, p2).Value() MW.Add(BRepBuilderAPI_MakeEdge(aline, surf1, 0., p1.Distance(p2)).Edge()) MKF = BRepBuilderAPI_MakeFace() MKF.Init(surf1, False, 1e-6) MKF.Add(MW.Wire()) FP = MKF.Face() breplib_BuildCurves3d(FP) display.EraseAll() MKP = BRepFeat_MakePrism(S, FP, F, D1, 0, True) MKP.PerformThruAll() res1 = MKP.Shape() display.DisplayShape(res1) # Protrusion next(faces) F2 = next(faces) surf2 = BRep_Tool_Surface(F2) Pl2 = Geom_Plane.DownCast(surf2) D2 = Pl2.Pln().Axis().Direction().Reversed() MW2 = BRepBuilderAPI_MakeWire() p1, p2 = gp_Pnt2d(100., 100.), gp_Pnt2d(200., 100.) aline = GCE2d_MakeLine(p1, p2).Value() MW2.Add(BRepBuilderAPI_MakeEdge(aline, surf2, 0., p1.Distance(p2)).Edge()) p1, p2 = gp_Pnt2d(200., 100.), gp_Pnt2d(150., 200.) aline = GCE2d_MakeLine(p1, p2).Value() MW2.Add(BRepBuilderAPI_MakeEdge(aline, surf2, 0., p1.Distance(p2)).Edge()) p1, p2 = gp_Pnt2d(150., 200.), gp_Pnt2d(100., 100.) aline = GCE2d_MakeLine(p1, p2).Value() MW2.Add(BRepBuilderAPI_MakeEdge(aline, surf2, 0., p1.Distance(p2)).Edge()) MKF2 = BRepBuilderAPI_MakeFace() MKF2.Init(surf2, False, 1e-6) MKF2.Add(MW2.Wire()) MKF2.Build() FP = MKF2.Face() breplib_BuildCurves3d(FP) MKP2 = BRepFeat_MakePrism(res1, FP, F2, D2, 0, True) MKP2.PerformThruAll() display.EraseAll() trf = gp_Trsf() trf.SetTranslation(gp_Vec(0, 0, 300)) gtrf = gp_GTrsf() gtrf.SetTrsf(trf) tr = BRepBuilderAPI_GTransform(MKP2.Shape(), gtrf, True) fused = BRepAlgoAPI_Fuse(tr.Shape(), MKP2.Shape()) fused.Build() display.DisplayShape(fused.Shape()) display.FitAll()
height_value = heightmap.getpixel((i - 1, j))[0] v4 = gp_Pnt(i, j + 1, float(height_value) / 10) # boundaries b1 = boundary_curve_from_2_points(v1, v2) b2 = boundary_curve_from_2_points(v2, v3) b3 = boundary_curve_from_2_points(v3, v4) b4 = boundary_curve_from_2_points(v4, v1) # bConstrainedFilling = GeomFill_ConstrainedFilling(8, 2) bConstrainedFilling.Init(b1, b2, b3, b4, False) srf1 = bConstrainedFilling.Surface() # make a face from this srf patch = BRepBuilderAPI_MakeFace() bounds = True toldegen = 1e-6 patch.Init(srf1, bounds, toldegen) patch.Build() display.DisplayShape(patch.Face()) # then create faces txt = "\r" txt += "{:03d} / {:03d}".format(i, width) txt += " - " txt += "{:03d} / {:03d}".format(j, height) sys.stdout.write(txt) sys.stdout.flush() #print("%s%%" % int(float(i) / width * 100)) # display.process_events() print() display.FitAll()
def DisplayShape(self, shapes, material=None, texture=None, color=None, transparency=None, update=False): """ display one or a set of displayable objects """ SOLO = False # assume multiple instances by default # if a gp_Pnt is passed, first convert to vertex if issubclass(shapes.__class__, gp_Pnt): vertex = BRepBuilderAPI_MakeVertex(shapes) shapes = [vertex.Shape()] SOLO = True elif isinstance(shapes, gp_Pnt2d): vertex = BRepBuilderAPI_MakeVertex( gp_Pnt(shapes.X(), shapes.Y(), 0)) shapes = [vertex.Shape()] SOLO = True # if a Geom_Curve is passed elif callable(getattr(shapes, "GetHandle", None)): handle = shapes.GetHandle() if issubclass(handle.__class__, Handle_Geom_Curve): edge = BRepBuilderAPI_MakeEdge(handle) shapes = [edge.Shape()] SOLO = True elif issubclass(handle.__class__, Handle_Geom2d_Curve): edge2d = BRepBuilderAPI_MakeEdge2d(handle) shapes = [edge2d.Shape()] SOLO = True elif issubclass(handle.__class__, Handle_Geom_Surface): bounds = True toldegen = 1e-6 face = BRepBuilderAPI_MakeFace() face.Init(handle, bounds, toldegen) face.Build() shapes = [face.Shape()] SOLO = True elif isinstance(shapes, Handle_Geom_Surface): bounds = True toldegen = 1e-6 face = BRepBuilderAPI_MakeFace() face.Init(shapes, bounds, toldegen) face.Build() shapes = [face.Shape()] SOLO = True elif isinstance(shapes, Handle_Geom_Curve): edge = BRepBuilderAPI_MakeEdge(shapes) shapes = [edge.Shape()] SOLO = True elif isinstance(shapes, Handle_Geom2d_Curve): edge2d = BRepBuilderAPI_MakeEdge2d(shapes) shapes = [edge2d.Shape()] SOLO = True elif issubclass(shapes.__class__, TopoDS_Shape): shapes = [shapes] SOLO = True ais_shapes = [] for shape in shapes: if material or texture: if texture: self.View.SetSurfaceDetail(V3d_TEX_ALL) shape_to_display = AIS_TexturedShape(shape) filename, toScaleU, toScaleV, toRepeatU, toRepeatV, originU, originV = texture.GetProperties( ) shape_to_display.SetTextureFileName( TCollection_AsciiString(filename)) shape_to_display.SetTextureMapOn() shape_to_display.SetTextureScale(True, toScaleU, toScaleV) shape_to_display.SetTextureRepeat(True, toRepeatU, toRepeatV) shape_to_display.SetTextureOrigin(True, originU, originV) shape_to_display.SetDisplayMode(3) elif material: shape_to_display = AIS_Shape(shape) shape_to_display.SetMaterial(material) else: # TODO: can we use .Set to attach all TopoDS_Shapes # to this AIS_Shape instance? shape_to_display = AIS_Shape(shape) ais_shapes.append(shape_to_display.GetHandle()) if not SOLO: # computing graphic properties is expensive # if an iterable is found, so cluster all TopoDS_Shape under # an AIS_MultipleConnectedInteractive #shape_to_display = AIS_MultipleConnectedInteractive() for ais_shp in ais_shapes: # TODO : following line crashes with oce-0.18 # why ? fix ? #shape_to_display.Connect(i) self.Context.Display(ais_shp, False) shape_to_display = ais_shapes return shape_to_display # set the graphic properties if material is None: #The default material is too shiny to show the object #color well, so I set it to something less reflective shape_to_display.SetMaterial(Graphic3d_NOM_NEON_GNC) if color: if isinstance(color, str): color = get_color_from_name(color) for shp in ais_shapes: self.Context.SetColor(shp, color, False) if transparency: shape_to_display.SetTransparency(transparency) if update: # only update when explicitely told to do so self.Context.Display(shape_to_display.GetHandle(), False) # especially this call takes up a lot of time... self.FitAll() self.Repaint() else: self.Context.Display(shape_to_display.GetHandle(), False) if SOLO: return ais_shapes[0] else: return shape_to_display
def write_face(self, points_face, list_points_edge, topo_face, toledge): """ Method to recreate a Face associated to a geometric surface after the modification of Face points. It returns a TopoDS_Face. :param points_face: the new face points array. :param list_points_edge: new edge points :param topo_face: the face to be modified :param toledge: tolerance on the surface creation after modification :return: TopoDS_Face (Shape) :rtype: TopoDS_Shape """ # convert Face to Geom B-spline Surface nurbs_converter = BRepBuilderAPI_NurbsConvert(topo_face) nurbs_converter.Perform(topo_face) nurbs_face = nurbs_converter.Shape() topo_nurbsface = topods.Face(nurbs_face) h_geomsurface = BRep_Tool.Surface(topo_nurbsface) h_bsurface = geomconvert_SurfaceToBSplineSurface(h_geomsurface) bsurface = h_bsurface nb_u = bsurface.NbUPoles() nb_v = bsurface.NbVPoles() # check consistency if points_face.shape[0] != nb_u * nb_v: raise ValueError("Input control points do not have not have the " "same number as the geometric face!") # cycle on the face points indice_cpt = 0 for iu in range(1, nb_u + 1): for iv in range(1, nb_v + 1): cpt = points_face[indice_cpt] bsurface.SetPole(iu, iv, gp_Pnt(cpt[0], cpt[1], cpt[2])) indice_cpt += 1 # create modified new face new_bspline_tface = BRepBuilderAPI_MakeFace() toler = precision_Confusion() new_bspline_tface.Init(bsurface, False, toler) # cycle on the wires face_wires_explorer = TopExp_Explorer( topo_nurbsface.Oriented(TopAbs_FORWARD), TopAbs_WIRE) ind_edge_total = 0 while face_wires_explorer.More(): # get old wire twire = topods_Wire(face_wires_explorer.Current()) # cycle on the edges ind_edge = 0 wire_explorer_edge = TopExp_Explorer( twire.Oriented(TopAbs_FORWARD), TopAbs_EDGE) # check edges order on the wire mode3d = True tolerance_edges = toledge wire_order = ShapeAnalysis_WireOrder(mode3d, tolerance_edges) # an edge list deformed_edges = [] # cycle on the edges while wire_explorer_edge.More(): tedge = topods_Edge(wire_explorer_edge.Current()) new_bspline_tedge = self.write_edge( list_points_edge[ind_edge_total], tedge) deformed_edges.append(new_bspline_tedge) analyzer = topexp() vfirst = analyzer.FirstVertex(new_bspline_tedge) vlast = analyzer.LastVertex(new_bspline_tedge) pt1 = BRep_Tool.Pnt(vfirst) pt2 = BRep_Tool.Pnt(vlast) wire_order.Add(pt1.XYZ(), pt2.XYZ()) ind_edge += 1 ind_edge_total += 1 wire_explorer_edge.Next() # grouping the edges in a wire, then in the face # check edges order and connectivity within the wire wire_order.Perform() # new wire to be created stol = ShapeFix_ShapeTolerance() new_bspline_twire = BRepBuilderAPI_MakeWire() for order_i in range(1, wire_order.NbEdges() + 1): deformed_edge_i = wire_order.Ordered(order_i) if deformed_edge_i > 0: # insert the deformed edge to the new wire new_edge_toadd = deformed_edges[deformed_edge_i - 1] stol.SetTolerance(new_edge_toadd, toledge) new_bspline_twire.Add(new_edge_toadd) if new_bspline_twire.Error() != 0: stol.SetTolerance(new_edge_toadd, toledge * 10.0) new_bspline_twire.Add(new_edge_toadd) else: deformed_edge_revers = deformed_edges[ np.abs(deformed_edge_i) - 1] stol.SetTolerance(deformed_edge_revers, toledge) new_bspline_twire.Add(deformed_edge_revers) if new_bspline_twire.Error() != 0: stol.SetTolerance(deformed_edge_revers, toledge * 10.0) new_bspline_twire.Add(deformed_edge_revers) # add new wire to the Face new_bspline_tface.Add(new_bspline_twire.Wire()) face_wires_explorer.Next() return topods.Face(new_bspline_tface.Face())