def makePieSlice(r, theta0, theta1, z_min, z_max): p0 = gp_Pnt(0, 0, z_min) p1 = gp_Pnt(r * cos(theta0), r * sin(theta0), z_min) p2 = gp_Pnt(r * cos(theta1), r * sin(theta1), z_min) edges = [] los = TopTools_ListOfShape() me = BRepBuilderAPI_MakeEdge(p0, p1) edges.append(me.Edge()) los.Append(me.Edge()) ax = gp_Ax2(gp_Pnt(0, 0, z_min), gp_Dir(0, 0, 1), gp_Dir(1, 0, 0)) circ = gp_Circ(ax, r) me = BRepBuilderAPI_MakeEdge(circ, theta0, theta1) edges.append(me.Edge()) los.Append(me.Edge()) me = BRepBuilderAPI_MakeEdge(p2, p0) edges.append(me.Edge()) los.Append(me.Edge()) """ mw = BRepBuilderAPI_MakeWire() for i in edges: mw.Add(i) """ mw = BRepBuilderAPI_MakeWire() mw.Add(los) pln = gp_Pln(gp_Pnt(0, 0, z_min), gp_Dir(0, 0, 1)) mf = BRepBuilderAPI_MakeFace(pln, mw.Wire()) face = mf.Face() mp = BRepPrimAPI_MakePrism(face, gp_Vec(0, 0, z_max - z_min)) return mp.Shape()
def _loop_topo(self, edges=True): if self.done: self._reinitialize() topologyType = topods_Edge if edges else topods_Vertex seq = [] hashes = [] # list that stores hashes to avoid redundancy occ_seq = TopTools_ListOfShape() while self.wire_explorer.More(): # loop edges if edges: current_item = self.wire_explorer.Current() # loop vertices else: current_item = self.wire_explorer.CurrentVertex() current_item_hash = current_item.__hash__() if not current_item_hash in hashes: hashes.append(current_item_hash) occ_seq.Append(current_item) self.wire_explorer.Next() # Convert occ_seq to python list occ_iterator = TopTools_ListIteratorOfListOfShape(occ_seq) while occ_iterator.More(): topo_to_add = topologyType(occ_iterator.Value()) seq.append(topo_to_add) occ_iterator.Next() self.done = True return iter(seq)
def split2(base, cutters): # https://www.opencascade.com/doc/occt-7.0.0/overview/html/ # occt_user_guides__boolean_operations.html#occt_algorithms_10a builder = BRepAlgoAPI_Section() tools = TopTools_ListOfShape() for cutter in cutters: tools.Append(cutter) builder.ComputePCurveOn1()
def thick_solid(event=None): S = BRepPrimAPI_MakeBox(150, 200, 110).Shape() topo = Topo(S) vert = next(topo.vertices()) shapes = TopTools_ListOfShape() for f in topo.faces_from_vertex(vert): shapes.Append(f) _thick_solid = BRepOffsetAPI_MakeThickSolid(S, shapes, 15, 0.01) display.EraseAll() display.DisplayShape(_thick_solid.Shape()) display.FitAll()
def update_shape(self, change=None): d = self.declaration #: Get the shape to apply the fillet to s = self.get_shape() faces = TopTools_ListOfShape() for f in self.get_faces(s): faces.Append(f) if faces.IsEmpty(): return self.shape = BRepOffsetAPI_MakeThickSolid( s.shape.Shape(), faces, d.offset, d.tolerance, self.offset_modes[d.offset_mode], d.intersection, False, self.join_types[d.join_type])
def shell(self, faceList, thickness, tolerance=0.0001): """ make a shelled solid of given by removing the list of faces :param faceList: list of face objects, which must be part of the solid. :param thickness: floating point thickness. positive shells outwards, negative shells inwards :param tolerance: modelling tolerance of the method, default=0.0001 :return: a shelled solid """ occ_faces_list = TopTools_ListOfShape() for f in faceList: occ_faces_list.Append(f.wrapped) shell_builder = BRepOffsetAPI_MakeThickSolid(self.wrapped, occ_faces_list, thickness, tolerance) shell_builder.Build() return self.__class__(shell_builder.Shape())
def subtract(shape1, shape2): """Boolean difference of two shapes. Parameters ---------- shape1, shape2 : TopoDS_Shape Surfaces. Returns ------- difference : TopoDS_Shape The set difference :code:`shape1 \ shape2`. Notes ----- The implementation follows the following sources: - https://techoverflow.net/2019/06/14/how-to-fuse-topods_shapes-in-opencascade-boolean-and/ - https://github.com/tpaviot/pythonocc-demos/blob/master/examples/core_boolean_fuzzy_cut_emmenthaler.py#L41-L54 For Boolean operations in Open CASCADE, see its `documentation <https://dev.opencascade.org/doc/overview/html/specification__boolean_operations.html>`_. """ arguments = TopTools_ListOfShape() arguments.Append(shape1) tools = TopTools_ListOfShape() tools.Append(shape2) difference = BRepAlgoAPI_Cut() difference.SetTools(tools) difference.SetArguments(arguments) difference.Build() return difference.Shape()
def fuzzy_cut(shape_A, shape_B, tol=5e-5, parallel=False): """ returns shape_A - shape_B """ cut = BRepAlgoAPI_Cut() L1 = TopTools_ListOfShape() L1.Append(shape_A) L2 = TopTools_ListOfShape() L2.Append(shape_B) cut.SetArguments(L1) cut.SetTools(L2) cut.SetFuzzyValue(tol) cut.SetRunParallel(parallel) cut.Build() return cut.Shape()
def _loop_topo(self, topologyType, topologicalEntity=None, topologyTypeToAvoid=None): ''' this could be a faces generator for a python TopoShape class that way you can just do: for face in srf.faces: processFace(face) ''' topoTypes = { TopAbs_VERTEX: TopoDS_Vertex, TopAbs_EDGE: TopoDS_Edge, TopAbs_FACE: TopoDS_Face, TopAbs_WIRE: TopoDS_Wire, TopAbs_SHELL: TopoDS_Shell, TopAbs_SOLID: TopoDS_Solid, TopAbs_COMPOUND: TopoDS_Compound, TopAbs_COMPSOLID: TopoDS_CompSolid } assert topologyType in topoTypes.keys(), '%s not one of %s' % ( topologyType, topoTypes.keys()) self.topExp = TopExp_Explorer() # use self.myShape if nothing is specified if topologicalEntity is None and topologyTypeToAvoid is None: self.topExp.Init(self.myShape, topologyType) elif topologicalEntity is None and topologyTypeToAvoid is not None: self.topExp.Init(self.myShape, topologyType, topologyTypeToAvoid) elif topologyTypeToAvoid is None: self.topExp.Init(topologicalEntity, topologyType) elif topologyTypeToAvoid: self.topExp.Init(topologicalEntity, topologyType, topologyTypeToAvoid) seq = [] hashes = [] # list that stores hashes to avoid redundancy occ_seq = TopTools_ListOfShape() while self.topExp.More(): current_item = self.topExp.Current() current_item_hash = current_item.__hash__() if not current_item_hash in hashes: hashes.append(current_item_hash) occ_seq.Append(current_item) self.topExp.Next() # Convert occ_seq to python list occ_iterator = TopTools_ListIteratorOfListOfShape(occ_seq) while occ_iterator.More(): topo_to_add = self.topoFactory[topologyType](occ_iterator.Value()) seq.append(topo_to_add) occ_iterator.Next() if self.ignore_orientation: # filter out those entities that share the same TShape # but do *not* share the same orientation filter_orientation_seq = [] for i in seq: _present = False for j in filter_orientation_seq: if i.IsSame(j): _present = True break if _present is False: filter_orientation_seq.append(i) return filter_orientation_seq else: return iter(seq)
while aFaceExplorer.More(): aFace = topods.Face(aFaceExplorer.Current()) if face_is_plane(aFace): aPlane = geom_plane_from_face(aFace) # We want the highest Z face, so compare this to the previous faces aPnt = aPlane.Location() aZ = aPnt.Z() if aZ > zMax: zMax = aZ faceToRemove = aFace aFaceExplorer.Next() facesToRemove = TopTools_ListOfShape() facesToRemove.Append(faceToRemove) myBody = BRepOffsetAPI_MakeThickSolid(myBody.Shape(), facesToRemove, -thickness / 50.0, 0.001) # Set up our surfaces for the threading on the neck neckAx2_Ax3 = gp_Ax3(neckLocation, gp_DZ()) aCyl1 = Geom_CylindricalSurface(neckAx2_Ax3, myNeckRadius * 0.99) aCyl2 = Geom_CylindricalSurface(neckAx2_Ax3, myNeckRadius * 1.05) # Set up the curves for the threads on the bottle's neck aPnt = gp_Pnt2d(2.0 * math.pi, myNeckHeight / 2.0) aDir = gp_Dir2d(2.0 * math.pi, myNeckHeight / 4.0) anAx2d = gp_Ax2d(aPnt, aDir)