Dear Jelle, I was able to locate the self-intersection points using ShapeAnalysis_Wire. There was some difficulty, because it needs a face underlying the analysed wire.
The function 'faceAroundPlanarWire' below calculates such face assuming that the wire is planar. I would like to understand why a face is needed to find edge intersections? Anyway, the more important question is, how to proceed. The new functions 'fixWire' ' faceAroundPlanarWire' below find the correct self-intersection of the wire in my previous example. But I cannot figure out how to use ShapeUpgrade_WireDivide as you suggested. It seems that I have to call ShapeUpgrade_WireDivide's method 'SetSplitCurve2dTool (const Handle(ShapeUpgrade_SplitCurve2d)&splitCurve2dTool)'. For the ShapeUpgrade_SplitCurve2d I have to call 'SetSplitValues (const Handle(TColStd_HSequenceOfReal)&SplitValues)'. But what are the SplitValues? Is it the curve parameter at the intersection measured for indivual edges? I don't think so, because 'SetSplitSection' does not get any information about *which* edges are intersecting. Are the SplitValues the curve parameter at the intersection measured for the whole wire? To my knowledge there is no notion of the curve of a wire, is it? So how can I get the SplitValues after I got the intersection points (variable pts in function fixWire below)? ---- new code fragments: ---- def faceAroundPlanarWire(wire): topo=Topo(wire) pts=TColgp_HArray1OfPnt(0,topo.number_of_vertices()-1) i=0 for v in topo.vertices(): pts.SetValue(i,bt.Pnt(v)) i+=1 gpbap=GeomPlate_BuildAveragePlane(pts.GetHandle(),pts.Length(),1e-7,1,1) plane=gpbap.Plane() umin,umax,vmin,vmax=gpbap.MinMaxBox() mf=BRepBuilderAPI_MakeFace(plane,umin,umax,vmin,vmax) return mf.Face() def fixWire(wire): f=faceAroundPlanarWire(wire) saw=ShapeAnalysis_Wire() saw.Init(wire,f,1e-6) res=IntRes2d_SequenceOfIntersectionPoint() pts=TColgp_SequenceOfPnt() errs=TColStd_SequenceOfReal() print saw.Precision() for i in range(4): for k in range(i+1,4): print i,k,saw.CheckIntersectingEdges(i,k,res,pts,errs),res.Length(),pts.Length() ----------------------------- I also appreciate any other documentation or examples about the use of the ShapeUpgrade_WireDivide class. The reference documentation does not help, and with google I find nothing better. Thank you Björn ----- Ursprüngliche Mail ---- > Von: Jelle Feringa <jelleferi...@gmail.com> > An: pythonOCC users mailing list. <pythonocc-users@gna.org> > Gesendet: Donnerstag, den 12. August 2010, 11:59:03 Uhr > Betreff: Re: [Pythonocc-users] face from self-intersecting wire, ShapeFix > > Sorry, hit send too soon… > > Have you had a look at > > ShapeUpgrade_WireDivide > > ShapeAnalysis_Wire will help you find out which are intersecting edges. > > Björn, if you manage to fix this ( confident you will ;) than would you > please > > >share this example with us, such that way may include it in the /examples ? > > Thanks, > > -jelle > > On Aug 12, 2010, at 11:20 AM, Free Cad wrote: > > > Hi again, > > can you help me use ShapeFix in the correct way, or suggest other > > solutions >to a > > > problem with self-intersecting wires? > > > > The code below generates an example of such a wire. There is a small loop >close > > > to the point (1.0,1.0,0.0) which is the reason why no face can be made > > from >it, > > > I guess. > > > > The code also shows my attempt to solve the problem using >sf=ShapeFix_Wire(). > > > But sf.Perform() always fails, even if the wire is without problems (using > > vertex definitions as in the line which is commented out). > > > > What is the simplest solution to generate a face from self-intersecting >wires > > > _automatically_? In my example, the small loop could be collapsed to a >single > > > vertex, or the wire could be split into two (the large loop and the small >loop) > > > - both solutions would be fine. > > How about OCC's ShapeHealing functions? Are they more powerful than >ShapeFix? I > > > don't understand the relation between ShapeFix and ShapeHealing. Is >ShapeHealing > > > available in the non-commercial OCC distribution? > > > > > > Thank you > > Björn > > > > --- code example: --- > > from OCC.BRepBuilderAPI import * > > from OCC.gp import * > > from OCC.ShapeFix import * > > from OCC.TopoDS import * > > > > def fixWire(wire): > > sf=ShapeFix_Wire() > > sf.Load(wire) > > sf.SetFixIntersectingEdgesMode(1) > > sf.SetFixNonAdjacentIntersectingEdgesMode(1) > > sf.SetFixSelfIntersectingEdgeMode(1) > > if sf.Perform(): > > print 'Fix Successful' > > return sf.Wire() > > else: > > print 'Fix Unsuccessful' > > return wire > > > > def vertex(x,y,z): > > mv=BRepBuilderAPI_MakeVertex(gp_Pnt(x,y,z)) > > return mv.Vertex() > > def edge(v1,v2): > > me=BRepBuilderAPI_MakeEdge(v1,v2) > > return me.Edge() > > def face(w): > > mf=BRepBuilderAPI_MakeFace(w) > > return mf.Face() > > def wire(e1,e2,e3,e4): > > mw=BRepBuilderAPI_MakeWire(e1) > > mw.Add(e2); mw.Add(e3); mw.Add(e4); > > return mw.Wire() > > > > v=[vertex(0,0,0),vertex(1,0,0),vertex(0.95,1,0),vertex(1,1,0)] #self > > intersecting, no face visible > > #v=[vertex(0,0,0),vertex(1,0,0),vertex(1,1,0),vertex(0.9,1,0)] #valid wire > > e=[] > > for i in range(4): > > e.append(edge(v[i-1],v[i])) > > w=wire(e[0],e[1],e[2],e[3]) > > f=face(fixWire(w)) > > > > from OCC.Display.SimpleGui import * > > display, start_display, add_menu, add_function_to_menu = init_display() > > display.DisplayShape([w,f]) > > start_display() > > > > > > > > > > > > _______________________________________________ > > Pythonocc-users mailing list > > Pythonocc-users@gna.org > > https://mail.gna.org/listinfo/pythonocc-users > > > _______________________________________________ > Pythonocc-users mailing list > Pythonocc-users@gna.org > https://mail.gna.org/listinfo/pythonocc-users > _______________________________________________ Pythonocc-users mailing list Pythonocc-users@gna.org https://mail.gna.org/listinfo/pythonocc-users