0001 function [D, s0] = vb_solid_angle_grk(V,F,xx)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022 Nskip = 100;
0023 NSKIP = 1000;
0024
0025
0026
0027 NF = size(F,1);
0028 NV = size(V,1);
0029
0030
0031 D = zeros(NV,NV);
0032
0033
0034
0035 x1 = V(F(:,1),:);
0036 x2 = V(F(:,2),:);
0037 x3 = V(F(:,3),:);
0038
0039
0040 z1 = x2-x1;
0041 z2 = x3-x1;
0042 s0 = vb_cross2(z1,z2);
0043 S = sum(s0.^2,2);
0044 Sinv2 = 1./S;
0045 S = sqrt(S);
0046
0047
0048 xxS = (xx(F(:,1),:)+xx(F(:,2),:)+xx(F(:,3),:))./3;
0049 ix = find( sum(s0.*xxS,2) < 0 );
0050
0051 tmp = x2(ix,:);
0052 x2(ix,:) = x3(ix,:);
0053 x3(ix,:) = tmp;
0054
0055 tmp = F(ix,2);
0056 F(ix,2) = F(ix,3);
0057 F(ix,3) = tmp;
0058
0059 s0(ix,:) = -1*s0(ix,:);
0060
0061
0062
0063
0064
0065
0066
0067
0068 for n = 1:NF
0069
0070 ip = [(4*x1(n,:) + x2(n,:) + x3(n,:))/6; ...
0071 ( x1(n,:) + 4*x2(n,:) + x3(n,:))/6; ...
0072 ( x1(n,:) + x2(n,:) + 4*x3(n,:))/6];
0073
0074
0075 ix = [1:(n-1), (n+1):NF];
0076
0077 Fn = F(ix,:);
0078 s = s0(ix,:);
0079 y1 = x1(ix,:);
0080 y2 = x2(ix,:);
0081 y3 = x3(ix,:);
0082
0083 Sinv = Sinv2(ix);
0084
0085
0086 D0 = zeros(3,NV);
0087
0088
0089 for i = 1:3
0090
0091 x0 = ip(i,:);
0092 y0 = x0(ones(NF-1,1),:);
0093
0094
0095 [omega1,omega2,omega3] = ...
0096 vb_solid_other(y0,y1,y2,y3,s,Sinv);
0097
0098
0099 for j = 1:NF-1
0100 D0(i,Fn(j,1)) = D0(i,Fn(j,1))+omega1(j);
0101 D0(i,Fn(j,2)) = D0(i,Fn(j,2))+omega2(j);
0102 D0(i,Fn(j,3)) = D0(i,Fn(j,3))+omega3(j);
0103 end
0104 end
0105
0106
0107
0108 D(F(n,1),:) = D(F(n,1),:)+S(n)/36*(4*D0(1,:)+D0(2,:)+D0(3,:));
0109 D(F(n,2),:) = D(F(n,2),:)+S(n)/36*(D0(1,:)+4*D0(2,:)+D0(3,:));
0110 D(F(n,3),:) = D(F(n,3),:)+S(n)/36*(D0(1,:)+D0(2,:)+4*D0(3,:));
0111
0112 if mod(n,Nskip)==0, fprintf('-'); end;
0113 if mod(n,NSKIP)==0, fprintf(' %3.0f %% done\n', 100*n/NF); end;
0114 end
0115
0116
0117 D = (-1/(2*pi))*D;
0118
0119 return