geomfum.wrap package#
Submodules#
geomfum.wrap.diffusionnet module#
Implementation of the DiffusionNet feature extractor for 3D shapes.
References
..DiffusionNet: Discretization Agnostic Learning on Surfaces Nicholas Sharp, Souhaib Attaiki, Keenan Crane, Maks Ovsjanikov https://arxiv.org/abs/2012.00888 ..https://github.com/dongliangcao/Self-Supervised-Multimodal-Shape-Matching by Dongliang Cao ..https://github.com/nmwsharp/diffusion-net
- class geomfum.wrap.diffusionnet.BaseFeatureExtractor[source]#
Bases:
ABCAbstract base class for neural network feature extractors.
- class geomfum.wrap.diffusionnet.DiffusionNet(in_channels, out_channels, hidden_channels=128, n_block=4, last_activation=None, mlp_hidden_channels=None, output_at='vertices', dropout=True, with_gradient_features=True, with_gradient_rotations=True, diffusion_method='spectral', k_eig=128, cache_dir=None)[source]#
Bases:
ModuleDiffusionNet: stacked of DiffusionBlocks.
- Parameters:
in_channels (int) – Number of input channels.
out_channels (int) – Number of output channels.
hidden_channels (int) – Number of hidden channels in diffusion block. Default 128.
n_block (int) – Number of diffusion blocks. Default 4.
last_activation (nn.Module or None) – Output layer. Default None.
mlp_hidden_channels (List or None) – MLP hidden layers. Default None means [hidden_channels, hidden_channels].
output_at (str) – Produce outputs at various mesh elements by averaging from vertices. One of [‘vertices’, ‘edges’, ‘faces’, ‘global_mean’]. Default ‘vertices’.
dropout (bool) – Whether use dropout in mlp. Default True.
with_gradient_features (bool) – Whether use SpatialGradientFeatures in DiffusionBlock. Default True.
with_gradient_rotations (bool) – Whether use gradient rotations in SpatialGradientFeatures. Default True.
diffusion_method (str) – Diffusion method applied in diffusion layer. One of [‘spectral’, ‘implicit_dense’]. Default ‘spectral’.
k_eig (int) – Number of eigenvalues/eigenvectors to compute diffusion. Default 128.
cache_dir (str or None) – Cache dir contains all pre-computed spectral operators. Default None.
- forward(verts, faces=None, feats=None, frames=None, mass=None, L=None, evals=None, evecs=None, gradX=None, gradY=None)[source]#
Compute the forward pass of the DiffusionNet.
- Parameters:
verts (torch.Tensor) – Input vertices [B, V, 3].
faces (torch.Tensor, optional) – Input faces [B, F, 3]. Default None.
feats (torch.Tensor, optional) – Input features. Default None.
frames (torch.Tensor) – Tangent frames for vertices.
mass (torch.Tensor) – Diagonal elements in mass matrix.
L (torch.SparseTensor) – Sparse Laplacian matrix.
evals (torch.Tensor) – Eigenvalues of Laplacian Matrix.
evecs (torch.Tensor) – Eigenvectors of Laplacian Matrix.
gradX (torch.SparseTensor) – Real part of gradient matrix.
gradY (torch.SparseTensor) – Imaginary part of gradient matrix.
- Returns:
torch.Tensor – Output features.
- class geomfum.wrap.diffusionnet.DiffusionNetBlock(in_channels, mlp_hidden_channels, dropout=True, diffusion_method='spectral', with_gradient_features=True, with_gradient_rotations=True)[source]#
Bases:
ModuleBuilding Block of DiffusionNet.
- Parameters:
in_channels (int) – Number of input channels.
mlp_hidden_channels (List) – List of mlp hidden channels.
dropout (bool) – Whether use dropout in MLP. Default True.
diffusion_method (str) – Method for diffusion. Default “spectral”.
with_gradient_features (bool) – Whether use spatial gradient feature. Default True.
with_gradient_rotations (bool) – Whether use spatial gradient rotation. Default True.
- forward(feat_in, mass, L, evals, evecs, gradX, gradY)[source]#
Compute the forward pass of the diffusion block.
- Parameters:
feat_in (torch.Tensor) – Input feature vector [B, V, C].
mass (torch.Tensor) – Diagonal elements of mass matrix [B, V].
L (torch.SparseTensor) – Sparse Laplacian matrix [B, V, V].
evals (torch.Tensor) – Eigenvalues of Laplacian Matrix [B, K].
evecs (torch.Tensor) – Eigenvectors of Laplacian Matrix [B, V, K].
gradX (torch.SparseTensor) – Real part of gradient matrix [B, V, V].
gradY (torch.SparseTensor) – Imaginary part of gradient matrix [B, V, V].
- Returns:
torch.Tensor – Output feature vector.
- class geomfum.wrap.diffusionnet.DiffusionnetFeatureExtractor(in_channels=3, out_channels=128, hidden_channels=128, n_block=4, last_activation=None, mlp_hidden_channels=None, output_at='vertices', dropout=True, with_gradient_features=True, with_gradient_rotations=True, diffusion_method='spectral', k=128, cache_dir=None, device=device(type='cpu'), descriptor=None)[source]#
Bases:
BaseFeatureExtractor,ModuleFeature extractor that uses DiffusionNet for geometric deep learning on 3D mesh data.
- Parameters:
in_channels (int) – Number of input feature channels (e.g., 3 for xyz). Default is 3.
out_channels (int) – Number of output feature channels. Default is 128.
hidden_channels (int) – Number of hidden channels in the network. Default is 128.
n_block (int) – Number of DiffusionNet blocks. Default is 4.
last_activation (nn.Module or None) – Activation function applied to the output. Default is None.
mlp_hidden_channels (List[int] or None) – Hidden layer sizes in the MLP blocks. Default is None.
output_at (str) – Output type — one of [‘vertices’, ‘edges’, ‘faces’, ‘global_mean’]. Default is ‘vertices’.
dropout (bool) – Whether to apply dropout in MLP layers. Default is True.
with_gradient_features (bool) – Whether to compute and include spatial gradient features. Default is True.
with_gradient_rotations (bool) – Whether to use gradient rotations in spatial features. Default is True.
diffusion_method (str) – Diffusion method used — one of [‘spectral’, ‘implicit_dense’]. Default is ‘spectral’.
k (int) – Number of eigenvectors/eigenvalues used for spectral diffusion. Default is 128.
cache_dir (str or None) – Path to cache directory for storing/loading spectral operators. Default is None.
device (torch.device) – Device to run the model on. Default is CPU.
descriptor (Descriptor or None) – Optional descriptor to compute input features. If None, uses vertex coordinates.
- class geomfum.wrap.diffusionnet.LearnedTimeDiffusion(in_channels, method='spectral')[source]#
Bases:
ModuleApplied diffusion with learned time per-channel.
In the spectral domain this becomes f_out = e ^ (lambda_i * t) * f_in
- Parameters:
in_channels (int) – Number of input channels.
method (str) – Method to perform time diffusion. Default ‘spectral’.
- forward(feat, L, mass, evals, evecs)[source]#
Forward pass of the diffusion layer.
- Parameters:
feat (torch.Tensor) – Feature vector [B, V, C].
L (torch.SparseTensor) – Sparse Laplacian matrix [B, V, V].
mass (torch.Tensor) – Diagonal elements in mass matrix [B, V].
evals (torch.Tensor) – Eigenvalues of Laplacian matrix [B, K].
evecs (torch.Tensor) – Eigenvectors of Laplacian matrix [B, V, K].
- Returns:
feat_diffuse (torch.Tensor) – Diffused feature vector [B, V, C].
- class geomfum.wrap.diffusionnet.MiniMLP(layer_sizes, dropout=False, activation=<class 'torch.nn.modules.activation.ReLU'>, name='miniMLP')[source]#
Bases:
SequentialA simple MLP with configurable hidden layer sizes.
- Parameters:
layer_sizes (List) – List of layer size.
dropout (bool) – Whether use dropout. Default False.
activation (nn.Module) – Activation function. Default ReLU.
name (str) – Module name. Default ‘miniMLP’
- class geomfum.wrap.diffusionnet.SpatialGradientFeatures(in_channels, with_gradient_rotations=True)[source]#
Bases:
ModuleCompute dot-products between input vectors. Uses a learned complex-linear layer to keep dimension down.
- Parameters:
in_channels (int) – Number of input channels.
with_gradient_rotations (bool) – Whether with gradient rotations. Default True.
- class geomfum.wrap.diffusionnet.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
geomfum.wrap.igl module#
Igl wrapper.
- class geomfum.wrap.igl.IglMeshLaplacianFinder[source]#
Bases:
BaseLaplacianFinderAlgorithm to find the Laplacian of a mesh.
geomfum.wrap.plotly module#
Plotly plotting module.
- class geomfum.wrap.plotly.PlotlyMeshPlotter(colormap='viridis')[source]#
Bases:
PlotlyShapePlotterPlotting object to display meshes.
- class geomfum.wrap.plotly.PlotlyPointCloudPlotter(colormap='viridis')[source]#
Bases:
PlotlyShapePlotterPlotting object to display point clouds.
- class geomfum.wrap.plotly.PlotlyShapePlotter(colormap='viridis')[source]#
Bases:
ShapePlotterBase plotting object for 3D shapes using Plotly.
- add_vectors(origins, vectors, color='blue', scale=1.0, name='vectors')[source]#
Add vector field visualization.
- Parameters:
origins (array-like, shape=[n_points, 3]) – Starting points for vectors.
vectors (array-like, shape=[n_points, 3]) – Vector directions and magnitudes.
color (str) – Color of the vectors.
scale (float) – Scale factor for vector length.
name (str) – Name for the vector trace.
- highlight_vertices(coords, color='red', size=4)[source]#
Highlight vertices on shape.
- Parameters:
coords (array-like, shape=[n_vertices, 3]) – Coordinates of vertices to highlight.
color (str) – Color of the highlighted vertices.
size (int) – Size of the highlighted vertices.
- save(filename, **kwargs)[source]#
Save plot to file.
- Parameters:
filename (str) – Filename to save to.
**kwargs – Additional arguments passed to plotly’s write_html or write_image.
- class geomfum.wrap.plotly.ShapePlotter[source]#
Bases:
ABCPlotting object.
Primitive clas to plot meshes, pointclouds or specific useful informations (scalar functions, landmarks, etc..)
geomfum.wrap.pointnet module#
Wrap for PointNet feature extractor.
References
Qi, C. R., Su, H., Mo, K., & Guibas, L. J. (2017). PointNet: Deep learning on point sets for 3D classification and segmentation. In Proceedings of the IEEE conference on computer vision and pattern recognition (pp. 652-660). Qi, C. R., Su, H., Yi, L., & Guibas, L. J. (2017). PointNet++: Deep hierarchical feature learning on point sets in a metric space. In Advances in neural information processing systems (pp. 5098-5108). riccardomarin/Diff-FMaps by Riccardo Marin
- class geomfum.wrap.pointnet.BaseFeatureExtractor[source]#
Bases:
ABCAbstract base class for neural network feature extractors.
- class geomfum.wrap.pointnet.PointNet(in_channels=3, conv_channels=[64, 64, 128, 128, 1024], mlp_dims=[1024, 256, 256], head_channels=[512, 256, 256], out_features=128, dropout=0.3)[source]#
Bases:
ModuleFull PointNet model with feature head.
- Parameters:
conv_channels (list of int) – Output dimensions of initial PointNet convolution layers.
mlp_dims (list of int) – Hidden dimensions of global MLP applied to global features.
head_channels (list of int) – Output dimensions of the feature head layers.
out_features (int) – Final number of output features per point.
dropout (float) – Dropout rate applied before the final layer.
- class geomfum.wrap.pointnet.PointNetfeat(in_channels=3, conv_channels=[64, 64, 128, 128, 1024], mlp_dims=[1024, 256, 256])[source]#
Bases:
ModulePointNet local and global feature extractor.
- Parameters:
conv_channels (list of int) – List of output dimensions for each 1D convolution layer.
mlp_dims (list of int) – List of hidden dimensions for the global MLP layers.
- class geomfum.wrap.pointnet.PointnetFeatureExtractor(in_channels=3, out_channels=128, conv_channels=[64, 64, 128], mlp_dims=[512, 256, 128], head_channels=[256, 128], dropout=0.3, device=None, descriptor=None)[source]#
Bases:
BaseFeatureExtractor,ModuleFeature extractor using PointNet architecture.
- Parameters:
n_features (int) – Number of output features per point.
conv_channels (list of int) – Channels for convolution layers in the feature extractor.
mlp_dims (list of int) – Hidden dimensions for the global MLP.
head_channels (list of int) – Convolutional layers in the head network.
dropout (float) – Dropout probability.
device (torch.device or str) – Device on which the model is allocated.
descriptor (Descriptor or None) – Optional descriptor to compute input features. If None, uses vertex coordinates.
geomfum.wrap.polyscope module#
Wraps polyscope functions.
- class geomfum.wrap.polyscope.PsMeshPlotter(colormap='viridis', backend='')[source]#
Bases:
ShapePlotterPlotting object to display meshes.
- highlight_vertices(coords, color=(1.0, 0.0, 0.0), size=0.01)[source]#
Highlight vertices on a mesh using Polyscope by adding a point cloud.
- Parameters:
coords (array-like, shape = [n_vertices, 3]) – Coordinates of vertices to highlight.
color (tuple) – Color of the highlighted vertices (e.g., (1.0, 0.0, 0.0)).
radius (float) – Radius of the rendered points (visual size).
- set_vertex_colors(colors, name='colors')[source]#
Set vertex colors on mesh.
- Parameters:
colors (array-like, shape=[n_vertices, 3] or [n_vertices, 4]) – RGB or RGBA color values for each vertex (values in range [0, 1]).
name (str) – Name for the color quantity.
- class geomfum.wrap.polyscope.PsPointCloudPlotter(colormap='viridis', backend='')[source]#
Bases:
ShapePlotterPlotting object to display point clouds.
- add_point_cloud(pointcloud)[source]#
Add point cloud to plot.
- Parameters:
pointcloud (PointCloud) – Point cloud to be plotted.
- highlight_vertices(coords, color=(1.0, 0.0, 0.0), size=0.01)[source]#
Highlight specific points in the point cloud.
- Parameters:
coords (array-like, shape = [n_vertices, 3]) – Coordinates of vertices to highlight.
color (tuple) – Color of the highlighted vertices (e.g., (1.0, 0.0, 0.0)).
size (float) – Radius of the rendered points (visual size).
- set_vertex_colors(colors, name='colors')[source]#
Set vertex colors on point cloud.
- Parameters:
colors (array-like, shape=[n_vertices, 3] or [n_vertices, 4]) – RGB or RGBA color values for each vertex (values in range [0, 1]).
name (str) – Name for the color quantity.
geomfum.wrap.pot module#
Python Optimal Trasport wrapper.
- class geomfum.wrap.pot.BaseNeighborFinder(n_neighbors=1)[source]#
Bases:
ABCBase class for a Neighbor finder.
- Parameters:
n_neighbors (int) – Number of neighbors to find.
- class geomfum.wrap.pot.PotSinkhornNeighborFinder(n_neighbors=1, lambd=0.1, method='sinkhorn', max_iter=100)[source]#
Bases:
BaseNeighborFinderNeighbor finder based on Optimal Transport maps computed with Sinkhorn regularization.
- Parameters:
n_neighbors (int, default=1) – Number of neighbors to find.
lambd (float, default=1e-1) – Regularization parameter for Sinkhorn algorithm.
method (str, default=”sinkhorn”) – Method to use for Sinkhorn algorithm.
max_iter (int, default=100) – Maximum number of iterations for Sinkhorn algorithm.
References
[Cuturi2013]Marco Cuturi. “Sinkhorn Distances: Lightspeed Computation of Optimal Transport.” Advances in Neural Information Processing Systems (NIPS), 2013. http://marcocuturi.net/SI.html
geomfum.wrap.pp3d module#
potpourri3d wrapper.
nmwsharp/potpourri3d by Nicholas Sharp.
- class geomfum.wrap.pp3d.FinitePointSetMetric(shape)[source]#
-
Metric supporting distance matrices and source-to-all computations on discrete point sets.
- abstractmethod dist_from_source(source_point)[source]#
Distances from a source point.
- Parameters:
source_point (array-like, shape=[…]) – Index of source point.
- Returns:
dist (array-like, shape=[…] or list-like[array-like]) – Distance.
target_point (array-like, shape=[n_targets] or list-like[array-like]) – Target index.
- class geomfum.wrap.pp3d.Pp3dHeatDistanceMetric(shape, solver=None)[source]#
Bases:
_SingleDispatchMixins,FinitePointSetMetricHeat distance metric between vertices of a mesh.
- Parameters:
shape (TriangleMesh) – Mesh.
solver (pp3d.HeatMethodDistanceSolver) – Heat method distance solver class. ‘ ‘
References
[CWW2017]Crane, K., Weischedel, C., Wardetzky, M., 2017. The heat method for distance computation. Commun. ACM 60, 90–99. https://doi.org/10.1145/3131280
- class geomfum.wrap.pp3d.Pp3dMeshHeatDistanceMetric(shape)[source]#
Bases:
Pp3dHeatDistanceMetricHeat distance metric between vertices of a mesh.
- Parameters:
shape (TriangleMesh) – Mesh.
References
cite:: CWW2017
- class geomfum.wrap.pp3d.Pp3dPointSetHeatDistanceMetric(shape)[source]#
Bases:
Pp3dHeatDistanceMetricHeat distance metric between points of a PointCloud.
- Parameters:
shape (PointCloud) – Point cloud.
References
cite:: CWW2017
geomfum.wrap.pyfm module#
pyFM wrapper.
- class geomfum.wrap.pyfm.FunctionalOperator(shape)[source]#
Bases:
ABCAbstract class fot Functional operator.
- class geomfum.wrap.pyfm.PyFmFaceOrientationOperator(shape)[source]#
Bases:
VectorFieldOperatorOrientation operator associated to a gradient field.
For a given function \(g\) on the vertices, this operator linearly computes \(< \grad(f) x \grad(g)\), n> for each vertex by averaging along the adjacent faces. In practice, we compute \(< n x \grad(f), \grad(g) >\) for simpler computation.
- class geomfum.wrap.pyfm.PyfmEuclideanFarthestVertexSampler(min_n_samples)[source]#
Bases:
BaseSamplerFarthest point Euclidean sampling.
- Parameters:
min_n_samples (int) – Minimum number of samples to target.
- class geomfum.wrap.pyfm.PyfmFaceDivergenceOperator(shape)[source]#
Bases:
VectorFieldOperatorDivergence of a function on a mesh.
- class geomfum.wrap.pyfm.PyfmFaceValuedGradient(shape)[source]#
Bases:
FunctionalOperatorGradient of a function on a mesh.
Computes the gradient of a function on f using linear interpolation between vertices.
- class geomfum.wrap.pyfm.PyfmHeatKernelSignature(scale=True, n_domain=3, domain=None)[source]#
Bases:
SpectralDescriptorHeat kernel signature using pyFM.
- Parameters:
scale (bool) – Whether to scale weights to sum to one.
n_domain (int) – Number of domain points. Ignored if
domainis not None.domain (callable or array-like, shape=[n_domain]) – Method to compute time points (
f(shape, n_domain)) or time points.
- class geomfum.wrap.pyfm.PyfmLandmarkHeatKernelSignature(scale=True, n_domain=3, domain=None)[source]#
Bases:
SpectralDescriptorLandmark-based Heat kernel signature using pyFM.
- Parameters:
scale (bool) – Whether to scale weights to sum to one.
n_domain (int) – Number of domain points. Ignored if
domainis not None.domain (callable or array-like, shape=[n_domain]) – Method to compute domain points (
f(shape)) or domain points.
- class geomfum.wrap.pyfm.PyfmLandmarkWaveKernelSignature(scale=True, sigma=None, n_domain=3, domain=None)[source]#
Bases:
SpectralDescriptorLandmark-based Wave kernel signature using pyFM.
- Parameters:
scale (bool) – Whether to scale weights to sum to one.
sigma (float) – Standard deviation. Ignored if
domainis a callable (other than default one).n_domain (int) – Number of energy points. Ignored if
domainis not a callable.domain (callable or array-like, shape=[n_domain]) – Method to compute domain points (
f(shape)) or domain points.
- class geomfum.wrap.pyfm.PyfmMeshLaplacianFinder[source]#
Bases:
BaseLaplacianFinderAlgorithm to find the Laplacian of a mesh.
- class geomfum.wrap.pyfm.PyfmWaveKernelSignature(scale=True, sigma=None, n_domain=3, domain=None, landmarks=False)[source]#
Bases:
SpectralDescriptorWave kernel signature using pyFM.
- Parameters:
scale (bool) – Whether to scale weights to sum to one.
sigma (float) – Standard deviation. Ignored if
domainis a callable (other than default one).n_domain (int) – Number of energy points. Ignored if
domainis not a callable.domain (callable or array-like, shape=[n_domain]) – Method to compute domain points (
f(shape)) or domain points.
- class geomfum.wrap.pyfm.SpectralDescriptor(spectral_filter=None, domain=None, sigma=1, scale=True, landmarks=False, k=None)[source]#
Bases:
Descriptor,ABCSpectral descriptor computed from Laplacian eigenfunctions with spectral filters.
- Parameters:
spectral_filter (SpectralFilter) – Spectral filter.
domain (callable or array-like, shape=[n_domain]) – Method to compute domain points (
f(basis, n_domain)) or domain points.sigma (float) – Standard deviation for the Gaussian.
scale (bool) – Whether to scale weights to sum to one.
landmarks (bool) – Whether to compute landmarks based descriptors.
k (int, optional) – Number of eigenvalues and eigenvectors to use. If None, basis.use_k is used.
- class geomfum.wrap.pyfm.WksDefaultDomain(n_domain, sigma=None, n_overlap=7, n_trans=2)[source]#
Bases:
objectDefault domain generator for Wave Kernel Signature using logarithmic energy sampling.
- Parameters:
shape (Shape.) – Shape with basis.
n_domain (int) – Number of energy points to use.
n_overlap (int) – Controls Gaussian overlap. Ignored if
sigmais not None.n_trans (int) – Number of standard deviations to translate energy bound by.
- geomfum.wrap.pyfm.get_orientation_op(grad_field, vertices, faces, normals, per_vert_area, rotated=False)[source]#
Compute the linear orientation operator associated to a gradient field grad(f).
This operator computes g -> < grad(f) x grad(g), n> (given at each vertex) for any function g In practice, we compute < n x grad(f), grad(g) > for simpler computation.
- Parameters:
grad_field – (n_f,3) gradient field on the mesh
vertices – (n_v,3) coordinates of vertices
faces – (n_f,3) indices of vertices for each face
normals – (n_f,3) normals coordinate for each face
per_vert_area – (n_v,) voronoi area for each vertex
rotated (bool) – whether gradient field is already rotated by n x grad(f)
- Returns:
operator (sparse.csc_matrix or list[sparse.csc_matrix], shape=[n_vertices, n_verticess]) – (n_v,n_v) orientation operator.
Notes
vectorized version of
pyFm.geometry.mesh.get_orientation_op.
geomfum.wrap.pymeshlab module#
pymeshlab wrapper.
- class geomfum.wrap.pymeshlab.PymeshlabPoissonSampler(min_n_samples)[source]#
Bases:
BaseSamplerPoisson disk sampling.
- Parameters:
min_n_samples (int) – Minimum number of samples to target.
geomfum.wrap.pyrmt module#
pyRMT wrapper.
- class geomfum.wrap.pyrmt.HierarchicalShape(low, high)[source]#
Bases:
ABCHierarchical shape. An HierarchicalShape is composed of a low-resolution and a high-resolution shape, with methods to transfer functions between the two resolutions.
- Parameters:
low (Shape) – Low-resolution shape.
high (Shape) – High-resolution shape.
- extend_basis(set_as_basis=True)[source]#
Extend basis.
See section 3.3. of [MBMR2023] for details.
- Parameters:
set_as_basis (bool) – Whether to set as basis.
- Returns:
vecs (array-like, shape=[high.n_vertices, spectrum_size]) – Eigenvectors.
References
[MBMR2023]Filippo Maggioli, Daniele Baieri, Simone Melzi, and Emanuele Rodolà. “ReMatching: Low-Resolution Representations for Scalable Shape
Correspondence.” arXiv, October 30, 2023. https://doi.org/10.48550/arXiv.2305.09274.
- class geomfum.wrap.pyrmt.PyrmtHierarchicalMesh(mesh, min_n_samples)[source]#
Bases:
HierarchicalShapeHierarchical mesh from PyRMT.
Based on [MBMR2023].
- Parameters:
mesh (TriangleMesh) – High-resolution mesh.
min_n_samples (int) – Minimum number of vertices in low-resolution mesh.
References
[MBMR2023]Filippo Maggioli, Daniele Baieri, Simone Melzi, and Emanuele Rodolà. “ReMatching: Low-Resolution Representations for Scalable Shape Correspondence.” arXiv, October 30, 2023. https://doi.org/10.48550/arXiv.2305.09274.
- class geomfum.wrap.pyrmt.RMTMesh#
Bases:
pybind11_object- baryc_map(self: PyRMT.RMTMesh, arg0: Annotated[numpy.typing.NDArray[numpy.float64], '[m, n]', 'flags.writeable', 'flags.f_contiguous']) scipy.sparse.csc_matrix[numpy.float64]#
- clean_up(self: PyRMT.RMTMesh) None#
- make_manifold(self: PyRMT.RMTMesh) None#
- remesh(self: PyRMT.RMTMesh, arg0: SupportsInt | SupportsIndex) PyRMT.RMTMesh#
- property triangles#
- property vertices#
- class geomfum.wrap.pyrmt.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
geomfum.wrap.pyvista module#
Wraps pyvista functions.
- class geomfum.wrap.pyvista.PvMeshPlotter(colormap='viridis', **kwargs)[source]#
Bases:
ShapePlotterPlotting object to display meshes.
- add_mesh(mesh, **kwargs)[source]#
Add mesh to plot.
- Parameters:
mesh (TriangleMesh) – Mesh to be plotted.
- highlight_vertices(coords, color='red', size=0.01)[source]#
Highlight vertices on the mesh using PyVista.
- Parameters:
coords (array-like, shape = [n_vertices, 3]) – Coordinates of vertices to highlight.
color (str or tuple) – Color of the highlighted vertices.
size (float) – Size of the highlighted vertices (radius of spheres).
- class geomfum.wrap.pyvista.PvPointCloudPlotter(colormap='viridis', **kwargs)[source]#
Bases:
ShapePlotterPlotting object to display point clouds.
- add_point_cloud(pointcloud, **kwargs)[source]#
Add point cloud to plot.
- Parameters:
pointcloud (PointCloud) – Point cloud to be plotted.
- highlight_vertices(coords, color='red', size=0.01)[source]#
Highlight specific points in the point cloud.
- Parameters:
coords (array-like, shape = [n_vertices, 3]) – Coordinates of vertices to highlight.
color (str or tuple) – Color of the highlighted vertices.
size (float) – Size of the highlighted vertices (radius of spheres).
geomfum.wrap.robust module#
robust_laplacian wrapper.
- class geomfum.wrap.robust.RobustMeshLaplacianFinder(mollify_factor=1e-05)[source]#
Bases:
BaseLaplacianFinderAlgorithm to find the Laplacian of a mesh.
- Parameters:
mollify_factor (float) – Amount of intrinsic mollification to perform.
- class geomfum.wrap.robust.RobustPointCloudLaplacianFinder(mollify_factor=1e-05, n_neighbors=30)[source]#
Bases:
BaseLaplacianFinderAlgorithm to find the Laplacian of a point cloud.
- Parameters:
mollify_factor (float) – Amount of intrinsic mollification to perform.
n_neighbors (float) – Number of nearest neighbors to use when constructing local triangulations.
geomfum.wrap.transformer module#
Transformer for Feature Extraction.
Copyright (c) 2025 Alessandro Riva
References
- [RRM2024] Riva, A., Raganato, A, Melzi, S., “Localized Gaussians as Self-Attention Weights for Point Clouds Correspondence”,
Smart Tools and Applications in Graphics, 2024, arXiv:2409.13291
- class geomfum.wrap.transformer.AttentionLayer(embed_dim, num_heads, dropout: float = 0.0, attn_bias: bool = True, ff_mult: int = 4)[source]#
Bases:
ModuleAttention Layer for the Transformer.
- Parameters:
embed_dim (int) – Dimension of the used embedding
num_heads (int) – Number of attention heads
dropout (float) – Dropout rate
attn_bias (bool) – Set the use of leaned bias in the output linear layer of the attention heads
ff_mult (int) – Dimension factor of the feed forward section of the attention layer. The dimension expansion is computed as ff_mult * embed_dim
- forward(x, y, attn_mask=None, x_mask=None, y_mask=None, attn_prev=None)[source]#
Forward pass of the Attention Layer.
- Parameters:
x (torch.Tensor) – Tokens of x tensor of shape (batch_size, num_points_x, embed_dim)
y (torch.Tensor) – Tokens of y tensor of shape (batch_size, num_points_y, embed_dim)
attn_mask (torch.Tensor) – Mask tensor for the attention weights of shape (batch_size, num_heads, num_points_x, num_points_y) or (batch_size, num_points_x, num_points_y). If (batch_size, num_points_x, num_points_y) the mask will be broadcasted over the num_heads dimension
x_mask (torch.Tensor) – Mask tensor of x of shape (batch_size, num_points_x)
y_mask (torch.Tensor) – Mask tensor of y of shape (batch_size, num_points_y)
attn_prev (torch.Tensor) – Attention weights of the previous layer to be used in the residual attention of shape (batch_size, num_heads, num_points_x, num_points_y)
- Returns:
output (torch.Tensor) – Attention output tensor of shape (batch_size, num_points_x, embed_dim)
hiddens (dict) – Intermediate activations of the attention mechanism
- class geomfum.wrap.transformer.BaseFeatureExtractor[source]#
Bases:
ABCAbstract base class for neural network feature extractors.
- class geomfum.wrap.transformer.MultiHeadAttention(embed_dim, num_heads: int, dropout: float = 0.0, bias: bool = True)[source]#
Bases:
ModuleMulti-Head Attention layer.
- Parameters:
embed_dim (int) – Dimension of the used embedding
num_heads (int) – Number of attention heads
dropout (float) – Dropout rate
bias (bool) – Set the use of leaned bias in the output linear layer of the attention heads
- forward(query: Tensor, key: Tensor, value: Tensor, attn_mask: Tensor = None, attn_prev: Tensor = None)[source]#
Forward pass of the Multi-Head Attention layer.
- Parameters:
query (torch.Tensor) – Query vectors of x
key (torch.Tensor) – Key vectors of y
value (torch.Tensor) – Value vectors of y
attn_mask (torch.Tensor) – Mask tensor for the attention weights of shape (batch_size, num_heads, num_points_x, num_points_y) or (batch_size, num_points_x, num_points_y). If (batch_size, num_points_x, num_points_y) the mask will be broadcasted over the num_heads dimension
attn_prev (torch.Tensor) – Attention weights of the previous layer to be used in the residual attention of shape (batch_size, num_heads, num_points_x, num_points_y)
- Returns:
output (torch.Tensor) – Attention output tensor of shape (batch_size, num_points_x, embed_dim)
hiddens (dict) – Intermediate activations of the attention mechanism
- class geomfum.wrap.transformer.Transformer(embed_dim, num_heads, num_layers, dropout=0.0, residual=False)[source]#
Bases:
ModuleTransformer for feature extraction.
- Parameters:
embed_dim (int) – Dimension of the used embedding
num_heads (int) – Number of attention heads
num_layers (int) – Number of attention layers
dropout (float) – Dropout rate
residual (bool) – Boolean control the use of the residual attention
- forward(x, y, attn_mask=None, x_mask=None, y_mask=None, return_hiddens=False)[source]#
Forward pass of the Transformer.
- Parameters:
x (torch.Tensor) – Tokens of x tensor of shape (batch_size, num_points_x, embed_dim)
y (torch.Tensor) – Tokens of y tensor of shape (batch_size, num_points_y, embed_dim)
attn_mask (torch.Tensor) – Mask tensor for the attention weights of shape (batch_size, num_heads, num_points_x, num_points_y) or (batch_size, num_points_x, num_points_y). If (batch_size, num_points_x, num_points_y) the mask will be broadcasted over the num_heads dimension
x_mask (torch.Tensor) – Mask tensor of x of shape (batch_size, num_points_x)
y_mask (torch.Tensor) – Mask tensor of y of shape (batch_size, num_points_y)
return_hiddens (bool) – Boolean to return intermediate activations of the attention mechanism. If True the output is a tuple (output, hiddens)
- Returns:
output (torch.Tensor) – Attention output tensor of shape (batch_size, num_points_x, embed_dim)
hiddens (dict) – Intermediate activations of the attention mechanism
- class geomfum.wrap.transformer.TransformerFeatureExtractor(in_channels: int = 3, embed_dim: int = 256, num_heads: int = 8, num_layers: int = 4, out_channels: int = 512, dropout: float = 0.1, use_global_pool: bool = True, k_neighbors: int = 16, device=None, descriptor=None)[source]#
Bases:
BaseFeatureExtractor,ModuleTransformer Feature Extractor for point clouds.
This feature extractor uses the Transformer architecture to extract features from shapes.
- Parameters:
in_channels (int) – Input feature dimension (typically 3 for xyz coordinates)
embed_dim (int) – Embedding dimension for the transformer
num_heads (int) – Number of attention heads
num_layers (int) – Number of transformer layers
output_dim (int) – Output feature dimension
dropout (float) – Dropout probability
use_global_pool (bool) – Whether to use global max pooling for global features
Module contents#
Registration of various wrapped components in GeomFum.
- geomfum.wrap.has_package(package_name)[source]#
Check if package is installed.
- Parameters:
package_name (str) – Package name.
- geomfum.wrap.register_face_divergence_operator(key, obj_name, requires=(), as_default=False)#
Register an implementation with optional package dependencies.
- Parameters:
key (str) – Key.
obj_name (class name) – Name of the object to register.
requires (str or tuple) – Required packages.
as_default (bool) – Whether to set it as default.
- geomfum.wrap.register_face_orientation_operator(key, obj_name, requires=(), as_default=False)#
Register an implementation with optional package dependencies.
- Parameters:
key (str) – Key.
obj_name (class name) – Name of the object to register.
requires (str or tuple) – Required packages.
as_default (bool) – Whether to set it as default.
- geomfum.wrap.register_face_valued_gradient(key, obj_name, requires=(), as_default=False)#
Register an implementation with optional package dependencies.
- Parameters:
key (str) – Key.
obj_name (class name) – Name of the object to register.
requires (str or tuple) – Required packages.
as_default (bool) – Whether to set it as default.
- geomfum.wrap.register_feature_extractor(key, obj_name, requires=(), as_default=False)#
Register an implementation with optional package dependencies.
- Parameters:
key (str) – Key.
obj_name (class name) – Name of the object to register.
requires (str or tuple) – Required packages.
as_default (bool) – Whether to set it as default.
- geomfum.wrap.register_heat_distance_metric(key_out, key_in, obj_name, requires=(), as_default=False)#
Register implementation in nested registry structure.
- Parameters:
key_out (Hashable) – Key for outer register dict.
key_in (str) – Key for object in inner register.
obj_name (class name) – Name of the object to register.
requires (str or tuple) – Required packages.
as_default (bool) – Whether to set it as default.
- geomfum.wrap.register_heat_kernel_signature(key, obj_name, requires=(), as_default=False)#
Register an implementation with optional package dependencies.
- Parameters:
key (str) – Key.
obj_name (class name) – Name of the object to register.
requires (str or tuple) – Required packages.
as_default (bool) – Whether to set it as default.
- geomfum.wrap.register_hierarchical_mesh(key, obj_name, requires=(), as_default=False)#
Register an implementation with optional package dependencies.
- Parameters:
key (str) – Key.
obj_name (class name) – Name of the object to register.
requires (str or tuple) – Required packages.
as_default (bool) – Whether to set it as default.
- geomfum.wrap.register_landmark_heat_kernel_signature(key, obj_name, requires=(), as_default=False)#
Register an implementation with optional package dependencies.
- Parameters:
key (str) – Key.
obj_name (class name) – Name of the object to register.
requires (str or tuple) – Required packages.
as_default (bool) – Whether to set it as default.
- geomfum.wrap.register_landmark_wave_kernel_signature(key, obj_name, requires=(), as_default=False)#
Register an implementation with optional package dependencies.
- Parameters:
key (str) – Key.
obj_name (class name) – Name of the object to register.
requires (str or tuple) – Required packages.
as_default (bool) – Whether to set it as default.
- geomfum.wrap.register_laplacian_finder(key_out, key_in, obj_name, requires=(), as_default=False)#
Register implementation in nested registry structure.
- Parameters:
key_out (Hashable) – Key for outer register dict.
key_in (str) – Key for object in inner register.
obj_name (class name) – Name of the object to register.
requires (str or tuple) – Required packages.
as_default (bool) – Whether to set it as default.
- geomfum.wrap.register_mesh_plotter(key, obj_name, requires=(), as_default=False)#
Register an implementation with optional package dependencies.
- Parameters:
key (str) – Key.
obj_name (class name) – Name of the object to register.
requires (str or tuple) – Required packages.
as_default (bool) – Whether to set it as default.
- geomfum.wrap.register_neighbor_finder(key, obj_name, requires=(), as_default=False)#
Register an implementation with optional package dependencies.
- Parameters:
key (str) – Key.
obj_name (class name) – Name of the object to register.
requires (str or tuple) – Required packages.
as_default (bool) – Whether to set it as default.
- geomfum.wrap.register_point_cloud_plotter(key, obj_name, requires=(), as_default=False)#
Register an implementation with optional package dependencies.
- Parameters:
key (str) – Key.
obj_name (class name) – Name of the object to register.
requires (str or tuple) – Required packages.
as_default (bool) – Whether to set it as default.
- geomfum.wrap.register_poisson_sampler(key, obj_name, requires=(), as_default=False)#
Register an implementation with optional package dependencies.
- Parameters:
key (str) – Key.
obj_name (class name) – Name of the object to register.
requires (str or tuple) – Required packages.
as_default (bool) – Whether to set it as default.
- geomfum.wrap.register_wave_kernel_signature(key, obj_name, requires=(), as_default=False)#
Register an implementation with optional package dependencies.
- Parameters:
key (str) – Key.
obj_name (class name) – Name of the object to register.
requires (str or tuple) – Required packages.
as_default (bool) – Whether to set it as default.