def getTestFace(): P1 = gp_Pnt(0., 0., 0.) P12 = gp_Pnt(0., 2., 2.) P2 = gp_Pnt(0., 10., 0.) P3 = gp_Pnt(0., 10., 10.) P4 = gp_Pnt(0., 0., 10.) P5 = gp_Pnt(5., 5., 5.) SceneDrawPoint('p1', P1) SceneDrawPoint('p12', P12) SceneDrawPoint('p2', P2) SceneDrawPoint('p3', P3) SceneDrawPoint('p4', P4) SceneDrawPoint('p5', P5) W = BRepBuilderAPI_MakePolygon() W.Add(P1) W.Add(P12) W.Add(P2) W.Add(P3) W.Add(P4) W.Add(P1) SceneDrawShape('w', W.Shape()) # Initialize a BuildPlateSurface BPSurf = GeomPlate_BuildPlateSurface(3, 15, 2) # Create the curve constraints anExp = BRepTools_WireExplorer() anExp.Init(W.Wire()) while anExp.More(): E = anExp.Current() C = BRepAdaptor_HCurve() C.ChangeCurve().Initialize(E) Cont = BRepFill_CurveConstraint(C, 0) BPSurf.Add(Cont) anExp.Next() # Point constraint PCont = GeomPlate_PointConstraint(P5, 0) BPSurf.Add(PCont) # Compute the Plate surface BPSurf.Perform() # Approximation of the Plate surface MaxSeg = 9 MaxDegree = 8 CritOrder = 0 PSurf = BPSurf.Surface() dmax = max(0.0001, 10 * BPSurf.G0Error()) Tol = 0.0001 Mapp = GeomPlate_MakeApprox(PSurf, Tol, MaxSeg, MaxDegree, dmax, CritOrder) Surf = Mapp.Surface() # create a face corresponding to the approximated Plate Surface Umin, Umax, Vmin, Vmax = PSurf.Bounds() #MF = BRepBuilderAPI_MakeFace (Surf, Umin, Umax, Vmin, Vmax, Tol) MF = BRepBuilderAPI_MakeFace(Surf, Tol) return MF
def edges(self) -> List[BRepEdge]: edges = [] explorer = BRepTools_WireExplorer(self.loop) while explorer.More(): edge = explorer.Current() edges.append(BRepEdge(edge)) explorer.Next() return edges
class WireExplorer(object): ''' Wire traversal ''' def __init__(self, wire): assert isinstance(wire, TopoDS_Wire), 'not a TopoDS_Wire' self.wire = wire self.wire_explorer = BRepTools_WireExplorer(self.wire) self.done = False def _reinitialize(self): self.wire_explorer = BRepTools_WireExplorer(self.wire) self.done = False 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 ordered_edges(self): return self._loop_topo(edges=True) def ordered_vertices(self): return self._loop_topo(edges=False)
def curve(self): """ :return: The curve formed by concatenating all the underlying curves of the edges. :rtype: afem.geometry.entities.NurbsCurve """ geom_convert = GeomConvert_CompCurveToBSplineCurve() exp = BRepTools_WireExplorer(self.object) tol = self.tol_max while exp.More(): e = TopoDS.Edge_(exp.Current()) exp.Next() adp_crv = BRepAdaptor_Curve(e) geom_convert.Add(adp_crv.BSpline(), tol) geom_curve = geom_convert.BSplineCurve() return Curve.wrap(geom_curve)
class WireExplorer: ''' Wire traversal ''' def __init__(self, wire): if not isinstance(wire, TopoDS_Wire): raise AsssertionError('not a TopoDS_Wire') self.wire = wire self.wire_explorer = BRepTools_WireExplorer(self.wire) self.done = False def _reinitialize(self): self.wire_explorer = BRepTools_WireExplorer(self.wire) self.done = False def _loop_topo(self, edges=True): if self.done: self._reinitialize() topologyType = topods_Edge if edges else topods_Vertex seq = [] occ_seq = [] while self.wire_explorer.More(): # loop edges if edges: current_item = self.wire_explorer.Current() # loop vertices else: current_item = self.wire_explorer.CurrentVertex() occ_seq.append(current_item) self.wire_explorer.Next() # Convert occ_seq to python list for elem in occ_seq: topo_to_add = topologyType(elem) seq.append(topo_to_add) self.done = True return iter(seq) def ordered_edges(self): return self._loop_topo(edges=True) def ordered_vertices(self): return self._loop_topo(edges=False)
class WireExplorer: """ Wire traversal """ def __init__(self, wire: TopoDS_Wire) -> None: if not isinstance(wire, TopoDS_Wire): raise AssertionError("not a TopoDS_Wire") self.wire = wire self.wire_explorer = BRepTools_WireExplorer(self.wire) self.done = False def _reinitialize(self) -> None: self.wire_explorer = BRepTools_WireExplorer(self.wire) self.done = False def _loop_topo(self, edges: Optional[bool] = True) -> Iterator[Any]: if self.done: self._reinitialize() topology_type = topods_Edge if edges else topods_Vertex seq = [] while self.wire_explorer.More(): # loop edges if edges: current_item = self.wire_explorer.Current() # loop vertices else: current_item = self.wire_explorer.CurrentVertex() seq.append(topology_type(current_item)) self.wire_explorer.Next() self.done = True return iter(seq) def ordered_edges(self) -> Iterator[TopoDS_Edge]: return self._loop_topo(edges=True) def ordered_vertices(self) -> Iterator[TopoDS_Vertex]: return self._loop_topo(edges=False)
def __init__(self, wire, face=None): if face is None: explorer = BRepTools_WireExplorer(wire.object) else: explorer = BRepTools_WireExplorer(wire.object, face.object) edges = [] current_verts = [] while explorer.More(): ei = Edge(explorer.Current()) vi = Vertex(explorer.CurrentVertex()) edges.append(ei) current_verts.append(vi) explorer.Next() # CurrentVertex doesn't get the last vertex. Try to get it. ordered_verts = list(current_verts) if edges: vi = Vertex(explorer.CurrentVertex()) ordered_verts.append(vi) self._edges = edges self._current_verts = current_verts self._ordered_verts = ordered_verts
def getWireStartPointAndTangentDir(aWire): ex = BRepTools_WireExplorer(aWire) edge = ex.Current() vertex = ex.CurrentVertex() v = getVectorTangentToCurveAtPoint(edge, 0) return BRep_Tool.Pnt(vertex), gp_Dir(v)