Preserve offline geometry, marking, replay and evaluation pipelines with source manifests and synthetic tests. Research qualification does not activate these methods as production navigation.
62 lines
3.6 KiB
Python
62 lines
3.6 KiB
Python
"""Plan both required render footprints from the initial observed ground.
|
|
|
|
No detected object, prior map, semantic score or failed check is an input.
|
|
The existing terrain bootstrap is unchanged; all high-resolution views are
|
|
scheduled before the first high-resolution render.
|
|
"""
|
|
from pathlib import Path
|
|
import copy,json
|
|
import numpy as np
|
|
|
|
POLICY=dict(sample_m=1.,camera_grid_m=10.,usable_half_width_m=27.,
|
|
view_width_m=60.,required_views=2,max_additional_views=80)
|
|
|
|
def complete_coverage(points,centers,policy=POLICY):
|
|
points=np.asarray(points,float).reshape(-1,2)
|
|
centers=np.asarray(centers,float).reshape(-1,2)
|
|
if not np.isfinite(points).all() or not np.isfinite(centers).all():
|
|
raise ValueError('Nonfinite coverage geometry')
|
|
if not len(points):raise ValueError('No observed-ground coverage targets')
|
|
points=np.unique(points,axis=0)
|
|
half=policy['usable_half_width_m'];required=policy['required_views']
|
|
counts=(abs(points[:,None,:]-centers[None,:,:]).max(2)<=half).sum(1)
|
|
before=counts.copy();step=policy['camera_grid_m']
|
|
candidates=np.unique(np.round(points/step)*step,axis=0)
|
|
candidates=np.asarray([c for c in candidates if not np.any(np.max(abs(centers-c),axis=1)<1e-6)])
|
|
result=[]
|
|
while np.any(counts<required):
|
|
if len(result)>=policy['max_additional_views']:raise ValueError('Initial observation budget exceeded')
|
|
if not len(candidates):raise ValueError('Cannot provide distinct observation footprints')
|
|
covered=abs(candidates[:,None,:]-points[None,:,:]).max(2)<=half
|
|
gains=(covered&(counts<required)).sum(1);i=int(np.argmax(gains))
|
|
if gains[i]==0:raise ValueError('Uncovered initial ground domain')
|
|
center=candidates[i].copy();result.append(dict(center=center.tolist(),new_coverage_samples=int(gains[i])))
|
|
counts+=covered[i];candidates=np.delete(candidates,i,axis=0)
|
|
return result,dict(target_samples=len(points),initial_two_view_samples=int((before>=required).sum()),
|
|
planned_two_view_samples=int((counts>=required).sum()),minimum_views=int(counts.min()),
|
|
additional_views=len(result),unknown_ground_inferred=False,object_input=False)
|
|
|
|
def plan(survey,index):
|
|
survey=Path(survey);points=[]
|
|
for tile in index['tiles']:
|
|
path=survey/tile['id']/'surface-atlas.npz'
|
|
if not path.is_file():continue
|
|
with np.load(path)as z:
|
|
depth=z['z'];cell=float(z['cell_m']);low=z['bounds'][0];stride=max(1,round(POLICY['sample_m']/cell))
|
|
rr,cc=np.where(np.isfinite(depth[::stride,::stride]));rr*=stride;cc*=stride
|
|
points.append(np.c_[low[0]+(cc+.5)*cell,low[1]+(depth.shape[0]-rr-.5)*cell])
|
|
if not points:raise ValueError('Missing bootstrap observations')
|
|
centers=np.array([np.mean(t['bounds_xy'],axis=0)for t in index['tiles']])
|
|
additions,report=complete_coverage(np.concatenate(points),centers)
|
|
tiles=[];jobs={}
|
|
for i,row in enumerate(additions):
|
|
center=np.asarray(row['center']);nearest=index['tiles'][int(np.argmin(np.linalg.norm(centers-center,axis=1)))]
|
|
job=copy.deepcopy(json.loads((survey/nearest['id']/'job.json').read_text()))
|
|
name=f'primary-support-{i:03d}';bounds=[(center-30).tolist(),(center+30).tolist()]
|
|
top=next(v for v in job['views']if v['id']=='top');delta=center-np.asarray(top['eye'][:2])
|
|
top['eye'][:2]=center.tolist();top['target'][:2]=(np.asarray(top['target'][:2])+delta).tolist()
|
|
job['bounds_xy']=bounds;jobs[name]=job
|
|
tiles.append(dict(id=name,status='planned',bounds_xy=bounds,role='initial-two-view-support',**row))
|
|
return tiles,jobs,dict(schema='missioncore.initial-observation-coverage/v1',policy=POLICY,**report)
|
|
|