Gpytoolbox

repository·main·Indexed 42 days ago

https://github.com/sgsellan/gpytoolbox

A Python-based geometry processing toolbox providing research utility functions for geometry processing tasks. Compatible with Python 3.10 through 3.13, it includes tools for mesh decimation, cotangent Laplacian computation, biharmonic energy calculation, and winding number computation. The library uses a dual-licensing model, with the main module under the MIT license and the gpytoolbox.copyleft module under the GPL license.

Tokens
15.8K
Snippets
69
Records
81
Agent score
53%

What's inside Gpytoolbox

  1. Understand Gpytoolbox licensing (MIT vs GPL)

    main

    Gpytoolbox uses a dual-licensing model based on which modules you import:

    • MIT License (Permissive): Applies to the main gpytoolbox module and its individual functions. Use this for standard research and development.
      • Example: import gpytoolbox or from gpytoolbox import regular_square_mesh.
    • GPL License (Restrictive): Applies to the gpytoolbox.copyleft module. If you import from this module, your code must comply with GPL terms.
      • Example: from gpytoolbox.copyleft import mesh_boolean.
  2. Install Gpytoolbox from Git

    main

    To build Gpytoolbox from a specific git commit (e.g., for development or to access features in the main branch not yet released), clone the repository and install it locally:

    1. Clone the repository.
    2. Install numpy.
    3. Run the local installation command.
    python -m pip install numpy
    python -m pip install .
  3. Install C++ bindings for Gpytoolbox

    main

    Certain functionalities in Gpytoolbox use C++ bindings. These must be compiled manually if you require that specific functionality. The process is platform-dependent and requires cmake and a C++ compiler.

    MacOS

    mkdir build
    cd build
    cmake ..
    make -j2

    Ubuntu

    sudo apt-get update
    sudo apt-get upgrade
    sudo apt-get install libmpfr-dev libgmp-dev
    mkdir build
    cd build
    cmake ..
    make -j2

    Windows

    mkdir build
    cd build
    cmake -DCMAKE_BUILD_TYPE=Release ..
    cmake --build "." --config Release
  4. Generate random points on a mesh with random_points_on_mesh

    main

    The random_points_on_mesh function allows you to sample a set of points uniformly distributed across the surface of a mesh. This is useful for tasks like point cloud generation or surface analysis.

    To use this function, you typically provide a mesh object (such as one from trimesh or a similar geometry processing library) and specify the number of points you wish to sample.

    from gpytoolbox.random_points_on_mesh import random_points_on_mesh
    
    # Assuming 'mesh' is a valid mesh object
    points = random_points_on_mesh(mesh, num_points=1000)
  5. Decimate a mesh using src.gpytoolbox.decimate

    main

    The decimate module provides functionality to reduce the number of faces/vertices in a mesh (decimation).

    Note: The specific API details (parameters and return types) are defined in the src.gpytoolbox.decimate module. Refer to the function signatures in the source code for exact parameter names and expected mesh formats.

  6. Use squared_distance_precompute for efficient distance queries

    main

    The squared_distance_precompute class provides a precomputed AABB (Axis-Aligned Bounding Box) tree to accelerate repeated closest-point queries. It wraps libigl's C++ igl::AABB implementation, allowing you to build the bounding volume hierarchy once and reuse it across multiple calls to squared_distance, signed_distance, or winding_number. This avoids the $O(n)$ cost of rebuilding the tree for every query.

    Usage Patterns

    1. Via the squared_distance wrapper: Pass the precomputed tree instance to the aabb parameter of the gpytoolbox.squared_distance function.
    2. Directly via the tree object: Call the .squared_distance(P) method on the tree instance itself for closest-point queries.

    Input Handling for F

    If the face/edge index matrix F is not provided:

    • 2D input: V is treated as an ordered closed polyline.
    • 3D input: V is treated as a point cloud.
    # Pattern 1: Passing to the wrapper
    v, f = gpytoolbox.read_mesh("bunny.obj")
    tree = gpytoolbox.squared_distance_precompute(v, f)
    for _ in range(num_iters):
        P = 2*np.random.rand(num_samples,3)-4
        sqrD, I, lmbs = gpytoolbox.squared_distance(P, v, F=f, use_cpp=True, aabb=tree)
    
    # Pattern 2: Direct query
    tree = gpytoolbox.squared_distance_precompute(v, f)
    sqrD, I, C = tree.squared_distance(P)
  7. How AABB tree subdivision works

    main

    The AABB tree is constructed by identifying the dimension with the largest spread (difference between max and min coordinates) and splitting the elements into two groups based on the median value along that axis.

    This process continues recursively until each leaf node contains only one element (or a single triangle/simplex). The tree structure allows for fast spatial lookups by traversing the hierarchy of bounding boxes.

  8. How Gaussian Process precomputation works

    main

    The gaussian_process_precompute class implements two main modes of operation depending on whether inducing points are provided:

    1. Full GP (No Inducing Points): Uses the full training set. It computes and factorizes the covariance matrix $K + \sigma_n^2 I$. This is exact but scales cubically with the number of training points.
    2. Sparse GP (With X_induced): Uses a set of inducing points to approximate the GP. This reduces complexity, making it suitable for larger datasets. It computes a matrix $\Sigma_{inv}$ involving the inducing points and the training points to perform the approximation.

    Both modes support using observed gradients (grad_y_train) and compact kernel support to optimize computation.