Skip to content

Commit d4a4947

Browse files
committed
Add static method combine_faces in NurbsHandler
1 parent eb92585 commit d4a4947

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

pygem/nurbshandler.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -549,6 +549,52 @@ def write_face(self, points_face, list_points_edge, topo_face, toledge):
549549

550550
return OCC.TopoDS.topods.Face(new_bspline_tface.Face())
551551

552+
@staticmethod
553+
def combine_faces(compshape, sew_tolerance):
554+
"""
555+
Method to combine faces in a shell by adding connectivity and continuity
556+
:param compshape: TopoDS_Shape
557+
:param sew_tolerance: tolerance for sewing
558+
:return: Topo_Shell
559+
"""
560+
561+
offsew = BRepOffsetAPI_FindContigousEdges(sew_tolerance)
562+
sew = BRepBuilderAPI_Sewing(sew_tolerance)
563+
564+
face_explorers = TopExp_Explorer(compshape, TopAbs_FACE)
565+
n_faces = 0
566+
# cycle on Faces
567+
while face_explorers.More():
568+
tface = OCC.TopoDS.topods.Face(face_explorers.Current())
569+
sew.Add(tface)
570+
offsew.Add(tface)
571+
n_faces += 1
572+
face_explorers.Next()
573+
574+
offsew.Perform()
575+
offsew.Dump()
576+
sew.Perform()
577+
shell = sew.SewedShape()
578+
sew.Dump()
579+
580+
shell = OCC.TopoDS.topods.Shell(shell)
581+
shell_fixer = ShapeFix_Shell()
582+
shell_fixer.FixFaceOrientation(shell)
583+
584+
if shell_fixer.Perform():
585+
print("{} shells fixed! ".format(shell_fixer.NbShells()))
586+
else:
587+
print "Shells not fixed! "
588+
589+
new_shell = shell_fixer.Shell()
590+
591+
if OCC.BRepAlgo.brepalgo_IsValid(new_shell):
592+
print "Shell valid! "
593+
else:
594+
print "Shell failed! "
595+
596+
return new_shell
597+
552598
def write_shape_to_file(self, shape, filename):
553599
"""
554600
Abstract method to write the 'shape' to the `filename`.

0 commit comments

Comments
 (0)