shuishen
18 hours ago 385be2eca72eb3833efa4be0a0088b34e764788a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
from __future__ import annotations
 
import sys
import unittest
from pathlib import Path
 
import numpy as np
 
sys.path.insert(0, str(Path(__file__).resolve().parents[1]))
from diagnose_multimodal_projection import z_buffer_render  # noqa: E402
 
 
class ProjectionDiagnosticTests(unittest.TestCase):
    def test_z_buffer_keeps_nearest_colour_for_one_pixel(self) -> None:
        pixels = np.array([[2.0, 3.0], [2.0, 3.0], [1.0, 1.0]])
        depth = np.array([8.0, 2.0, 3.0])
        colors = np.array([[1.0, 0.0, 0.0], [0.0, 1.0, 0.0], [0.0, 0.0, 1.0]])
        render, mask = z_buffer_render(pixels, depth, np.array([True, True, True]), colors, 6, 6)
        np.testing.assert_array_equal(render[3, 2], [0, 255, 0])
        self.assertEqual(int(mask.sum() / 255), 2)
 
 
if __name__ == "__main__":
    unittest.main()