[Gmsh] 2D bitmap files to 3D mesh

Robert Funnell robert.funnell at mcgill.ca
Wed Mar 31 14:44:27 CEST 2010

Fred-Johan -

There is software around that would probably help with what you're 
doing, including commercial software such as Simpleware and the 
Tarantula programme referred to in Bernhard Kubicek's response.

I myself am developing my own suite of software for generating 
surfaces from 3-D image data and then using Gmsh to generate volume 
finite-element meshes. The software is not really ready for prime time 
but you can see some limited documentation at 

My approach involves manual or semi-automatic image segmentation. I 
have not yet worked with fully labelled voxels such as you have, but 
my semi-automatic methods might be able to do something with such 
data. If you're interested, we could discuss this further off-list.

- Robert

On Tue, 30 Mar 2010, Fred-Johan Pettersen wrote:

> Hi,
> I have looked around and found that there is at least two other who tried to do the same as I did [1], that is: read a bunch of images, typically from a CT or similar, where each image represent a slice of a 3D structure, and create a mesh from it.
> I'll describe my case in more detail:
> The 3D (x,y,z) data is in the format of a bunch of 2D(x,y) image files where each file represent a given z-value. Each datapoint in 3D is called a voxel, and the voxel may be one of around 30 different integers. Each integer value represent a material type. Each material type is typicalled lumped together in smaller or larger lumps.
> My dataset has more than 150,000,000 voxels, and is thus a bit on the big side for usage in a FEM-simulator, which is my goal. But the simulator (COMSOL multiphysics) can read Nastran BDF-files, and Gmsh can create such files. So what I want is to read my 2D-files into Gmsh, create a 3D mesh, and then export it to a Nastran file. I might sub-sample the 3D-matrix to produce coarser data, but this doesn' solve my problem by itself. I need a mesh that is rather fine at the surfaces, but the mesh may be much coarser inside the lumps of a given material.
> What I have tried so far, and that didn' work very well was this: I wrote a C-program that reads all my 2D-files,and placed them in a 3D array. I then created STL-files (3D surface mesh), one fle for each material type, which I imported successfully into Gmsh, and then created Nastran files. This approach could have worked fine if it wasn't for the fact that there are holes in the "lumps" filled with other materials, and there are places where, for instance, two cubes of the same material (voxels) shares an edge or even only a vertex in 3D space. This isn' handled very well by Gmsh. The method I tried was this:
> // Read file 1 and create volume.
> Merge "file_1.stl";
> Surface Loop(1) = {1};
> Volume(1) = {1};
> // Mesh settings
> Mesh.Format = 31;
> Since this didn' work, I am hoping that some of you might know of another way to do what I want.
> Regarding the previous postings (se links below), I think the method Gary was asking about was something like this:
> for(z=0; z < number_of_2D_files; z++)
> Read 2D-file.
> Define each area with same value in the 2D-file as a surface (sizes from one pixel to whole file).
> Extrude all surfaces along z-axis.
> This method is fine if it is possible to do (I need more experienced Gmsh users to comment on this), and if it is possible to merge materials of same type one the z-layer below or above so that we reduce the number of volumes.
> I belive that is enough information to understand my problem. Does anybody have a solution?
> Best regards,
> Fred-Johan Pettersen
> [1]:
> http://www.geuz.org/pipermail/gmsh/2006/002055.html
> http://www.geuz.org/pipermail/gmsh/2008/003183.html
> http://www.geuz.org/pipermail/gmsh/2008/003193.html