Coder Social home page Coder Social logo

marchingcubecpp's Introduction

Marching Cube C++

A public domain header-only marching cube implementation in C/C++ without anything fancy. Only dependencies are cmath and vector headers. I could get rid of vector and just use plain arrays, but it is more convenient for my personal projects to keep that way, though one could easily modify the implementation.

This work was motivated by this public domain implementation of the marching cube: https://github.com/nsf/mc which gives a fully runnable example in OpenGL. I thought it could be simplified and could make a good header-only library.

Behaviour

Calling MC::marching_cube will create an indexed mesh with vertices and normals defined in their own std::vector's. By default, data is allocated for vertices, normals and triangle indices. You can change the default allocated space using the function MC::setDefaultArraySizes.

The output mesh represents the zero-isosurface of the input scalar field. Coordinates of the vertices will follow the grid discretization: a 128x128x128 grid will create a mesh embedded in the axis-aligned box from Vec3(0) to Vec3(128).

You can optionally enable double precision by defining MC_CPP_USE_DOUBLE_PRECISION before including the header.

Use

First define MC_CPP_ENABLE and then include MC.h in your project. Example:

#define MC_IMPLEM_ENABLE
#include "MC.h"

int main()
{
	// First compute a scalar field
	const int n = 100;
	MC::MC_FLOAT* field = new MC::MC_FLOAT[n * n * n];
	// [...]
	
	// Compute isosurface using marching cube
	MC::mcMesh mesh;
	MC::marching_cube(field, n, n, n, mesh);

	// Dot whatever you want with the mesh
	// [...]

	return 0;
}

You may find a complete example in main.cpp file. Running the program in the repository will output an obj file showing the isosurface of a single perlin noise octave.

Licence

Double Licence, whatever fits you best: Public domain or MIT License.

marchingcubecpp's People

Contributors

aparis69 avatar quagla avatar oseiskar 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.