-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathpds_pc.py
64 lines (51 loc) · 1.91 KB
/
pds_pc.py
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
import os
import sys
import numpy as np
import pymeshlab
from multiprocessing import Pool
#print(pymeshlab.__version__)
#assert False
num_point=48000
base_path='data'
save_path='data'
cat_list=os.listdir(base_path) #['03001627']
path_list=[]
save_path_list=[]
for cat in cat_list[:13]:
mesh_list=os.listdir(os.path.join(base_path,cat))
for mesh_name in mesh_list:
path_list.append(os.path.join(base_path,cat,mesh_name))
save_path_list.append(os.path.join(save_path,cat,mesh_name))
class HiddenPrints:
def __enter__(self):
self._original_stdout = sys.stdout
sys.stdout = open(os.devnull, "w")
def __exit__(self, exc_type, exc_val, exc_tb):
sys.stdout.close()
sys.stdout = self._original_stdout
idx_list=list(range(len(path_list)))
def multiprocess(func):
p = Pool(80)
p.map(func, idx_list)
p.close()
p.join()
def pds(idx):
if 1:
#if not os.path.exists(os.path.join(save_path_list[idx],'%d.npy'%num_point)):
#with HiddenPrints():
print(os.path.join(save_path_list[idx], '%d.npy' % num_point),' is preparing.')
ms_set = pymeshlab.MeshSet()
ms_set.load_new_mesh(os.path.join(os.path.join(path_list[idx], 'scaled_model.off')))
ms_set.generate_sampling_poisson_disk(samplenum=int(num_point / (1 - 0.006)), exactnumflag=True)
pc = np.array(ms_set.current_mesh().vertex_matrix())
#index = np.random.choice(np.arange(pc.shape[0]), num_point)
#pc = pc[index, :]
if not os.path.exists(save_path_list[idx]):
os.makedirs(save_path_list[idx])
np.save(os.path.join(save_path_list[idx],'%d.npy'%num_point),pc.astype(np.float32))
print(os.path.join(save_path_list[idx],'%d.npy'%num_point),' is prepared.')
del pc,ms_set #,index
else:
print('skip ',os.path.join(save_path_list[idx],'%d.npy'%num_point))
if __name__=='__main__':
multiprocess(pds)