2626from compas_libigl ._types_std import VectorVectorInt # noqa: F401
2727
2828
29- def map_mesh (target_mesh , pattern_mesh , clip_boundaries = True , tolerance = 1e-6 ):
29+ def map_mesh (target_mesh , pattern_mesh , clip_boundaries = True , simplify_borders = True , fixed_vertices = None , tolerance = 1e-6 ):
3030 """
3131 Map a 2D pattern mesh onto a 3D target.
3232
@@ -36,10 +36,18 @@ def map_mesh(target_mesh, pattern_mesh, clip_boundaries=True, tolerance=1e-6):
3636 A tuple of (vertices, faces) representing the target mesh.
3737 pattern_mesh : tuple[list[list[float]], list[list[int]]]
3838 A tuple of (vertices, faces) representing the pattern mesh.
39- clip_boundaries : bool
39+ clip_boundaries : bool, optional
4040 Whether to clip the pattern mesh to the boundaries of the target mesh.
41- tolerance : float
41+ Default is True.
42+ simplify_borders : bool, optional
43+ Whether to simplify the border of the pattern mesh.
44+ Default is True.
45+ fixed_vertices : list[list[float]], optional
46+ A list of fixed points on the target mesh.
47+ Default is None.
48+ tolerance : float, optional
4249 The tolerance for point comparison, to remove duplicates.
50+ Default is 1e-6.
4351
4452 Returns
4553 -------
@@ -61,16 +69,30 @@ def map_mesh(target_mesh, pattern_mesh, clip_boundaries=True, tolerance=1e-6):
6169 f_numpy = np .array (f , dtype = np .int32 )
6270 pattern_v_numpy = np .array (pv , dtype = np .float64 )
6371
72+ # Handle fixed_vertices - provide empty array if None
73+
74+ fixed_vertices_vectorint = VectorInt ()
75+ if fixed_vertices is None :
76+ fixed_vertices_vectorint = VectorInt ()
77+ else :
78+ fixed_vertices_vectorint = VectorInt (fixed_vertices )
79+
80+ # Convert pattern_f from Python list to VectorVectorInt which is expected by C++ code
81+
82+ pattern_f_vec = VectorVectorInt ()
83+ for face in pf :
84+ pattern_f_vec .append (face )
85+
6486 # Perform the mapping
6587 pv_numpy_copy , pf_numpy_cleaned , p_normals , pattern_is_boundary , pattern_groups = _mapping .map_mesh_with_automatic_parameterization (
66- v_numpy , f_numpy , pattern_v_numpy , pf , clip_boundaries , tolerance
88+ v_numpy , f_numpy , pattern_v_numpy , pattern_f_vec , clip_boundaries , simplify_borders , fixed_vertices_vectorint , tolerance
6789 )
6890
6991 # Return the result as a tuple
7092 return pv_numpy_copy , pf_numpy_cleaned , p_normals , pattern_is_boundary , pattern_groups
7193
7294
73- def map_pattern_to_mesh (name , mesh , clip_boundaries = True , tolerance = 1e-6 , pattern_u = 16 , pattern_v = 16 ):
95+ def map_pattern_to_mesh (name , mesh , clip_boundaries = True , tolerance = 1e-6 , pattern_u = 16 , pattern_v = 16 , simplify_borders = True , fixed_vertices = None ):
7496 """
7597 Map a 2D pattern mesh onto a 3D target.
7698
@@ -100,14 +122,24 @@ def map_pattern_to_mesh(name, mesh, clip_boundaries=True, tolerance=1e-6, patter
100122
101123 mesh : compas.datastructures.Mesh
102124 The target mesh.
103- clip_boundaries : bool
125+ clip_boundaries : bool, optional
104126 Whether to clip the pattern mesh to the boundaries of the target mesh.
105- tolerance : float
127+ Default is True.
128+ tolerance : float, optional
106129 The tolerance for point comparison, to remove duplicates.
107- pattern_u : int
130+ Default is 1e-6.
131+ pattern_u : int, optional
108132 The number of pattern vertices in the u direction.
109- pattern_v : int
133+ Default is 16.
134+ pattern_v : int, optional
110135 The number of pattern vertices in the v direction.
136+ Default is 16.
137+ simplify_borders : bool, optional
138+ Whether to simplify the border of the pattern mesh.
139+ Default is True.
140+ fixed_vertices : list[list[float]], optional
141+ A list of fixed points on the target mesh.
142+ Default is None.
111143
112144 Returns
113145 -------
@@ -165,6 +197,8 @@ def map_pattern_to_mesh(name, mesh, clip_boundaries=True, tolerance=1e-6, patter
165197 pf = tessagon_mesh ["face_list" ]
166198
167199 v , f = mesh .to_vertices_and_faces ()
168- mapped_vertices , mapped_faces , mapped_normals , mapped_is_boundary , mapped_groups = map_mesh ((v , f ), (pv , pf ), clip_boundaries = clip_boundaries , tolerance = tolerance )
200+ mapped_vertices , mapped_faces , mapped_normals , mapped_is_boundary , mapped_groups = map_mesh (
201+ (v , f ), (pv , pf ), clip_boundaries = clip_boundaries , simplify_borders = simplify_borders , fixed_vertices = fixed_vertices , tolerance = tolerance
202+ )
169203
170204 return Mesh .from_vertices_and_faces (mapped_vertices , mapped_faces )
0 commit comments