# Creating a mesh from .nrrd file using marching cube

Hello, I am trying to create a 3D mesh for my application. For this, I am reading the .nrrd files which contain the information about the segmentation and want to create a 3D model from these .nrrd files. I read about marching cubes algorithm, but I am not sure as to how to get from loading and reading the .nrrd file to using Marching cubes to reconstruct the model.

I could use a brief explanation as to how to reconstruct the model from segmentations (.nrrd files). Any example will also help. Thanks.

Hi! VTK has a huge examples website which can be good for learning about all sorts of operations.

Hereâ€™s the MarchingCubes one you will probably be interested in: C++ or Python

You will also probably need to switch to a vtkNrrdReader instead of the one used in this example.

1 Like

Thanks Andrew, I was able to reconstruct a model. But, I wasnâ€™t able to understand how does the values of a segmentation get read by the algorithm as the input. To illustrate the difference :
When I use the segmentation as visualized in 3D slicer the corresponding result of the algorithm is

whereas when I visualize the volume as visualized in the 3D slicer the corresponding result is

I understand there must be some parameters that need to be changed and maybe thereâ€™s a little bit of preprocessing of the images that need to be done.

Iâ€™d really appreciate if you could point me towards reading material as to how these parameters should be manipulated to get the desired results of rendering volumes from segmentation.

The parameter in MarchingCubes is often called the IsoValue. If you have, say a binary image of values only 0 and 1. Then when you have an IsoValue of 0.5. Then the surface halfway inbetween the two will be extracted.

If your image is composed of values say 0 through 1000 with a lot of detail in it. Maybe 0 is air. 500 is some tissue, 800 is bone. Then to pick out only the bone. You could use isovalue 800. Or an isovalue just before it.

In that example â€śiso->SetValue(0, 1150);â€ť is setting the isovalue to 1150. Anything above 1150 is considered â€śinsideâ€ť, anything below 1150 is considered â€śoutsideâ€ť. So, of course if you try to use isovalue 1150 on an image only composed of values 0â€™s and 1â€™s you will get nothing as everything is considered outside (below) 1150.

Hereâ€™s one of the many nice videos online about MarchingCubes if you want all the details: Coding Adventure: Marching Cubes - YouTube

2 Likes

Thanks Andrew, this was really helpful.