File Exchange

Triangular Mesh Refinement

version 1.2.0.0 (9.53 KB) by Dirk-Jan Kroon

Dirk-Jan Kroon (view profile)

This function will refine a triangular mesh with 4-split spline interpolation

Updated 16 Feb 2010

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.

Cite As

Dirk-Jan Kroon (2020). Triangular Mesh Refinement (https://www.mathworks.com/matlabcentral/fileexchange/16215-triangular-mesh-refinement), MATLAB Central File Exchange. Retrieved .

Ali Afzali

Ali Afzali (view profile)

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?

Mohcine

Mohcine (view profile)

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

Andrea Rovinelli

Andrea Rovinelli (view profile)

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

Marta (view profile)

Great work yet again, Dirk!

Reynaldo

Reynaldo (view profile)

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"

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

Thomas-Glyn Cox

Edward Bender

Edward Bender (view profile)

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