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.
Dirk-Jan Kroon (2020). Smooth Triangulated Mesh (https://www.mathworks.com/matlabcentral/fileexchange/26710-smooth-triangulated-mesh), MATLAB Central File Exchange. Retrieved .
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...
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).
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
Error in smoothpatch (line 55)
thank you sir
when I run it, it sometimes exceed the memory limit but sometimes not, do you have any idea on it?
My problem is solved, just recompile ( mex smoothpatch_curvature_double.c -v) after making Phillip's modifications.
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 = mxCreateNumericArray(1, VertexNA, mxDOUBLE_CLASS, mxREAL);
plhs = 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)
Matlab returns the error
Undefined function or variable 'smoothpatch_curvature_double'.
an example input file will be very helpful.
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.
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!
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
Your code is excellent for my test data. Good work
very helpful. Excellent code with great documentation.
Inspired: Export Voxel Data
Find the treasures in MATLAB Central and discover how the community can help you!Start Hunting!