gnp package

Subpackages

Submodules

gnp.estimator module

class gnp.estimator.GeometryEstimator(pcd: Tensor, orientation: Tensor, function_values: Tensor | None = None, model_name: str = 'clean_30k', batch_size: int = 8192, device: str = 'cpu', **data_kwargs: dict | None)[source]

Bases: object

Class used for geometry estimation using the pre-trained PatchGNP.

Parameters:
  • pcd (torch.Tensor) -- Point cloud data (N, 3).

  • orientation (torch.Tensor) -- Normal vectors for each point (N, 3).

  • function_values (torch.Tensor, optional) -- Function values defined on the point cloud, by default None.

  • model_name (str) -- Name of the pre-trained model to use, by default "clean_30k". Options: "clean_30k", "clean_50k", "noise_70k", "outlier_50k".

  • batch_size (int, optional) -- Batch size for processing patches, by default 8192.

  • device (str, optional) -- Device to run the model on, by default "cpu".

  • **data_kwargs -- Additional keyword arguments for data configuration. These will override the default data configurations.

estimate_quantities(quantity_names: list[str]) dict[str, Tensor][source]

Estimate geometric quantities on the point cloud. This function returns a dictionary containing the estimated scalar and/or vector values.

Parameters:

quantity_names (list[str]) -- List of quantity names to estimate. Available quantities include: 'xyz_coordinates', 'normals', 'tangents', 'mean_curvature', 'gaussian_curvature', 'pca_coordinates', 'normals_pca', 'tangents_pca', 'metric', 'shape', 'weingarten', 'inverse_metric', 'inverse_metric_derivatives', 'det_metric', 'laplace_beltrami_from_coefficients'.

Returns:

A dictionary where keys are the quantity names and values are the estimated tensors.

Return type:

dict[str, torch.Tensor]

flow_step(delta_t: float, subsample_radius: float, smooth_radius: float, smooth_x: bool) dict[source]

Perform a single step of mean curvature flow on the point cloud.

Parameters:
  • delta_t (float) -- Time step for the flow.

  • subsample_radius (float) -- Radius used for subsampling points after the flow step.

  • smooth_radius (float) -- Radius used for smoothing the mean curvature before the flow step.

  • smooth_x (bool) -- Whether to smooth the point cloud coordinates before the flow step.

Returns:

A dictionary containing the updated point cloud data ('x'), normals, and mean curvature.

Return type:

dict

gmls_weights(patch_data: PatchData, mask: Tensor, radius: float = 1.0, p: int = 4) tuple[Tensor, Tensor][source]

Compute the weights for the generalized moving least squares (GMLS) method.

Parameters:
  • patch_data (PatchData) -- PatchData object containing coordinate data.

  • mask (torch.Tensor) -- A boolean mask indicating which points in the patch data to use.

  • radius (float, optional) -- Radius to truncate the weight function, by default 1.0.

  • p (int, optional) -- The exponent for the weight function, by default 4.

Returns:

A tuple containing: - The weight matrices for each patch (batch_size, 1, num_points). - The dense mask used to create the dense batch.

Return type:

tuple[torch.Tensor, torch.Tensor]

laplace_beltrami_legendre_blocks(surface: Surface) Tensor[source]

Compute the Laplace-Beltrami operator of Legendre basis functions.

Parameters:

surface (Surface) -- Surface object containing patch information and basis functions.

Returns:

A tensor containing the Laplace-Beltrami operator applied

Return type:

torch.Tensor

legendre_blocks(surface: Surface, mask: Tensor) Tensor[source]

Evaluate Legendre basis functions for each point in the patches.

This method evaluates the Legendre basis functions at the local uv coordinates of the points specified by the mask and returns them as a dense tensor, batched by patch.

Parameters:
  • surface (Surface) -- Surface object containing patch data and basis functions.

  • mask (torch.Tensor) -- A boolean mask to select which points' local coordinates to use for the evaluation.

Returns:

A dense tensor of Legendre basis function evaluations, with shape (num_patches, max_points_in_patch, num_basis_functions).

Return type:

torch.Tensor

mean_flow(num_steps: int, save_data_per_step: int, delta_t: float, subsample_radius: float, smooth_radius: float, smooth_x: bool) list[dict][source]

Perform mean curvature flow on the point cloud over multiple steps.

This method iteratively applies the mean curvature flow step and saves the state of the point cloud at specified intervals.

Parameters:
  • num_steps (int) -- The total number of flow steps to perform.

  • save_data_per_step (int) -- The interval at which to save the point cloud data. For example, a value of 5 means data is saved every 5 steps.

  • delta_t (float) -- Time step for each flow step.

  • subsample_radius (float) -- Radius used for subsampling points after each flow step.

  • smooth_radius (float) -- Radius used for smoothing the mean curvature before each flow step.

  • smooth_x (bool) -- Whether to smooth the point cloud coordinates before each flow step.

Returns:

A list of dictionaries. Each dictionary contains the point cloud data ('x'), 'normals', and 'mean_curvature' at a saved step.

Return type:

list[dict]

patch_data(**datakwargs) PatchData[source]

Create a PatchData object from the point cloud data.

This method configures and generates patches from the input point cloud data, which can then be used by the model for predictions.

Parameters:

**datakwargs -- Keyword arguments to override data configuration settings.

Returns:

A PatchData object containing the point cloud data structured into patches.

Return type:

PatchData

stiffness_matrix_gmls(drop_ratio: float = 0.1, radius: float = 1.0, p: int = 4, remove_outliers: bool = False, outlier_threshold: float = 0.2) tuple[csr_array, Tensor, Tensor][source]

Compute the stiffness matrix using the generalized moving least squares (GMLS) method.

Parameters:
  • drop_ratio (float, optional) -- Ratio of points to drop. Defaults to 0.1.

  • radius (float, optional) -- Radius to truncate weight function. Defaults to 1..

  • p (int, optional) -- Degree p of the weight function. Defaults to 4.

  • remove_outliers (bool, optional) -- Whether to remove outliers. Defaults to False.

  • outlier_threshold (float, optional) -- The threshold used to determine which points are labeled as outliers. Only used if remove_outliers is True.

Returns:

  • sp.csr_array -- Stiffness matrix for solving the Laplace-Beltrami PDE

  • torch.Tensor -- Mask for which values to solve collocation problem on.

  • torch.Tensor -- Mask for points that are removed in smoothing. If remove_outliers is False then the mask will be all true.

surface_patch(patch_data: PatchData | None = None) Surface[source]

Create a Surface from the input patch data using the predictions from the model.

Parameters:

patch_data (PatchData, optional) -- Batch containing the input patch data. If patch_data is None defaults to self.patch_data()

Returns:

Surface object.

Return type:

Surface

gnp.utils module

class gnp.utils.QueryTorchGeometric(x: Tensor, device='cpu')[source]

Bases: object

A wrapper for performing k-nearest neighbor and radius queries on a point cloud using PyTorch Geometric.

Parameters:
  • x (torch.Tensor) -- The point cloud data to be queried, of shape (N, D).

  • device (str, optional) -- The device to store the point cloud on, by default "cpu".

query_knn(queries: Tensor, k: int) Tuple[Tensor, Tensor][source]

Find the k-nearest neighbors for a set of query points.

Parameters:
  • queries (torch.Tensor) -- The query points, of shape (M, D).

  • k (int) -- The number of nearest neighbors to find.

Returns:

A tuple containing: - The distances to the k-nearest neighbors, shape (M, k). - The indices of the k-nearest neighbors, shape (M, k).

Return type:

Tuple[torch.Tensor, torch.Tensor]

static query_radius(x: Tensor, y: Tensor, radius: float, max_num_neighbors: int = 100) Tuple[Tensor, Tensor][source]

Find all points in x within a given radius of points in y.

This method finds all pairs (i, j) such that the distance between x[i] and y[j] is less than the radius.

Parameters:
  • x (torch.Tensor) -- The point cloud to search within (the "haystack").

  • y (torch.Tensor) -- The query points (the "needles").

  • radius (float) -- The search radius.

  • max_num_neighbors (int, optional) -- The maximum number of neighbors to return for each query point, by default 100.

Returns:

A tuple containing: - index_x: Indices of the found points in x. - index_y: Indices of the corresponding query points in y.

Return type:

Tuple[torch.Tensor, torch.Tensor]

gnp.utils.smooth_values_by_gaussian(x: Tensor, values: Tensor, radius: float) Tensor[source]

Smooth values on a point cloud using a truncated Gaussian kernel.

For each point, this function computes a weighted average of the values of its neighbors within a given radius. The weights are determined by a Gaussian function of the distance.

Parameters:
  • x (torch.Tensor) -- The input data points, shape (N, D).

  • values (torch.Tensor) -- The values associated with each point to be smoothed, shape (N,).

  • radius (float) -- The truncation radius for the Gaussian kernel. The standard deviation of the Gaussian is set to one-third of this radius.

Returns:

A tensor of shape (N,) containing the smoothed values.

Return type:

torch.Tensor

gnp.utils.subsample_points_by_radius(x: Tensor, radius: float) Tensor[source]

Subsample points using a parallel maximal independent set approach.

Parameters:
  • x (torch.Tensor) -- The input points to subsample, shape (N, D).

  • radius (float) -- The radius for defining neighborhoods.

Returns:

A tensor containing the indices of the subsampled points.

Return type:

torch.Tensor

gnp.config module

gnp.config.load_config(path: Path) dict[source]

Load a configuration file from a yaml file.

Parameters:

path (str) -- Path to the yaml file.

Returns:

Dictionary containing the configuration parameters.

Return type:

dict

gnp.config.load_model(config: dict, model_path: Path, device: str) PatchGNP[source]

Load a model from a directory.

Parameters:

model_dir (Path) -- Path to the model directory.

Returns:

The loaded model.

Return type:

PatchGNP

Module contents