Search code examples
gnuplotvoxel

Visualizing a voxelization using gnuplot


I need to visualize a voxelization using gnuplot.

Each voxel is of the form:

x y z [active] where [active] can be either a 1 or a 0.

The x,y,z is the relative position in a grid, so they're just integers.

An example might be:

0 0 0 1
1 0 0 1
2 0 0 0
...
32 15 20 1
33 15 20 0
34 15 20 1

This seems like it would simplify down to being a 3D Plot with color, similar to this question.

However, I can't use it verbatim, as there are a couple significant differences. The most significant is that my points don't inherently have any connectivity to them, because they're voxels and not points. So drawing it as a sheet as they showed wouldn't work:

enter image description here

Drawing cubes at each point would be great, but I have a feeling that's more complicated than it's worth. Is there any fairly easy way to get a drawing that might get somewhat close? Even if it's just points in 3D, that might be good enough if they're distinct.


Solution

  • 3D points colored by value in column 4 using a smooth color palette:

      splot "data.dat" using 1:2:3:4 with points lc palette
    

    3D points colored by value in column 4 using integer linetypes. In your case the expected values are 0/1 so we bump that up by 1 to use linetypes 1 and 2:

      splot "data.dat" using 1:2:3:($4 + 1) with points lc variable
    

    I don't understand what you mean by "drawing cubes at each point". You can choose the point symbols by specifying a point type (shorthand "pt") and point size (shorthand {ps"). Here we use large solid squares

     splot "data.dat" using 1:2:3($4 + 1) with point lc variable pt 5 ps 3
    

    Additional comment If your points lie mostly on a plane or other smooth surface as implied by the figure you show, then you may be able to derive and plot that surface itself rather than plotting individual points. It is not clear whether the 0/1 attribute corresponds to points that are on/off that surface. If so you should select only the appropriate subset of points to derive the surface. Various algorithms can be chosen to derive the surface, I won't try to summarize here but see the gnuplot documentation for set dgrid3d. This rendering mode would probably make 3D interaction more responsive for large data sets, but it is not clear to me how to combine it with visualization of the localization of your 0/1 point subsets. I would need to know more about the properties and significance of your column values. The following command sequence selects the subset of points with 4th column value zero and plots them as a surface.

    set dgrid3d
    splot "data.dat" using ($4==0 ? $1 : NaN):2:3 with lines