Skip to main content

A collection of algorithms for iso-sufrace extraction on GPU. Supports pytorch.

Project description

isoext: Isosurface Extraction on GPU

PyPI version

Overview

Welcome to isoext — a Python library designed for efficient isosurface extraction, leveraging the power of GPU computing and comes with pytorch support. Our library attempts to implement a collection of classic isosurface extraction algorithms. Currently, only the following algorithms are supported, but more will come in the future:

isoext also comes with a Marching Cubes table generator, which you can use to integrate Marching Cubes into your own project or extend isoext with more algorithms. All the lookup tables we used are generated by the generator.

Installation

To install isoext, make sure CUDA Toolkit is installed and run:

pip install isoext

Quick Start

Here's a simple example to get you started:

import isoext
from isoext.sdf import *

aabb = [-1, -1, -1, 1, 1, 1]
res = 128
grid = isoext.make_grid(aabb, res)

torus_a = TorusSDF(R=0.75, r=0.15)
torus_b = RotationOp(sdf=torus_a, axis=[1, 0, 0], angle=90)
torus_c = RotationOp(sdf=torus_a, axis=[0, 1, 0], angle=90)

sphere_a = SphereSDF(radius=0.75)

sdf = IntersectionOp([
    sphere_a, 
    NegationOp(UnionOp([
        torus_a, torus_b, torus_c
    ]))
])
sdf_v = sdf(grid) # must be a cuda pytorchtensor

isolevel = 0

v, f = isoext.marching_cubes(sdf_v, aabb=aabb, level=isolevel, method="nagae")

isoext.write_obj('test.obj', v, f)

Marching Cubes

Arguments

isoext.marching_cubes accepts the following arguments:

  • grid: A CUDA PyTorch tensor representing the scalar field. It should be a 3D tensor. If cells is provided, grid must be of shape (2N, 2, 2), where N is the number of cells.
  • aabb: (Optional) A list or tuple of 6 floats representing the axis-aligned bounding box [xmin, ymin, zmin, xmax, ymax, zmax]. If provided, cells must not be given.
  • cells: (Optional) A CUDA PyTorch tensor of shape (2N, 2, 2, 3) representing the cell positions. If provided, aabb must not be given.
  • level: (Optional) The isovalue at which to extract the isosurface. Default is 0.0.
  • method: (Optional) The marching cubes algorithm to use. Currently, lorensen and nagae are supported. Default is nagae.

Return Value

The function returns a tuple (vertices, faces):

  • vertices: A CUDA PyTorch tensor of shape (V, 3) representing the vertex positions.
  • faces: A CUDA PyTorch tensor of shape (F, 3) representing the triangular faces.
  • If no faces are found, both vertices and faces will be None.

Marching Cubes Table Generator

You can find the generator in luts/gen_mc_lut.py. Available methods are in luts/mc_methods. For example, to generate the table for lorensen, run:

cd luts
python gen_mc_lut.py mc_methods/lorensen.json output

This will generate the luts and as well as the meshes of all the cases inside the output/lorensen folder.

Task List

  • Fix docstring.
  • Add more Marching Cubes variants.
  • Add Dual Contouring.
  • Add Dual Marching Cubes.

License

isoext is released under the MIT License. Feel free to use it in your projects.

Acknowledgments

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

isoext-0.4.0.tar.gz (24.7 kB view details)

Uploaded Source

File details

Details for the file isoext-0.4.0.tar.gz.

File metadata

  • Download URL: isoext-0.4.0.tar.gz
  • Upload date:
  • Size: 24.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.9.20

File hashes

Hashes for isoext-0.4.0.tar.gz
Algorithm Hash digest
SHA256 e4ed32a346a350da46d2b6fae6de670d6414e107428e82a8f2c9a86ce7d6ab3e
MD5 ce37623c29f8560731aa04cd348f1ed3
BLAKE2b-256 0aea10897b348fc8ec2685877c174e39fef30045f18d19df20057b83aaa4f65f

See more details on using hashes here.

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