Home > vbmeg > external > iso2mesh > cgals2m.m

cgals2m

PURPOSE ^

SYNOPSIS ^

function [node,elem,face]=cgals2m(v,f,opt,maxvol,varargin)

DESCRIPTION ^

 [node,elem,face]=cgals2m(v,f,opt,maxvol)

 wrapper for CGAL 3D mesher (CGAL 3.5 and newer)
 convert a triangular surface to tetrahedral mesh

 http://www.cgal.org/Manual/3.5/doc_html/cgal_manual/Mesh_3/Chapter_main.html

 author: Qianqian Fang (fangq <at> nmr.mgh.harvard.edu)

 input:
     v: the node coordinate list of a surface mesh (nn x 3)
     f: the face element list of a surface mesh (be x 3)
     opt: parameters for CGAL mesher, if opt is a structure, then
         opt.radbound: defines the maximum surface element size
         opt.angbound: defines the miminum angle of a surface triangle
         opt.distbound: defines the maximum distance between the 
         center of the surface bounding circle and center of the 
         element bounding sphere
         opt.reratio:  maximum radius-edge ratio
         if opt is a scalar, it only specifies radbound.
     maxvol: target maximum tetrahedral elem volume

 output:
     node: output, node coordinates of the tetrahedral mesh
     elem: output, element list of the tetrahedral mesh, the last 
          column is the region id
     face: output, mesh surface element list of the tetrahedral mesh
          the last column denotes the boundary ID

 -- this function is part of iso2mesh toolbox (http://iso2mesh.sf.net)

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [node,elem,face]=cgals2m(v,f,opt,maxvol,varargin)
0002 %
0003 % [node,elem,face]=cgals2m(v,f,opt,maxvol)
0004 %
0005 % wrapper for CGAL 3D mesher (CGAL 3.5 and newer)
0006 % convert a triangular surface to tetrahedral mesh
0007 %
0008 % http://www.cgal.org/Manual/3.5/doc_html/cgal_manual/Mesh_3/Chapter_main.html
0009 %
0010 % author: Qianqian Fang (fangq <at> nmr.mgh.harvard.edu)
0011 %
0012 % input:
0013 %     v: the node coordinate list of a surface mesh (nn x 3)
0014 %     f: the face element list of a surface mesh (be x 3)
0015 %     opt: parameters for CGAL mesher, if opt is a structure, then
0016 %         opt.radbound: defines the maximum surface element size
0017 %         opt.angbound: defines the miminum angle of a surface triangle
0018 %         opt.distbound: defines the maximum distance between the
0019 %         center of the surface bounding circle and center of the
0020 %         element bounding sphere
0021 %         opt.reratio:  maximum radius-edge ratio
0022 %         if opt is a scalar, it only specifies radbound.
0023 %     maxvol: target maximum tetrahedral elem volume
0024 %
0025 % output:
0026 %     node: output, node coordinates of the tetrahedral mesh
0027 %     elem: output, element list of the tetrahedral mesh, the last
0028 %          column is the region id
0029 %     face: output, mesh surface element list of the tetrahedral mesh
0030 %          the last column denotes the boundary ID
0031 %
0032 % -- this function is part of iso2mesh toolbox (http://iso2mesh.sf.net)
0033 %
0034 
0035 fprintf(1,'creating surface and tetrahedral mesh from a polyhedral surface ...\n');
0036 
0037 exesuff=fallbackexeext(getexeext,'cgalpoly');
0038 
0039 ang=30;
0040 ssize=6;
0041 approx=0.5;
0042 reratio=3;
0043 
0044 flags=varargin2struct(varargin{:});
0045 
0046 if(~isstruct(opt))
0047     ssize=opt;
0048 end
0049 
0050 if(isstruct(opt) && length(opt)==1)  % does not support settings for multiple labels
0051     if(isfield(opt,'radbound'))   ssize=opt.radbound; end
0052     if(isfield(opt,'angbound'))   ang=opt.angbound; end
0053     if(isfield(opt,'distbound'))  approx=opt.distbound; end
0054     if(isfield(opt,'reratio'))    reratio=opt.reratio; end
0055 end
0056 if(getoptkey('DoRepair',0,flags)==1)
0057     [v,f]=meshcheckrepair(v,f);
0058 end
0059 saveoff(v,f,mwpath('pre_cgalpoly.off'));
0060 deletemeshfile(mwpath('post_cgalpoly.mesh'));
0061 
0062 randseed=hex2dec('623F9A9E'); % "U+623F U+9A9E"
0063 
0064 if(~isempty(getvarfrom({'caller','base'},'ISO2MESH_RANDSEED')))
0065         randseed=getvarfrom({'caller','base'},'ISO2MESH_RANDSEED');
0066 end
0067 
0068 cmd=sprintf('"%s%s" "%s" "%s" %.16f %.16f %.16f %.16f %.16f %d',mcpath('cgalpoly'),exesuff,...
0069     mwpath('pre_cgalpoly.off'),mwpath('post_cgalpoly.mesh'),ang,ssize,...
0070     approx,reratio,maxvol,randseed);
0071 system(cmd);
0072 if(~exist(mwpath('post_cgalpoly.mesh'),'file'))
0073     error(sprintf('output file was not found, failure was encountered when running command: \n%s\n',cmd));
0074 end
0075 [node,elem,face]=readmedit(mwpath('post_cgalpoly.mesh'));
0076 
0077 fprintf(1,'node number:\t%d\ntriangles:\t%d\ntetrahedra:\t%d\nregions:\t%d\n',...
0078     size(node,1),size(face,1),size(elem,1),length(unique(elem(:,end))));
0079 fprintf(1,'surface and volume meshes complete\n');

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