pythonocc-core icon indicating copy to clipboard operation
pythonocc-core copied to clipboard

close open shell boundary

Open andysfd opened this issue 1 year ago • 3 comments

Hello

I imported a Step file representing an open shell (<class 'TopoDS_Shell'>). I now want to find a correct and easy method to close the two existing holes. I searched several documentations but couldn't find a function for this purpose.

question

Furtherone i need to check points inside and outside the shell and the distances, which i successfully accomplished with BRepClass3d_SolidClassifier and BRepExtrema_DistShapeShape. However to get correct results at the beginning of the shell i need to properly close it.

question2

Thanks in advance for any help! Wish you all a happy new year

andysfd avatar Jan 09 '24 10:01 andysfd

For each red wire, you can build a face using the BRepBuilderAPI_MakeFace class:

face_1 = BRepBuilderAPI_MakeFace(red_wire_1).Face()
face_2 = BRepBuilderAPI_MakeFace(red_wire_2).Face()

In order to get those wires, use the TopologyExplorer class:

from OCC.Extend.DataExchange import read_step_file
from OCC.Extend.TopologyUtils import TopologyExplorer
step_shp = read_step_file("yourstepfile.stp")
wires = TopologyExplorer(step_shp).wires()

and loop over wires

tpaviot avatar Jan 09 '24 12:01 tpaviot

so i could extract the vertices of the openings and construct my own faces?

But isn't there a robust solution? i do not know how to detect the edges / vertices associated to the openings. I thought about using ShapeAnalysis_FreeBounds or something but had no success.

When i simply extract the wires and sew them togeter its still open, meaning the red_wire does not exist yet in the model and needs to be constructed from the existing edges.

andysfd avatar Jan 09 '24 13:01 andysfd

i managed to do it, although i don't think it is the cleanest solution:

I extracted the faces and used the sewing algorithm in order to detect the boundaries with .FreeEdges. I then extracted the edges and joined them consecutively to a new face.

Is there an other algorithm which gives me FreeEdges without the need for resewing of the already existing shell?

wires = TopologyExplorer(shp).wires()
faces=[]
for wire in wires:
    faces.append(BRepBuilderAPI_MakeFace(wire).Face())

sew = BRepBuilderAPI_Sewing() 
for face in faces:
    sew.Add(face)
sew.Perform()  

print("Free edge", sew.NbFreeEdges())
free_edges =[]
for i in range(1, sew.NbFreeEdges()+1):
    free_edges.append(sew.FreeEdge(i))

image

andysfd avatar Jan 10 '24 09:01 andysfd