统一 2D/3D 深度色条为同一量程。
将 2D 闩锁的深度色彩区间推给 3D 自动着色,固定量程仍跟旋钮。用 test_shared_depth_scale 与深度闩锁冒烟用例验证。
This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
"""2D and 3D depth colour bars name one interval."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from types import SimpleNamespace
|
||||
|
||||
import numpy as np
|
||||
from orisys_app_shared.scene3d.contracts import FieldDescriptor
|
||||
from orisys_studio.scene3d.gl_backend import _field_scalar_range
|
||||
|
||||
|
||||
def _field(quantity: str, values, *, signed: bool = False) -> SimpleNamespace:
|
||||
arr = np.asarray(values, dtype=np.float32)
|
||||
return SimpleNamespace(
|
||||
descriptor=FieldDescriptor(quantity, "1", "approximate", signed),
|
||||
scalar=arr,
|
||||
valid=np.isfinite(arr),
|
||||
)
|
||||
|
||||
|
||||
def test_depth_automatic_scale_uses_the_shared_2d_span() -> None:
|
||||
field = _field("depth_response", np.linspace(0.0, 9.0, 16).reshape(4, 4))
|
||||
assert _field_scalar_range(
|
||||
field,
|
||||
previous=(0.0, 2.0),
|
||||
shared_depth_scale=(0.0, 1.0),
|
||||
) == (0.0, 1.0)
|
||||
|
||||
|
||||
def test_flow_ignores_the_shared_depth_span() -> None:
|
||||
field = _field("flow_magnitude", np.linspace(0.0, 9.0, 16).reshape(4, 4))
|
||||
span = _field_scalar_range(
|
||||
field,
|
||||
previous=None,
|
||||
shared_depth_scale=(0.0, 1.0),
|
||||
)
|
||||
assert span is not None
|
||||
assert span != (0.0, 1.0)
|
||||
assert span[1] > span[0]
|
||||
|
||||
|
||||
def test_depth_without_a_shared_span_still_measures_the_field() -> None:
|
||||
field = _field("depth_response", np.linspace(0.0, 9.0, 16).reshape(4, 4))
|
||||
span = _field_scalar_range(
|
||||
field,
|
||||
previous=None,
|
||||
shared_depth_scale=None,
|
||||
)
|
||||
assert span is not None
|
||||
assert span[0] == 0.0
|
||||
assert span[1] > 1.0
|
||||
|
||||
|
||||
def test_a_degenerate_shared_span_falls_back_to_the_measurement() -> None:
|
||||
field = _field("depth_response", np.linspace(0.0, 9.0, 16).reshape(4, 4))
|
||||
span = _field_scalar_range(
|
||||
field,
|
||||
previous=None,
|
||||
shared_depth_scale=(1.0, 1.0),
|
||||
)
|
||||
assert span is not None
|
||||
assert span != (1.0, 1.0)
|
||||
@@ -920,6 +920,11 @@ def test_depth_view_reports_missing_data_and_fixes_its_scale(make_window):
|
||||
window._on_run_tick()
|
||||
latched = window.arrow_panel.depth_scale_label.text()
|
||||
assert latched
|
||||
shared = window.mesh3d_panel._shared_depth_scale
|
||||
assert shared == window._depth_range_value
|
||||
assert shared is not None
|
||||
assert shared[0] == pytest.approx(0.0)
|
||||
assert shared[1] == pytest.approx(1.0)
|
||||
|
||||
window._last_rendered_view_mode = None
|
||||
stuck.emit(ui_check._fake_packet(2, depth=np.linspace(0.0, 9.0, 64).reshape(8, 8)))
|
||||
@@ -927,6 +932,9 @@ def test_depth_view_reports_missing_data_and_fixes_its_scale(make_window):
|
||||
assert window.arrow_panel.depth_scale_label.text() == latched, (
|
||||
"the depth colour scale re-fitted on every frame"
|
||||
)
|
||||
assert window.mesh3d_panel._shared_depth_scale == shared, (
|
||||
"the 3D depth colour span must stay locked to the 2D latch"
|
||||
)
|
||||
_finish(window, stuck)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user