File Exchange

image thumbnail

Smooth Triangulated Mesh

version (9.14 KB) by Dirk-Jan Kroon
Accurate smoothing of triangulated patch / mesh


Updated 26 Mar 2010

View License

This function smooths a triangulated Mesh / Patch.

Supports accurate curvature flow smoothing. Which smooths in the direction of the normal keeping the edge ratio's the same.
Also supports Laplacian smoothing with inverse vertice-distance based umbrella weights, making the edge lengths more uniform.

Can be used to smooth iso-surface meshes, for scale space and simplification of patches.

Mathieu Desbrun et al. "Implicit Faring of Irregular Meshes using Diffusion and Curvature Flow"
Alexander Belyaev. "Curvature Estimation"

The code is written in Matlab and partly in c-code for speed up reasons.

Please leave a comment in case of a bug, like the code, or know a good improvement.

Cite As

Dirk-Jan Kroon (2020). Smooth Triangulated Mesh (, MATLAB Central File Exchange. Retrieved .

Comments and Ratings (31)

Jan Nabo

Error in smoothpatch (line 55)


Naveen B

thank you sir

when I run it, it sometimes exceed the memory limit but sometimes not, do you have any idea on it?

@Giovanni Santantonio
My problem is solved, just recompile ( mex smoothpatch_curvature_double.c -v) after making Phillip's modifications.

@Giovanni Santantonio
Same for me.

@Phillip Marlow, I'm in your same situation. I've tried to fix it using your solution, but it had the only effect to reduce the occurrences of the out of memory exception (it occurs 8 times out of 10). Do you think there are other way to try to fix this error?

This is working miracles. Handles 100k points in seconds! Simple and easy to use with lots of annotations. Thank you so much.

I had to apply Philip Marlow's fix to the c-files, now runs like a charm!

On my system, smooth_curvature_patch_double.c would often throw an out of memory error when generating the output arrays. I'm not sure why this error occurs but I fixed it by replacing:

plhs[0] = mxCreateNumericArray(1, VertexNA, mxDOUBLE_CLASS, mxREAL);


plhs[0] = mxCreateDoubleMatrix(1, VertexN, mxREAL);

Also you don't need create the work arrays called VerticesN2X,VerticesN2Y, and VerticesN2Z . Just create the output arrays before the main loop and refer to the output array (e.g., VerticesOX) wherever you would use the work array (e.g., VerticesN2X).

Thank you Dirk-Jan for sharing your code.

For those with the error "Undefined function or variable 'smoothpatch_curvature_double'.", you first need to compile the 'c' code using mex:
mex smoothpatch_curvature_double.c -v
mex smoothpatch_inversedistance_double.c -v
mex vertex_neighbours_double.c -v

I am trying to run the test code with mri data and I get an dimension mismatch. Has anyone else encountered this problem and have a solution?

Subscripted assignment dimension mismatch.
Error in smoothpatch (line 90)

Luca Amerio

Matlab returns the error
Undefined function or variable 'smoothpatch_curvature_double'.

Paul Zhou

an example input file will be very helpful.

Excellent job


Dear Dr. Dirk-Jan Kroon, in your implementation, when you compute the curvature, you directly used the angle, while in the original literature a cot(angle) function is used. This is actually a decreasing function. Would you like to offer an explanation? Thanks in advance.

perfect !!!

Reza Behkam

Kelvin Chow


Why matlab can't find the smoothpatch_curvature_double.c? Can you tell me
how to patch the C code in Matlab?
I am in a worry to handle this question.Thanks in advance !



Hi, can anyone explain to me why the mean curvature weight is the angle not the cotangent in smoothpatch_curvature_double.c ?

only one word: Awesome!! As a note, just remember to mex the c file included in the package,otherwise it will not work.


I get this error: Undefined function 'smoothpatch_curvature_double' for input arguments of type 'cell'. (Windows 7, ver 2014b). The .c file is path.


Smoothing is excellent and execution is fast.

Question (if anyone is still monitoring?): I find that the result produces an empty gap between the smooth geometry and raw data isocaps. Is there anyway to remedy this? Working with flow domains, I cannot lose the specifics of this geometry.

Thanks and nice work!

Benjamin I

Very useful and very fast. Thanks.

this work is very useful to me.but I don't know how to use it,can you give a me a example?thank you

dai zhengguo

Your code is excellent for my test data. Good work

Siyi Deng

very helpful. Excellent code with great documentation.


Comments "\\" to "\* *\". Now the code works with the Linux Gcc compiler.

MATLAB Release Compatibility
Created with R2009b
Compatible with any release
Platform Compatibility
Windows macOS Linux

Inspired: Export Voxel Data