Code Monkey home page Code Monkey logo

marchingcubes.jl's Introduction

License CI PkgEval Coverage Status MarchingCubes Downloads

MarchingCubes

Julia port of Efficient Implementation of Marching Cubes' Cases with Topological Guarantees.

Public article available here.

Implementation

Adapted to Julia (1 based indexing) from the original c++ implementation (0 based indexing).

Tiny benchmark - visualization with ParaView

$ g++ -O3 ply.c main.cpp MarchingCubes.cpp
$ ./a.out
Marching Cubes ran in 0.007834 secs.
$ julia --check-bounds=no
julia> using BenchmarkTools, MarchingCubes
julia> mc = MarchingCubes.scenario();
julia> @btime march($mc)
  7.865 ms (0 allocations: 0 bytes)
julia> @btime march_legacy($mc)
  9.268 ms (0 allocations: 0 bytes)
julia> using PlyIO
julia> MarchingCubes.output(PlyIO, mc)  # writes "test.ply" (can be opened in a viewer, e.g. ParaView)

Test scenario output: ParaView Torus

MWE demonstrating visualization with MeshViz.jl

using MarchingCubes
using GLMakie
using MeshViz
using Meshes

mc = MarchingCubes.scenario()
march(mc)
msh = MarchingCubes.makemesh(Meshes, mc)
display(viz(msh))

Meshviz Mesh

MWE demonstrating visualization with GeometryBasics.jl and Makie.jl

using GeometryBasics
using MarchingCubes
using GLMakie

mc = MarchingCubes.scenario()
march(mc)
msh = MarchingCubes.makemesh(GeometryBasics, mc)

fap = mesh(msh; color = :gray)
display(fap)

Makie Mesh

Original BibTeX

@article{marching_cubes_jgt,
    author = {Thomas Lewiner and Hélio Lopes and Antônio Wilson Vieira and Geovan Tavares},
    title = {Efficient implementation of marching cubes cases with topological guarantees},
    year = {2003},
    month = {december},
    journal = {Journal of Graphics Tools},
    volume = {8},
    number = {2},
    pages = {1--15},
    publisher = {A.K.Peters},
    doi = {10.1080/10867651.2003.10487582},
    url = {\url{http://thomas.lewiner.org/pdfs/marching_cubes_jgt.pdf}}
}

License

This code is free to use under the terms of the MIT license.

marchingcubes.jl's People

Contributors

ickaser avatar nickkeepfer avatar t-bltg avatar timholy avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

marchingcubes.jl's Issues

faces with zero volume in large models

The following is a mesh analysis with SpaceClaim of a mesh generated in C with the LewinerMarchingCubes from NeurolabUSC, modified to accept Int64 and thus large numbers of voxels and arrays instead of NIIFTI:Screenshot 2023-11-26 144911

The listed 'errors' are not actually errors.

However, with MarchingCubes.jl, there are 8514 faces with zero volume, out of 5,421,474 faces:
Screenshot 2023-11-26 145055

I suspect that the 2000 x 2000 x 1995 voxels are hitting an Int32 limit somewhere, or there is a slight error in the LUT's due to the 1-index conversion. I think the latter is more plausible. The source data is 30 GB, so we'd need to arrange some way to transfer this if you are interested in trying to reproduce the result.

Feature request: make mesh more amenable to other Julia datatypes?

One of the reasons I want to use this module is to be able to put together a pure-Julia data pipeline for micro-CT data. To that end, it would be helpful if I could take the mesh generated by this project, and pull it over to Makie.jl or some other Julia plotting software.

It seems to me like it shouldn't be too difficult to modify the code base to use Triangles from GeometryBasics.jl , then make the mesh compatible with Meshes.jl and therefore MeshViz .

I can help with this, I think (although maybe not very fast).

"Invalid triangles" when isosurface value is not 0.0

Something goes wrong with the algorithm when I use a nonzero isosurface value.

Here's my MWE:

using MarchingCubes
xi = [1.0, 2, 3, 4, 5]
dat = [(x-3)^2 + (y-3)^2 + (z-3)^2 for x in xi, y in xi, z in xi]
datsub = dat .- 5.0

m1 = MC(dat)
march(m1, 5.0)

m2 = MC(datsub)
march(m2)

march(m1, 5,0) gives me a lot of warnings about invalid triangles:

┌ Warning: Invalid triangle 6
└ @ MarchingCubes C:\Users\iwheeler\.julia\packages\MarchingCubes\V0hg7\src\MarchingCubes.jl:557
┌ Warning: Invalid triangle 12
└ @ MarchingCubes C:\Users\iwheeler\.julia\packages\MarchingCubes\V0hg7\src\MarchingCubes.jl:557

on up to triangle 128, with many repeats. On the other hand,
march(m2) runs just fine, and when I examine its output with PlyIO and Paraview, it gives me the sphere I expect.

TagBot trigger issue

This issue is used to trigger TagBot; feel free to unsubscribe.

If you haven't already, you should update your TagBot.yml to include issue comment triggers.
Please see this post on Discourse for instructions and more details.

If you'd like for me to do this for you, comment TagBot fix on this issue.
I'll open a PR within a few hours, please be patient!

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.