Git Product home page Git Product logo

marching_cubes's Introduction

Marching cubes implementation for the volumina 3D viewer

Build status Build Status

Creates a 3D iso surface from a 3D volume.

Release Notes:

0.3:

  • fixed fortran order expectation (#26) Note: previously data was expected in fortran order. A workaround was to supply volume.T with C-order data to march. This should not be done anymore. march works with C- and F-order data now.

0.2:

  • fixed number of smoothing rounds off by one error (#23) Note: in order to get consistent results with older versions, you'll have to decrement the number of smoothing rounds by 1. So instead of e.g. march(volume, 4), go for march(volume, 3).

Why not these?

  • skimage
    1. too slow (factor 10 - 20)
    2. incorrect normals (shading looks ugly)
  • vtk
    1. huge dependency
    2. does not support python3.x

Example usage

Mesh generation:

from marching_cubes import march
from numpy import load

volume = load("test/data/input/sample.npy")  # 128x128x128 uint8 volume

# extract the mesh where the values are larger than or equal to 1
# everything else is ignored
vertices, normals, faces = march(volume, 0)  # zero smoothing rounds
smooth_vertices, smooth_normals, faces = march(volume, 3)  # 3 smoothing rounds

# mesh statistics:
# 82464  vertices
# 82464  normals
# 165048 faces(triangles)
# duration:  0.158s
# smoothing: +0.254s
# [CPU: AMD A8-4500M 1.9 GHz]

Displaying:

from pyqtgraph.opengl import GLViewWidget, MeshData
from pyqtgraph.opengl.items.GLMeshItem import GLMeshItem

from PyQt4.QtGui import QApplication

app = QApplication([])
view = GLViewWidget()

mesh = MeshData(vertices / 100, faces)  # scale down - because camera is at a fixed position 
# or mesh = MeshData(smooth_vertices / 100, faces)
mesh._vertexNormals = normals
# or mesh._vertexNormals = smooth_normals

item = GLMeshItem(meshdata=mesh, color=[1, 0, 0, 1], shader="normalColor")

view.addItem(item)
view.show()
app.exec_()

Example images

No smoothing

no smoothing

3 smoothing rounds

3 smoothing rounds

This library is work in progress

Todo:

  • repair workaround for volumes with different shapes

marching_cubes's People

Contributors

derthorsten avatar fynnbe avatar k-dominik avatar nielsbuwen avatar stuarteberg avatar

Stargazers

 avatar

Watchers

 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.