feat(semantics): version scene edits and refine paint geometry
This commit is contained in:
@@ -20,6 +20,10 @@ MAX_EDITOR_RINGS = 128
|
||||
MAX_EDITOR_WORK = 2_000_000
|
||||
|
||||
|
||||
class ComponentRefusal(ValueError):
|
||||
"""Expected local geometry/support failure; never a sampler/source exception."""
|
||||
|
||||
|
||||
def digest(value):
|
||||
return hashlib.sha256(
|
||||
json.dumps(value, sort_keys=True, allow_nan=False, separators=(",", ":")).encode()
|
||||
@@ -114,15 +118,7 @@ def vectorize(labels, *, pixel_to_scene, source_id):
|
||||
return result
|
||||
|
||||
|
||||
def editor_features(proposal, *, height_at, height_source):
|
||||
"""Validate and lift exact components, WITHOUT inferring a subtype/template/group.
|
||||
|
||||
Caller supplies observed surface heights at the returned XY vertices. There
|
||||
is no flat/nearest-height fallback. This creates features only: the caller
|
||||
must independently verify scene identity/admission before any map import.
|
||||
"""
|
||||
from k1link.simulation.ai_polygon.semantic_edits import validate_holes, validate_path
|
||||
|
||||
def _editor_preflight(proposal, height_source):
|
||||
payload = {k: v for k, v in proposal.items() if k != "proposal_sha256"}
|
||||
if proposal.get("schema_version") != SCHEMA or digest(payload) != proposal.get(
|
||||
"proposal_sha256"
|
||||
@@ -136,6 +132,11 @@ def editor_features(proposal, *, height_at, height_source):
|
||||
vertices = 0
|
||||
if len(proposal["features"]) > 20000:
|
||||
raise ValueError("Editor feature budget exceeded")
|
||||
identifiers = [f.get("id") for f in proposal["features"]]
|
||||
if any(not isinstance(i, str) or not i for i in identifiers) or len(
|
||||
set(identifiers)
|
||||
) != len(identifiers):
|
||||
raise ValueError("Missing or duplicate component identity")
|
||||
for raw in proposal["features"]:
|
||||
geo = raw["geometry"]
|
||||
if geo["type"] != "Polygon":
|
||||
@@ -150,23 +151,43 @@ def editor_features(proposal, *, height_at, height_source):
|
||||
work += edges * edges
|
||||
if vertices > 300000 or work > MAX_EDITOR_WORK:
|
||||
raise ValueError("Editor validation work budget exceeded; no lossy fallback")
|
||||
|
||||
|
||||
def editor_features(proposal, *, height_at, height_source):
|
||||
"""Strict all-or-nothing lift, WITHOUT inferring a subtype/template/group.
|
||||
|
||||
Caller supplies observed surface heights at the returned XY vertices. There
|
||||
is no flat/nearest-height fallback. This creates features only: the caller
|
||||
must independently verify scene identity/admission before any map import.
|
||||
"""
|
||||
from k1link.simulation.ai_polygon.semantic_edits import validate_holes, validate_path
|
||||
|
||||
_editor_preflight(proposal, height_source)
|
||||
result = []
|
||||
for raw in proposal["features"]:
|
||||
feature = copy.deepcopy(raw)
|
||||
geometry = feature["geometry"]
|
||||
if geometry["type"] != "Polygon" or not shape(geometry).is_valid:
|
||||
raise ValueError("Unsupported editor geometry")
|
||||
raise ComponentRefusal("Unsupported editor geometry")
|
||||
rings = []
|
||||
for ring in geometry["coordinates"]:
|
||||
xy = np.asarray(ring[:-1], dtype=float)
|
||||
z = np.asarray(height_at(xy.copy()), dtype=float)
|
||||
if z.shape != (len(xy),) or not np.isfinite(z).all():
|
||||
raise ValueError("Missing observed height support")
|
||||
if z.shape != (len(xy),):
|
||||
raise ValueError("Height callback returned an invalid shape")
|
||||
if not np.isfinite(z).all():
|
||||
raise ComponentRefusal("Missing observed height support")
|
||||
points = np.column_stack([xy, z]).tolist()
|
||||
points.append(points[0][:])
|
||||
validate_path(points, True)
|
||||
try:
|
||||
validate_path(points, True)
|
||||
except ValueError as error:
|
||||
raise ComponentRefusal(str(error)) from error
|
||||
rings.append(points)
|
||||
validate_holes(rings)
|
||||
try:
|
||||
validate_holes(rings)
|
||||
except ValueError as error:
|
||||
raise ComponentRefusal(str(error)) from error
|
||||
feature["geometry"]["coordinates"] = rings
|
||||
feature["properties"].update({
|
||||
"class": "road_marking", "authority": "observation-only",
|
||||
@@ -176,3 +197,33 @@ def editor_features(proposal, *, height_at, height_source):
|
||||
})
|
||||
result.append(feature)
|
||||
return result
|
||||
|
||||
|
||||
def editor_components(proposal, *, height_at, height_source):
|
||||
"""Explicit partial lift; every original component is admitted OR deferred.
|
||||
|
||||
Integrity and total resource bounds remain atomic, before any sampling.
|
||||
A component-level geometry/height refusal keeps the exact original 2-D
|
||||
feature and reason. No vertex removal, repair, height inference or semantic
|
||||
class inference occurs. Admission is NOT confirmation of road paint.
|
||||
The caller must retain/display deferred data alongside admitted features.
|
||||
"""
|
||||
_editor_preflight(proposal, height_source)
|
||||
admitted, deferred = [], []
|
||||
for raw in proposal["features"]:
|
||||
single = {k: v for k, v in proposal.items() if k != "proposal_sha256"}
|
||||
single["features"] = [raw]
|
||||
single["proposal_sha256"] = digest(single)
|
||||
try:
|
||||
admitted.extend(editor_features(
|
||||
single, height_at=height_at, height_source=height_source
|
||||
))
|
||||
except ComponentRefusal as error:
|
||||
deferred.append(dict(feature=copy.deepcopy(raw), reason=str(error)))
|
||||
return dict(
|
||||
schema_version="missioncore.paint-editor-admission/v1",
|
||||
proposal_sha256=proposal["proposal_sha256"],
|
||||
source_sha256=proposal["source_sha256"], height_source=height_source,
|
||||
features=admitted, deferred=deferred,
|
||||
complete=not deferred, review_status="unreviewed",
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user