-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathgen_shapenet_cut2_hdf5.m
85 lines (66 loc) · 2.48 KB
/
gen_shapenet_cut2_hdf5.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
% read data
mainpath = 'data/hdf5_data';
data_path = strcat( mainpath, '/*.h5');
data_files = dir(data_path);
mkdir data/shapenet_cut;
point_num = 512;
for n=1:length(data_files)
data_path = strcat( mainpath, '/', data_files(n).name);
data = h5read(data_path,'/data');
label = h5read(data_path,'/label');
pid = h5read(data_path,'/pid');
num = 0;
x = length(data(:, 1, 1));
y = length(data(1, :, 1));
z = length(data(1, 1, :));
for i = 1:z
xyzPoints = data(:,:,i);
xyzPoints = xyzPoints(1:3,:);
xyzPoints = xyzPoints';
xyzLabel = label(i);
% figure;
% pcshow(xyzPoints);
% title('Original');
out_path = strcat('./data/shapenet_cut/',num2str(num),'_', data_files(n).name);
num = num + 1;
%%%%%%%%%%%%%%%% random cut part of the object %%%%%%%%%%%%%%%
% create 15 ramdom plains
count = 0;
while count < 30
% a * x + b * y + c * z = 0
points = xyzPoints;
a = (rand - 0.5) * 2;
b = (rand - 0.5) * 2;
c = (rand - 0.5) * 2;
points(:, 1) = points(:, 1) * a;
points(:, 2) = points(:, 2) * b;
points(:, 3) = points(:, 3) * c;
S = sum(points,2);
A1 = S >= 0;
cut1 = xyzPoints(A1 ~= 0,:);
A2 = S < 0;
cut2 = xyzPoints(A2 ~= 0,:);
% figure;
% pcshow(cut1);
% title('cut1');
% figure;
% pcshow(cut2);
% title('cut2');
if (length(cut1(:, 1)) > point_num) && (length(cut2(:, 1)) > point_num)
cut1 = cut1';
cut1_path = strcat( '/cut',num2str(count*2 + 1));
h5create(out_path, cut1_path,[length(cut1(:, 1)) length(cut1(1,:))],'Datatype','single');
h5write(out_path,cut1_path ,cut1);
cut2 = cut2';
cut2_path = strcat( '/cut',num2str(count*2 + 2));
h5create(out_path,cut2_path,[length(cut2(:, 1)) length(cut2(1,:))],'Datatype','single');
h5write(out_path, cut2_path,cut2);
count = count + 1;
end
end
h5create(out_path,'/label',[1],'Datatype','uint8');
h5write(out_path,'/label',xyzLabel);
end
processing = data_files(n).name
num
end