Compatibility

Most of the time, users experience problems in converting data between different software packages. To aid this problem a little bit, NURBS-Python provides a compatibility module for converting control points sets into NURBS-Python compatible ones.

The following example illustrates the usage of compatibility module:

 1from geomdl import NURBS
 2from geomdl import utilities as utils
 3from geomdl import compatibility as compat
 4from geomdl.visualization import VisMPL
 5
 6#
 7# Surface exported from your CAD software
 8#
 9
10# Dimensions of the control points grid
11p_size_u = 4
12p_size_v = 3
13
14# Control points in u-row order
15p_ctrlpts = [[0, 0, 0], [1, 0, 6], [2, 0, 0], [3, 0, 0],
16             [0, 1, 0], [1, 1, 0], [2, 1, 0], [3, 1, -3],
17             [0, 2, -3], [1, 2, 0], [2, 2, 3], [3, 2, 0]]
18
19# Weights vector
20p_weights = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
21
22# Degrees
23p_degree_u = 3
24p_degree_v = 2
25
26
27#
28# Prepare data for import
29#
30
31# Combine weights vector with the control points list
32t_ctrlptsw = compat.combine_ctrlpts_weights(p_ctrlpts, p_weights)
33
34# Since NURBS-Python uses v-row order, we need to convert the exported ones
35n_ctrlptsw = compat.flip_ctrlpts_u(t_ctrlptsw, p_size_u, p_size_v)
36
37# Since we have no information on knot vectors, let's auto-generate them
38n_knotvector_u = utils.generate_knot_vector(p_degree_u, p_size_u)
39n_knotvector_v = utils.generate_knot_vector(p_degree_v, p_size_v)
40
41
42#
43# Import surface to NURBS-Python
44#
45
46# Create a NURBS surface instance
47surf = NURBS.Surface()
48
49# Fill the surface object
50surf.degree_u = p_degree_u
51surf.degree_v = p_degree_v
52surf_set_ctrlpts(n_ctrlptsw, p_size_u, p_size_v)
53surf.knotvector_u = n_knotvector_u
54surf.knotvector_v = n_knotvector_v
55
56# Set evaluation delta
57surf.delta = 0.05
58
59# Set visualization component
60vis_comp = VisMPL.VisSurface()
61surf.vis = vis_comp
62
63# Render the surface
64surf.render()

Please see Compatibility Module Documentation for more details on manipulating and exporting control points.

NURBS-Python has some other options for exporting and importing data. Please see File Formats page for details.