Generating voxels for stl files

Hi All,
I have a stl file of the surfaces of some complex geometries. The stl file contains the coordinates for the vertices on the surfaces of the geometries. However, I am now interested in filling the volume of each geometries with vertices so that the bigger the gometry is, the higher amount of vertices it should get.
Till now, the only idea that came to my mind is to mesh the stl files with volume elements and then extract the centroid of each volume elements. This way I can fill each geometries with specific number of vertices based on their volumes. However, since the geometries are highly complex, this process, meshing them with CAE software, can be very time consuming. I am now wondering if there is a function in matlab that can fill the volume of each geometry with a network of vertices so that the bigger geometries have more vertices in them compared to the smaller ones.
I will be really thankful if someone can help me with this problem.
Many thanks in advance,

2 Comments

Can you show sample geomtry?
Hi Darova,
Sure. Attached is the sample geometry. Please consider that there are many of these small geometries in the final file.
Best,
M

Sign in to comment.

Answers (2)

darova
darova on 13 May 2020
First you need to separate each region of interest (try clusterdata or kmeans)
Once you separate each blob generate pointcloud
Use alphaShape with inShape option to identificate points inside

4 Comments

Thank you so much for your help.
I will give it a try and will let you know if it works.
Best,
M
Hi darova,
Thanks for letting me know about this very genius method.
I followed your instructions but there is a problem with the run time.
What I did was actually to fill a cubic volume space around each geometries with points and then try to determine which of them are located inside the alphashape using inShape command.
The dimensions of this cubic volume is determined by the minimum and maximum coordinates of each geometry in each directions (X,Y and Z).
In some cases this can create an unnecessary huge number of points that can increase the run time exceedingly specially when the geometry looks like a curved disc. Is there any way to fill a more limited space around the geometries rather than considering the cubic volume?
Thanks.
What abou this?
clc,clear
ff = stlread('sample.stl');
ind = clusterdata(ff.vertices,10); % group data in 10 regions
cmap = rand(10,3); % generate 10 random colors
cla
f1 = ind(ff.faces); % find faces of groups
ff1.vertices = ff.vertices;
for i = 1:10
ix = find(f1(:,1)==i); % find group
ff1.faces = ff.faces(ix,:); % faces of group
ff1.facecolor= rand(1,3); % random color
patch(ff1) % display region
end
axis vis3d
result
Do you the number of separate regions?
Thanks a lot for your help. I need to give it a try. Will let you know if it works. By the way, it seems a brilliant idea!

Sign in to comment.

Asked:

on 13 May 2020

Answered:

DGM
on 5 Apr 2025

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!