Calculating volume from either an STL or Voxel-based file
8 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I have a bunch of part files that were converted to both .stl and voxel-based (.mat) formats. I need to evaluate these parts in terms of volume but am struggling to do so. I would imagine you could just count the number of voxels from the voxelized format but don't know how to go about doing that. The files were converted via this function: https://www.mathworks.com/matlabcentral/fileexchange/27390-mesh-voxelisation
Also being new to voxels I am a little shaky on their format. I have the files voxelized at 100,100,100. Is this the resolution of the part where there is a grid of 100x100x100 that the cubes occupy? Or is the part already gridded off and there are 100 voxels per grid segment?
0 comentarios
Respuestas (1)
DGM
el 8 de Oct. de 2025 a las 22:09
Editada: DGM
el 9 de Oct. de 2025 a las 12:11
If you define the grid inputs as 100 (x3), then you're taking your part (of whatever size) and subdividing it into 100x100x100 parts. Unless you kept the grid output vectors, you lose all the scale information that tells us how big any of the voxels are.
You might be able to go back and find the scale if you have the original models or other information, but it's not clear that it's the best way to do the task. For example, if you used scalar inputs to define a uniform grid in the call to VOXELISE():
% number of grid divisions specified in the call to VOXELISE()
N = [100 100 100]; % [x y z]
% the extents of the bounding box
% (assuming you have the original STL vertices)
mn = min(V,[],1);
mx = max(V,[],1);
% the size and volume of a voxel
voxsize = (mx-mn)./(nx + 0.5)
voxvol = prod(voxsize)
If you defined the grid using one other other supported methods, it would be different.
Otherwise, if you have STL files which form closed surfaces, then you can just calculate their area and volume.
In either case, the units are whatever the units are in the STL. What are the units of an STL? Depends, but millimeters is common. Where is it recorded? It's typically not recorded anywhere in the file. If it is stored in the file, where is it? Somewhere in the header text. There is no convention for how it will be formatted or when it will be present. You have to just look with your eyeballs. The R2018b decoder cannot read the header text, so you'll have to use external software or a third party decoder such as FEX #182013. If it's ASCII STL, you could read it with a text editor. If it's binary, I guess you could also just read it with a good hex editor.
0 comentarios
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!