gnp.geometry module

gnp.geometry.surface

class gnp.geometry.surface.Surface(patch_data: PatchData, basis_coefficients: Tensor, use_original: bool = False)[source]

Bases: object

Surface for computing geometric quantities from basis coefficients used at evaluation time.

Parameters:
  • patch_data (Batch) -- Patch data in local coordinates from PatchTensor.

  • basis_coefficients (torch.Tensor) -- Basis coefficients representing the surface (e.g., Legendre coefficients).

property batch

Batch identifier for which cluster which points belong to.

Returns:

Batch indices.

Return type:

torch.Tensor

property det_metric: Tensor[source]

Compute the determinant of the metric tensor of the surface patches

Returns:

determinant of the metric tensor of the surface patches

Return type:

torch.Tensor

property gaussian_curvature: Tensor[source]

Compute the Gaussian curvature tensor of the surface patches

Returns:

Gaussian curvature tensor of the surface patches

Return type:

torch.Tensor

property inverse_metric: Tensor[source]

Compute the inverse metric tensor of the surface patches

Returns:

inverse metric tensor of the surface patches

Return type:

torch.Tensor

property inverse_metric_derivatives: Tensor[source]

Compute the derivatives of the inverse metric tensor of the surface patches

Returns:

derivatives of the inverse metric tensor of the surface patches

Return type:

torch.Tensor

property laplace_beltrami_basis_terms: Tensor[source]

Compute the Laplace-Beltrami operator on each of the basis functions.

Returns:

(n, 16) tensor containing the Laplace-Beltrami operator applied to the basis functions.

Return type:

torch.Tensor

property laplace_beltrami_first_terms: Tensor[source]

Compute the first terms of the Laplace-Beltrami operator. These terms are multiplied to the second derivatives of the function.

Returns:

The first terms of the laplace-beltrami operator.

Return type:

torch.Tensor

laplace_beltrami_from_coefficients(function_coefficients: Tensor) Tensor[source]

Compute the Laplace-Beltrami operator from the surface coefficients and the function coefficients.

Parameters:

function_coefficients (torch.Tensor) -- Basis coefficients representing the function.

Returns:

Laplace-Beltrami operator applied to the function.

Return type:

torch.Tensor

property laplace_beltrami_second_terms: Tensor[source]

Compute the second terms of the Laplace-Beltrami operator. These terms are multiplied to the first derivatives of the function.

Returns:

The second terms of the laplace-beltrami operator.

Return type:

torch.Tensor

property local_coordinate_basis: Tensor

Return the local PCA basis coordinates at each point

Returns:

local coordinates of the surface patches

Return type:

torch.Tensor

property local_coordinates[source]

Returns the local coordinates of the patch data.

Returns:

local coordinates of the patch data.

Return type:

torch.Tensor

property mean_curvature: Tensor[source]

Compute the mean curvature tensor of the surface patches

Returns:

mean curvature tensor of the surface patches

Return type:

torch.Tensor

property metric: Tensor[source]

Compute the metric tensor of the surface patches

Returns:

metric tensor of the surface patches

Return type:

torch.Tensor

property normals: Tensor[source]

Compute the normals of the surface patches in global coordinates

Returns:

normals of the surface patches

Return type:

torch.Tensor

property normals_pca: Tensor[source]

Compute the normals of the surface patches in local coordinates

Returns:

normals of the surface patches

Return type:

torch.Tensor

property pca_coordinates: Tensor[source]

Compute the PCA coordinates of the surface patches

Returns:

PCA coordinates of the surface patches

Return type:

torch.Tensor

property shape: Tensor[source]

Compute the shape tensor of the surface patches

Returns:

shape tensor of the surface patches

Return type:

torch.Tensor

property tangents: Tensor[source]

Compute the tangents of the surface patches in global coordinates

Returns:

tangents of the surface patches

Return type:

torch.Tensor

property tangents_pca: Tensor[source]

Compute the tangents of the surface patches in local coordinates

Returns:

tangents of the surface patches

Return type:

torch.Tensor

property weingarten: Tensor[source]

Compute the Weingarten tensor of the surface patches

Returns:

Weingarten tensor of the surface patches

Return type:

torch.Tensor

property xyz_coordinates: Tensor[source]

Compute the xyz coordinates of the surface patches

Returns:

xyz coordinates of the surface patches

Return type:

torch.Tensor

gnp.geometry.legendre

class gnp.geometry.legendre.Legendre1D(degree: int = 3)[source]

Bases: object

Computes 1D Legendre polynomials and their derivatives.

This class pre-computes the coefficients of Legendre polynomials up to a specified degree and provides methods to evaluate the polynomials and their derivatives on batches of input data.

Parameters:

degree (int) -- The maximum degree of the Legendre polynomials, by default 3.

derivative(x: Tensor, order: int) Tensor[source]

Compute the n-th order derivative of the Legendre polynomials.

Parameters:
  • x (torch.Tensor) -- Input tensor of any shape.

  • order (int) -- The order of the derivative to compute.

Returns:

A tensor of shape (*x.shape, degree + 1) containing the evaluated derivatives.

Return type:

torch.Tensor

evaluate(x: Tensor) Tensor[source]

Evaluate Legendre polynomials P_0(x), ..., P_degree(x).

Parameters:

x (torch.Tensor) -- Input tensor of any shape.

Returns:

A tensor of shape (*x.shape, degree + 1) containing the evaluated polynomials for each input value.

Return type:

torch.Tensor

gradient(x: Tensor) Tensor[source]

Compute the first derivative of the Legendre polynomials.

Parameters:

x (torch.Tensor) -- Input tensor of any shape.

Returns:

A tensor containing the first derivatives.

Return type:

torch.Tensor

hessian(x: Tensor) Tensor[source]

Compute the second derivative of the Legendre polynomials.

Parameters:

x (torch.Tensor) -- Input tensor of any shape.

Returns:

A tensor containing the second derivatives.

Return type:

torch.Tensor

class gnp.geometry.legendre.Legendre2D(degree: int)[source]

Bases: object

Computes a 2D Legendre basis from the tensor product of 1D polynomials.

This class constructs a basis of 2D functions L_{i,j}(u,v) = P_i(u) * P_j(v) and provides methods to evaluate the basis functions and their derivatives.

Parameters:

degree (int) -- The maximum degree for the 1D Legendre polynomials used to construct the 2D basis.

compute_from_coeffs(values: Tensor, coeffs: Tensor, batch: Tensor | None = None)[source]

Compute a linear combination of values and coefficients.

This is a helper to compute sum(coeffs * values).

Parameters:
  • values (torch.Tensor) -- The pre-evaluated values, e.g., basis functions or their derivatives. Shape (N, num_components).

  • coeffs (torch.Tensor) -- The coefficients. Shape (M, num_components) or (N, num_components).

  • batch (torch.Tensor, optional) -- Mapping from N points to M coefficient sets. Defaults to None.

Returns:

The result of the linear combination, shape (N, 1).

Return type:

torch.Tensor

property degree_indices

Get the pairs of degrees (i, j) for each 2D basis function.

Returns:

A tensor of shape (2, num_components) where each column is a pair of degrees [i, j].

Return type:

torch.Tensor

derivatives_from_coeffs(xy_data: Tensor, coeffs: Tensor, batch: Tensor | None = None) Tensor[source]

Compute derivatives of a function defined by coefficients.

The function is f(u,v) = sum(coeffs * L_{i,j}(u,v)). This method computes df/du, df/dv, d2f/dudv, d2f/du2, and d2f/dv2.

Parameters:
  • xy_data (torch.Tensor) -- Input (u,v) coordinates of shape (N, 2).

  • coeffs (torch.Tensor) -- Coefficients for the Legendre basis.

  • batch (torch.Tensor, optional) -- Mapping from points to coefficient sets. Defaults to None.

Returns:

A tensor of shape (N, 5) containing the five derivative values for each point.

Return type:

torch.Tensor

evaluate(x: Tensor) Tensor[source]

Evaluate all 2D basis functions L_{i,j}(u,v) at given (u,v) coordinates.

Parameters:

x (torch.Tensor) -- Input tensor of shape (..., 2) containing (u,v) coordinates.

Returns:

A tensor of shape (..., num_components) containing the evaluated 2D basis functions.

Return type:

torch.Tensor

evaluate_derivatives(xy_data: Tensor) tuple[Tensor, Tensor, Tensor, Tensor, Tensor][source]

Evaluate all first and second order partial derivatives of the basis.

Parameters:

xy_data (torch.Tensor) -- Input (u,v) coordinates of shape (..., 2).

Returns:

A tuple of tensors: (dx, dy, dxdy, dxdx, dydy), each containing the evaluations of the corresponding partial derivative for every basis function.

Return type:

tuple[torch.Tensor, torch.Tensor, torch.Tensor, torch.Tensor, torch.Tensor]

evaluate_from_coeffs(xy_data: Tensor, coeffs: Tensor, batch: Tensor | None = None) Tensor[source]

Evaluate a function defined by coefficients on the Legendre basis.

The function is f(u,v) = sum(coeffs * L_{i,j}(u,v)).

Parameters:
  • xy_data (torch.Tensor) -- Input tensor of shape (N, 2) with (u,v) coordinates.

  • coeffs (torch.Tensor) -- Coefficients for the Legendre basis. Can be shape (M, num_components) if using batch, or (N, num_components) otherwise.

  • batch (torch.Tensor, optional) -- A tensor of shape (N,) mapping each point in xy_data to a set of coefficients. If None, coeffs must be shape (N, num_components). Defaults to None.

Returns:

A tensor of shape (N, 1) with the evaluated function values.

Return type:

torch.Tensor

gradient(x: Tensor) Tensor[source]

Compute the gradient of each 2D basis function.

Parameters:

x (torch.Tensor) -- Input tensor of shape (..., 2) containing (u,v) coordinates.

Returns:

A tensor of shape (..., 2, num_components) where the second-to-last dimension corresponds to the partial derivatives [dL/du, dL/dv].

Return type:

torch.Tensor

hessian(x: Tensor) Tensor[source]

Compute the Hessian matrix for each 2D basis function.

Parameters:

x (torch.Tensor) -- Input tensor of shape (..., 2) containing (u,v) coordinates.

Returns:

A tensor of shape (..., 2, 2, num_components) representing the Hessian matrix [[d2L/du2, d2L/dudv], [d2L/dvdu, d2L/dv2]] for each basis function.

Return type:

torch.Tensor

property num_components

The total number of basis functions in the 2D basis.

Module contents