Skip to content

Commit 7f32e9b

Browse files
committed
Add static method parse_face in NurbsHandler
1 parent 61bc49d commit 7f32e9b

File tree

1 file changed

+85
-0
lines changed

1 file changed

+85
-0
lines changed

pygem/nurbshandler.py

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ def __init__(self):
5353
self._control_point_position = None
5454
self.tolerance = 1e-6
5555
self.shape = None
56+
self.check_topo = 0
5657

5758
def _check_infile_instantiation(self):
5859
"""
@@ -249,6 +250,90 @@ def check_topology(self):
249250
else:
250251
self.check_topo = 0
251252

253+
@staticmethod
254+
def parse_face(topo_face):
255+
"""
256+
Method to parse a single Face (a single patch nurbs surface).
257+
It returns a matrix with all the coordinates of control points of the
258+
Face and a second list with all the control points related to the
259+
Edges of the Face.
260+
261+
:param topo_face: the input Face
262+
263+
:return: mesh_points_face: it is a `n_points`-by-3 matrix containing the
264+
coordinates of the control points of the Face (a nurbs surface)
265+
266+
:return: mesh_points_edge: it is a list of `n_points`-by-3 matrix
267+
268+
:rtype: tuple(numpy.ndarray, list)
269+
270+
"""
271+
# get some Face - Edge - Vertex data map information
272+
mesh_points_edge = []
273+
face_exp_wire = TopExp_Explorer(topo_face, TopAbs_WIRE)
274+
# loop on wires per face
275+
while face_exp_wire.More():
276+
twire = OCC.TopoDS.topods_Wire(face_exp_wire.Current())
277+
wire_exp_edge = TopExp_Explorer(twire, TopAbs_EDGE)
278+
# loop on edges per wire
279+
while wire_exp_edge.More():
280+
edge = OCC.TopoDS.topods_Edge(wire_exp_edge.Current())
281+
bspline_converter = BRepBuilderAPI_NurbsConvert(edge)
282+
bspline_converter.Perform(edge)
283+
bspline_tshape_edge = bspline_converter.Shape()
284+
h_geom_edge, a, b = BRep_Tool_Curve(OCC.TopoDS.topods_Edge(
285+
bspline_tshape_edge))
286+
h_bspline_edge = geomconvert_CurveToBSplineCurve(h_geom_edge)
287+
bspline_geom_edge = h_bspline_edge.GetObject()
288+
289+
nb_poles = bspline_geom_edge.NbPoles()
290+
291+
# Edge geometric properties
292+
edge_ctrlpts = TColgp_Array1OfPnt(1, nb_poles)
293+
bspline_geom_edge.Poles(edge_ctrlpts)
294+
295+
points_single_edge = np.zeros((0, 3))
296+
for i in range(1, nb_poles + 1):
297+
ctrlpt = edge_ctrlpts.Value(i)
298+
ctrlpt_position = np.array([[ctrlpt.Coord(1),
299+
ctrlpt.Coord(2),
300+
ctrlpt.Coord(3)]])
301+
points_single_edge = np.append(points_single_edge,
302+
ctrlpt_position,
303+
axis=0)
304+
305+
mesh_points_edge.append(points_single_edge)
306+
307+
wire_exp_edge.Next()
308+
309+
face_exp_wire.Next()
310+
# extract mesh points (control points) on Face
311+
mesh_points_face = np.zeros((0, 3))
312+
# convert Face to Geom B-spline Face
313+
nurbs_converter = BRepBuilderAPI_NurbsConvert(topo_face)
314+
nurbs_converter.Perform(topo_face)
315+
nurbs_face = nurbs_converter.Shape()
316+
h_geomsurface = BRep_Tool.Surface(OCC.TopoDS.topods.Face(nurbs_face))
317+
h_bsurface = geomconvert_SurfaceToBSplineSurface(h_geomsurface)
318+
bsurface = h_bsurface.GetObject()
319+
320+
# get access to control points (poles)
321+
nb_u = bsurface.NbUPoles()
322+
nb_v = bsurface.NbVPoles()
323+
ctrlpts = TColgp_Array2OfPnt(1, nb_u, 1, nb_v)
324+
bsurface.Poles(ctrlpts)
325+
326+
for indice_u_direction in range(1, nb_u + 1):
327+
for indice_v_direction in range(1, nb_v + 1):
328+
ctrlpt = ctrlpts.Value(indice_u_direction, indice_v_direction)
329+
ctrlpt_position = np.array([[ctrlpt.Coord(1),
330+
ctrlpt.Coord(2),
331+
ctrlpt.Coord(3)]])
332+
mesh_points_face = np.append(mesh_points_face,
333+
ctrlpt_position, axis=0)
334+
335+
return mesh_points_face, mesh_points_edge
336+
252337
def write_shape_to_file(self, shape, filename):
253338
"""
254339
Abstract method to write the 'shape' to the `filename`.

0 commit comments

Comments
 (0)