Home > vbmeg > external > iso2mesh > vol2mesh.m

vol2mesh

PURPOSE ^

SYNOPSIS ^

function [node,elem,face,regions]=vol2mesh(img,ix,iy,iz,opt,maxvol,dofix,method,isovalues)

DESCRIPTION ^

 [node,elem,face,regions]=vol2mesh(img,ix,iy,iz,opt,maxvol,dofix,method,isovalues)

 convert a binary (or multi-valued) volume to tetrahedral mesh

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

 input:
     img: a volumetric binary image
     ix,iy,iz: subvolume selection indices in x,y,z directions
     opt: as defined in vol2surf.m
     maxvol: target maximum tetrahedral elem volume
                when method='cgalmesh', maxvol can specify the target
                for each label (subregion index) by the following syntax
                'label1=size1:label2=size2:...'
     dofix: 1: perform mesh validation&repair, 0: skip repairing
     method: 'cgalsurf' or omit: use CGAL surface mesher
         'simplify': use binsurface and then simplify
         'cgalmesh': use CGAL 3.5 3D mesher for direct mesh generation [new]

         generally speaking, 'cgalmesh' is the most robust path
         if you want to product meshes from binary or multi-region
         volumes, however, its limitations include 1) only accept 
         uint8 volume, and 2) can not extract meshes from gray-scale
         volumes. If ones goal is to process a gray-scale volume,
         he/she should use the 'cgalsurf' option. 'simplify' approach
         is not recommended unless other options has failed.
     isovalues: a list of isovalues where the levelset is defined

 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
        region: optional output. if opt.autoregion is set to 1, region
              saves the interior points for each closed surface component

 -- 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,regions]=vol2mesh(img,ix,iy,iz,opt,maxvol,dofix,method,isovalues)
0002 %
0003 % [node,elem,face,regions]=vol2mesh(img,ix,iy,iz,opt,maxvol,dofix,method,isovalues)
0004 %
0005 % convert a binary (or multi-valued) volume to tetrahedral mesh
0006 %
0007 % author: Qianqian Fang (fangq <at> nmr.mgh.harvard.edu)
0008 %
0009 % input:
0010 %     img: a volumetric binary image
0011 %     ix,iy,iz: subvolume selection indices in x,y,z directions
0012 %     opt: as defined in vol2surf.m
0013 %     maxvol: target maximum tetrahedral elem volume
0014 %                when method='cgalmesh', maxvol can specify the target
0015 %                for each label (subregion index) by the following syntax
0016 %                'label1=size1:label2=size2:...'
0017 %     dofix: 1: perform mesh validation&repair, 0: skip repairing
0018 %     method: 'cgalsurf' or omit: use CGAL surface mesher
0019 %         'simplify': use binsurface and then simplify
0020 %         'cgalmesh': use CGAL 3.5 3D mesher for direct mesh generation [new]
0021 %
0022 %         generally speaking, 'cgalmesh' is the most robust path
0023 %         if you want to product meshes from binary or multi-region
0024 %         volumes, however, its limitations include 1) only accept
0025 %         uint8 volume, and 2) can not extract meshes from gray-scale
0026 %         volumes. If ones goal is to process a gray-scale volume,
0027 %         he/she should use the 'cgalsurf' option. 'simplify' approach
0028 %         is not recommended unless other options has failed.
0029 %     isovalues: a list of isovalues where the levelset is defined
0030 %
0031 % output:
0032 %     node: output, node coordinates of the tetrahedral mesh
0033 %     elem: output, element list of the tetrahedral mesh, the last
0034 %           column is the region ID
0035 %     face: output, mesh surface element list of the tetrahedral mesh
0036 %           the last column denotes the boundary ID
0037 %        region: optional output. if opt.autoregion is set to 1, region
0038 %              saves the interior points for each closed surface component
0039 %
0040 % -- this function is part of iso2mesh toolbox (http://iso2mesh.sf.net)
0041 %
0042 
0043 if(nargin>=8)
0044     if(strcmp(method,'cgalmesh'))
0045         vol=img(ix,iy,iz);
0046         if(length(unique(vol(:)))>64 & dofix==1)
0047             error([ 'it appears that you are processing a ' ...
0048                                 'grayscale image. Currently cgalmesher ' ...
0049                                 'does not support grayscale images. ' ...
0050                                 'Please use "cgalsurf" method to mesh a grayscale ' ...
0051                                 'volume. If you are certain to run cgalmesher ' ...
0052                                 'on your data, please set dofix=0 and run this again.' ]);
0053         end
0054         [node elem,face]=cgalv2m(vol,opt,maxvol);
0055         return;
0056     end
0057 end
0058 
0059 %first, convert the binary volume into isosurfaces
0060 if(nargin==8)
0061     [no,el,regions,holes]=vol2surf(img,ix,iy,iz,opt,dofix,method);
0062 elseif(nargin==9)
0063     [no,el,regions,holes]=vol2surf(img,ix,iy,iz,opt,dofix,method,isovalues);
0064 else
0065         [no,el,regions,holes]=vol2surf(img,ix,iy,iz,opt,dofix,'cgalsurf');
0066 end
0067 %then, create volumetric mesh from the surface mesh
0068 if(nargin>=8)
0069    if(strcmp(method,'cgalpoly'))
0070     [node,elem,face]=cgals2m(no(:,1:3),el(:,1:3),opt,maxvol);
0071         return;
0072    end
0073 end
0074 
0075 [node,elem,face]=surf2mesh(no,el,[],[],1,maxvol,regions,holes);

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