Giter VIP home page Giter VIP logo

pymcubes's Introduction

PyMCubes

PyMCubes is an implementation of the marching cubes algorithm to extract isosurfaces from volumetric data. The volumetric data can be given as a three-dimensional NumPy array or as a Python function f(x, y, z). The first option is much faster, but it requires more memory and becomes unfeasible for very large volumes.

PyMCubes also provides a function to export the results of the marching cubes as COLLADA (.dae) files. This requires the PyCollada library.

Installation

Just as any standard Python package, clone or download the project and run:

$ cd path/to/PyMCubes
$ python setup.py build
$ python setup.py install

If you do not have write permission on the directory of Python packages, install with the --user option:

$ python setup.py install --user

Example

The following example creates a data volume with spherical isosurfaces and extracts one of them (i.e., a sphere) with PyMCubes. The result is exported as sphere.dae:

>>> import numpy as np
>>> import mcubes

# Create a data volume (30 x 30 x 30)
>>> X, Y, Z = np.mgrid[:30, :30, :30]
>>> u = (X-15)**2 + (Y-15)**2 + (Z-15)**2 - 8**2

# Extract the 0-isosurface
>>> vertices, triangles = mcubes.marching_cubes(u, 0)

# Export the result to sphere.dae
>>> mcubes.export_mesh(vertices, triangles, "sphere.dae", "MySphere")

The second example is very similar to the first one, but it uses a function to represent the volume instead of a NumPy array:

>>> import numpy as np
>>> import mcubes

# Create the volume
>>> f = lambda x, y, z: x**2 + y**2 + z**2

# Extract the 16-isosurface
>>> vertices, triangles = mcubes.marching_cubes_func((-10,-10,-10), (10,10,10),
... 100, 100, 100, f, 16)

# Export the result to sphere2.dae
>>> mcubes.export_mesh(vertices, triangles, "sphere2.dae", "MySphere")

pymcubes's People

Contributors

j6k4m8 avatar pmneila avatar zebastian avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.