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 Version History

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 (35)

Simon Kulozik

Chaging all int to size_t (and compiling, of course) solved to problem for me. However, I am still unsure if this is the most efficient solution...

Simon Kulozik

I am having the same issue as Hans. Which int's should be changed to size_t? All? seems very memory demanding to me (I'm not an expert in c, though).

Hans Dunning

Hi Dirk Jan,

Thanks for this code, has helped me many times!

I recently encountered memory issues around the time I switched to Matlab 2020a (although I don't understand how this could be version related). It was fixed by changing the correct int's into size_t's in the c files. Maybe this could help someone else.

hello, how can i compile C code Matlab? I have an error during the code. Thank

Jan Nabo

Error in smoothpatch (line 55)


Naveen B

thank you sir

Jae Shin Yoon

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

Ahmed Zankoor

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

Ahmed Zankoor

@Giovanni Santantonio
Same for me.

Mehdi Chouchane

Giovanni Santantonio

@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?

Bugra Kaytanli

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

Martin Kefer

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

Phillip Marlow

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.

Alina Bialkowski

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

Alexandra Signoriello

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.

Mohammad Aminpour

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.

Franck n'guyen

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 !



Shengda Wang

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

Shengda Wang

Andrea Rovinelli

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.

Haiyang Wang

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.

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

Inspired: Export Voxel Data

Community Treasure Hunt

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

Start Hunting!