Compatibility and Conversion

This module contains conversion operations related to control points, such as flipping arrays and adding weights.

Function Reference

geomdl.compatibility.combine_ctrlpts_weights(ctrlpts, weights=None)

Multiplies control points by the weights to generate weighted control points.

This function is dimension agnostic, i.e. control points can be in any dimension but weights should be 1D.

The weights function parameter can be set to None to let the function generate a weights vector composed of 1.0 values. This feature can be used to convert B-Spline basis to NURBS basis.

Parameters:
  • ctrlpts (list, tuple) – unweighted control points
  • weights (list, tuple or None) – weights vector; if set to None, a weights vector of 1.0s will be automatically generated
Returns:

weighted control points

Return type:

list

geomdl.compatibility.flip_ctrlpts(ctrlpts, size_u, size_v)

Flips a list of 1-dimensional control points from v-row order to u-row order.

u-row order: each row corresponds to a list of u values

v-row order: each row corresponds to a list of v values

Parameters:
  • ctrlpts (list, tuple) – control points in v-row order
  • size_u (int) – size in u-direction (row length)
  • size_v (int) – size in v-direction (column length)
Returns:

control points in u-row order

Return type:

list

geomdl.compatibility.flip_ctrlpts2d(ctrlpts2d, size_u=0, size_v=0)

Flips a list of surface 2-D control points from [u][v] to [v][u] order.

Parameters:
  • ctrlpts2d (list, tuple) – 2-D control points
  • size_u (int) – size in U-direction (row length)
  • size_v (int) – size in V-direction (column length)
Returns:

flipped 2-D control points

Return type:

list

geomdl.compatibility.flip_ctrlpts2d_file(file_in='', file_out='ctrlpts_flip.txt')

Flips u and v directions of a 2D control points file and saves flipped coordinates to a file.

Parameters:
  • file_in (str) – name of the input file (to be read)
  • file_out (str) – name of the output file (to be saved)
Raises:

IOError – an error occurred reading or writing the file

geomdl.compatibility.flip_ctrlpts_u(ctrlpts, size_u, size_v)

Flips a list of 1-dimensional control points from u-row order to v-row order.

u-row order: each row corresponds to a list of u values

v-row order: each row corresponds to a list of v values

Parameters:
  • ctrlpts (list, tuple) – control points in u-row order
  • size_u (int) – size in u-direction
  • size_v (int) – size in v-direction
Returns:

control points in v-row order

Return type:

list

geomdl.compatibility.generate_ctrlpts2d_weights(ctrlpts2d)

Generates unweighted control points from weighted ones in 2-D.

This function

  1. Takes in 2-D control points list whose coordinates are organized like (x*w, y*w, z*w, w)
  2. Converts the input control points list into (x, y, z, w) format
  3. Returns the result
Parameters:ctrlpts2d (list) – 2-D control points (P)
Returns:2-D weighted control points (Pw)
Return type:list
geomdl.compatibility.generate_ctrlpts2d_weights_file(file_in='', file_out='ctrlpts_weights.txt')

Generates unweighted control points from weighted ones in 2-D.

  1. Takes in 2-D control points list whose coordinates are organized like (x*w, y*w, z*w, w)
  2. Converts the input control points list into (x, y, z, w) format
  3. Saves the result to a file
Parameters:
  • file_in (str) – name of the input file (to be read)
  • file_out (str) – name of the output file (to be saved)
Raises:

IOError – an error occurred reading or writing the file

geomdl.compatibility.generate_ctrlpts_weights(ctrlpts)

Generates unweighted control points from weighted ones in 1-D.

This function

  1. Takes in 1-D control points list whose coordinates are organized in (x*w, y*w, z*w, w) format
  2. Converts the input control points list into (x, y, z, w) format
  3. Returns the result
Parameters:ctrlpts (list) – 1-D control points (P)
Returns:1-D weighted control points (Pw)
Return type:list
geomdl.compatibility.generate_ctrlptsw(ctrlpts)

Generates weighted control points from unweighted ones in 1-D.

This function

  1. Takes in a 1-D control points list whose coordinates are organized in (x, y, z, w) format
  2. converts into (x*w, y*w, z*w, w) format
  3. Returns the result
Parameters:ctrlpts (list) – 1-D control points (P)
Returns:1-D weighted control points (Pw)
Return type:list
geomdl.compatibility.generate_ctrlptsw2d(ctrlpts2d)

Generates weighted control points from unweighted ones in 2-D.

This function

  1. Takes in a 2D control points list whose coordinates are organized in (x, y, z, w) format
  2. converts into (x*w, y*w, z*w, w) format
  3. Returns the result

Therefore, the returned list could be a direct input of the NURBS.Surface class.

Parameters:ctrlpts2d (list) – 2-D control points (P)
Returns:2-D weighted control points (Pw)
Return type:list
geomdl.compatibility.generate_ctrlptsw2d_file(file_in='', file_out='ctrlptsw.txt')

Generates weighted control points from unweighted ones in 2-D.

This function

  1. Takes in a 2-D control points file whose coordinates are organized in (x, y, z, w) format
  2. Converts into (x*w, y*w, z*w, w) format
  3. Saves the result to a file

Therefore, the resultant file could be a direct input of the NURBS.Surface class.

Parameters:
  • file_in (str) – name of the input file (to be read)
  • file_out (str) – name of the output file (to be saved)
Raises:

IOError – an error occurred reading or writing the file

geomdl.compatibility.separate_ctrlpts_weights(ctrlptsw)

Divides weighted control points by weights to generate unweighted control points and weights vector.

This function is dimension agnostic, i.e. control points can be in any dimension but the last element of the array should indicate the weight.

Parameters:ctrlptsw (list, tuple) – weighted control points
Returns:unweighted control points and weights vector
Return type:list