how to Drawing 3d Voxel data
100 views (last 30 days)
I want to draw voxels in 3d space (I have them stored in a 3d matrix). i used patch to do this (or voxel function from file exchange, draws every face of each voxel). here is my code
%PlotVoxelInput Summary of this function goes here
% Detailed explanation goes here
%file='Lev input/Model 128/bone_model_3061.raw';
[A, count] = fread(fileID);
%set figure parameters
daspect([1 1 1])
%get 3d data
here is voxel function from file exchange
%VOXEL function to draw a 3-D voxel in a 3-D plot
% will draw a voxel at 'start' of size 'size' of color 'color' and
% transparency alpha (1 for opaque, 0 for transparent)
% Default size is 1
% Default color is blue
% Default alpha value is 1
% start is a three element vector [x,y,z]
% size the a three element vector [dx,dy,dz]
% color is a character string to specify color
% (type 'help plot' to see list of valid colors)
% voxel([2 3 4],[1 2 3],'r',0.7);
% axis([0 10 0 10 0 10]);
% Suresh Joel Apr 15,2003
% Updated Feb 25, 2004
disp('Too few arguements for voxel');
l=1; %default length of side of voxel is 1
c='b'; %default color of voxel is blue
disp('Too many arguements for voxel');
x=[i(1)+[0 0 0 0 d(1) d(1) d(1) d(1)]; ...
i(2)+[0 0 d(2) d(2) 0 0 d(2) d(2)]; ...
i(3)+[0 d(3) 0 d(3) 0 d(3) 0 d(3)]]';
The problem is that matlab crashes if i try to plot a 128X128X128 voxel file (only 2Mb). when i say crashes i mean its simply stuck. nothing happens and it seems most of my computer resources are trying to plot this I am pretty sure its not my pc thats the problem (i7, 8Gb RAM, bench results: 0.2806 0.2195 0.1979 0.2687 0.6053 0.6086). anyone know how can i plot these voxels?
Walter Roberson on 4 Dec 2012
See the Faces and Vertices properties of patch() at http://www.mathworks.com/help/matlab/ref/patch_props.html
That is, instead of creating one patch per voxel, create one (or more) patches that has face and vertex information appropriate for a number of voxels. The voxels do not need to be adjacent to each other. You do not need to construct a left-face if the left voxel is set, not create a bottom face if the bottom voxel is set, not create a front face if the voxel in front is set.
It might be a bit much to create a single patch with all of the voxel information. One patch per slice might be better.
Are you sure you want to create all of this at once?? You are using alpha = 1 for all patches, so it is not possible to see through any face to any detail below, so usually for graphics purpose it is only worth creating the voxels that would be on the "outside" from the line of sight. You might want to set all of the "outside" at once so that you can rotate without recalculating. If your thought was to allow zooming in to the object to see interior detail, then instead of calculating everything at once, please consider using the zoom PreAction or PostAction callback to determine what the new coordinates will be, and calculate what will be visible from the new view and create the patches for that. It is perfectly acceptable for zoom (or pan) callbacks to change the graphics object that are visible, adding or removing, so as to provide only the relevant information.
More Answers (3)
Badreddine Alane on 12 May 2019
what im doing exactly is that i I have a matrix(i extracted it from 3d point cloud) with 3 columns (x, y and z coordinates) and 41472 lines. So, each line represents one point in a volume .i want to plot a voxel for this point cloud from this matrix, but i think it's not what i should give as an input for the voxel_impoved.(i have tried to draw a voxel for each point,and also tried it for the fulll matrix ) .it's first time for me working on the voxel form, hope someone will help .