Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

3D voxel Display in matlab

Tags:

matlab

voxel

I have a grid, it is 3D and it stores a number.

Here is an example of my grid if it is 2*2*2:

(:, :, 1) -> [0, 0;
              0, 0]
(:, :, 2) -> [0, 0;
              0, 0]

The number 0 would usually be a number that I would like to represent with colour or nan if no voxel exists there. What i would like to do is display a voxel grid with matlab like in the following picture:

enter image description here

Except that the vocels should be coloured with the number in the cell.

Does anyone know how to do this, if there is a library or some way to write it myself?

like image 900
Fantastic Mr Fox Avatar asked Jul 25 '12 03:07

Fantastic Mr Fox


1 Answers

So I found out you can do it like this:

for x = 1:GridSize(1)
    for y = 1:GridSize(2)
        for z = 1:GridSize(3)

            if (~isnan(VoxelGrid(x, y, z)))

                cubeLength = VoxelGrid.resolution;

                plotcube(   [cubeLength cubeLength cubeLength], ...
                            [x, y, z], ...
                            0.9, ...
                            [colour, colour, colour])
             end
         end
     end
 end

This will print out a grey scale voxel representation like this:

enter image description here

Now i just need some help getting the colour working.

like image 116
Fantastic Mr Fox Avatar answered Sep 25 '22 13:09

Fantastic Mr Fox