def vertex_fillet(cube, vert): # apply a fillet on incident edges on a vertex afillet = BRepFilletAPI_MakeFillet(cube) cnt = 0 # find edges from vertex _map = TopTools_IndexedDataMapOfShapeListOfShape() topexp_MapShapesAndAncestors(cube, TopAbs_VERTEX, TopAbs_EDGE, _map) results = _map.FindFromKey(vert) topology_iterator = TopTools_ListIteratorOfListOfShape(results) while topology_iterator.More(): edge = topods_Edge(topology_iterator.Value()) topology_iterator.Next() first, last = topexp_FirstVertex(edge), topexp_LastVertex(edge) vertex, first_vert, last_vert = BRep_Tool().Pnt(vert), BRep_Tool().Pnt( first), BRep_Tool().Pnt(last) if edge.Orientation(): if not vertex.IsEqual(first_vert, 0.001): afillet.Add(0, 20., edge) else: afillet.Add(20, 0, edge) cnt += 1 afillet.Build() if afillet.IsDone(): return afillet.Shape() else: raise AssertionError('you failed on me you fool!')
def fillet(event=None): Box = BRepPrimAPI_MakeBox(gp_Pnt(-400, 0, 0), 200, 230, 180).Shape() fillet = BRepFilletAPI_MakeFillet(Box) # Add fillet on each edge for e in Topo(Box).edges(): fillet.Add(20, e) blendedBox = fillet.Shape() P1 = gp_Pnt(250, 150, 75) S1 = BRepPrimAPI_MakeBox(300, 200, 200).Shape() S2 = BRepPrimAPI_MakeBox(P1, 120, 180, 70).Shape() Fuse = BRepAlgoAPI_Fuse(S1, S2) FusedShape = Fuse.Shape() fill = BRepFilletAPI_MakeFillet(FusedShape) for e in Topo(FusedShape).edges(): fill.Add(e) for i in range(1, fill.NbContours() + 1): length = fill.Length(i) Rad = 0.15 * length fill.SetRadius(Rad, i, 1) blendedFusedSolids = fill.Shape() display.EraseAll() display.DisplayShape(blendedBox) display.DisplayShape(blendedFusedSolids) display.FitAll()
def fillet(self, radius, edgeList): """ Fillets the specified edges of this solid. :param radius: float > 0, the radius of the fillet :param edgeList: a list of Edge objects, which must belong to this solid :return: Filleted solid """ nativeEdges = [e.wrapped for e in edgeList] fillet_builder = BRepFilletAPI_MakeFillet(self.wrapped) for e in nativeEdges: fillet_builder.Add(radius, e) return self.__class__(fillet_builder.Shape())
def update_shape(self, change={}): d = self.declaration #: Get the shape to apply the fillet to children = [c for c in self.children()] if not children: raise ValueError("Fillet must have a child shape to operate on.") child = children[0] s = child.shape.Shape() shape = BRepFilletAPI_MakeFillet(s)#,self.shape_types[d.shape]) edges = d.edges if d.edges else child.topology.edges() for edge in edges: shape.Add(d.radius, edge) #if not shape.HasResult(): # raise ValueError("Could not compute fillet, radius possibly too small?") self.shape = shape
def createModel(self): # edges = makeEdgesFromPoints(self.points) # self.a1 = edge1 = BRepBuilderAPI_MakeEdge(getGpPt(self.a1), getGpPt(self.a2)) edge2 = BRepBuilderAPI_MakeEdge(getGpPt(self.a2), getGpPt(self.a3)) arc1 = GC_MakeArcOfCircle(getGpPt(self.a3), getGpPt(self.a4), getGpPt(self.a5)) edge3 = BRepBuilderAPI_MakeEdge(arc1.Value()) edge4 = BRepBuilderAPI_MakeEdge(getGpPt(self.a5), getGpPt(self.a6)) arc2 = GC_MakeArcOfCircle(getGpPt(self.a6), getGpPt(self.a7), getGpPt(self.a8)) edge5 = BRepBuilderAPI_MakeEdge(arc2.Value()) edge6 = BRepBuilderAPI_MakeEdge(getGpPt(self.a8), getGpPt(self.a9)) arc3 = GC_MakeArcOfCircle(getGpPt(self.a9), getGpPt(self.a10), getGpPt(self.a11)) edge7 = BRepBuilderAPI_MakeEdge(arc3.Value()) edge8 = BRepBuilderAPI_MakeEdge(getGpPt(self.a11), getGpPt(self.a12)) edge9 = BRepBuilderAPI_MakeEdge(getGpPt(self.a12), getGpPt(self.a1)) # wire = makeWireFromEdges(edge1,edge2,edge3,edge4,edge5,edge6,edge7,edge8,edge9) wire = BRepBuilderAPI_MakeWire(edge1.Edge(), edge2.Edge(), edge3.Edge(), edge4.Edge()) wire = BRepBuilderAPI_MakeWire(wire.Wire(), edge5.Edge()) wire = BRepBuilderAPI_MakeWire(wire.Wire(), edge6.Edge()) wire = BRepBuilderAPI_MakeWire(wire.Wire(), edge7.Edge()) wire = BRepBuilderAPI_MakeWire(wire.Wire(), edge8.Edge()) wire = BRepBuilderAPI_MakeWire(wire.Wire(), edge9.Edge()) aFace = makeFaceFromWire(wire.Wire()) extrudeDir = self.L * self.wDir # extrudeDir is a numpy array prism = makePrismFromFace(aFace, extrudeDir) mkFillet = BRepFilletAPI_MakeFillet(prism) anEdgeExplorer = TopExp_Explorer(prism, TopAbs_EDGE) while anEdgeExplorer.More(): aEdge = topods.Edge(anEdgeExplorer.Current()) mkFillet.Add(self.T / 17., aEdge) anEdgeExplorer.Next() prism = mkFillet.Shape() return prism
def createModel(self): edges = makeEdgesFromPoints(self.points) wire = makeWireFromEdges(edges) aFace = makeFaceFromWire(wire) extrudeDir = self.T * self.wDir # extrudeDir is a numpy array prism = makePrismFromFace(aFace, extrudeDir) mkFillet = BRepFilletAPI_MakeFillet(prism) anEdgeExplorer = TopExp_Explorer(prism, TopAbs_EDGE) while anEdgeExplorer.More(): aEdge = topods.Edge(anEdgeExplorer.Current()) mkFillet.Add(self.T / 17. , aEdge) anEdgeExplorer.Next() prism = mkFillet.Shape() cylOrigin = self.secOrigin innerCyl = BRepPrimAPI_MakeCylinder(gp_Ax2(getGpPt(cylOrigin), getGpDir(self.wDir)), self.r1, self.H).Shape() result_shape = BRepAlgoAPI_Cut(prism, innerCyl).Shape() return result_shape
def createModel(self): edges = makeEdgesFromPoints(self.points) wire = makeWireFromEdges(edges) aFace = makeFaceFromWire(wire) extrudeDir = -self.T * self.shaftDir # extrudeDir is a numpy array boltHead = makePrismFromFace(aFace, extrudeDir) mkFillet = BRepFilletAPI_MakeFillet(boltHead) anEdgeExplorer = TopExp_Explorer(boltHead, TopAbs_EDGE) while anEdgeExplorer.More(): aEdge = topods.Edge(anEdgeExplorer.Current()) mkFillet.Add(self.T / 17. , aEdge) anEdgeExplorer.Next() boltHead = mkFillet.Shape() cylOrigin = self.origin boltCylinder = BRepPrimAPI_MakeCylinder(gp_Ax2(getGpPt(cylOrigin), getGpDir(self.shaftDir)), self.r, self.H).Shape() whole_Bolt = BRepAlgoAPI_Fuse(boltHead,boltCylinder).Shape() mkFillet = BRepFilletAPI_MakeFillet(whole_Bolt) return whole_Bolt
def variable_filleting(event=None): display.EraseAll() # Create Box Box = BRepPrimAPI_MakeBox(200, 200, 200).Shape() # Fillet Rake = BRepFilletAPI_MakeFillet(Box) ex = Topo(Box).edges() next(ex) next(ex) next(ex) Rake.Add(8, 50, next(ex)) Rake.Build() if Rake.IsDone(): evolvedBox = Rake.Shape() display.DisplayShape(evolvedBox) else: print("Rake not done.") # Create Cylinder Cylinder = BRepPrimAPI_MakeCylinder( gp_Ax2(gp_Pnt(-300, 0, 0), gp_Dir(0, 0, 1)), 100, 200).Shape() fillet = BRepFilletAPI_MakeFillet(Cylinder) TabPoint2 = TColgp_Array1OfPnt2d(0, 20) for i in range(0, 20): Point2d = gp_Pnt2d(i * 2 * pi / 19, 60 * cos(i * pi / 19 - pi / 2) + 10) TabPoint2.SetValue(i, Point2d) exp2 = Topo(Cylinder).edges() fillet.Add(TabPoint2, next(exp2)) fillet.Build() if fillet.IsDone(): LawEvolvedCylinder = fillet.Shape() display.DisplayShape(LawEvolvedCylinder) else: print("fillet not done.") ## TODO : fillet not done P = gp_Pnt(350, 0, 0) Box2 = BRepPrimAPI_MakeBox(P, 200, 200, 200).Shape() afillet = BRepFilletAPI_MakeFillet(Box2) TabPoint = TColgp_Array1OfPnt2d(1, 6) P1 = gp_Pnt2d(0., 8.) P2 = gp_Pnt2d(0.2, 16.) P3 = gp_Pnt2d(0.4, 25.) P4 = gp_Pnt2d(0.6, 55.) P5 = gp_Pnt2d(0.8, 28.) P6 = gp_Pnt2d(1., 20.) TabPoint.SetValue(1, P1) TabPoint.SetValue(2, P2) TabPoint.SetValue(3, P3) TabPoint.SetValue(4, P4) TabPoint.SetValue(5, P5) TabPoint.SetValue(6, P6) exp = Topo(Box2).edges() next(exp) next(exp) next(exp) afillet.Add(TabPoint, next(exp)) afillet.Build() if afillet.IsDone(): LawEvolvedBox = afillet.Shape() else: print("aFillet not done.") display.DisplayShape(LawEvolvedBox) display.FitAll()
myWireProfile = mkWire.Wire() # The face that we'll sweep to make the prism myFaceProfile = BRepBuilderAPI_MakeFace(myWireProfile) # We want to sweep the face along the Z axis to the height aPrismVec = gp_Vec(0, 0, height) myBody = BRepPrimAPI_MakePrism(myFaceProfile.Face(), aPrismVec) # Add fillets to all edges through the explorer mkFillet = BRepFilletAPI_MakeFillet(myBody.Shape()) anEdgeExplorer = TopExp_Explorer(myBody.Shape(), TopAbs_EDGE) while anEdgeExplorer.More(): anEdge = topods.Edge(anEdgeExplorer.Current()) mkFillet.Add(thickness / 12.0, anEdge) anEdgeExplorer.Next() myBody = mkFillet # Create the neck of the bottle neckLocation = gp_Pnt(0, 0, height) neckAxis = gp_DZ() neckAx2 = gp_Ax2(neckLocation, neckAxis) myNeckRadius = thickness / 4.0 myNeckHeight = height / 10.0 mkCylinder = BRepPrimAPI_MakeCylinder(neckAx2, myNeckRadius, myNeckHeight)
mkWire.Add(aMirroredWire) myWireProfile = mkWire.Wire() # Body : Prism the Profile myFaceProfile = MakeFace(myWireProfile) if myFaceProfile.IsDone(): bottomFace = myFaceProfile.Face() aPrismVec = gp_Vec(0, 0, myHeight) myBody = MakePrism(myFaceProfile.Shape(), aPrismVec) # Body : Apply Fillets mkFillet = MakeFillet(myBody.Shape()) aEdgeExplorer = Explorer(myBody.Shape(), OCC.TopAbs.TopAbs_EDGE) while aEdgeExplorer.More(): aEdge = OCC.TopoDS.topods_Edge(aEdgeExplorer.Current()) mkFillet.Add(myThickness / 12, aEdge) aEdgeExplorer.Next() myBody = mkFillet.Shape() # Body : Add the Neck neckLocation = OCC.gp.gp_Pnt(0, 0, myHeight) neckNormal = OCC.gp.gp_DZ() neckAx2 = OCC.gp.gp_Ax2(neckLocation, neckNormal) myNeckRadius = myThickness / 4 myNeckHeight = myHeight / 10 MKCylinder = MakeCylinder(neckAx2, myNeckRadius, myNeckHeight) myNeck = MKCylinder.Shape() myBody = Fuse(myBody, myNeck).Shape() # Body : Create a Hollowed Solid faceToRemove = OCC.TopoDS.TopoDS_Face()
#!/usr/bin/env python
def createModel(self): edges = makeEdgesFromPoints(self.points) wire = makeWireFromEdges(edges) aFace = makeFaceFromWire(wire) extrudeDir = self.T * self.wDir # extrudeDir is a numpy array prism = makePrismFromFace(aFace, extrudeDir) mkFillet = BRepFilletAPI_MakeFillet(prism) anEdgeExplorer = TopExp_Explorer(prism, TopAbs_EDGE) while anEdgeExplorer.More(): aEdge = topods.Edge(anEdgeExplorer.Current()) mkFillet.Add(self.T / 17., aEdge) anEdgeExplorer.Next() prism = mkFillet.Shape() cylOrigin = self.secOrigin # cylOrigin = self.secOrigin + self.T * self.wDir innerCyl = BRepPrimAPI_MakeCylinder( gp_Ax2(getGpPt(cylOrigin), getGpDir(self.wDir)), self.r1, self.H).Shape() # outerCyl = BRepPrimAPI_MakeCylinder(gp_Ax2(getGpPt(cylOrigin), getGpDir(self.wDir)), self.r2, self.H).Shape() # nutBody = BRepAlgoAPI_Fuse(prism, outerCyl).Shape() # my_cyl = BRepPrimAPI_MakeCylinder(9.0, 6.0).Shape() # result_shape = BRepAlgoAPI_Cut(nutBody, innerCyl).Shape() result_shape = BRepAlgoAPI_Cut(prism, innerCyl).Shape() # self.secOrigin = gp_Pnt(0 , 0 , 0) # neckNormal = gp_DZ() # # Threading : Create Surfaces # # nutAx2_bis = gp_Ax3(self.secOrigin , neckNormal) # aCyl1 = Geom_CylindricalSurface(nutAx2_bis , self.T * 0.99) # aCyl2 = Geom_CylindricalSurface(nutAx2_bis , self.T * 1.05) # #aCyl3 = Geom_CylindricalSurface(nutAx2_bis , self.T * 1.11) # aCyl1_handle = aCyl1.GetHandle() # aCyl2_handle = aCyl2.GetHandle() # #aCyl3_handle = aCyl3.GetHandle() # # # Threading : Define 2D Curves # aPnt = gp_Pnt2d(2. * math.pi , self.H / 2.) # aDir = gp_Dir2d(2. * math.pi , self.H / 4.) # aAx2d = gp_Ax2d(aPnt , aDir) # aMajor = 2. * math.pi # aMinor = self.H / 7. # anEllipse1 = Geom2d_Ellipse(aAx2d , aMajor , aMinor) # anEllipse2 = Geom2d_Ellipse(aAx2d , aMajor , aMinor / 4.) # anEllipse1_handle = anEllipse1.GetHandle() # anEllipse2_handle = anEllipse2.GetHandle() # aArc1 = Geom2d_TrimmedCurve(anEllipse1_handle, 0 , math.pi) # aArc2 = Geom2d_TrimmedCurve(anEllipse2_handle, 0 , math.pi) # aArc1_handle = aArc1.GetHandle() # aArc2_handle = aArc2.GetHandle() # anEllipsePnt1 = anEllipse1.Value(0) # anEllipsePnt2 = anEllipse1.Value(math.pi) # aSegment = GCE2d_MakeSegment(anEllipsePnt1 , anEllipsePnt2) # # # Threading : Build Edges and Wires # # aEdge1OnSurf1 = BRepBuilderAPI_MakeEdge( aArc1_handle , aCyl1_handle) # aEdge2OnSurf1 = BRepBuilderAPI_MakeEdge( aSegment.Value() , aCyl1_handle) # aEdge1OnSurf2 = BRepBuilderAPI_MakeEdge( aArc2_handle , aCyl2_handle) # aEdge2OnSurf2 = BRepBuilderAPI_MakeEdge( aSegment.Value() , aCyl2_handle) # threadingWire1 = BRepBuilderAPI_MakeWire(aEdge1OnSurf1.Edge() , aEdge2OnSurf1.Edge())#aEdge3OnSurf1.Edge()) # self.threading1 = threadingWire1 # threadingWire2 = BRepBuilderAPI_MakeWire(aEdge1OnSurf2.Edge() , aEdge2OnSurf2.Edge())#aEdge3OnSurf2.Edge()) # BRepLib.breplib.BuildCurves3d(threadingWire1.Shape()) # BRepLib.breplib.BuildCurves3d(threadingWire2.Shape()) # # # Create Threading # # aTool = BRepOffsetAPI_ThruSections(True) # aTool.AddWire(threadingWire1.Wire()) # aTool.AddWire(threadingWire2.Wire()) # aTool.CheckCompatibility(False) # myThreading = aTool.Shape() # # #Building the resulting compound # # aRes = TopoDS_Compound() # aBuilder = BRep.BRep_Builder() # aBuilder.MakeCompound(aRes) # aBuilder.Add(aRes, result_shape) # aBuilder.Add(aRes, myThreading) # final_shape = BRepAlgoAPI_Cut(result_shape, myThreading).Shape() return result_shape
def create_model(self): ###################################################### edges = [] if self.R2 == 0.0 or self.R1 == 0.0: self.a3 = self.a4 = self.a5 edge1 = make_edge(getGpPt(self.a1), getGpPt(self.a2)) edges.append(edge1) edge2 = make_edge(getGpPt(self.a2), getGpPt(self.a3)) edges.append(edge2) edge3 = make_edge(getGpPt(self.a3), getGpPt(self.a6)) edges.append(edge3) # arc2 = GC_MakeArcOfCircle(getGpPt(self.a6), getGpPt(self.a7), getGpPt(self.a8)) # edge4 = make_edge(arc2.Value()) # edges.append(edge4) # edge5 = make_edge(getGpPt(self.a8), getGpPt(self.a9)) # edges.append(edge5) # edge6 = make_edge(getGpPt(self.a9), getGpPt(self.a12)) # edges.append(edge6) # edge7 = make_edge(getGpPt(self.a12), getGpPt(self.a1)) # edges.append(edge7) edge4 = make_edge(getGpPt(self.a6), getGpPt(self.a9)) edges.append(edge4) edge5 = make_edge(getGpPt(self.a9), getGpPt(self.a12)) edges.append(edge5) edge6 = make_edge(getGpPt(self.a12), getGpPt(self.a1)) edges.append(edge6) else: edge1 = make_edge(getGpPt(self.a1), getGpPt(self.a2)) edges.append(edge1) edge2 = make_edge(getGpPt(self.a2), getGpPt(self.a3)) edges.append(edge2) arc1 = GC_MakeArcOfCircle(getGpPt(self.a3), getGpPt(self.a4), getGpPt(self.a5)) edge3 = make_edge(arc1.Value()) edges.append(edge3) edge4 = make_edge(getGpPt(self.a5), getGpPt(self.a6)) edges.append(edge4) arc2 = GC_MakeArcOfCircle(getGpPt(self.a6), getGpPt(self.a7), getGpPt(self.a8)) edge5 = make_edge(arc2.Value()) edges.append(edge5) edge6 = make_edge(getGpPt(self.a8), getGpPt(self.a9)) edges.append(edge6) arc3 = GC_MakeArcOfCircle(getGpPt(self.a9), getGpPt(self.a10), getGpPt(self.a11)) edge7 = make_edge(arc3.Value()) edges.append(edge7) edge8 = make_edge(getGpPt(self.a11), getGpPt(self.a12)) edges.append(edge8) edge9 = make_edge(getGpPt(self.a12), getGpPt(self.a1)) edges.append(edge9) wire = makeWireFromEdges(edges) aFace = makeFaceFromWire(wire) extrudeDir = self.L * self.wDir # extrudeDir is a numpy array prism = makePrismFromFace(aFace, extrudeDir) mkFillet = BRepFilletAPI_MakeFillet(prism) anEdgeExplorer = TopExp_Explorer(prism, TopAbs_EDGE) while anEdgeExplorer.More(): aEdge = topods.Edge(anEdgeExplorer.Current()) mkFillet.Add(self.T / 17., aEdge) anEdgeExplorer.Next() prism = mkFillet.Shape() return prism
myFaceProfile = BRepBuilderAPI_MakeFace(myWireProfile) aPrismVec = gp_Vec(0, 0, myHeight) myBody = OCC.BRepPrimAPI.BRepPrimAPI_MakePrism(myFaceProfile.Face(), aPrismVec) mkFillet = BRepFilletAPI_MakeFillet(myBody.Shape()) anEdgeExplorer = OCC.TopExp.TopExp_Explorer(myBody.Shape(), OCC.TopAbs.TopAbs_EDGE) while anEdgeExplorer.More(): anEdge = topods.Edge(anEdgeExplorer.Current()) # Add edge to fillet algorithm # ... mkFillet.Add(myThickness / 12.0, anEdge) anEdgeExplorer.Next() myBody = mkFillet.Shape() neckLocation = gp_Pnt(0, 0, myHeight) neckAxis = OCC.gp.gp_DZ() neckAx2 = gp_Ax2(neckLocation, neckAxis) myNeckRadius = myThickness / 4.0 myNeckHeight = myHeight / 10.0 MKCylinder = OCC.BRepPrimAPI.BRepPrimAPI_MakeCylinder(neckAx2, myNeckRadius, myNeckHeight) myNeck = MKCylinder.Shape() myBody = OCC.BRepAlgoAPI.BRepAlgoAPI_Fuse(myBody, myNeck)