Repository navigation
Expand file tree
/
Copy pathpotree_convert_test.py
More file actions
98 lines (76 loc) · 3.48 KB
/
Copy pathpotree_convert_test.py
File metadata and controls
98 lines (76 loc) · 3.48 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
87
88
89
90
91
92
93
94
95
96
97
98
#!/usr/bin/env python3
"""Test PotreeConverter preserves original_index attribute."""
import json
import subprocess
import tempfile
from pathlib import Path
from convert import find_potree_converter
def run_potree_converter(las_path: str, output_dir: str):
"""Run PotreeConverter on a LAS file."""
converter, ld_path = find_potree_converter()
env = {"LD_LIBRARY_PATH": ld_path} if ld_path else None
result = subprocess.run(
[converter, las_path, "-o", output_dir],
capture_output=True,
text=True,
env=env,
)
if result.returncode != 0:
print(f"STDOUT: {result.stdout}")
print(f"STDERR: {result.stderr}")
raise RuntimeError(f"PotreeConverter failed with code {result.returncode}")
return result.stdout
def get_las_point_count(las_path: str) -> int:
"""Get point count from LAS file."""
import laspy
with laspy.open(las_path) as f:
return f.header.point_count
def test_potree_converter(las_file: str):
"""Test that PotreeConverter preserves original_index."""
las_path = Path(las_file)
if not las_path.exists():
raise FileNotFoundError(f"Input file not found: {las_file}")
# Get expected point count
expected_count = get_las_point_count(las_file)
print(f"Input LAS has {expected_count} points")
with tempfile.TemporaryDirectory() as tmpdir:
output_dir = Path(tmpdir) / "potree_output"
# Run converter
print("Running PotreeConverter...")
run_potree_converter(las_file, str(output_dir))
# Check output files exist
assert (output_dir / "metadata.json").exists(), "metadata.json not found"
assert (output_dir / "octree.bin").exists(), "octree.bin not found"
assert (output_dir / "hierarchy.bin").exists(), "hierarchy.bin not found"
print("Output files exist: metadata.json, octree.bin, hierarchy.bin")
# Load and verify metadata
with open(output_dir / "metadata.json") as f:
metadata = json.load(f)
# Check point count
assert metadata["points"] == expected_count, \
f"Point count mismatch: {metadata['points']} vs {expected_count}"
print(f"Point count matches: {metadata['points']}")
# Check original_index attribute exists
attr_names = [a["name"] for a in metadata["attributes"]]
assert "original_index" in attr_names, \
f"original_index not in attributes: {attr_names}"
print("original_index attribute found")
# Check original_index properties
original_index_attr = next(
a for a in metadata["attributes"] if a["name"] == "original_index"
)
assert original_index_attr["type"] == "uint32", \
f"original_index type should be uint32, got {original_index_attr['type']}"
assert original_index_attr["min"] == [0], \
f"original_index min should be [0], got {original_index_attr['min']}"
assert original_index_attr["max"] == [expected_count - 1], \
f"original_index max should be [{expected_count - 1}], got {original_index_attr['max']}"
print(f"original_index: min=0, max={expected_count - 1}, type=uint32")
# Check rgb attribute exists
assert "rgb" in attr_names, f"rgb not in attributes: {attr_names}"
print("rgb attribute found")
print("TEST PASSED")
if __name__ == "__main__":
import sys
las_file = sys.argv[1] if len(sys.argv) > 1 else "centroids.las"
test_potree_converter(las_file)