shuishen
10 hours ago fbb068ec702338d609c1ca6eddbdb9f182d8f211
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
"""Generate reproducible point-cloud fixtures for the CPU Demo tests.
 
The fixtures have known geometry and are not presented as field data.  The
console accepts actual PLY/PCD/XYZ/LAS/LAZ products from a survey or an ODM
reconstruction; these two inputs verify the processing contract before one is
used on a larger collection.
"""
 
from __future__ import annotations
 
import argparse
from pathlib import Path
 
import numpy as np
import open3d as o3d
 
 
def _write_cloud(path: Path, points: np.ndarray) -> None:
    cloud = o3d.geometry.PointCloud()
    cloud.points = o3d.utility.Vector3dVector(points)
    colors = np.tile(np.array([[0.35, 0.62, 0.41]], dtype=float), (len(points), 1))
    colors[points[:, 2] > 1.0] = [0.83, 0.34, 0.12]
    cloud.colors = o3d.utility.Vector3dVector(colors)
    if not o3d.io.write_point_cloud(str(path), cloud, write_ascii=False):
        raise RuntimeError(f"Could not write {path}")
 
 
def normal_scene(seed: int = 42) -> np.ndarray:
    """A dense flat site with one roof and one rounded elevated object."""
    rng = np.random.default_rng(seed)
    ground_xy = rng.uniform(-12, 12, size=(5_000, 2))
    ground = np.column_stack((ground_xy, rng.normal(0, 0.025, size=len(ground_xy))))
    roof_xy = rng.uniform([-4.5, -3.0], [3.5, 3.0], size=(2_400, 2))
    roof = np.column_stack((roof_xy, rng.normal(2.8, 0.035, size=len(roof_xy))))
    wall_y = rng.uniform(-3, 3, size=600)
    walls = np.vstack((
        np.column_stack((np.full(600, -4.5), wall_y, rng.uniform(0, 2.8, 600))),
        np.column_stack((np.full(600, 3.5), wall_y, rng.uniform(0, 2.8, 600))),
    ))
    crown = rng.normal([7.2, 6.0, 3.0], [1.0, 1.0, 0.7], size=(1_000, 3))
    return np.vstack((ground, roof, walls, crown))
 
 
def difficult_scene(seed: int = 7) -> np.ndarray:
    """A sparse scene with tilted terrain, a small roof, and isolated high noise."""
    rng = np.random.default_rng(seed)
    ground_xy = rng.uniform(-12, 12, size=(750, 2))
    ground_z = 0.035 * ground_xy[:, 0] - 0.02 * ground_xy[:, 1] + rng.normal(0, 0.06, len(ground_xy))
    ground = np.column_stack((ground_xy, ground_z))
    roof_xy = rng.uniform([-2.5, -2.0], [1.4, 1.7], size=(270, 2))
    roof_z = 0.035 * roof_xy[:, 0] - 0.02 * roof_xy[:, 1] + 2.0 + rng.normal(0, 0.06, len(roof_xy))
    roof = np.column_stack((roof_xy, roof_z))
    noise_xy = rng.uniform(-12, 12, size=(35, 2))
    noise = np.column_stack((noise_xy, rng.uniform(1.6, 4.2, len(noise_xy))))
    return np.vstack((ground, roof, noise))
 
 
def main() -> int:
    parser = argparse.ArgumentParser(description="Generate known-geometry PLY validation fixtures.")
    parser.add_argument("--output", type=Path, required=True)
    args = parser.parse_args()
    args.output.mkdir(parents=True, exist_ok=True)
    _write_cloud(args.output / "normal_site.ply", normal_scene())
    _write_cloud(args.output / "difficult_sparse_site.ply", difficult_scene())
    return 0
 
 
if __name__ == "__main__":
    raise SystemExit(main())