Skip to content

[go] Add dynamic segmentation for LiDAR background regions#388

Open
ddol wants to merge 3 commits into
mainfrom
codex/add-dynamic-segmentation-for-lidar-regions
Open

[go] Add dynamic segmentation for LiDAR background regions#388
ddol wants to merge 3 commits into
mainfrom
codex/add-dynamic-segmentation-for-lidar-regions

Conversation

@ddol

@ddol ddol commented Mar 15, 2026

Copy link
Copy Markdown
Member

Summary

Implements dynamic region segmentation for the LiDAR background grid with warmup initialisation and a web chart endpoint.

Changes

  • internal/lidar/background.go — Add dynamic segmentation logic to BackgroundGrid, including warmup initialisation (+506 lines)
  • internal/lidar/monitor/webserver.go — Add tooltip formatter and chart endpoint for background regions visualisation (+94 lines)

Commits

  • 2e4931c Add lidar background regions
  • 9a6ae75 Fix tooltip formatter in background regions chart
  • a4f3701 Add warmup initialisation to BackgroundGrid

3 commits, 2 files changed, +593 −7

Copilot AI review requested due to automatic review settings March 15, 2026 04:09

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds dynamic region segmentation to the LiDAR background grid so background update behaviour can vary by derived region, and exposes a new debug chart endpoint to visualise those regions and their parameters.

Changes:

  • Extend BackgroundGrid with region segmentation state (region index + derived per-region parameters) and apply per-region overrides during background updates after settling.
  • Add warmup initialisation tracking and trigger one-time region derivation once the grid has settled.
  • Add a new /debug/lidar/background/regions go-echarts scatter plot endpoint (with tooltip formatter) and link it from the LiDAR debug dashboard.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 7 comments.

File Description
internal/lidar/background.go Adds region segmentation structures/derivation, warmup initialisation state, and per-region parameter overrides in ProcessFramePolar.
internal/lidar/monitor/webserver.go Adds “Background Regions” debug chart endpoint and dashboard panel, including custom tooltip formatting.

Comment on lines +1507 to +1509
if g.SettlingComplete && !g.RegionsReady && g.nonzeroCellCount > 0 {
buildRegionsLocked(g)
}
Comment on lines +851 to +889
regionCells := make([][]int, 0)
for idx := range g.Cells {
if classes[idx] < 0 || regionIndex[idx] != -1 {
continue
}
targetClass := classes[idx]
queue := []int{idx}
regionIndex[idx] = len(regionCells)
component := []int{idx}
for q := 0; q < len(queue); q++ {
cellIdx := queue[q]
ring := cellIdx / g.AzimuthBins
az := cellIdx % g.AzimuthBins
neighbors := [4]int{
g.Idx(ring, (az-1+g.AzimuthBins)%g.AzimuthBins),
g.Idx(ring, (az+1)%g.AzimuthBins),
-1,
-1,
}
if ring > 0 {
neighbors[2] = g.Idx(ring-1, az)
}
if ring < g.Rings-1 {
neighbors[3] = g.Idx(ring+1, az)
}
for _, nIdx := range neighbors {
if nIdx < 0 || nIdx >= len(g.Cells) {
continue
}
if classes[nIdx] != targetClass || regionIndex[nIdx] != -1 {
continue
}
regionIndex[nIdx] = len(regionCells)
queue = append(queue, nIdx)
component = append(component, nIdx)
}
}
regionCells = append(regionCells, component)
}
Comment on lines +987 to +1005
idMap := make(map[int]int, len(finalRegions))
regions := make([]BackgroundRegion, 0, len(finalRegions))
for _, ri := range finalRegions {
newID := len(regions)
idMap[ri.ID] = newID
meanRange := ri.SumRange / float64(ri.CellCount)
meanSpread := ri.SumSpread / float64(ri.CellCount)
meanTimes := ri.SumTimes / float64(ri.CellCount)
meanNorm := ri.SumNorm / float64(ri.CellCount)
params := deriveRegionParams(g.Params, meanNorm)
regions = append(regions, BackgroundRegion{
ID: newID,
CellCount: ri.CellCount,
MeanRange: float32(meanRange),
MeanSpread: float32(meanSpread),
MeanTimesSeen: float32(meanTimes),
MeanNormSpread: float32(meanNorm),
Params: params,
})
Comment on lines +1525 to +1531
charts.WithVisualMapOpts(opts.VisualMap{
Show: opts.Bool(true),
Calculable: opts.Bool(true),
Min: 0,
Max: float32(maxRegion),
Dimension: "2",
InRange: &opts.VisualMapInRange{Color: []string{"#003f5c", "#2f4b7c", "#665191", "#a05195", "#d45087", "#f95d6a", "#ff7c43", "#ffa600", "#62d2a2", "#4f9da6", "#a7c5eb", "#f0a6ca"}},
Comment on lines +1469 to +1474
stride := 3
if v := r.URL.Query().Get("stride"); v != "" {
if parsed, err := strconv.Atoi(v); err == nil && parsed > 0 {
stride = parsed
}
}
Comment on lines 1267 to 1273
g.mu.Lock()
if bm.StartTime.IsZero() {
bm.StartTime = now
if !g.WarmupInitialized && g.Params.WarmupMinFrames > 0 && !g.SettlingComplete {
g.WarmupFramesRemaining = g.Params.WarmupMinFrames
g.WarmupInitialized = true
}
if g.WarmupFramesRemaining == 0 && g.Params.WarmupMinFrames > 0 && !g.SettlingComplete {
g.WarmupFramesRemaining = g.Params.WarmupMinFrames
Comment on lines 640 to +649
g.ChangesSinceSnapshot = 0
g.ForegroundCount = 0
g.BackgroundCount = 0
g.nonzeroCellCount = 0
g.WarmupFramesRemaining = 0
g.WarmupInitialized = false
g.SettlingComplete = false
g.RegionIndex = nil
g.Regions = nil
g.RegionsReady = false
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants