QUIMICOMP Facyt - UC

C and C++ libraries of Marching Cubes 33

Last updated: September 27, 2023


This page contains information about the Marching Cubes 33 library in C language, developed in our laboratory, and its adaptation to C++ language. The libraries has been compiled with GCC in macOS and Linux, with MinGW / MinGW-w64 and Microsoft Visual C++ in Windows.
The MC33 and MC33++ libraries can be used and distributed under the terms of the MIT license, described in the "LICENSE.txt" file that is included in the compressed folder of the source code.

Download latest versions:

C++ language, v5.2


C language, v5.3


SOURCEFORGE

GitHub


SOURCEFORGE

GitHub



September 2023
Version 5.3 of the MC33 library in C language.
Fixed issues that arise when modifying build options.

March 2022
Version 5.2 of the MC33 library in C language and version 5.2 of the MC33 library in C++ language.
The codes of both libraries were cleaned. Minor fixes were made. Now the libraries are also available on Github.

December 2021
Version 5.1 of the MC33 library in C language and version 5.1 of the MC33 library in C++ language.
Corrected the transformation of the normals in both libraries. This error caused the normals to be calculated incorrectly when the spacing of the grid points is different in different dimensions.
Added the function generate_grid_from_fn to create grids from a function double f(double x, double y, double z). This facilitates the creation of implicit surfaces, such as those shown in the screenshots image of the example using the GLUT library.

Implicit surfaces

C library:
This library will now be compiled in C (not C++), but it is still possible to include the code directly and compile it in C++. All C++ instructions in the example using the GLUT library have been changed to C language.

C++ library:
Added functions to interpolate the grid value at any xyz point within the grid boundaries. Trilinear and tricubic interpolation have been added so far.

More information is available in README.md file of each library.

August 2021
Important fixes to the MC33 libraries in C and C++ language.

Version 5.0 of the MC33 library in C language:
●The lookup table was modified to reduce the code size of the MC33_FindCase function. ●Code causing repeated vertices and zero-area triangles was corrected. ●Added a second example that uses the GLUT library instead of FLTK. ●An error in the determination of the triangulation pattern for case 13 has been corrected (this error has been present since the third version).

Version 5.0 of the MC33 library in C++ language:
●The lookup table was modified to reduce the code size of the MC33::find_case function. ●Code causing repeated vertices and zero-area triangles was corrected. ●Subgrid creation has been added to the grid3d class. Subgrids are created by assigning pointers to the original grid data, without duplicating the data. This new feature can be used to create lower resolution grids and split the original grid. ●Subgrid handling was added to the FLTK example. ●A function that reverses the normals and another that reverses the order of the vertices of the triangles have been added to the surface class. ●An error in the determination of the triangulation pattern for case 13 has been corrected (this error has been present since the third version). ●The MC33::size_of_isosurface function was fixed. Now it calculates the correct isosurface size when the vertex data type is double.
flower low res flower half
bunny subgrid present subgrid

June 2021
Version 4.1 of the MC33 library in C++ language. Minor modifications in the header file and in the grid3d code. These issues do not affect the performance of the library. The FLTK example has been improved, it is now possible to delete surfaces from memory. Also a new example using GLUT instead of FLTK has been added.
To show the capabilities of the library, The huge "flower" and "beechnut" datasets were used. The datasets were downloaded from the Research Datasets page of the Visualization and Multimedia Lab of the University of Zürich.
The following images are screenshots of the FLTK example program compiled with MSYS2 - MinGW-w64, running in Windows 10 64-bit operating system. The first image corresponds to the  flower dataset , the program was executed in a laptop with Intel® Core™ i5-1035G1 CPU @ 1.00GHz and 8GB RAM. The memory occupied by the isosurface is 386 MiB. The second image corresponds to the  beechnut dataset , the program was executed in a desktop with AMD Ryzen™ 3 3100 4-Core Processor @ 3.6GHz, 16GB RAM and AMD Radeon RX 580 Series Graphics Card with 8GB video memory. The memory occupied by the isosurface is 2.67 GiB.
flower dataset beechnut dataset

April 2021
New version of the MC33 library in C++ language. The efficiency was increased. Now the isosurface is calculated in a different way, it is no longer necessary to use a pointer to a surface object (thanks to Julien Hess for the suggestion):
        grid3D G;
        G.read_dat_file("filename.dat");
        MC33 MC;
        MC.set_grid3d(G);
        .
        .
        .
        surface S;
        MC.calculate_isosurface(S, isovalue);

Also added a MC33 class member function that calculates the surface size (only the size, does not build the surface).
And I thank Miguel Díaz (IVIC doctoral student) for correcting an error in the modelview matrix of the gl_window class in the example program (TestMC33.cpp).

October 2020
The MC33++ v3.0 library has a bug that affects the shape of the surface at the –x edge of the grid.
The line 477 of MC33.cpp file:
        p[1] = surfint(0,y + 1,0,r);
has to be changed by:
        p[1] = surfint(0,y + 1,z,r);
to fix this bug.

August 2020
This new version corrects the appearance of repeated vertices on the isosurfaces, which arise when the isovalue is equal to some of the values of the points on the grid. Special care was taken to treat the edges of the grid. The code was extensively tested. I appreciate the help of Julien Hess (Consultant of MATHICSE – Group) for reporting library defects and providing the grids where those defects occurred. Due to suggestions from Julien Hess, the new version of the MC33++ library has additional functions belonging to the grid3d class, which allow the modification and filling of the grid3d object (the grid) without the need to read the data from a file. And the discrepancy of the numeric type of the members of the grid3d and MC33 classes was corrected (Now you can use double type for members of MC33 class).

July 2020
I had decided not to release another version of the MC33 library in C language, but due to a mistake in final 2 version, I had to release final 3 version. I used some tricks to increase the speed in calculating the isosurface.

March 2020
Two new versions were added: MC33++ v2.0 and MC33 v final 2. The processing time of these versions is a bit greater than that of MC33 paper. The great advantage of these new versions is that the format of the surface structure was changed. A single array / vector is used for each type of data: indices, coordinates, normals and colors. It is now possible to use the OpenGL glDrawElements function. The efficiency of drawing the surface increased significantly. The routines that display the surface are included in the MC33.h file in the include folder of the C++ version, and also in the testMC33.cpp file in the example folder of the C version


Download links

Li braryDescriptionRe lease dateSource code
MC33 ++ v5.2
Marching Cubes 33 library in C++ language
Minor modifications.

Mar 2022source forge. net

github.com
MC33 v5.2
Marching Cubes 33 library in C language
Minor modifications.

Mar 2022source forge. net

github.com
MC33 ++ v5.1Marching Cubes 33 library in C++ language
Fixed transformation of normals. The generate_grid_from_fn function was added (to the grid3d class) to create grids from a function f(x,y,z). Added functions to interpolate the grid value within the grid boundaries.
Dec 2021source forge. net
MC33 v5.1Marching Cubes 33 library in C language
Fixed transformation of normals. The generate_grid_from_fn function was added to create grids from a function f(x,y,z). Now, by default, the library is compiled in C (not C++) and the example using the GLUT library is in C language.
Dec 2021source forge. net
MC33 ++ v5.0Major modification of the Marching Cubes 33 library in C++ language. Code causing repeated vertices and zero-area triangles was corrected. Subgrid creation has been added to the grid3d class. An error in the determination of the triangulation pattern for case 13 has been corrected.Aug 2021source forge. net
MC33 v5.0Major modification of the Marching Cubes 33 library in C language. Code causing repeated vertices and zero-area triangles was corrected. Added a second example that uses the GLUT library instead of FLTK. An error in the determination of the triangulation pattern for case 13 has been corrected.Aug 2021source forge. net
MC33 ++ v4.1Marching Cubes 33 library in C++ language. MC33_VERSION_MAJOR and MC33_VERSION_MINOR identifiers were added to the header file. The static library compilation error related to the size_t data type was fixed. Minor modifications were made to the grid3d class code. The FLTK example code was improved and a new example code that uses the GLUT library was added.Jun 2021source forge. net
MC33 ++ v4.0Marching Cubes 33 library in C++ language. The way to calculate the isosurface has been changed. Added a MC33 class member function that calculates the surface size. The fast inverse square root is no longer used. Added use of the Intel® SSE approximate reciprocal square root (_mm_rsqrt_ss). The code of the FLTK example program (TestMC33.cpp) was modified and a sign error in the modelview matrix of gl_window class was corrected.Apr 2021source forge. net
MC33 ++ v3.0Major modification of the Marching Cubes 33 library in C++ language. The isosurface no longer contains duplicate vertices. The numeric type of the MC33 class members can be chosen (between float or double) before compiling the library. There are new functions in the grid3d class to assign the data and parameters of the grids.Aug 2020source forge. net
MC33 v4Major modification of the Marching Cubes 33 library in C language. The isosurface no longer contains duplicate vertices.Aug 2020source forge. net
MC33 ++ v2.1Minor modification of the second version of the Marching Cubes 33 library in C++ language.
Unused #define have been removed. The speed in the calculation of the isosurfaces was slightly increased.
Jul 2020source forge. net
MC33 v final 3Another final version of the Marching Cubes 33 library in C language.
This version fixes a big mistake in version 2: In the free _surface _memory function the memory occupied by the vertex array is not freed. The speed in the calculation of the isosurfaces was also slightly increased.
Jul 2020source forge. net
MC33 ++ v2.0Second version of the Marching Cubes 33 library in C++ language.
The structure surface of this library now uses vectors to store the data. It is less efficient in calculating the isosurface, but it is much more efficient in drawing it.
Feb 2020source forge. net
MC33 v final 2Another final version of the Marching Cubes 33 library in C language.
The structure surface of this library now uses single arrays to store the data, and all global variables were moved to a structure. See README.TXT file for more details. It is less efficient in calculating the isosurface, but it is much more efficient in drawing it.
Feb 2020source forge. net
MC33 ++ v1.0First version of the Marching Cubes 33 library in C++ language, adapted from the library MC33 v final.
The Solution File to compile the library with Visual Studio community 2017, and an example that uses this library, are included.
This library still uses malloc and realloc for memory allocation of the isosurface and the 3D grid.
Aug 2019source forge. net
MC33 v finalFinal version of the Marching Cubes 33 library in C language.
The code of this library is more efficient and was obtained by slightly modifying the library code described in the paper:
A Fast and Memory-Saving Marching Cubes 33 Implementation with the correct interior test
This C library compiled with visual C++ did not behave correctly. Compiling it as a C++ code (/TP option) fixed the problem.
An example in C++ that uses this library was added.
Aug 2019source forge. net
MC33 paperVersion described in the paper mentioned aboveJun 2018jcgt.org
source forge. net
Old versionFirst version published on the Internet of the Marching Cubes 33 library in C language. This is an outdated version, with some bugs.Sep 2012facyt. uc. edu. ve
source forge. net

⨳ The example also needs the FLTK library.



The following table compares the processing speed of the libraries, using 4 datasets. The tests were performed on a laptop with an Intel® Core™ i3-2350M CPU @ 2.30 GHz (4 GiB RAM). The test codes were compiled with g++ of MinGW-w64 GCC in Windows 7 64-bit operating system. Aggressive optimization compiler options -Ofast and -funroll-loops were used. The calculation time of the MC33 paper version was taken as a reference.

Performance comparison

Li braryDataset
bunnyCT headstag beetlepre sent
MC33 ++ v4.01.107
V: 1705393
T: 3403472
1.139
V: 271473
T: 543293
1.064
V: 3774434
T: 7558326
1.126
V: 3261696
T: 6486287
MC33 ++ v3.00.991
V: 1705393
T: 3403472
0.916
V: 271473
T: 543293
0.982
V: 3774434
T: 7558326
0.958
V: 3261696
T: 6486287
MC33 v41.035
V: 1705393
T: 3403472
0.933
V: 271473
T: 543293
1.039
V: 3774434
T: 7558326
0.990
V: 3261696
T: 6486287
MC33 ++ v2.11.001
V: 1705560
T: 3403806
0.935
V: 271554
T: 543444
0.995
V: 3777215
T: 7563816
0.979
V: 3263395
T: 6489335
MC33 v final 31.065
V: 1705560
T: 3403806
0.959
V: 271554
T: 543444
1.077
V: 3777215
T: 7563816
1.023
V: 3263395
T: 6489335
MC33 ++ v2.00.975
V: 1705560
T: 3403806
0.920
V: 271554
T: 543444
0.982
V: 3777215
T: 7563816
0.960
V: 3263395
T: 6489335
MC33 v final 20.957
V: 1705560
T: 3403806
0.901
V: 271554
T: 543444
0.978
V: 3777215
T: 7563816
0.891
V: 3263395
T: 6489335
MC33 ++ v1.01.093
V: 1705560
T: 3403806
1.058
V: 271553
T: 543438
1.061
V: 3777215
T: 7563816
1.040
V: 3263382
T: 6489250
MC33 v final1.128
V: 1705560
T: 3403806
1.087
V: 271553
T: 543438
1.091
V: 3777215
T: 7563816
1.063
V: 3263382
T: 6489250
MC33 paper1.000
V: 1705560
T: 3403806
1.000
V: 271553
T: 543438
1.000
V: 3777215
T: 7563816
1.000
V: 3263382
T: 6489250
Old version0.688
V: 1705560
T: 3403806
0.634
V: 333004
T: 666523
0.638
V: 3777215
T: 7563924
0.706
V: 3263380
T: 6489535

The bunny (512×512×361) and CThead (256×256×113) datasets were read using the read_scanfiles function and the isovalue used in the tests was 1500. The stagbeetle (832×832×494) and present (492×492×442) datasets were read using the read_dat_file function and the isovalue used in the tests was 500.

The comparison of the processing speed with other libraries not developed in our laboratory is found in the paper:
Vega, D., Abache, J., Coll, D., A Fast and Memory-Saving Marching Cubes 33 Implementation with the correct interior test, Journal of Computer Graphics Techniques (JCGT), vol. 8, no. 3, 1-18, 2019



The Solution File to compile the library with Visual Studio and the Makefile to compile with GCC (on Linux, macOS or msys2/MinGW) were included in the source code for most versions of both libraries. A C++ example of the use of each library was also included. To compile this example, it is necessary install the FLTK library. The Makefiles are also included to compile the example with msys2/MinGW and Debian/GCC. Screen shots of the example compiled in Windows are shown below.

bunny dataset present dataset

CTHead dataset stagbeetle dataset

bonsai raw dataset engine raw dataset

If you find any error in the codes or have difficulty compiling the library and the example, please write to:
dvega@uc.edu.ve or dvega68@yahoo.com