Skip to main content

A Python C++ extension based on VoxSurf for voxelization of 3D meshes.

Project description

PyVoxSurf

A Python C++ extension based on VoxSurf for voxelization of 3D meshes.

NOTE: PyPi distribution is only compatible with Microsoft Windows

Principle

  1. Rasterize triangles using three 2D axis aligned grids, using integer arithmetic (fixed floating point) for robust triangle interior checks
  2. [Optional] Fill interior of voxelized surface with either of two schemes: Inside - fastest method evaluates whether a voxel is inside from only one direction or Robust - evaluates whether a voxel is inside from all three directions and a voting determines final status

Usage

pyvoxsurf.voxelize_stl

Argument Type Default Description
filename string Filename of .stl file
resolution integer Number of voxel slices in the z-axis
bounds [2x3] array [Optional] Min and max bounds in (x, y, z) coordinates of desired voxel volume
voxel_fill string "None" [Optional] "None", "Inside", or "Robust" type of filling
import pyvoxsurf
from mayavi import mlab

volume1 = pyvoxsurf.voxelize_stl("model.stl",200,[],"Robust")
print(volume1.shape)

# Visualize voxelized model
from tvtk.util.ctf import PiecewiseFunction
mlab.figure(size=(800,800))
vol = mlab.pipeline.volume(mlab.pipeline.scalar_field(volume1))
mlab.title('Voxelized model',height=0.9,size=0.5)
mlab.orientation_axes()
otf = PiecewiseFunction()
otf.add_point(0,0)
otf.add_point(0.001, 1)
otf.add_point(1,1)
vol._otf = otf
vol._volume_property.set_scalar_opacity(otf)
mlab.show()

volume1

pyvoxsurf.voxelize

Argument Type Default Description
vertices [nx3] array Vertex positions in (x, y, z) coordinates
triangle_indices [nx3] array Indices of connected vertices forming triangles of mesh
bounds [2x3] array Min and max bounds in (x, y, z) coordinates of desired voxel volume
resolution integer Number of voxel slices in the z-axis
voxel_fill string "None" [Optional] "None", "Inside", or "Robust" type of filling
import pyvoxsurf
import trimesh
import numpy as np
from mayavi import mlab

mesh = trimesh.load("model.stl") # Load stl file

# Find the max and min coordinates of the mesh to form a bounding box
mesh_min_corner = [np.min(mesh.vertices[:,0]), np.min(mesh.vertices[:,1]), np.min(mesh.vertices[:,2])]
mesh_max_corner = [np.max(mesh.vertices[:,0]), np.max(mesh.vertices[:,1]), np.max(mesh.vertices[:,2])]
bounds = np.stack((mesh_min_corner,mesh_max_corner))

volume2 = pyvoxsurf.voxelize(mesh.vertices,mesh.faces,bounds,100,"Inside")
print(volume2.shape)

# Visualize voxelized model
from tvtk.util.ctf import PiecewiseFunction
mlab.figure(size=(800,800))
vol = mlab.pipeline.volume(mlab.pipeline.scalar_field(volume2))
mlab.title('Voxelized model',height=0.9,size=0.5)
mlab.orientation_axes()
otf = PiecewiseFunction()
otf.add_point(0,0)
otf.add_point(0.001, 1)
otf.add_point(1,1)
vol._otf = otf
vol._volume_property.set_scalar_opacity(otf)
mlab.show()

volume2

Credits

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

pyvoxsurf-1.0.7.tar.gz (3.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pyvoxsurf-1.0.7-cp38-cp38-win_amd64.whl (99.2 kB view details)

Uploaded CPython 3.8Windows x86-64

File details

Details for the file pyvoxsurf-1.0.7.tar.gz.

File metadata

  • Download URL: pyvoxsurf-1.0.7.tar.gz
  • Upload date:
  • Size: 3.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.4.0 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.8.3

File hashes

Hashes for pyvoxsurf-1.0.7.tar.gz
Algorithm Hash digest
SHA256 e872a37c5e9ea9f400bbfc268b6af2723ce59b6575d56f269e2c206049dc3e42
MD5 911cbf43f561d5e0e07474b041ebd569
BLAKE2b-256 bb16402dd4328b556040bfa3f8f7ddc1af44e5493b753372f4708c670ed71e57

See more details on using hashes here.

File details

Details for the file pyvoxsurf-1.0.7-cp38-cp38-win_amd64.whl.

File metadata

  • Download URL: pyvoxsurf-1.0.7-cp38-cp38-win_amd64.whl
  • Upload date:
  • Size: 99.2 kB
  • Tags: CPython 3.8, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.4.0 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.8.3

File hashes

Hashes for pyvoxsurf-1.0.7-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 999d0877e50ddb5cb67c350c07d9d2a60f9e75e6110ef2301db16971ffeed070
MD5 53dbd593b7c6dbc414342b16940e38d5
BLAKE2b-256 8381f37687b9d44384017c334caf8b12352ffcf4a874010326085a8c15e77f7c

See more details on using hashes here.

Supported by

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