Skip to content

Commit 5b090d8

Browse files
committed
Add method parse_shape in NurbsHandler
1 parent 7f32e9b commit 5b090d8

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed

pygem/nurbshandler.py

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,70 @@ def parse_face(topo_face):
334334

335335
return mesh_points_face, mesh_points_edge
336336

337+
def parse_shape(self, filename):
338+
"""
339+
Method to parse a Shape with multiple objects (1 compound = multi-shells
340+
and 1 shell = multi-faces)
341+
It returns a list of matrix with all the coordinates of control points
342+
of each Face and a second list with all the control points related to
343+
Edges of each Face.
344+
345+
:param filename: the input filename.
346+
347+
:return: list of (mesh_points: `n_points`-by-3 matrix containing
348+
the coordinates of the control points of the Face (surface),
349+
edge_points: it is a list of numpy.narray)
350+
:rtype: a list of shells
351+
352+
"""
353+
self.infile = filename
354+
self.shape = self.load_shape_from_file(filename)
355+
356+
self.check_topology()
357+
358+
# parse and get control points
359+
l_shells = [] # an empty list of shells
360+
n_shells = 0
361+
362+
if self.check_topo == 0:
363+
364+
shells_explorer = TopExp_Explorer(self.shape, TopAbs_SHELL)
365+
366+
# cycle on shells
367+
while shells_explorer.More():
368+
topo_shell = OCC.TopoDS.topods.Shell(shells_explorer.Current())
369+
shell_faces_explorer = TopExp_Explorer(topo_shell, TopAbs_FACE)
370+
l_faces = [] # an empty list of faces per shell
371+
372+
# cycle on faces
373+
while shell_faces_explorer.More():
374+
topo_face = OCC.TopoDS.topods.Face(shell_faces_explorer
375+
.Current())
376+
mesh_point, edge_point = self.parse_face(topo_face)
377+
l_faces.append((mesh_point, edge_point))
378+
shell_faces_explorer.Next()
379+
380+
l_shells.append(l_faces)
381+
n_shells += 1
382+
shells_explorer.Next()
383+
384+
else:
385+
# cycle only on faces
386+
shell_faces_explorer = TopExp_Explorer(self.shape, TopAbs_FACE)
387+
l_faces = [] # an empty list of faces per shell
388+
389+
while shell_faces_explorer.More():
390+
topo_face = OCC.TopoDS.topods.Face(shell_faces_explorer
391+
.Current())
392+
mesh_point, edge_point = self.parse_face(topo_face)
393+
l_faces.append((mesh_point, edge_point))
394+
shell_faces_explorer.Next()
395+
396+
l_shells.append(l_faces)
397+
n_shells += 1
398+
399+
return l_shells
400+
337401
def write_shape_to_file(self, shape, filename):
338402
"""
339403
Abstract method to write the 'shape' to the `filename`.

0 commit comments

Comments
 (0)