Enables local refinement at mesh markers
2 次查看(过去 30 天)
显示 更早的评论
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 个评论
KSSV
2024-1-24
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.
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Statistics and Machine Learning Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!