1 function N=PatchNormals3D(FV)
\r
2 % This function PATCHNORMALS calculates the normals of a triangulated
\r
3 % mesh. PATCHNORMALS calls the patchnormal_double.c mex function which
\r
4 % first calculates the normals of all faces, and after that calculates
\r
5 % the vertice normals from the face normals weighted by the angles
\r
8 % N=PatchNormals3D(FV);
\r
11 % FV : A struct containing FV.faces with a facelist Nx3 and FV.vertices
\r
12 % with a Nx3 vertices list. Such a structure is created by Matlab
\r
15 % N : A Mx3 list with the normals of all vertices
\r
18 % % Compile the c-coded function
\r
19 % mex PatchNormalsDouble.c -v
\r
21 % % Load a triangulated mesh of a sphere
\r
24 % % Calculate the normals
\r
25 % N=PatchNormals3D(FV);
\r
27 % % Show the normals
\r
28 % figure, patch(FV,'FaceColor',[1 0 0]); axis square; hold on;
\r
29 % for i=1:size(N,1);
\r
30 % p1=FV.vertices(i,:); p2=FV.vertices(i,:)+10*N(i,:);
\r
31 % plot3([p1(1) p2(1)],[p1(2) p2(2)],[p1(3) p2(3)],'g-');
\r
34 % Function is written by D.Kroon University of Twente (June 2009)
\r
37 sizev=size(FV.vertices);
\r
38 % Check size of vertice array
\r
39 if((sizev(2)~=3)||(length(sizev)~=2))
\r
40 error('patchnormals:inputs','The vertice list is not a m x 3 array')
\r
43 sizef=size(FV.faces);
\r
44 % Check size of vertice array
\r
45 if((sizef(2)~=3)||(length(sizef)~=2))
\r
46 error('patchnormals:inputs','The vertice list is not a m x 3 array')
\r
49 % Check if vertice indices exist
\r
50 if(max(FV.faces(:))>size(FV.vertices,1))
\r
51 error('patchnormals:inputs','The face list contains an undefined vertex index')
\r
54 % Check if vertice indices exist
\r
55 if(min(FV.faces(:))<1)
\r
56 error('patchnormals:inputs','The face list contains an vertex index smaller then 1')
\r
59 [Nx,Ny,Nz]=PatchNormalsDouble(double(FV.faces(:,1)),double(FV.faces(:,2)),double(FV.faces(:,3)),double(FV.vertices(:,1)),double(FV.vertices(:,2)),double(FV.vertices(:,3)));
\r
61 N=zeros(length(Nx),3);
\r