ridge-bake: r_max_m fits each card tile's linear map at its own distance (R = d)
The per-column median distances inside a tile are no longer part of the fit: the card sits at the tile's distance_m, as ruling ridge-offset-range-fit has it. Vienna's r_max_m is 98.2 m (was 56.1). Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
920e37e385
commit
30e4ee549a
2 changed files with 20 additions and 20 deletions
|
|
@ -35,7 +35,7 @@ Files are `Copernicus_DSM_COG_10_<N|S>dd_00_<E|W>ddd_00_DEM.tif`; the list below
|
|||
4. **Seams.** `coverage` counts the visible rows of the opaque view per log-distance bin and column. `seams` finds one seam per authored split per column by dynamic programming (seam carving, forward energy): it sits in a gap between depths, moving it costs 2 per bin plus the visible rows it sweeps (so it never hops across a ridge between two columns and splits it side by side), a seam inside visible terrain is cheap to cross-fade, the authored depth only breaks ties. Seam k stays 0.4 nat beyond seam k-1. The DP runs over the ring three times side by side and keeps the middle lap, so a seam is continuous across the wrap (column 6399 to 0) and a tile boundary is only a crop.
|
||||
5. **Cards.** `cards` runs per tile, on that tile's columns and the matching normals (it is column-independent: a tile is a crop of per-column results, so no seam appears at a tile boundary). It makes card i from the first visible hit at or beyond seam i-1 (layered depth: a farther card keeps the terrain a nearer ridge hides), alpha 1 minus a smoothstep over seam i in log-distance (the cross-fade), crest rows with fractional coverage, distance and normal interpolated between samples by angle, albedo from a small height and slope material, cropped to the rows where alpha is not zero. The rows of card i > 0 below the angle of its first sample (hit and first sample of the card) are its **wall**: the extruded face of the ridge the card starts at, which keeps that sample's distance, wears the ground material at its height with the face up, and is flagged `wall` (card 0 has none: its rows there are the ground). The alpha-over composite of the cards equals the opaque view; `check_cover` refuses a tile that differs by more than 0.02.
|
||||
6. **Tiles.** The ring is absolute compass, column 0 = north, column c at azimuth (c + 0.5) / 6400 x 360; `places.json`'s `az_deg` / `look_at` is only the rest azimuth (`view.look_az_deg`). Tile t owns columns [200 t, 200 t + 200) (11.25 degrees) and its files hold [200 t - 2, 200 t + 202): two columns of real neighbour data each side (the client's ink pass and lighting read one texel each way; the client crops it), taken periodically by `ridge.ring_cols`. Per card and tile the file is cropped to the rows where that tile's 8-bit alpha is not zero (`top`, `h`); a card that holds nothing in a tile is `null` there (the client interpolates its distance from the neighbours); a card with no solid pixel in any tile is refused.
|
||||
7. **Distance and the offset range.** The bake holds no camera (ruling `ridge-camera-full-ring`). `pack` gives each card tile `distance_m` = exp(median ln d) over the tile's solid pixels that are not wall (its interior 200 columns); the client derives each card's slide from that and the viewer's offset r and heading. `camera.r_max_m` is the largest |r| (never above half the nearest card's smallest tile distance) at which, for every tile, card and phi (24 steps of the camera's angle on the circle against its heading), the least-squares line `a + s beta` fitted to the exact view angle `atan2(R sin beta - r sin phi, R cos beta - r cos phi)` over the widest viewport (`HFOV_MAX_DEG` = 72 / 1.1) errs by at most `FIT_PX_MAX` = 24 card px; R is the card's per-column median distance in the tile, the line uses the tile's `distance_m`, and the resident gate (below) must hold at r_max_m too. `FIT_PX_MAX` is provisional, tuned by eye (ruling `ridge-offset-range-fit`). A bake whose `r_max_m` is below `R_MAX_FLOOR_M` = 25 m is refused, naming the card and tile.
|
||||
7. **Distance and the offset range.** The bake holds no camera (ruling `ridge-camera-full-ring`). `pack` gives each card tile `distance_m` = exp(median ln d) over the tile's solid pixels that are not wall (its interior 200 columns); the client derives each card's slide from that and the viewer's offset r and heading. `camera.r_max_m` is the largest |r| (never above half the nearest card's smallest tile distance) at which, for every tile, card and phi (24 steps of the camera's angle on the circle against its heading), the least-squares line `a + s beta` fitted to the exact view angle `atan2(R sin beta - r sin phi, R cos beta - r cos phi)` over the widest viewport (`HFOV_MAX_DEG` = 72 / 1.1) errs by at most `FIT_PX_MAX` = 24 card px; the card sits at the tile's `distance_m` (R = d) and the line is fitted for that same distance, and the resident gate (below) must hold at r_max_m too. `FIT_PX_MAX` is provisional, tuned by eye (ruling `ridge-offset-range-fit`). A bake whose `r_max_m` is below `R_MAX_FLOOR_M` = 25 m is refused, naming the card and tile.
|
||||
8. **Normals.** `normals` takes the along-ray slope and the across-ray slope at equal distance (neighbouring columns, same sample), both times the vertical exaggeration.
|
||||
|
||||
Files per card `i` and tile `t`: `card-<i>-t<tt>-colour.webp` (lossy RGB albedo, lossless straight alpha) and `card-<i>-t<tt>-geometry.webp` (lossless: R, G = (n + 1) / 2 for the normal's along and across components, B = log-distance normalised between `encoding.log_d_min` and `log_d_max`; wall pixels write R = G = 255, a code outside the unit disc that no real normal reaches), each 204 columns wide. The manifest lists the cards nearest first (`near_m`, `far_m`: the median seam depths over the ring) and `tiles[t][i]` = `{ top, h, distance_m, colour, geometry }` or `null`; the runtime paints the cards last to first. The `bake_id` is the sha256 of the files, tile-major, then card, colour then geometry.
|
||||
|
|
|
|||
|
|
@ -139,20 +139,20 @@ def check_budget(n_cards, tile_bytes, bands, r_max_m, rmin_m):
|
|||
n = run_tiles(r_max_m, rmin_m); res = resident_bytes(bands, n)
|
||||
if res > RESIDENT_BYTES_MAX: raise ValueError(f'{n} consecutive tiles light to {res} bytes, above {RESIDENT_BYTES_MAX}')
|
||||
|
||||
def fit_px(d, rs, r, px_per_deg):
|
||||
"""The worst error, in card pixels, of the card's linear slide at offset r (m): over the camera's angle phi on its circle against its heading (PHI_STEPS) and the viewport (beta in +-HFOV_MAX_DEG / 2), the exact view angle of a cylinder point at distance R,
|
||||
alpha = atan2(R sin beta - r sin phi, R cos beta - r cos phi), against the least-squares line a + s beta fitted to it for the tile's distance_m d; R runs over rs, the card's per-column median distances in the tile, so a card whose distance varies inside the tile counts."""
|
||||
b = np.radians(np.linspace(-HFOV_MAX_DEG / 2, HFOV_MAX_DEG / 2, 33))[None, None, :]; p = np.linspace(0, 2 * math.pi, PHI_STEPS, endpoint=False)[None, :, None]
|
||||
ang = lambda R: np.arctan2(R * np.sin(b) - r * np.sin(p), R * np.cos(b) - r * np.cos(p)); bc = b - b.mean(); A = ang(np.float64(d)); s = (A * bc).sum(-1, keepdims=True) / (bc * bc).sum(); line = A.mean(-1, keepdims=True) + s * bc
|
||||
return math.degrees(float(np.abs(ang(np.asarray(rs, np.float64)[:, None, None]) - line).max())) * px_per_deg
|
||||
def fit_table(dist, cols, r, px_per_deg):
|
||||
def fit_px(d, r, px_per_deg):
|
||||
"""The worst error, in card pixels, of a card tile's linear slide at offset r (m): over the camera's angle phi on its circle against its heading (PHI_STEPS) and the viewport (beta in +-HFOV_MAX_DEG / 2), the exact view angle of a cylinder point at the tile's
|
||||
distance d, alpha = atan2(d sin beta - r sin phi, d cos beta - r cos phi), against the least-squares line a + s beta fitted to it (ruling ridge-offset-range-fit)."""
|
||||
b = np.radians(np.linspace(-HFOV_MAX_DEG / 2, HFOV_MAX_DEG / 2, 33))[None, :]; p = np.linspace(0, 2 * math.pi, PHI_STEPS, endpoint=False)[:, None]
|
||||
A = np.arctan2(d * np.sin(b) - r * np.sin(p), d * np.cos(b) - r * np.cos(p)); bc = b - b.mean(); s = (A * bc).sum(-1, keepdims=True) / (bc * bc).sum(); line = A.mean(-1, keepdims=True) + s * bc
|
||||
return math.degrees(float(np.abs(A - line).max())) * px_per_deg
|
||||
def fit_table(dist, r, px_per_deg):
|
||||
"""(tiles, cards) fit_px of every card tile at offset r; nan where the card is null in that tile."""
|
||||
return np.array([[np.nan if d is None else fit_px(d, cols[t][i], r, px_per_deg) for i, d in enumerate(row)] for t, row in enumerate(dist)])
|
||||
def solve_r_max(dist, cols, bands, px_per_deg):
|
||||
return np.array([[np.nan if d is None else fit_px(d, r, px_per_deg) for d in row] for row in dist])
|
||||
def solve_r_max(dist, bands, px_per_deg):
|
||||
"""The largest offset r (m, down to 0.1 m) at which every card tile fits within FIT_PX_MAX and the resident gate holds: never above half the nearest card's smallest tile distance. Scans r upward from 0 on 128 steps to the first failure, then bisects that step.
|
||||
Refuses (naming the card and tile that bind) a bake whose r_max_m is below R_MAX_FLOOR_M."""
|
||||
near = min((row[0], t) for t, row in enumerate(dist) if row[0] is not None); rmin = near[0]; cap = 0.5 * rmin
|
||||
ok = lambda r: bool(np.nanmax(fit_table(dist, cols, r, px_per_deg)) <= FIT_PX_MAX) and resident_bytes(bands, run_tiles(r, rmin)) <= RESIDENT_BYTES_MAX
|
||||
ok = lambda r: bool(np.nanmax(fit_table(dist, r, px_per_deg)) <= FIT_PX_MAX) and resident_bytes(bands, run_tiles(r, rmin)) <= RESIDENT_BYTES_MAX
|
||||
lo, hi = 0.0, None
|
||||
for r in np.linspace(0, cap, 129)[1:]:
|
||||
if ok(r): lo = float(r)
|
||||
|
|
@ -166,7 +166,7 @@ def solve_r_max(dist, cols, bands, px_per_deg):
|
|||
r_max = math.floor(lo * 10) / 10
|
||||
if r_max < R_MAX_FLOOR_M:
|
||||
if cap < R_MAX_FLOOR_M: raise ValueError(f'r_max_m {r_max:g} is below {R_MAX_FLOOR_M:g} m: card 0 stands {rmin:.0f} m away in tile {near[1]} and the offset stays under half of that')
|
||||
tb = fit_table(dist, cols, R_MAX_FLOOR_M, px_per_deg); t, i = np.unravel_index(int(np.nanargmax(tb)), tb.shape)
|
||||
tb = fit_table(dist, R_MAX_FLOOR_M, px_per_deg); t, i = np.unravel_index(int(np.nanargmax(tb)), tb.shape)
|
||||
if tb[t, i] > FIT_PX_MAX: raise ValueError(f'r_max_m {r_max:g} is below {R_MAX_FLOOR_M:g} m: card {i} in tile {t} errs {tb[t, i]:.1f} card px at {R_MAX_FLOOR_M:g} m (the bound is {FIT_PX_MAX:g})')
|
||||
n = run_tiles(R_MAX_FLOOR_M, rmin); raise ValueError(f'r_max_m {r_max:g} is below {R_MAX_FLOOR_M:g} m: at {R_MAX_FLOOR_M:g} m, {n} consecutive tiles light to {resident_bytes(bands, n)} bytes, above {RESIDENT_BYTES_MAX}')
|
||||
return r_max
|
||||
|
|
@ -238,24 +238,24 @@ def bake_place(pid):
|
|||
|
||||
def pack(bake):
|
||||
"""The tiles of a bake as bytes plus their manifest facts. Per card tile: distance_m = exp(median ln d) over the solid (alpha >= 0.5) pixels that are not wall of the interior TILE_W columns (a tile with none falls back to its non-wall, then any, lit pixels);
|
||||
a card with no rows in a tile is null there. Per card: the median seam depths over the ring. camera.r_max_m: solve_r_max over the card tiles' distances and per-column median distances. Refuses a card empty in every tile (naming the splits) and a card with
|
||||
a card with no rows in a tile is null there. Per card: the median seam depths over the ring. camera.r_max_m: solve_r_max over the card tiles' distances. Refuses a card empty in every tile (naming the splits) and a card with
|
||||
no solid terrain apart from its wall in any tile. Returns dict(cards, tiles, camera, report) (report is printed, not written)."""
|
||||
sm = bake['seams']; sp = bake['splits_km']; k = len(sp) + 1; ppd = bake['view']['px_per_deg_h']; inner = slice(APRON, APRON + TILE_W); enc = bake['meta']['encoding']
|
||||
for i in range(k):
|
||||
if all(tile[i]['alpha'].shape[0] == 0 for tile in bake['cards']): raise ValueError(f"card {i} is empty: it lies between the splits {' and '.join(f'{sp[j]:g} km' for j in (i - 1, i) if 0 <= j < len(sp))} (card_split_km {sp}) and holds no terrain nothing nearer hides; move or remove a split")
|
||||
tiles, dist, cols, bands = [], [], [], []; any_solid = [False] * k
|
||||
tiles, dist, bands = [], [], []; any_solid = [False] * k
|
||||
for tile in bake['cards']:
|
||||
row, drow, crow, brow = [], [], [], []
|
||||
row, drow, brow = [], [], []
|
||||
for i, c in enumerate(tile):
|
||||
if c['alpha'].shape[0] == 0: row.append(None); drow.append(None); crow.append(None); continue
|
||||
if c['alpha'].shape[0] == 0: row.append(None); drow.append(None); continue
|
||||
al, wl, ld = c['alpha'][:, inner], c['wall'][:, inner], c['logd'][:, inner]; solid = (al >= 0.5) & ~wl; any_solid[i] |= bool(solid.any())
|
||||
pool = next((m, l) for m, l in ((solid, ld), ((al > 0) & ~wl, ld), (al > 0, ld), (c['alpha'] > 0, c['logd'])) if m.any())
|
||||
dm = float(np.exp(np.median(pool[1][pool[0]]))); rc = [float(np.exp(np.median(ld[:, x][solid[:, x]]))) for x in range(TILE_W) if solid[:, x].any()]
|
||||
row.append(dict(top=c['top'], colour=encode_colour(c['albedo'], c['alpha']), geometry=encode_geometry(c['n_r'], c['n_t'], c['logd'], enc, c['wall']), distance_m=dm)); drow.append(dm); crow.append(np.array(rc if rc else [dm])); brow.append(c['alpha'].shape[0])
|
||||
tiles.append(row); dist.append(drow); cols.append(crow); bands.append(brow)
|
||||
dm = float(np.exp(np.median(pool[1][pool[0]])))
|
||||
row.append(dict(top=c['top'], colour=encode_colour(c['albedo'], c['alpha']), geometry=encode_geometry(c['n_r'], c['n_t'], c['logd'], enc, c['wall']), distance_m=dm)); drow.append(dm); brow.append(c['alpha'].shape[0])
|
||||
tiles.append(row); dist.append(drow); bands.append(brow)
|
||||
for i in range(k):
|
||||
if not any_solid[i]: raise ValueError(f'card {i} holds no solid terrain apart from its wall rows')
|
||||
r_max = solve_r_max(dist, cols, bands, ppd); rmin = min(row[0] for row in dist if row[0] is not None); n = run_tiles(r_max, rmin); worst = np.nanmax(fit_table(dist, cols, r_max, ppd), axis=0)
|
||||
r_max = solve_r_max(dist, bands, ppd); rmin = min(row[0] for row in dist if row[0] is not None); n = run_tiles(r_max, rmin); worst = np.nanmax(fit_table(dist, r_max, ppd), axis=0)
|
||||
cards = [dict(near_m=float(np.median(sm[i - 1])) if i else None, far_m=float(np.median(sm[i])) if i < len(sm) else None) for i in range(k)]
|
||||
return dict(cards=cards, tiles=tiles, camera=dict(r_max_m=r_max), report=dict(fit_px=[float(x) for x in worst], run_tiles=n, resident_bytes=resident_bytes(bands, n), nearest_m=rmin))
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue