-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathio3d.py
73 lines (63 loc) · 2.32 KB
/
io3d.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
64
65
66
67
68
69
70
71
72
73
# -*- coding: utf-8 -*-
"""
Created on Wed May 22 12:20:18 2019
@author: Administrator
"""
import os
import struct
import numpy as np
def loadBCFile(path):
n = os.path.getsize(path) // 4
with open(path, 'rb') as f:
data_raw = struct.unpack('f' * n, f.read(n * 4))
data = np.asarray(data_raw, dtype=np.float32).reshape(3, n // 3)
return data
def loadBCNFile(path):
n = os.path.getsize(path) // 4
with open(path, 'rb') as f:
data_raw = struct.unpack('f' * n, f.read(n * 4))
data = np.asarray(data_raw, dtype=np.float32).reshape((3 + 3), n // (3 + 3))
return data
def loadBCNCFile(path):
n = os.path.getsize(path) // 4
with open(path, 'rb') as f:
data_raw = struct.unpack('f' * n, f.read(n * 4))
data = np.asarray(data_raw, dtype=np.float32).reshape((3 + 3 + 1), n // (3 + 3 + 1))
return data
def loadBCNKFile(path):
n1 = os.path.getsize(path) // 4 // (3 + 3 + 8) * (3 + 3)
n2 = os.path.getsize(path) // 4 // (3 + 3 + 8) * (8)
with open(path, 'rb') as f:
data_raw1 = struct.unpack('f' * n1, f.read(n1 * 4))
data_raw2 = struct.unpack('i' * n2, f.read(n2 * 4))
data1 = np.asarray(data_raw1, dtype=np.float32).reshape((3 + 3), n1 // (3 + 3))
data2 = np.asarray(data_raw2, dtype=np.float32).reshape((8), n2 // (8)) * 100
data = np.vstack((data1, data2))
return data
def loadCOFFFile(path):
n = os.path.getsize(path) // 4
with open(path,'rb') as f:
raw_data = struct.unpack('f' * n, f.read(n * 4))
data = np.asarray(raw_data, dtype=np.float32)
return data
def saveBCFile(path, data):
if not data.shape[0] == 3:
raise 'BC shape error'
data_raw = data.reshape(-1)
n = data_raw.shape[0]
with open(path, 'wb') as f:
f.write(struct.pack('f' * n, *data_raw))
def saveBCNFile(path, data):
if not data.shape[0] == 6:
raise 'BCN shape error'
data_raw = data.reshape(-1)
n = data_raw.shape[0]
with open(path, 'wb') as f:
f.write(struct.pack('f' * n, *data_raw))
def saveBCNCFile(path, data):
if not data.shape[0] == 7:
raise 'BCNC shape error'
data_raw = data.reshape(-1)
n = data_raw.shape[0]
with open(path, 'wb') as f:
f.write(struct.pack('f' * n, *data_raw))