File size: 2,346 Bytes
b2004ce | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 | """Regression checks for debug overlays fed maps that are not full resolution.
`build_fast_shadow_lighting_maps` caps its shade map at
FAST_SHADOW_MAX_DIMENSION, but the pipeline still holds the full-resolution
surface mask and hands both to `record_lighting`. Before this was handled the
in-place `finite &= mask` raised
operands could not be broadcast together with
shapes (640,482) (1280,963) (640,482)
which failed *every* conversion whenever debug artifacts were enabled --
including the default, since DEBUG_ARTIFACTS_ENABLED defaults to "1" and only
the gpu and hf profiles turn it off.
"""
import unittest
import numpy as np
from services.debug.overlays import debug_scalar_map
class DebugScalarMapTests(unittest.TestCase):
def test_accepts_a_mask_larger_than_the_map(self):
values = np.linspace(0.4, 1.2, 640 * 482, dtype=np.float32).reshape(640, 482)
mask = np.zeros((1280, 963), dtype=np.uint8)
mask[400:1200, 100:900] = 1
output = debug_scalar_map(values, mask)
# The overlay follows the map it is visualising, not the mask.
self.assertEqual(output.shape, (640, 482, 3))
def test_still_blanks_pixels_outside_the_surface(self):
# A mask covering only the top half must still black out the bottom
# half after being resized down onto the map.
values = np.full((64, 48), 1.0, dtype=np.float32)
values[:, 0] = 0.2 # give the percentile range something to work with
mask = np.zeros((128, 96), dtype=np.uint8)
mask[:64, :] = 1
output = debug_scalar_map(values, mask)
self.assertTrue((output[-1] == 0).all(), "bottom row should be outside the mask")
self.assertFalse((output[0] == 0).all(), "top row should be inside the mask")
def test_matching_shapes_are_unchanged(self):
values = np.linspace(0.0, 1.0, 32 * 32, dtype=np.float32).reshape(32, 32)
mask = np.ones((32, 32), dtype=np.uint8)
output = debug_scalar_map(values, mask)
self.assertEqual(output.shape, (32, 32, 3))
def test_no_mask_is_still_allowed(self):
values = np.linspace(0.0, 1.0, 16 * 16, dtype=np.float32).reshape(16, 16)
output = debug_scalar_map(values, None)
self.assertEqual(output.shape, (16, 16, 3))
if __name__ == "__main__":
unittest.main()
|