Files
NODEDC_MISSION_CORE/simulation/urban-plan-research/systematic/search_views.py
T
DCCONSTRUCTIONS 69dc566665 feat(research): preserve urban geometry pipelines and qualification suites
Preserve offline geometry, marking, replay and evaluation pipelines with source manifests and synthetic tests. Research qualification does not activate these methods as production navigation.
2026-10-29 09:10:00 +03:00

48 lines
2.5 KiB
Python

"""Read accepted extra Gaussian renders without copying or mutating them."""
from pathlib import Path
import json,numpy as np,cv2
from functools import lru_cache
from PIL import Image
from discovery_evidence import DiscoveryViews
from fit_scene import project,world
def warp_semantic(field,source_uv,dest_uv,size):
H=cv2.getPerspectiveTransform(np.asarray(source_uv,'float32'),np.asarray(dest_uv,'float32'))
return cv2.warpPerspective(field.astype('float32'),H,(size,size),flags=cv2.INTER_LINEAR,borderMode=cv2.BORDER_CONSTANT,borderValue=0)
class SearchViews(DiscoveryViews):
def __init__(self,tiles,*args):
self.root=Path('/coverage_base/coverage')
extra=json.loads((self.root/'manifest.json').read_text())['tiles'] if (self.root/'manifest.json').exists() else []
planned=Path('/ortho/observation-coverage.json')
initial=json.loads(planned.read_text()) if planned.exists() else dict(complete=True,tiles=[])
if not initial['complete']:raise ValueError('Incomplete initial observation coverage')
self.initial={t['id']for t in initial['tiles']}
tiles=list(tiles)+initial['tiles']
self.additional={t['id']for t in extra};self.original=list(tiles)
super().__init__(tiles+extra,*args)
@lru_cache(maxsize=128)
def geometry(self,name):
if name in self.additional:
with np.load(self.root/name/'top.geometry.npz')as z:return dict(z)
return super().geometry(name)
@lru_cache(maxsize=12)
def inputs(self,name):
if name not in self.additional:return super().inputs(name)
with np.load(self.root/name/'vehicle.npz')as z:vehicle=z['vehicle'].astype('float32')
return np.asarray(Image.open(self.root/name/'ground.png').convert('RGB')),vehicle
def semantics(self,name,size):
if name not in self.additional:
with np.load(Path('/evidence_plan/evidence')/(name+'.npz'))as z:
return cv2.resize(z['road marking'].astype('float32'),(size,size))
tile=next(t for t in self.tiles if t['id']==name);center=np.mean(tile['bounds_xy'],axis=0)
original=min(self.original,key=lambda t:np.linalg.norm(np.mean(t['bounds_xy'],axis=0)-center))['id']
dst=np.array([[0,0],[size-1,0],[size-1,size-1],[0,size-1]],float)
xy=world((dst+.5)*1200/size-.5,self.geometry(name))
with np.load(Path('/evidence_plan/evidence')/(original+'.npz'))as z:field=z['road marking'].astype('float32')
uv=(project(xy,self.geometry(original))+.5)*field.shape[0]/1200-.5
return warp_semantic(field,uv,dst,size)