Home > vbmeg > external > iso2mesh > remeshsurf.m

remeshsurf

PURPOSE ^

SYNOPSIS ^

function [newno,newfc]=remeshsurf(node,face,opt)

DESCRIPTION ^

 [newno,newfc]=remeshsurf(node,face,opt)

 remesh a triangular surface and the output is guaranteed to be
 free of self-intersecting element. This function is similar to 
 meshresample, but it can both downsample or upsample a mesh

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

 input:
     node: list of nodes on the input suface mesh, 3 columns for x,y,z
     face: list of trianglular elements on the surface, [n1,n2,n3,region_id]
     opt: function parameters
       opt.gridsize:  resolution for the voxelization of the mesh
       opt.closesize: if there are openings, set the closing diameter
       opt.elemsize:  the size of the element of the output surface
       if opt is a scalar, it defines the elemsize and gridsize=opt/4

 output:
     newno:  list of nodes on the resulting suface mesh, 3 columns for x,y,z
     newfc:  list of trianglular elements on the surface, [n1,n2,n3,region_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 [newno,newfc]=remeshsurf(node,face,opt)
0002 %
0003 % [newno,newfc]=remeshsurf(node,face,opt)
0004 %
0005 % remesh a triangular surface and the output is guaranteed to be
0006 % free of self-intersecting element. This function is similar to
0007 % meshresample, but it can both downsample or upsample a mesh
0008 %
0009 % author: Qianqian Fang (fangq <at> nmr.mgh.harvard.edu)
0010 %
0011 % input:
0012 %     node: list of nodes on the input suface mesh, 3 columns for x,y,z
0013 %     face: list of trianglular elements on the surface, [n1,n2,n3,region_id]
0014 %     opt: function parameters
0015 %       opt.gridsize:  resolution for the voxelization of the mesh
0016 %       opt.closesize: if there are openings, set the closing diameter
0017 %       opt.elemsize:  the size of the element of the output surface
0018 %       if opt is a scalar, it defines the elemsize and gridsize=opt/4
0019 %
0020 % output:
0021 %     newno:  list of nodes on the resulting suface mesh, 3 columns for x,y,z
0022 %     newfc:  list of trianglular elements on the surface, [n1,n2,n3,region_id]
0023 %
0024 % -- this function is part of iso2mesh toolbox (http://iso2mesh.sf.net)
0025 %
0026 
0027 p0=min(node);
0028 p1=max(node);
0029 
0030 if(isstruct(opt))
0031    if(isfield(opt,'gridsize'))
0032       dx=opt.gridsize;
0033    end
0034 else
0035   dx=opt/4;
0036 end
0037 
0038 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0039 % step 1: convert the old surface to a volumetric image
0040 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0041 img=surf2vol(node,face,p0(1)-dx:dx:p1(1)+dx,p0(2)-dx:dx:p1(2)+dx,p0(3)-dx:dx:p1(3)+dx);
0042 
0043 eg=surfedge(face);
0044 closesize=0;
0045 
0046 if(~isempty(eg) & isstruct(opt))
0047    if(isfield(opt,'closesize'))
0048      closesize=opt.closesize;
0049    end
0050 end
0051 
0052 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0053 % step 2: fill holes in the volumetric binary image
0054 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0055 
0056 img=fillholes3d(img,closesize);
0057 
0058 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0059 % step 3: convert the filled volume to a new surface
0060 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0061 
0062 if(isstruct(opt))
0063    if(isfield(opt,'elemsize'))
0064       opt.radbound=opt.elemsize/dx;
0065       [newno,newfc]=v2s(img,0.5,opt,'cgalsurf');
0066    end
0067 else
0068   opt=struct('radbound',opt/dx);
0069   [newno,newfc]=v2s(img,0.5,opt,'cgalsurf');
0070 end
0071 
0072 newno(:,1:3)=newno(:,1:3)*dx;
0073 newno(:,1)=newno(:,1)+p0(1);
0074 newno(:,2)=newno(:,2)+p0(2);
0075 newno(:,3)=newno(:,3)+p0(3);

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