Home > vbmeg > external > iso2mesh > sample > demo_merge_surfaces.m

demo_merge_surfaces

PURPOSE ^

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

SYNOPSIS ^

This is a script file.

DESCRIPTION ^

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
   Merge multiple surfaces and remove self-intersection elements
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0002 %   Merge multiple surfaces and remove self-intersection elements
0003 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0004 
0005 % generate a mesh for
0006 load rat_head.mat
0007 [node0,face0]=v2s(volimage,0.5,2);
0008 
0009 c0=mean(meshcentroid(node0,face0(:,1:3)));
0010 c1=2*[18.5 20.7 20.9]-c0;
0011 
0012 [cnode,cface]=meshacylinder(c0,c1,4);
0013 [cnode,cface]=meshcheckrepair(cnode,cface(:,1:3));
0014 
0015 % combine two surfaces, producing 4 pieces of subsurfaces: surf 1
0016 % outside/inside of surf2 and surf2 outside/inside of surf1
0017 
0018 [no,el]=surfboolean(node0,face0(:,1:3),'all',cnode,cface);
0019 figure
0020 plotmesh(no,el,'y>20')
0021 
0022 % take the first surface only
0023 
0024 % el(:,4)==1: surf 1 outside of surf 2; el(:,4)==3: surf 1 inside of surf 2
0025 [no,el]=surfboolean(node0,face0(:,1:3),'first',cnode,cface);
0026 figure
0027 plotmesh(no,el)
0028 
0029 % the mesh after boolean operation can have self-intersecting elements, one
0030 % has to fix those defects before passing to s2m
0031 
0032 [no1,el1]=meshcheckrepair(no(:,1:3),el(:,1:3),'meshfix');
0033 
0034 %ISO2MESH_TETGENOPT=' -A -q 0.8 -a 10 ';
0035 [node,elem,face]=s2m(no1,el1,1,10);
0036 figure;
0037 plotmesh(node,face)

Generated on Mon 22-May-2023 06:53:56 by m2html © 2005