room-visualizer / test_fast_shadow_transfer.py
github-actions[bot]
Automated Deploy: 236abd04451d1439492ce6c7af505fb0dafbc30a
dbf1f41
Raw History Blame Contribute Delete
1.46 kB
"""Focused regression checks for the low-cost room-shadow extraction path."""
import unittest
import numpy as np
from config.lighting import SHADE_MAP_MAX, SHADE_MAP_MIN
from config.runtime import FAST_SHADOW_MAX_DIMENSION
from services.lighting.luminance import decode_relative_map
from services.lighting.shading import build_fast_shadow_lighting_maps
class FastShadowTransferTests(unittest.TestCase):
def test_returns_compact_map_that_preserves_a_cast_shadow(self):
height, width = 1200, 1600
image = np.full((height, width, 3), 190, dtype=np.uint8)
image[650:1050, 850:1250] = 70
mask = np.zeros((height, width), dtype=np.uint8)
mask[400:1150, 100:1500] = 1
result = build_fast_shadow_lighting_maps(image, mask)
self.assertIsNotNone(result)
shade_map = result["shadeMap"]
self.assertLessEqual(max(shade_map.shape), FAST_SHADOW_MAX_DIMENSION)
self.assertLess(shade_map.size, height * width)
decoded = decode_relative_map(shade_map, SHADE_MAP_MIN, SHADE_MAP_MAX)
shadow = decoded[int(850 * shade_map.shape[0] / height), int(1050 * shade_map.shape[1] / width)]
lit = decoded[int(850 * shade_map.shape[0] / height), int(450 * shade_map.shape[1] / width)]
self.assertLess(shadow, lit)
self.assertIsNone(result["showroomShadeMap"])
self.assertIsNone(result["reflectionMap"])
if __name__ == "__main__":
unittest.main()