clc;
clear;
close all;
warning off;
%调用几种测试数据
SEL = 2;
if SEL == 1
load EXAMPLE
G1 = source;
fai = 0.15;
X = G1(:,1).*cos(2*pi*fai)-G1(:,3).*sin(2*pi*fai);
Y = G1(:,2);
Z = G1(:,1).*sin(2*pi*fai)+G1(:,3).*cos(2*pi*fai);
T = [X,Y,Z];
source(:,1) = T(:,1)+1200;
source(:,2) = T(:,2)+200;
source(:,3) = T(:,3)+400;
end
if SEL == 2
load model_25_partial.mat
%旋转,方便观察是否配准
G1 = node_xyz';
fai = 0.15;
X = G1(:,1).*cos(2*pi*fai)-G1(:,3).*sin(2*pi*fai);
Y = G1(:,2);
Z = G1(:,1).*sin(2*pi*fai)+G1(:,3).*cos(2*pi*fai);
T = [X,Y,Z];
source(:,1) = T(:,1)+1200;
source(:,2) = T(:,2)+200;
source(:,3) = T(:,3)+400;
fsource = face_node';
load model_25.mat
target = node_xyz';
ftarget = face_node';
end
if SEL == 3
load model_5_partial.mat
%旋转,方便观察是否配准
G1 = node_xyz';
fai = 0.15;
X = G1(:,1).*cos(2*pi*fai)-G1(:,3).*sin(2*pi*fai);
Y = G1(:,2);
Z = G1(:,1).*sin(2*pi*fai)+G1(:,3).*cos(2*pi*fai);
T = [X,Y,Z];
source(:,1) = T(:,1)+1200;
source(:,2) = T(:,2)+200;
source(:,3) = T(:,3)+400;
fsource = face_node';
load model_5.mat
target = node_xyz';
ftarget = face_node';
end
figure;
subplot(1,2,1);
trisurf(ftarget,target(:,1),target(:,2),target(:,3),'facecolor','y','Edgecolor','none');
hold on
light
lighting phong;
set(gca,'DataAspectRatio',[1 1 1],'PlotBoxAspectRatio',[1 1 1]);
trisurf(fsource,source(:,1),source(:,2),source(:,3),'facecolor','g','Edgecolor','none');
[error,Reallignedsource,transform,Derr]=rigidICP(target,source);
subplot(1,2,2);
trisurf(ftarget,target(:,1),target(:,2),target(:,3),'facecolor','y','Edgecolor','none');
hold on
light
set(gca,'DataAspectRatio',[1 1 1],'PlotBoxAspectRatio',[1 1 1]);
trisurf(fsource,Reallignedsource(:,1),Reallignedsource(:,2),Reallignedsource(:,3),'facecolor','g','Edgecolor','none');
light
title('ICP算法配准结果');
figure;
plot(Derr,'b-o');
xlabel('迭代次数');
ylabel('迭代误差');
grid on