import h5py
import numpy as np
import os
import math
from open3d import *
filename = '/home/jp/project/pointnet/sem_seg/indoor3d_sem_seg_hdf5_data/ply_data_all_0.h5'
f = h5py.File(filename, 'r')
index_start = 0
index_end = 1
data = f['data']
label = f['label']
one_data = data[index_start:index_end, :, :]
one_label = label[index_start:index_end]
one_data = np.concatenate(one_data, axis=0)
one_label = np.concatenate(one_label, axis=0)
data_shape = np.shape(one_data)
WIDTH = data_shape[0]
POINTS = WIDTH
# pack RGB
rgb = []
for i in range(POINTS):
value = 0
value += one_data[i, 3]*255*65536
value += one_data[i, 4]*255*256
value += one_data[i, 5]*255
value = value + 16777216
rgb.append(value)
path = '/home/jp/project/test/out/seg.pcd'
if os.path.exists(path):
os.remove(path)
out = open(path, 'a')
# headers
out.write('# .PCD v.7 - Point Cloud Data file format\nVERSION .7\nFIELDS x y z rgb\nSIZE 4 4 4 4\nTYPE F F F U\nCOUNT 1 1 1 1')
string = '\nWIDTH ' + str(WIDTH)
out.write(string)
out.write('\nHEIGHT 1\nVIEWPOINT 0 0 -2 0 1 0 0')
string = '\nPOINTS ' + str(POINTS)
out.write(string)
out.write('\nDATA ascii')
#datas
for i in range(POINTS):
string = '\n' + str(one_data[i, 0]) + ' ' + str(one_data[i, 1]) + ' ' +str(one_data[i, 2]) + ' ' + str(int(rgb[i]))
out.write(string)
out.close()