Enables local refinement at mesh markers

2 views (last 30 days)
Chenglin Li
Chenglin Li on 24 Jan 2024
Commented: Chenglin Li on 24 Jan 2024
I have marked the surfaces in the mesh that I want to refine and the tetrahedra where the faces are located (the row indexes and values have been extracted), but applying loop refinement refines the entire mesh, so how do I modify the program to enable refinement of parts of the mesh?
function [newVertices, newFaces] = linearSubdivision(vertices, faces)
% Linear subdivision for triangle meshes
global edgeVertex;
global newIndexOfVertices;
newFaces = [];
newVertices = vertices;
nVertices = size(vertices,2);
nFaces = size(faces,2);
edgeVertex= zeros(nVertices, nVertices);
newIndexOfVertices = nVertices;
% ------------------------------------------------------------------------ %
% create a matrix of edge-vertices and a new triangulation (newFaces).
%
% * edgeVertex(x,y): index of the new vertex between (x,y)
%
% 0riginal vertices: va, vb, vc.
% New vertices: vp, vq, vr.
%
% vb vb
% / \ / \
% / \ vp--vq
% / \ / \ / \
% va ----- vc -> va-- vr --vc
%
for i=1:nFaces
[vaIndex, vbIndex, vcIndex] = deal(faces(1,i), faces(2,i), faces(3,i));
vpIndex = addEdgeVertex(vaIndex, vbIndex);
vqIndex = addEdgeVertex(vbIndex, vcIndex);
vrIndex = addEdgeVertex(vaIndex, vcIndex);
fourFaces = [vaIndex,vpIndex,vrIndex; vpIndex,vbIndex,vqIndex; vrIndex,vqIndex,vcIndex; vrIndex,vpIndex,vqIndex]';
newFaces = [newFaces, fourFaces];
end;
% ------------------------------------------------------------------------ %
% positions of the new vertices
for v1=1:nVertices-1
for v2=v1:nVertices
vNIndex = edgeVertex(v1,v2);
if (vNIndex~=0)
newVertices(:,vNIndex) = 1/2*(vertices(:,v1)+vertices(:,v2));
end;
end;
end;
end
% ---------------------------------------------------------------------------- %
function vNIndex = addEdgeVertex(v1Index, v2Index)
global edgeVertex;
global newIndexOfVertices;
if (v1Index>v2Index) % setting: v1 <= v2
vTmp = v1Index;
v1Index = v2Index;
v2Index = vTmp;
end;
if (edgeVertex(v1Index, v2Index)==0) % new vertex
newIndexOfVertices = newIndexOfVertices+1;
edgeVertex(v1Index, v2Index) = newIndexOfVertices;
end;
vNIndex = edgeVertex(v1Index, v2Index);
return;
end
  2 Comments
KSSV
KSSV on 24 Jan 2024
You have to input only those face which you want to refine. Might be you are inputting all the faces and vertices to the function.
Chenglin Li
Chenglin Li on 24 Jan 2024
Yes, I entered the faces I want to refine, but only the entered faces are refined, but I want to show both the refined part and the unrefined part at the same time, and now the generated points and faces are only for the refined part and do not contain the unrefined ones.

Sign in to comment.

Answers (0)

Categories

Find more on Statistics and Machine Learning Toolbox in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!