subTriLocal

Below is a demonstration of the features of the subTriLocal function

Contents

clear; close all; clc;

Syntax

[outputStruct]=subTriLocal(inputStruct);

Description

This function refines (using the subTri function) the triangles in F defined by indFaces and splits neighbouring triangles to create a conforming mesh. This way local refinement can be achieved. The output mesh is stored in Fq and Vq and a face color list Cq can also be requested which lists whether a triangle is unaltered (Cq==1), is subdevided (Cq==2) or has been split to connect the two regions (Cq==3). The optional input f (default is 0) defines the location of the new points introduced for the transition elements. Using f>0 (and <1) will place these points closer to the coarse mesh nodes. The optional output indInitial is a list containing all the original nodes.

Examples

Plot settings

fontSize=15;
faceAlpha=1;
edgeColor=0.*ones(1,3);
edgeWidth=2;

Example: Refining a local region of a mesh (e.g. the top half of a sphere)

Building example geometry

%Defining geodesic dome
r=1; %sphere radius
n=2; %Refinements
[F,V,~]=geoSphere(n,r);

Define face list for refinement

L=V(:,3)>0.5;
LF=all(L(F),2);
indFaces=find(LF);

inputStruct.F=F;
inputStruct.V=V;
inputStruct.indFaces=indFaces;
[outputStruct]=subTriLocal(inputStruct);
Fq=outputStruct.F;
Vq=outputStruct.V;
Cq=outputStruct.faceTypeLabel;

Plotting results

%Create face color data to visualize selection
C=ones(size(F,1),1);
C(indFaces)=2;

hf=cFigure;
subplot(1,2,1); hold on;
title('Initial','FontSize',fontSize);
xlabel('X','FontSize',fontSize); ylabel('Y','FontSize',fontSize); zlabel('Z','FontSize',fontSize);
hp=patch('Faces',F,'Vertices',V,'FaceColor','flat','CData',C,'FaceAlpha',faceAlpha,'lineWidth',edgeWidth,'edgeColor',edgeColor);
% [hp]=patchNormPlot(Fq,Vq,0.2);
camlight headlight;
set(gca,'FontSize',fontSize);
view(3); axis tight;  axis equal;  grid on;

subplot(1,2,2); hold on;
title('Refined','FontSize',fontSize);
xlabel('X','FontSize',fontSize); ylabel('Y','FontSize',fontSize); zlabel('Z','FontSize',fontSize);
hp=patch('Faces',Fq,'Vertices',Vq,'FaceColor','flat','CData',Cq,'FaceAlpha',faceAlpha,'lineWidth',edgeWidth,'edgeColor',edgeColor);
% [hp]=patchNormPlot(Fq,Vq,0.2);
camlight headlight;
set(gca,'FontSize',fontSize);
colormap(autumn); colorbar;
view(3); axis tight;  axis equal;  grid on;

For the above a default f of 0 was assumed. Note the difference when instead f=0.25 is used.

f=0.25;

inputStruct.F=F;
inputStruct.V=V;
inputStruct.indFaces=indFaces;
inputStruct.f=f;
[outputStruct]=subTriLocal(inputStruct);
Fq=outputStruct.F;
Vq=outputStruct.V;
Cq=outputStruct.faceTypeLabel;

Plotting results

%Create face color data to visualize selection
C=ones(size(F,1),1);
C(indFaces)=2;

hf=cFigure;
subplot(1,2,1); hold on;
title('Initial','FontSize',fontSize);
xlabel('X','FontSize',fontSize); ylabel('Y','FontSize',fontSize); zlabel('Z','FontSize',fontSize);
hp=patch('Faces',F,'Vertices',V,'FaceColor','flat','CData',C,'FaceAlpha',faceAlpha,'lineWidth',edgeWidth,'edgeColor',edgeColor);
% [hp]=patchNormPlot(Fq,Vq,0.2);
camlight headlight;
set(gca,'FontSize',fontSize);
view(3); axis tight;  axis equal;  grid on;

subplot(1,2,2); hold on;
title('Refined','FontSize',fontSize);
xlabel('X','FontSize',fontSize); ylabel('Y','FontSize',fontSize); zlabel('Z','FontSize',fontSize);
hp=patch('Faces',Fq,'Vertices',Vq,'FaceColor','flat','CData',Cq,'FaceAlpha',faceAlpha,'lineWidth',edgeWidth,'edgeColor',edgeColor);
% [hp]=patchNormPlot(Fq,Vq,0.2);
camlight headlight;
set(gca,'FontSize',fontSize);
colormap(autumn); colorbar;
view(3); axis tight;  axis equal;  grid on;

Smoothening the output mesh

The output mesh can be smoothening normally or using constrained smoothing and using the optional indInitial output. The points defined by indInitial are plotted on the mesh. Note however that smoothening may undo the change induced by the factor f.

indFaces=1:60;

inputStruct.F=F;
inputStruct.V=V;
inputStruct.indFaces=indFaces;
inputStruct.f=f;
[outputStruct]=subTriLocal(inputStruct);

Fq=outputStruct.F;
Vq=outputStruct.V;
Cq=outputStruct.faceTypeLabel;
indInitial=outputStruct.indInitial;

smoothPar.Alpha=0.1;
smoothPar.Beta=0.5;
smoothPar.Method='HC';
smoothPar.n=100;
smoothPar.RigidConstraints=indInitial;
[Vq]=tesSmooth(Fq,Vq,[],smoothPar);

Plotting results

%Create face color data to visualize selection
C=ones(size(F,1),1);
C(indFaces)=2;

hf=cFigure;
subplot(1,2,1); hold on;
title('Initial','FontSize',fontSize);
xlabel('X','FontSize',fontSize); ylabel('Y','FontSize',fontSize); zlabel('Z','FontSize',fontSize);
hp=patch('Faces',F,'Vertices',V,'FaceColor','flat','CData',C,'FaceAlpha',faceAlpha,'lineWidth',edgeWidth,'edgeColor',edgeColor);
% [hp]=patchNormPlot(Fq,Vq,0.2);
camlight headlight;
set(gca,'FontSize',fontSize);
view(3); axis tight;  axis equal;  grid on;

subplot(1,2,2); hold on;
title('Refined','FontSize',fontSize);
xlabel('X','FontSize',fontSize); ylabel('Y','FontSize',fontSize); zlabel('Z','FontSize',fontSize);
hp=patch('Faces',Fq,'Vertices',Vq,'FaceColor','flat','CData',Cq,'FaceAlpha',faceAlpha,'lineWidth',edgeWidth,'edgeColor',edgeColor);
% [hp]=patchNormPlot(Fq,Vq,0.2);
plotV(Vq(indInitial,:),'k.','MarkerSize',50);
camlight headlight;
set(gca,'FontSize',fontSize);
colormap(autumn); colorbar;
view(3); axis tight;  axis equal;  grid on;

Keeping track of face data or color information

%Create example color information
[C]=vertexToFaceMeasure(F,V(:,2));

inputStruct.F=F;
inputStruct.V=V;
inputStruct.C=C;
inputStruct.indFaces=indFaces;
[outputStruct]=subTriLocal(inputStruct);
Fq=outputStruct.F;
Vq=outputStruct.V;
Cq=outputStruct.C;

Plotting results

hf=cFigure;
subplot(1,2,1); hold on;
title('Initial','FontSize',fontSize);
xlabel('X','FontSize',fontSize); ylabel('Y','FontSize',fontSize); zlabel('Z','FontSize',fontSize);
hp=patch('Faces',F,'Vertices',V,'FaceColor','flat','CData',C,'FaceAlpha',faceAlpha,'lineWidth',edgeWidth,'edgeColor',edgeColor);
% [hp]=patchNormPlot(Fq,Vq,0.2);
camlight headlight;
set(gca,'FontSize',fontSize);
view(3); axis tight;  axis equal;  grid on;

subplot(1,2,2); hold on;
title('Refined','FontSize',fontSize);
xlabel('X','FontSize',fontSize); ylabel('Y','FontSize',fontSize); zlabel('Z','FontSize',fontSize);
hp=patch('Faces',Fq,'Vertices',Vq,'FaceColor','flat','CData',Cq,'FaceAlpha',faceAlpha,'lineWidth',edgeWidth,'edgeColor',edgeColor);
% [hp]=patchNormPlot(Fq,Vq,0.2);
camlight headlight;
set(gca,'FontSize',fontSize);
colormap(hsv(size(Cq,1))); colorbar;
view(3); axis tight;  axis equal;  grid on;

GIBBON www.gibboncode.org

Kevin Mattheus Moerman, [email protected]

GIBBON footer text

License: https://github.com/gibbonCode/GIBBON/blob/master/LICENSE

GIBBON: The Geometry and Image-based Bioengineering add-On. A toolbox for image segmentation, image-based modeling, meshing, and finite element analysis.

Copyright (C) 2017 Kevin Mattheus Moerman

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.