Open CASCADE, the 3D modelling kernel
3D modeling & numerical simulation

Search the Forums
See All Topics
 

Edges to wire

Edges to wire
Matthias Kostka 2012/01/04 18:47
Hi,

i have a couple of edges (see attachment red color) and now i connect them to a wire with:

BRepBuilderAPI_MakeWire makeWire;
for (TopExp_Explorer ex(intersectionShape, TopAbs_EDGE); ex.More(); ex.Next())
{
makeWire.Add(TopoDS::Edge(ex.Current()));
}
makeWire.Build();

but i only get the green wire.

Looks like the the makeWire.Add(..) adds a not connected edge, but they are all connected (like the picture shows).

Thx for help
Matthias
You have to be logged in to download the attached file
Cauchy Ding 2012/01/06 02:19
Hi Matthias,

Before calling BRepBuilderAPI_MakeWire, you have to sort edges' order.

Ding
Matthias Kostka 2012/01/07 13:27
Thx Ding,

how could I do that?

Matthias
Cauchy Ding 2012/01/09 13:25
Hi Matthias,

If input edges don't contain any degenerated edge, you can use similar codes listed in attachment.
Hope it works for you.

Ding
You have to be logged in to download the attached file
Matthias Kostka 2012/01/10 00:26
Hi Ding,

thx for your time. i will take a look at your nice code. ;)

Thx Matthias
Sharad Verma 2012/07/02 10:52
Thanks Ding.. Thanks a lot.. :)
Sharad Verma 2012/07/09 15:40
Hi Ding,

This code doesn't work for the wire, which contains an edge twice. Same as a pipe contains twice the connecting edge, the above code doesn't return 4 edges, it returns only 3 edges.

Can you please give me corrected algo for the same?
Mark Blome 2012/07/09 17:02
Dear Shard Verma,

you can use ShapeAnalysis_WireOrder to sort edges, this is how I do it in Python using PythonOCC
wrappers for Opencascade. The funtion below will return a list of wires, in case you have provided edges
that are not connected:

def _buildWiresFromEdgeset(self, edgelist):
from OCC.TopExp import TopExp
from OCC.BRep import BRep_Tool
from OCC.ShapeAnalysis import ShapeAnalysis_WireOrder
from OCC.Precision import Precision
from OCC.BRepBuilderAPI import BRepBuilderAPI_MakeWire
from OCC.BRepBuilderAPI import BRepBuilderAPI_WireDone, BRepBuilderAPI_EmptyWire, BRepBuilderAPI_DisconnectedWire, BRepBuilderAPI_NonManifoldWire
wb_errdict={BRepBuilderAPI_WireDone:"No error", BRepBuilderAPI_EmptyWire:"Empty wire", BRepBuilderAPI_DisconnectedWire:"disconnected wire",
BRepBuilderAPI_NonManifoldWire:"non-manifold wire"}
sawo_statusdict={0:"all edges are direct and in sequence",
1:"all edges are direct but some are not in sequence",
2:"unresolved gaps remain",
-1:"some edges are reversed, but no gaps remain",
-2:"some edges are reversed and some gaps remain",
-10:"failure on reorder"}
TE = TopExp(); DS=TopoDS()
isclosed = False # in general, wires will not be closed
mode3d = True
SAWO = ShapeAnalysis_WireOrder(mode3d, Precision().PConfusion())
for edge in edgelist:
V1 = TE.FirstVertex(DS.Edge(edge))
V2 = TE.LastVertex(DS.Edge(edge))
pnt1 = BRep_Tool().Pnt(V1)
pnt2 = BRep_Tool().Pnt(V2)
SAWO.Add(pnt1.XYZ(), pnt2.XYZ())
SAWO.SetKeepLoopsMode(True)
SAWO.Perform(isclosed)
#print "SAWO.Status()", SAWO.Status()
if not SAWO.IsDone():
raise RuntimeError, "build wire: Unable to reorder edges: \n" + sawo_statusdict[SAWO.Status()]
else:
if SAWO.Status() not in [0, -1]:
pass # not critical, wirebuilder will handle this
SAWO.SetChains(Precision().PConfusion())
Wirelist = TT.IndexedListOfShape()
#print "Number of chains: ", SAWO.NbChains()
for i in range(SAWO.NbChains()):
wirebuilder = BRepBuilderAPI_MakeWire()
estart, eend = SAWO.Chain(i+1)
#print "Number of edges in chain", i, ": ", eend - estart + 1
if (eend - estart + 1)==0:
continue
for j in range(estart, eend+1):
idx = abs(SAWO.Ordered(j)) #<0 if edge should be reversed, which wirebuilder will handle for us
wirebuilder = s_addToWireBuilder(wirebuilder, edgelist[idx-1])
if wirebuilder is None:
raise RuntimeError, " build wire: Error adding edge number " + str(j+1) + " to Wire number " + str(i)
err = wirebuilder.Error()
if err != BRepBuilderAPI_WireDone:
raise RuntimeError, "Overlay2D: build wire: Error adding edge number " + str(j+1) + " to Wire number " + str(i) +": \n" + wb_errdict[err]
try:
wirebuilder.Build()
aWire = wirebuilder.Wire()
Wirelist.append(aWire)
except Exception, err:
raise RuntimeError, "Overlay2D: build wire: Creation of Wire number " + str(i) + " from edge(s) failed. \n" + str(err)
return Wirelist


def _addToWireBuilder(self, wirebuilder, aShape):
DS=TopoDS()
st = aShape.ShapeType()
if (not st in [TopAbs_WIRE, TopAbs_EDGE]):
raise RuntimeError, "_addToWireBuilder: Shape must be an edge or a wire."
edgelist = allEdges(aShape)
for i, edge in enumerate(edgelist):
try:
wirebuilder.Add(DS.Edge(edge))
except Exception, err:
raise RuntimeError, "build wire:Error adding edge number " + str(i) + "to Wirebuilder: \n" + str(err)
return wirebuilder
Timo 2014/04/03 15:27
Also ShapeAnalysis_FreeBounds::ConnectEdgesToWires can be used to build wires from unsorted edges. I guess Mark's solution has better performance but I didn't check it. After the call to ConnectEdgesToWires it might be necessary to fix the resulting wires.

Regards,
Timo
Timo 2014/04/03 15:28
See also http://www.opencascade.org/org/forum/thread_19660/?forum=3
 
 
Latest news
  • New features to enhance the development process
  • Open CASCADE Technology 6.7.1 is available for download!
  • Open CASCADE Technology 6.7.0 is available for download!

  • © OPEN CASCADE 2000 - 2014  |  Search  |  Contacts   |  Site map