1 function FV=SnakeMoveIteration3D(B,FV,Fext,gamma,kappa,delta,lambda)
\r
2 % This function will calculate one iteration of contour Snake movement
\r
4 % FV=SnakeMoveIteration2D(S,FV,Fext,gamma,kappa)
\r
7 % B : Internal force (smoothness) matrix
\r
8 % FV : The triangulated surface
\r
9 % Fext : External vector field (from image)
\r
11 % kappa : External (image) field weight
\r
12 % delta : Balloon Force weight
\r
13 % lambda: Weight which changes the direction of the image potential force
\r
14 % to the direction of the surface normal, value default 0.8
\r
15 % (range [0..1]) (Keeps the surface from self intersecting)
\r
18 % P : The (moved) contour points N x 2;
\r
20 % Function is written by D.Kroon University of Twente (July 2010)
\r
24 % Clamp contour to boundary
\r
25 V(:,1)=min(max(V(:,1),1),size(Fext,1));
\r
26 V(:,2)=min(max(V(:,2),1),size(Fext,2));
\r
27 V(:,3)=min(max(V(:,3),1),size(Fext,3));
\r
29 % Get image force on the contour points
\r
30 Fext1(:,1)=kappa*interp3(Fext(:,:,:,1),V(:,2),V(:,1),V(:,3));
\r
31 Fext1(:,2)=kappa*interp3(Fext(:,:,:,2),V(:,2),V(:,1),V(:,3));
\r
32 Fext1(:,3)=kappa*interp3(Fext(:,:,:,3),V(:,2),V(:,1),V(:,3));
\r
34 % Interp3, can give nan's if contour close to border
\r
35 Fext1(isnan(Fext1))=0;
\r
37 % Calculate the baloonforce on the contour points
\r
38 N=PatchNormals3D(FV);
\r
41 % This is the potential force, but only the component in the direction of
\r
42 % the surface normal
\r
43 Fext3=repmat(dot(Fext1,N,2),1,3).*N;
\r
45 V(:,1)=B * (gamma * V(:,1) + (Fext1(:,1)*(1-lambda) + Fext3(:,1)*lambda + Fext2(:,1)));
\r
46 V(:,2)=B * (gamma * V(:,2) + (Fext1(:,2)*(1-lambda) + Fext3(:,2)*lambda + Fext2(:,2)));
\r
47 V(:,3)=B * (gamma * V(:,3) + (Fext1(:,3)*(1-lambda) + Fext3(:,3)*lambda + Fext2(:,3)));
\r
49 % Clamp contour to boundary
\r
50 V(:,1)=min(max(V(:,1),1),size(Fext,1));
\r
51 V(:,2)=min(max(V(:,2),1),size(Fext,2));
\r
52 V(:,3)=min(max(V(:,3),1),size(Fext,3));
\r