-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelper.py
62 lines (48 loc) · 2.15 KB
/
helper.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
def vec3_to_list(vector3_in):
return [vector3_in.x, vector3_in.y, vector3_in.z]
def quaternion_to_list(quaternion_in):
return [quaternion_in.x, quaternion_in.y, quaternion_in.z, quaternion_in.w]
class PLYWriter:
"""Reused from IKG-Intersection project 2021"""
def __init__(self, file, fields, comments=None):
assert(file.mode == "wb")
self._file = file
self._counter = 0
header = 'ply\nformat binary_little_endian 1.0\nelement vertex 000000000000'
if comments is not None:
if isinstance(comments, str):
comments = comments.split("\n")
for comment in comments:
header += "\ncomment {}".format(comment)
for name, dtype in fields:
header += "\nproperty {} {}".format(dtype.__name__, name)
header += "\nend_header\n"
self._file.write(bytes(header, encoding='utf-8'))
def writeArray(self, data):
self._file.write(data.tobytes())
self._counter += data.shape[0]
def writeDataFrame(self, data):
self._file.write(data.to_records(index=False).tobytes())
self._counter += len(data)
def finish(self):
self._file.seek(51)
self._file.write(bytes("{:012d}".format(self._counter), encoding="utf-8"))
def dec_2_dms(decimal):
minute, second = divmod(decimal*3600, 60)
degree, minute = divmod(minute, 60)
return '%d° %d\' %.2f\"' %(degree, minute, second)
def extend_timespan_with_factor(time_span, time_multiplicator):
"""time_span is expected as tuple. Factor as number"""
try:
encounter_begin = (time_span[0].astype(int) / 10 ** 9)[0]
encounter_end = (time_span[1].astype(int) / 10 ** 9)[0]
except:
encounter_begin, encounter_end = time_span
# Calc length
encounter_duration = encounter_end - encounter_begin
# Subtract 1 from multiplicator and halve to archieve symmetrical extension value
single_buffer_only = (time_multiplicator - 1) / 2 * encounter_duration
# Add and subtract from start and end value
encounter_begin -= single_buffer_only
encounter_end += single_buffer_only
return encounter_begin, encounter_end