load('object3d.mat')
figure
pcshow(ptCloud)
xlabel('X(m)')
ylabel('Y(m)')
zlabel('Z(m)')
title('Original Point Cloud')
maxDistance = 0.02;
referenceVector = [0,0,1];
maxAngularDistance = 5;
[model1,inlierIndices,outlierIndices] = pcfitplane(ptCloud,...
maxDistance,referenceVector,maxAngularDistance);
plane1 = select(ptCloud,inlierIndices);
remainPtCloud = select(ptCloud,outlierIndices);
figure
pcshow(remainPtCloud)
title('台座の除去')
roi = [-inf,inf;0.4,inf;-inf,inf];
sampleIndices = findPointsInROI(remainPtCloud,roi);
[model2,inlierIndices,outlierIndices] = pcfitplane(remainPtCloud,...
maxDistance,'SampleIndices',sampleIndices);
plane2 = select(remainPtCloud,inlierIndices);
remainPtCloud = select(remainPtCloud,outlierIndices);
figure
pcshow(remainPtCloud)
title('左側の壁を除去')
roi = [-inf,inf;-inf,inf;0.9,1.2];
sampleIndices = findPointsInROI(remainPtCloud,roi);
[model3,inlierIndices,outlierIndices] = pcfitplane(remainPtCloud,...
maxDistance,'SampleIndices',sampleIndices);
plane3 = select(remainPtCloud,inlierIndices);
remainPtCloud = select(remainPtCloud,outlierIndices);
figure
h = pcshow(remainPtCloud)
title('左側の壁を除去')
points = remainPtCloud.Location;
points(any(isnan(points),2),:) = [];
rng default;
[idx,C] = kmeans(points,3);
hold on;
scatter3(C(:,1),C(:,2),C(:,3),200,[1 0 0],'filled');