Home > vbmeg > external > iso2mesh > s2v.m

s2v

PURPOSE ^

SYNOPSIS ^

function varargout=s2v(node,face,div,varargin)

DESCRIPTION ^

 [img,v2smap]=s2v(node,face,div)

 shortcut for surf2vol, coverting a surface to a volumetric image

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

 input:
     node: node list of the triangular surface, 3 columns for x/y/z
     face: triangle node indices, each row is a triangle
     div:  division number along the shortest edge of the mesh (resolution)
              if not given, div=50

 output:
     img: a volumetric binary image at position of ndgrid(xi,yi,zi)
        v2smap (optional): a 4x4 matrix denoting the Affine transformation to map
             the voxel coordinates back to the mesh space. One can use the 
             v2smap to convert a mesh generated from the rasterized volume
             into the original input mesh space (work coordinate system). For example:

             [img,map]=s2v(node,face);
             [no,el]=v2s(img,0.5,5);
             newno=map*[no ones(length(no),1)]';
             newno=newno(1:3,:)'; % newno and el now go back to the world coordinates

 -- 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 varargout=s2v(node,face,div,varargin)
0002 %
0003 % [img,v2smap]=s2v(node,face,div)
0004 %
0005 % shortcut for surf2vol, coverting a surface to a volumetric image
0006 %
0007 % author: Qianqian Fang (fangq <at> nmr.mgh.harvard.edu)
0008 %
0009 % input:
0010 %     node: node list of the triangular surface, 3 columns for x/y/z
0011 %     face: triangle node indices, each row is a triangle
0012 %     div:  division number along the shortest edge of the mesh (resolution)
0013 %              if not given, div=50
0014 %
0015 % output:
0016 %     img: a volumetric binary image at position of ndgrid(xi,yi,zi)
0017 %        v2smap (optional): a 4x4 matrix denoting the Affine transformation to map
0018 %             the voxel coordinates back to the mesh space. One can use the
0019 %             v2smap to convert a mesh generated from the rasterized volume
0020 %             into the original input mesh space (work coordinate system). For example:
0021 %
0022 %             [img,map]=s2v(node,face);
0023 %             [no,el]=v2s(img,0.5,5);
0024 %             newno=map*[no ones(length(no),1)]';
0025 %             newno=newno(1:3,:)'; % newno and el now go back to the world coordinates
0026 %
0027 % -- this function is part of iso2mesh toolbox (http://iso2mesh.sf.net)
0028 %
0029 
0030 p0=min(node);
0031 p1=max(node);
0032 
0033 if(size(node,1)==0 | size(face,1)==0)
0034   error('node and face can not be empty');
0035 end
0036 
0037 if(nargin<3)
0038   div=50;
0039 end
0040 
0041 if(div==0)
0042   error('div can not be 0');
0043 end
0044 
0045 dx=min(p1-p0)/div;
0046 
0047 if(dx<=eps)
0048   error('the input mesh is in a plane');
0049 end
0050 
0051 [varargout{1:2}]=surf2vol(node,face,p0(1)-dx:dx:p1(1)+dx,p0(2)-dx:dx:p1(2)+dx,p0(3)-dx:dx:p1(3)+dx,varargin{:});

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