File Exchange

image thumbnail

Triangular Mesh Refinement

version 1.2.0.0 (9.53 KB) by Dirk-Jan Kroon
This function will refine a triangular mesh with 4-split spline interpolation

21 Downloads

Updated 16 Feb 2010

View License

This function "refinepatch" can refine any triangular mesh surface ( patch) with 4-split spline interpolation, see screenshot.

Literature:
The spline interpolation of the face edges is done by the Opposite Edge Method, described in: "Construction of Smooth Curves and Surfaces from Polyhedral Models" by Leon A. Shirman

How it works:
The tangents (normals) and velocity on the edge points of all edges are calculated. Which are later used for b-spline interpolation when splitting the edges.
A tangent on an 3D line or edge is under defined and can rotate along the line, thus an (virtual) opposite vertex is used to fix the tangent and make it more like a surface normal.
B-spline interpolate a half way vertices between all existing vertices using the velocity and tangent from the edge points. After splitting a new face list is constructed with 4 times as many faces.

Implementation:
Some Matlab files are also available as MEX files to allow quick refinement of large meshes.

Please Leave a comment, if you find a bug, like the code or know improvements.

Comments and Ratings (12)

Ali Afzali

Dear Dirk-Jan,
your code doesn't work!!!!! could you help me to run it?
The error is: make_halfway_vertices (line 42)
select2=vals(index==i);".
Any idea of what it could be?

Thanks in advance

Mohcine

Hey, I have a question if someone can help me
is there is any way to refine just portion (a certain number of faces) only not the complet mesh
Thank you

I need some help.
It generates an error at line 42 of the make_halfway_vertices saying : "
Error in make_halfway_vertices (line 42)
select2=vals(index==i);".
Any idea of what it could be?

I'm using Matlab 2015a

Thnaks Andrea

Marta

Great work yet again, Dirk!

Reynaldo

Dear Dirk-Jan, this code has worked for some .ply files I am using, but there are a handful which are not working in your refinepatch method.

Are there certain criteria that must be met for this to work on a given triangulation?

Specifically I am using Sumner's camel-reference.obj file from the folder "camel poses from Figure 1"
http://people.csail.mit.edu/sumner/research/deftransfer/data.html#download.

The mex file throws an error which causes Matlab to exit. Has anyone else ran into this problem? Maybe the file does not have a certain necessary property for the method? Thanks

-Rey

This is an excellent file that does exactly what it says it does. It worked the first time. I don't know why someone else gave it a bad rating - I think it's perfect as is.

ivan scardanzan

it refines patches as claimed !
and given that
a)matlab does not have a better alternative tool
b) the functionality is important
it deserves a good rating

Duane Hanselman

This code produces pretty pictures, but is poorly documented and poorly written. It needs improvement--thus the reason for a 2=Needs Improvement ranking.

Can the input variables be defined differently?
%[V,F] = Refine_Mesh(V,F)
% The variable V is a list of vertices xyz coordinates
% The variable F is a list of faces described by indices of the vertices.

How do these correspond to MATLAB triangulation function arguments?, e.g., from TRIMESH
%TRIMESH(TRI,X,Y,Z,C) displays the triangles defined in the M-by-3 face matrix TRI as a mesh. A row of TRI contains indexes into the X,Y, and Z vertex vectors to define a single triangular face.

Your code was written using R2007a, but you still use obsolete structure functions getfield and setfield. Why? For example, Eb=getfield(Et,['F' num2str(Pneig(j)) 'T' num2str(i)]);
Perhaps it would be better to not use structures at all? That is, avoid
Et=struct(); % Edge tangents
Vt=struct(); % Edge velocity
The use of structures seems to make the code very cumbersome.

The H1 line is not informative and it would be good to describe the general algorithm in the text file so folks do not have to find the journal article to get the general idea of what is being done.

There is no use of vectorization, but clearly much of this code could be vectorized.

In MATLAB new lines are free, so there is no need to cram multiple MATLAB statements on a single line. Doing so makes it difficult to follow the code and may impede the JIT accelerator.

I am willing to change my rating if the code is revised.

Dirk-Jan Kroon

Oops, i forgot that little function val_even:

function bin=val_even(val)
bin=mod(val,2)==0

hazem wannous

Hello;
To compile your code, i need to the function 'val_even' which is undefined.
can you send me this function.
thanks

Updates

1.2.0.0

Fixed NaN bug in case of all neighbor vertices
Fixed Crash bug in case of vertex not present in face-list.

1.1.0.0

Know also c-code files are available, and mesh no longer have to be closed.

1.0.0.0

Matlab code used an unknown function val_even , to determine even or odd value..

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