forked from seung-lab/DracoPy
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathtests.py
More file actions
86 lines (74 loc) · 3.4 KB
/
tests.py
File metadata and controls
86 lines (74 loc) · 3.4 KB
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
85
86
import os
import DracoPy
import pytest
testdata_directory = "testdata_files"
def test_decoding_and_encoding_mesh_file():
expected_points = 104502
expected_faces = 208353
with open(os.path.join(testdata_directory, "bunny.drc"), "rb") as draco_file:
file_content = draco_file.read()
mesh_object = DracoPy.decode_buffer_to_mesh(file_content)
assert len(mesh_object.points) == expected_points
assert len(mesh_object.faces) == expected_faces
encoding_test = DracoPy.encode_mesh_to_buffer(
mesh_object.points, mesh_object.faces
)
with open("bunny_test.drc", "wb") as test_file:
test_file.write(encoding_test)
with open(os.path.join(testdata_directory, "bunny_test.drc"), "rb") as test_file:
file_content = test_file.read()
mesh_object = DracoPy.decode_buffer_to_mesh(file_content)
assert (mesh_object.encoding_options) is None
assert len(mesh_object.points) == expected_points
assert len(mesh_object.faces) == expected_faces
def test_decoding_improper_file():
with open(os.path.join(testdata_directory, "bunny.obj"), "rb") as improper_file:
file_content = improper_file.read()
with pytest.raises(DracoPy.FileTypeException):
DracoPy.decode_buffer_to_mesh(file_content)
def test_metadata():
with open(os.path.join(testdata_directory, "bunny.drc"), "rb") as draco_file:
file_content = draco_file.read()
mesh_object = DracoPy.decode_buffer_to_mesh(file_content)
encoding_options = {
"quantization_bits": 12,
"compression_level": 3,
"quantization_range": 1000,
"quantization_origin": [-100, -100, -100],
"create_metadata": True,
}
encoding_test = DracoPy.encode_mesh_to_buffer(
mesh_object.points, mesh_object.faces, **encoding_options
)
with open(
os.path.join(testdata_directory, "bunny_test.drc"), "wb"
) as test_file:
test_file.write(encoding_test)
with open(os.path.join(testdata_directory, "bunny_test.drc"), "rb") as test_file:
file_content = test_file.read()
mesh_object = DracoPy.decode_buffer_to_mesh(file_content)
eo = mesh_object.encoding_options
assert (eo) is not None
assert (eo.quantization_bits) == 12
assert (eo.quantization_range) == 1000
assert (eo.quantization_origin) == [-100, -100, -100]
def test_decoding_and_encoding_point_cloud_file():
expected_points = 107841
with open(
os.path.join(testdata_directory, "point_cloud_bunny.drc"), "rb"
) as draco_file:
file_content = draco_file.read()
point_cloud_object = DracoPy.decode_point_cloud_buffer(file_content)
assert len(point_cloud_object.points) == expected_points
encoding_test = DracoPy.encode_point_cloud_to_buffer(point_cloud_object.points)
with open(
os.path.join(testdata_directory, "point_cloud_bunny_test.drc"), "wb"
) as test_file:
test_file.write(encoding_test)
with open(
os.path.join(testdata_directory, "point_cloud_bunny_test.drc"), "rb"
) as test_file:
file_content = test_file.read()
point_cloud_object = DracoPy.decode_point_cloud_buffer(file_content)
assert (point_cloud_object.encoding_options) is None
assert len(point_cloud_object.points) == expected_points