File Exchange

image thumbnail

Polygon2Voxel

version 1.7 (16.4 KB) by

Convert a triangulated mesh into a voxel volume

22 Downloads

Updated

View License

This function polygon2function will convert a Triangulated Mesh into a Voxel Volume which will contain the discretized mesh.

Discretization of a polygon is done by splitting the polygon in smaller polygons, until the longest edge is smaller than 0.5 voxel, then the voxel beneath the vertice coordinates is set to one.

The function is fast because the main function is implemented in c-code /mex file (takes seconds on a core 2 duo with function compiled by Microsoft Visual Studio 2008.).

Try the example.

Bugs, successes and other comments are welcome!

Comments and Ratings (14)

As Stefan Roth pointed out, there is a problem on UNIX platforms. I had the same problem when trying to compile under ubuntu 11.10. Adding the macros indeed helps.

Stefan Roth

Great job thanks!

On Mac OS compyling the mex file leads to undefined symbol errors.

Adding the macros helps:

#define min(X,Y) ((X) < (Y) ? (X) : (Y))
#define max(X,Y) ((X) > (Y) ? (X) : (Y))

Dirk-Jan Kroon

Dirk-Jan Kroon (view profile)

*leo,
Only integer volume sizes are supported

leo

leo (view profile)

please check some kind of limitation.

I test a FV data,the data is from real CT images,so the range of object's x,y,z coordinate is about: 140:230 ,90:170, 725:820 , but in your code, I can not set the real range,only use [100 100 100], after test 'none','auto','center'.
only in 'auto', I can see the medical structure in the top left corner, but the structure is scaled down and original details can not be restored.

wall

wall (view profile)

GREAT

Dirk-Jan Kroon

Dirk-Jan Kroon (view profile)

*Rigo Trosendo
Thanks you for your comment. The code is basic, thus not based on any publications.

Great Job, Exactly what I needed. Is you algorithm based on any publication(s)?
Thanks

Yuanming Suo

Great tool. Just solve my need. Well documented.

Dirk-Jan Kroon

Dirk-Jan Kroon (view profile)

*Siyi Deng
I have updated the code today with an new version which outputs a logical volume.

Siyi Deng

Siyi Deng (view profile)

THis is indeed fantastic, however I would suggest to change the output Volume from datatype double to uint8 in c file and eventually to logical in m file; this will save lots of memory and make it faster, especially when volumeSize is large;

Incredible performance! Very good

Siyi Deng

Siyi Deng (view profile)

very helpful. Good job.

Updates

1.7

Function now also working without compiling c-code

1.6

Added boundary options

1.5

Now first index volume is 1,1,1 instead of 0,0,0, and YXZ dimensions as in Matlab convention (Thanks Yuanming SUO).

1.4

Changed output to Logicals instead of Double datatype

1.3

Small Bug fixed, for the case if all vertices are outside the volume. Only not draw the face if they are outside at the same side of the volume.

1.2

Linux Ubuntu Tested

1.1

Added center and resize options

MATLAB Release
MATLAB 7.8 (R2009a)

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video