Spline Surface#
- class SplineSurface(orders, knots_u=None, knots_v=None, control_points=None)[source]#
Bases:
ModuleThe bivariate B-Spline surface model class.
A bivariate B-spline surface is a parametric surface defined as the tensor product of two univariate B-spline curves:
\[S(x, y) = \sum_{i=1}^{n_x} \sum_{j=1}^{n_y} B_{i,k}(x) B_{j,s}(y) C_{i,j}, \quad x \in [x_1, x_m], y \in [y_1, y_l]\]where:
\(C \in \mathbb{R}^{n_x \times n_y}\) is the matrix of learnable control coefficients. Its entries \(C_{i,j}\) influence the shape of the surface but are not generally interpolated, except under certain knot multiplicities.
\(B_{i,k}(x)\) and \(B_{j,s}(y)\) are the B-spline basis functions defined over two orthogonal directions, with orders \(k\) and \(s\), respectively.
\(X = \{ x_1, x_2, \dots, x_m \}\) and \(Y = \{ y_1, y_2, \dots, y_l \}\) are the non-decreasing knot vectors along the two directions.
Initialization of the
SplineSurfaceclass.- Parameters:
orders (list[int]) – The orders of the spline along each parametric direction. Each order defines the degree of the corresponding basis as
degree = order - 1.knots_u (torch.Tensor | dict) – The knots of the spline along the first direction. For details on valid formats and initialization modes, see the
Splineclass. Default is None.knots_v (torch.Tensor | dict) – The knots of the spline along the second direction. For details on valid formats and initialization modes, see the
Splineclass. Default is None.control_points (torch.Tensor) – The control points defining the surface geometry. It must be a two-dimensional tensor of shape
[len(knots_u) - orders[0], len(knots_v) - orders[1]]. If None, they are initialized as learnable parameters with zero values. Default is None.
- Raises:
ValueError – If
ordersis not a list of integers.ValueError – If
knots_uis neither a torch.Tensor nor a dictionary, when provided.ValueError – If
knots_vis neither a torch.Tensor nor a dictionary, when provided.ValueError – If
control_pointsis not a torch.Tensor, when provided.ValueError – If
ordersis not a list of two elements.ValueError – If
knots_u,knots_v, andcontrol_pointsare all None.
- forward(x)[source]#
Forward pass for the
SplineSurfacemodel.- Parameters:
x (torch.Tensor | LabelTensor) – The input tensor.
- Returns:
The output tensor.
- Return type:
- derivative(x, degree_u, degree_v)[source]#
Compute the partial derivatives of the spline at the given points.
- Parameters:
x (torch.Tensor | LabelTensor) – The input tensor.
degree_u (int) – The degree of the derivative along the first parameter direction.
degree_v (int) – The degree of the derivative along the second parameter direction.
- Raises:
ValueError – If
degree_uis not an integer.ValueError – If
degree_vis not an integer.
- Returns:
The derivative tensor.
- Return type:
- gradient(x)[source]#
Convenience method to compute the gradient of the spline surface.
- Parameters:
x (torch.Tensor | LabelTensor) – The input tensor.
- Returns:
The gradient tensor.
- Return type:
- laplacian(x)[source]#
Convenience method to compute the laplacian of the spline surface.
- Parameters:
x (torch.Tensor | LabelTensor) – The input tensor.
- Returns:
The laplacian tensor.
- Return type:
- property knots#
The knots of the univariate splines defining the spline surface.
- Returns:
The knots.
- Return type:
- property control_points#
The control points of the spline.
- Returns:
The control points.
- Return type: