MATLAB Answers

0

how to divide a 3D figure in matlab in to cubes and getting the cubes's addresses

Asked by nasim mirzavand on 15 Jul 2019
Latest activity Answered by Walter Roberson
on 16 Jul 2019
Hi,
I need to write a code to divide a 3D figure in matlab in to cubes and getting the cubes's addresses, who can help me in this regard?
Best

  14 Comments

fill3 creates patch objects. With a bit of preprocessing for efficiency, the Face and Vertex properties could be extracted and used as input to the github code.
Thanks for your helps, would you mind please let me know how can I extract them , is there any kind of prewritten code for that purpose.
What is the purpose of that find() call?

Sign in to comment.

2 Answers

Answer by KSSV
on 16 Jul 2019

You can draw cubes by providing vertices and have index for each cube.

  0 Comments

Sign in to comment.


Answer by Walter Roberson
on 16 Jul 2019

% Step 1: Open the regions of interest file
B= dicominfo('C:\Users\mij\Music\RS.1.3.6.1.4.1.2452.6.3144839235.1145246484.2165573795.1001182548.dcm');
% Step 2: Start display
figure(1);
clf;
hold on;
% Step 3: Load number of regions of interest
roi = fieldnames(B.ROIContourSequence);
nroi= size(roi,1);
roi_cell = cell(nroi, 1);
% Step 4: Loop over all regions of interest
for i=1:nroi
% Step 4.1: Read the color of region of interest i
color=(B.ROIContourSequence.(roi{i}).ROIDisplayColor)/255;
% Step 4.2: Read the number of slices for region of interest i
slices=fieldnames(B.ROIContourSequence.(roi{i}).ContourSequence);
nslices=size(slices,1);
patches_info_cell = cell(nslices, 3);
% Step 4.3: Run over all the slices
for j=1:nslices
% Step 4.3.1: Find the number of points and their coordinates in
% the current slice
npoints=B.ROIContourSequence.(roi{i}).ContourSequence.(slices{j}).NumberOfContourPoints;
points=B.ROIContourSequence.(roi{i}).ContourSequence.(slices{j}).ContourData;
% Step 4.3.2: Convert single vector into 3D vector
x=points(1:3:3*npoints);
y=points(2:3:3*npoints);
z=points(3:3:3*npoints);
% Step 4.3.3: Plot the curve
H = fill3([x',x(1)],[y',y(1)],[z',z(1)],'r');
set(H,'FaceColor',color)
axis off ;
patches_info_cell(j,:) = {length(H.Faces), H.Faces, H.Vertices};
end
roi_cell{i} = patches_cell;
end
all_roi = vertcat(roi_cell{:});
At this point, if I have written the code correctly, then all_roi will be a something-by-3 cell array of information about contours for slices. Column 1 of the cell will be a scalar indicating the number of vertices, N, in the line. Column 2 of the cell will contain a row vector of face information, and it appears likely that it will be 1 : number of vertices, but if there are duplicate points in your contours that might not hold. Column 3 of the cell will contain an N x 3 2D array of vertex locations.
In preparing the vertex information for the github function, you should unique-ify the vertex coordinates as failure to do so could prevent some of the loops from closing properly; you will need to keep track of the original order (third output of unique)
You cannot just slam all of the face information together into one face array
  1. You need to renumber from local vertex numbers to over-all vertex numbers
  2. The number of vertices might not be the same for all faces. To create a proper face array in which each row describes one face, the shorter arrays must be padded with nan. The length information I stored saves some post-processing to find that information in order to figure out how wide the final face array will have to be.

  0 Comments

Sign in to comment.