// Synthetic LAS input. Run from a directory containing lidar_watershed.las.
import aner.dev
import aner.lidar
import aner.parallel
import aner.plot

let work = lidar.context_with(execution: parallel.local(workers: 4), memory_mb: 32)
let cloud = lidar.open(work, "lidar_watershed.las")
let ground = cloud.window(500000.0, 4420000.0, 500120.0, 4420100.0)
    .where_class(2, include_withheld: false)
let elevation = ground.grid(cell_size: 10.0)

print(cloud.metadata())
print(elevation.summary())
dev.capture("LAS source", cloud.metadata())
dev.capture("Selected ground returns", elevation.count())
dev.capture("10 m elevation grid", elevation)
dev.capture("Empty cell count", elevation.cell_count(2, 2))

let points = plot.point_cloud(ground, color: "z", max_points: 300, seed: 42)
    .labels("Easting (m)", "Northing (m)", "NAVD88 elevation (m)")
    .color_label("Elevation (m)").aspect("equal").view(-48.0, 30.0).view_zoom(1.65)
    .title("Synthetic watershed ground returns")
    .caption("Seed 42 shows 300 of 616 ground returns. Withheld records are excluded.")
    .theme(plot.theme("light")).size(980, 660)
let coverage = plot.lidar_grid(elevation)
    .labels("Easting (m)", "Northing (m)")
    .title("Ground-return coverage in 10 m cells")
    .caption("Color shows returns per cell for the full selection. Zero marks an empty cell.")
    .theme(plot.theme("light")).size(850, 650)

points.show()
coverage.show()
points.save("watershed-review.html")
points.save("watershed-points.svg")
coverage.save("watershed-coverage.svg")
