Skip to main content

An invigorating blend of 3D geometry tools in Python.

Project description

potpourri3d

A Python library of various algorithms and utilities for 3D triangle meshes and point clouds. Managed by Nicholas Sharp, with new tools added lazily as needed. Currently, mainly bindings to C++ tools from geometry-central.

pip install potpourri3d

The blend includes:

  • Mesh and point cloud reading/writing to a few file formats
  • Use heat methods to compute distance, parallel transport, logarithmic maps, and more

Installation

Potpourri3d is on the pypi package index with precompiled binaries for most configuations. Get it like:

pip install potpourri3d

If none of the precompiled binaries match your system, pip will attempt to compile the library from scratch. This requires cmake and a workng C++ compiler toolchain.

Note: Some bound functions invoke sparse linear solvers internally. The precompiled binaries use Eigen's solvers; using Suitesparse's solvers instead may significantly improve performance & robustness. To get them, locally compile the package on a machine with Suitesparse installed using the command below (relevant docs).

python -m pip install potpourri3d --no-binary potpourri3d

Documentation

Input / Output

Read/write meshes and point clouds from some common formats.

  • read_mesh(filename) Reads a mesh from file. Returns numpy matrices V, F, a Nx3 real numpy array of vertices and a Mx3 integer numpy array of 0-based face indices (or Mx4 for a quad mesh, etc).

    • filename the path to read the file from. Currently supports the same file types as geometry-central. The file type is inferred automatically from the path extension.
  • write_mesh(V, F, filename) Write a mesh from file. Returns numpy matrices V, F, a Vx3 real array of vertices and a Fx3 integer array of 0-based face indices (or Fx4 for a quad mesh, etc).

    • V a Nx3 real numpy array of vertices
    • F a Mx3 integer numpy array of faces, with 0-based vertex indices (or Mx4 for a quad mesh, etc).
    • filename the path to write the file to. Currently supports the same file types as geometry-central. The file type is inferred automatically from the path extension.

Mesh basic utilities

  • face_areas(V, F) computes a length-F real numpy array of face areas for a triangular mesh
  • vertex_areas(V, F) computes a length-V real numpy array of vertex areas for a triangular mesh (equal to 1/3 the sum of the incident face areas)
  • cotan_laplacian(V, F, denom_eps=0.) computes the cotan-Laplace matrix as a VxV real sparse csr scipy matrix. Optionally, set denom_eps to a small value like 1e-6 to get some additional stability in the presence of degenerate faces.

Mesh Distance

Use the heat method for geodesic distance to compute geodesic distance on surfaces. Repeated solves are fast after initial setup. Uses intrinsic triangulations internally for increased robustness.

import potpourri3d as pp3d

# = Stateful solves (much faster if computing distance many times)
solver = pp3d.MeshHeatMethodDistanceSolver(V,F)
dist = solver.compute_distance(7)
dist = solver.compute_distance_multisource([1,2,3])  

# = One-off versions
dist = pp3d.compute_distance(V,F,7)
dist = pp3d.compute_distance_multisource(V,F,[1,3,4])
  • MeshHeatMethodDistanceSolver(self, V, F, t_coef=1., use_robust=True) construct an instance of the solver class.
    • V a Nx3 real numpy array of vertices
    • F a Mx3 integer numpy array of faces, with 0-based vertex indices (triangle meshes only, but need not be manifold).
    • t_coef set the time used for short-time heat flow. Generally don't change this. If necessary, larger values may make the solution more stable at the cost of smoothing it out.
    • use_robust use intrinsic triangulations for increased robustness. Generaly leave this enabled.
  • MeshHeatMethodDistanceSolver.compute_distance(v_ind) compute distance from a single vertex, given by zero-based index. Returns an array of distances.
  • MeshHeatMethodDistanceSolver.compute_distance_multisource(v_ind_list) compute distance from the nearest of a collection of vertices, given by a list of zero-based indices. Returns an array of distances.
  • compute_distance(V, F, v_ind) Similar to above, but one-off instead of stateful. Returns an array of distances.
  • compute_distance_multisource(V, F, v_ind_list) Similar to above, but one-off instead of stateful. Returns an array of distances.

Mesh Vector Heat

Use the vector heat method to compute various interpolation & vector-based quantities on meshes. Repeated solves are fast after initial setup.

import potpourri3d as pp3d

# = Stateful solves
V, F = # a Nx3 numpy array of points and Mx3 array of triangle face indices
solver = pp3d.MeshVectorHeatSolver(V,F)

# Extend the value `0.` from vertex 12 and `1.` from vertex 17. Any vertex 
# geodesically closer to 12. will take the value 0., and vice versa 
# (plus some slight smoothing)
ext = solver.extend_scalar([12, 17], [0.,1.])

# Get the tangent frames which are used by the solver to define tangent data
# at each vertex
basisX, basisY, basisN = solver.get_tangent_frames()

# Parallel transport a vector along the surface
# (and map it to a vector in 3D)
sourceV = 22
ext = solver.transport_tangent_vector(sourceV, [6., 6.])
ext3D = ext[:,0,np.newaxis] * basisX +  ext[:,1,np.newaxis] * basisY

# Compute the logarithmic map
logmap = solver.compute_log_map(sourceV)
  • MeshVectorHeatSolver(self, V, F, t_coef=1.) construct an instance of the solver class.
    • V a Nx3 real numpy array of vertices
    • F a Mx3 integer numpy array of faces, with 0-based vertex indices (triangle meshes only, should be manifold).
    • t_coef set the time used for short-time heat flow. Generally don't change this. If necessary, larger values may make the solution more stable at the cost of smoothing it out.
  • MeshVectorHeatSolver.extend_scalar(v_inds, values) nearest-geodesic-neighbor interpolate values defined at vertices. Vertices will take the value from the closest source vertex (plus some slight smoothing)
    • v_inds a list of source vertices
    • values a list of scalar values, one for each source vertex
  • MeshVectorHeatSolver.get_tangent_frames() get the coordinate frames used to define tangent data at each vertex. Returned as a tuple of basis-X, basis-Y, and normal axes, each as an Nx3 array. May be necessary for change-of-basis into or out of tangent vector convention.
  • MeshVectorHeatSolver.transport_tangent_vector(v_ind, vector) parallel transports a single vector across a surface
    • v_ind index of the source vertex
    • vector a 2D tangent vector to transport
  • MeshVectorHeatSolver.transport_tangent_vectors(v_inds, vectors) parallel transports a collection of vectors across a surface, such that each vertex takes the vector from its nearest-geodesic-neighbor.
    • v_inds a list of source vertices
    • vectors a list of 2D tangent vectors, one for each source vertex
  • MeshVectorHeatSolver.compute_log_map(v_ind) compute the logarithmic map centered at the given source vertex
    • v_ind index of the source vertex

Point Cloud Distance & Vector Heat

Use the heat method for geodesic distance and vector heat method to compute various interpolation & vector-based quantities on point clouds. Repeated solves are fast after initial setup.

point cloud vector heat examples

import potpourri3d as pp3d

# = Stateful solves
P = # a Nx3 numpy array of points
solver = pp3d.PointCloudHeatSolver(P)

# Compute the geodesic distance to point 4
dists = solver.compute_distance(4)

# Extend the value `0.` from point 12 and `1.` from point 17. Any point 
# geodesically closer to 12. will take the value 0., and vice versa 
# (plus some slight smoothing)
ext = solver.extend_scalar([12, 17], [0.,1.])

# Get the tangent frames which are used by the solver to define tangent data
# at each point
basisX, basisY, basisN = solver.get_tangent_frames()

# Parallel transport a vector along the surface
# (and map it to a vector in 3D)
sourceP = 22
ext = solver.transport_tangent_vector(sourceP, [6., 6.])
ext3D = ext[:,0,np.newaxis] * basisX +  ext[:,1,np.newaxis] * basisY

# Compute the logarithmic map
logmap = solver.compute_log_map(sourceP)
  • PointCloudHeatSolver(self, P, t_coef=1.) construct an instance of the solver class.
    • P a Nx3 real numpy array of points
    • t_coef set the time used for short-time heat flow. Generally don't change this. If necessary, larger values may make the solution more stable at the cost of smoothing it out.
  • PointCloudHeatSolver.extend_scalar(p_inds, values) nearest-geodesic-neighbor interpolate values defined at points. Points will take the value from the closest source point (plus some slight smoothing)
    • v_inds a list of source points
    • values a list of scalar values, one for each source points
  • PointCloudHeatSolver.get_tangent_frames() get the coordinate frames used to define tangent data at each point. Returned as a tuple of basis-X, basis-Y, and normal axes, each as an Nx3 array. May be necessary for change-of-basis into or out of tangent vector convention.
  • PointCloudHeatSolver.transport_tangent_vector(p_ind, vector) parallel transports a single vector across a surface
    • p_ind index of the source point
    • vector a 2D tangent vector to transport
  • PointCloudHeatSolver.transport_tangent_vectors(p_inds, vectors) parallel transports a collection of vectors across a surface, such that each vertex takes the vector from its nearest-geodesic-neighbor.
    • p_inds a list of source points
    • vectors a list of 2D tangent vectors, one for each source point
  • PointCloudHeatSolver.compute_log_map(p_ind) compute the logarithmic map centered at the given source point
    • p_ind index of the source point

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

potpourri3d-0.0.2.tar.gz (1.3 MB view hashes)

Uploaded Source

Built Distributions

potpourri3d-0.0.2-cp39-cp39-win_amd64.whl (376.0 kB view hashes)

Uploaded CPython 3.9 Windows x86-64

potpourri3d-0.0.2-cp39-cp39-win32.whl (334.5 kB view hashes)

Uploaded CPython 3.9 Windows x86

potpourri3d-0.0.2-cp39-cp39-manylinux2010_x86_64.whl (655.7 kB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.12+ x86-64

potpourri3d-0.0.2-cp39-cp39-manylinux2010_i686.whl (630.2 kB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.12+ i686

potpourri3d-0.0.2-cp39-cp39-macosx_10_9_x86_64.whl (633.4 kB view hashes)

Uploaded CPython 3.9 macOS 10.9+ x86-64

potpourri3d-0.0.2-cp38-cp38-win_amd64.whl (378.8 kB view hashes)

Uploaded CPython 3.8 Windows x86-64

potpourri3d-0.0.2-cp38-cp38-win32.whl (334.4 kB view hashes)

Uploaded CPython 3.8 Windows x86

potpourri3d-0.0.2-cp38-cp38-manylinux2010_x86_64.whl (655.7 kB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.12+ x86-64

potpourri3d-0.0.2-cp38-cp38-manylinux2010_i686.whl (630.0 kB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.12+ i686

potpourri3d-0.0.2-cp38-cp38-macosx_10_9_x86_64.whl (633.3 kB view hashes)

Uploaded CPython 3.8 macOS 10.9+ x86-64

potpourri3d-0.0.2-cp37-cp37m-win_amd64.whl (378.7 kB view hashes)

Uploaded CPython 3.7m Windows x86-64

potpourri3d-0.0.2-cp37-cp37m-win32.whl (334.9 kB view hashes)

Uploaded CPython 3.7m Windows x86

potpourri3d-0.0.2-cp37-cp37m-manylinux2010_x86_64.whl (657.0 kB view hashes)

Uploaded CPython 3.7m manylinux: glibc 2.12+ x86-64

potpourri3d-0.0.2-cp37-cp37m-manylinux2010_i686.whl (633.1 kB view hashes)

Uploaded CPython 3.7m manylinux: glibc 2.12+ i686

potpourri3d-0.0.2-cp37-cp37m-macosx_10_9_x86_64.whl (632.2 kB view hashes)

Uploaded CPython 3.7m macOS 10.9+ x86-64

potpourri3d-0.0.2-cp36-cp36m-win_amd64.whl (378.6 kB view hashes)

Uploaded CPython 3.6m Windows x86-64

potpourri3d-0.0.2-cp36-cp36m-win32.whl (334.9 kB view hashes)

Uploaded CPython 3.6m Windows x86

potpourri3d-0.0.2-cp36-cp36m-manylinux2010_x86_64.whl (656.9 kB view hashes)

Uploaded CPython 3.6m manylinux: glibc 2.12+ x86-64

potpourri3d-0.0.2-cp36-cp36m-manylinux2010_i686.whl (632.8 kB view hashes)

Uploaded CPython 3.6m manylinux: glibc 2.12+ i686

potpourri3d-0.0.2-cp36-cp36m-macosx_10_9_x86_64.whl (632.3 kB view hashes)

Uploaded CPython 3.6m macOS 10.9+ x86-64

potpourri3d-0.0.2-cp35-cp35m-win_amd64.whl (378.6 kB view hashes)

Uploaded CPython 3.5m Windows x86-64

potpourri3d-0.0.2-cp35-cp35m-win32.whl (334.9 kB view hashes)

Uploaded CPython 3.5m Windows x86

potpourri3d-0.0.2-cp35-cp35m-manylinux2010_x86_64.whl (656.9 kB view hashes)

Uploaded CPython 3.5m manylinux: glibc 2.12+ x86-64

potpourri3d-0.0.2-cp35-cp35m-manylinux2010_i686.whl (632.8 kB view hashes)

Uploaded CPython 3.5m manylinux: glibc 2.12+ i686

potpourri3d-0.0.2-cp35-cp35m-macosx_10_9_x86_64.whl (632.3 kB view hashes)

Uploaded CPython 3.5m macOS 10.9+ x86-64

potpourri3d-0.0.2-cp27-cp27mu-manylinux2010_x86_64.whl (657.5 kB view hashes)

Uploaded CPython 2.7mu manylinux: glibc 2.12+ x86-64

potpourri3d-0.0.2-cp27-cp27mu-manylinux2010_i686.whl (633.6 kB view hashes)

Uploaded CPython 2.7mu manylinux: glibc 2.12+ i686

potpourri3d-0.0.2-cp27-cp27m-win_amd64.whl (379.6 kB view hashes)

Uploaded CPython 2.7m Windows x86-64

potpourri3d-0.0.2-cp27-cp27m-win32.whl (335.7 kB view hashes)

Uploaded CPython 2.7m Windows x86

potpourri3d-0.0.2-cp27-cp27m-manylinux2010_x86_64.whl (657.4 kB view hashes)

Uploaded CPython 2.7m manylinux: glibc 2.12+ x86-64

potpourri3d-0.0.2-cp27-cp27m-manylinux2010_i686.whl (633.6 kB view hashes)

Uploaded CPython 2.7m manylinux: glibc 2.12+ i686

potpourri3d-0.0.2-cp27-cp27m-macosx_10_9_x86_64.whl (632.5 kB view hashes)

Uploaded CPython 2.7m macOS 10.9+ x86-64

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page