geomfum.dataset package#
Submodules#
geomfum.dataset.notebook module#
Datasets for notebooks/docs.
- class geomfum.dataset.notebook.DownloadableFile(name, url)[source]#
Bases:
object(Down)loadable file.
- Parameters:
name (str) – File name (without directory).
url (str) – Url for file download.
- class geomfum.dataset.notebook.NotebooksDataset(data_dir=None, load_at_startup=False)[source]#
Bases:
objectDataset to use within notebooks.
- Parameters:
data_dir (str) – Directory where to store/access data.
load_at_startup (bool) – Whether to (down)load files at startup.
geomfum.dataset.torch module#
Datasets for Loading Meshes and Point Clouds using PyTorch.
- class geomfum.dataset.torch.Dataset[source]#
Bases:
Generic[_T_co]An abstract class representing a
Dataset.All datasets that represent a map from keys to data samples should subclass it. All subclasses should overwrite
__getitem__(), supporting fetching a data sample for a given key. Subclasses could also optionally overwrite__len__(), which is expected to return the size of the dataset by manySamplerimplementations and the default options ofDataLoader. Subclasses could also optionally implement__getitems__(), for speedup batched samples loading. This method accepts list of indices of samples of batch and returns list of samples.Note
DataLoaderby default constructs an index sampler that yields integral indices. To make it work with a map-style dataset with non-integral indices/keys, a custom sampler must be provided.
- class geomfum.dataset.torch.MeshDataset(dataset_dir, spectral=False, distances=False, correspondences=True, k=200, device=None)[source]#
Bases:
ShapeDatasetShapeDataset for loading and preprocessing mesh data.
- class geomfum.dataset.torch.PairsDataset(dataset=None, pair_mode='all', pairs_ratio=100, device=None)[source]#
Bases:
DatasetDataset of pairs of shapes. Each item is a pair (source, target) of shapes from the provided dataset.
- Parameters:
dataset (torch.utils.data.Dataset or list) – Preloaded dataset or list of shape data objects.
pair_mode (str, optional) – Strategy to generate pairs. Options: ‘all’, ‘random’. Default is ‘all’.
n_pairs (int, optional) – Number of random pairs to generate if pair_mode is ‘random’. Default is 100.
device (torch.device, optional) – Device to move the data to. If None, uses CUDA if available, else CPU.
- class geomfum.dataset.torch.PointCloud(vertices)[source]#
Bases:
ShapeUnstructured point cloud with k-NN connectivity and differential operators.
- Parameters:
vertices (array-like, shape=[n_vertices, 3]) – Vertices of the point cloud.
- property dist_matrix#
Pairwise distances between all points using the equipped metric.
- Returns:
_dist_matrix (array-like, shape=[n_vertices, n_vertices]) – Metric distance matrix.
- property edge_tangent_vectors#
Edge vectors projected onto local tangent planes.
- Returns:
edge_tangent_vectors (array-like, shape=[n_edges, 2]) – Tangent vectors of the edges, projected onto the local tangent plane.
- property edges#
Edge connectivity from k-NN graph.
- equip_with_metric(metric)[source]#
Equip point cloud with a distance metric.
- Parameters:
metric (class) – A metric class to use for the point cloud.
- classmethod from_file(filename)[source]#
Load point cloud from file.
- Returns:
mesh (PointCloud) – A point cloud.
- property knn_graph#
K-nearest neighbors connectivity graph.
- Returns:
knn_info (dict) – Dictionary containing: - ‘indices’: array-like, shape=[n_vertices, k] - neighbor indices for each vertex - ‘distances’: array-like, shape=[n_vertices, k] - distances to neighbors - ‘k’: int - number of neighbors - ‘nbrs_model’: sklearn.neighbors.NearestNeighbors - fitted model for reuse
- property n_vertices#
Number of points.
- Returns:
n_vertices (int)
- property vertex_normals#
Normal vectors estimated from local neighborhoods using PCA.
- Returns:
normals (array-like, shape=[n_vertices, 3]) – Normalized per-vertex normals estimated from local neighborhoods using PCA.
- property vertex_tangent_frames#
Local orthonormal coordinate frames at each point.
- Returns:
tangent_frame (array-like, shape=[n_vertices, 3, 3]) – Tangent frame of the mesh, where: - [n_vertices, 0, :] are the X basis vectors - [n_vertices, 1, :] are the Y basis vectors - [n_vertices, 2, :] are the vertex normals
- class geomfum.dataset.torch.PointCloudDataset(dataset_dir, spectral=False, distances=False, correspondences=True, k=200, device=None)[source]#
Bases:
ShapeDatasetShapeDataset for loading and preprocessing point cloud data.
- class geomfum.dataset.torch.ScipyGraphShortestPathMetric(shape, cutoff=None)[source]#
Bases:
_ScipyShortestPathMixins,FinitePointSetMetricGeodesic distance approximation using SciPy’s shortest path algorithm.
- Parameters:
shape (Shape) – Shape.
cutoff (float) – Length (sum of edge weights) at which the search is stopped.
- class geomfum.dataset.torch.ShapeDataset(dataset_dir, shape_type='mesh', spectral=False, distances=False, correspondences=True, k=200, device=None)[source]#
Bases:
DatasetGeneral dataset for loading and preprocessing meshes or point clouds.
- Parameters:
dataset_dir (str) – Path to the directory containing the dataset. We assume the dataset directory to have a subfolder shapes, for shapes, corr, for correspondences and dist, for cached distance matrices.
shape_type (str) – Type of shape to load. Either ‘mesh’ or ‘pointcloud’.
spectral (bool) – Whether to compute the spectral features.
distances (bool) – Whether to compute geodesic distance matrices. For computational reasons, these are not computed on the fly, but rather loaded from a precomputed .mat file.
correspondences (bool) – Whether to load correspondences.
k (int) – Number of eigenvectors to use for the spectral features.
device (torch.device, optional) – Device to move the data to.
- class geomfum.dataset.torch.TriangleMesh(vertices, faces)[source]#
Bases:
ShapeTriangulated surface mesh with vertices, faces, and differential operators.
- Parameters:
vertices (array-like, shape=[n_vertices, 3]) – Vertices of the mesh.
faces (array-like, shape=[n_faces, 3]) – Faces of the mesh.
- property dist_matrix#
Pairwise distances between all vertices using the equipped metric.
- Returns:
_dist_matrix (array-like, shape=[n_vertices, n_vertices]) – Metric distance matrix.
- property edge_tangent_vectors#
Edge vectors projected onto local tangent planes.
- Returns:
edge_tangent_vectors (array-like, shape=[n_edges, 2]) – Tangent vectors of the edges, projected onto the local tangent plane.
- property edges#
Edges of the mesh.
- Returns:
edges (array-like, shape=[n_edges, 2])
- equip_with_metric(metric)[source]#
Equip mesh with a distance metric.
- Parameters:
metric (class) – A metric class to use for the mesh.
- property face_area_vectors#
Face area vectors (unnormalized normals with magnitude equal to face area).
- Returns:
area_vectors (array-like, shape=[n_faces, 3]) – Per-face area vectors.
- property face_areas#
Area of each triangular face.
- Returns:
face_areas (array-like, shape=[n_faces]) – Per-face areas.
- property face_normals#
Unit normal vectors for each face.
- Returns:
normals (array-like, shape=[n_faces, 3]) – Per-face normals.
- property face_vertex_coords#
Extract vertex coordinates corresponding to each face.
- Returns:
vertices (array-like, shape=[{n_faces}, n_per_face_vertex, 3]) – Coordinates of the ith vertex of that face.
- classmethod from_file(filename)[source]#
Load mesh from file.
- Parameters:
filename (str) – Path to the mesh file.
- Returns:
mesh (TriangleMesh) – A triangle mesh.
- property n_faces#
Number of faces.
- Returns:
n_faces (int)
- property n_vertices#
Number of vertices.
- Returns:
n_vertices (int)
- property vertex_areas#
Area associated with each vertex (one-third of adjacent triangle areas).
- Returns:
vertex_areas (array-like, shape=[n_vertices]) – Per-vertex areas.
- property vertex_normals#
Unit normal vectors at vertices (area-weighted average of adjacent face normals).
- Returns:
normals (array-like, shape=[n_vertices, 3]) – Normalized per-vertex normals.
- property vertex_tangent_frames#
Local orthonormal coordinate frames at each vertex.
- Returns:
tangent_frame (array-like, shape=[n_vertices, 3, 3]) – Tangent frame of the mesh, where: - [n_vertices, 0, :] are the X basis vectors - [n_vertices, 1, :] are the Y basis vectors - [n_vertices, 2, :] are the vertex normals
- class geomfum.dataset.torch.VertexEuclideanMetric(shape)[source]#
Bases:
FinitePointSetMetricEuclidean distance metric in ambient embedding space.
- dist(point_a, point_b)[source]#
Distances between shape vertices.
- Parameters:
point_a (array-like, shape=[…]) – Index of source point.
point_b (array-like, shape=[…]) – Index of target point.
- Returns:
dist (array-like, shape=[…]) – Distance.
- dist_from_source(source_point)[source]#
Distances from source point.
- Parameters:
source_point (array-like, shape=[…]) – Index of source point.
- Returns:
dist (array-like, shape=[…] or array-like[array-like]) – Distance.
target_point (array-like, shape=[n_targets] or array-like[array-like]) – Target index.
Module contents#
Datasets Module. This module contains dataset classes to use in Geomfum. Including utils for dataset management, downloading, and processing.
- class geomfum.dataset.NotebooksDataset(data_dir=None, load_at_startup=False)[source]#
Bases:
objectDataset to use within notebooks.
- Parameters:
data_dir (str) – Directory where to store/access data.
load_at_startup (bool) – Whether to (down)load files at startup.