|
| 1 | +# |
| 2 | +# SPDX-FileCopyrightText: Copyright (c) 2021-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. |
| 3 | +# SPDX-License-Identifier: Apache-2.0 |
| 4 | +# |
| 5 | + |
| 6 | +import drjit as dr |
| 7 | +import mitsuba as mi |
| 8 | + |
| 9 | +import sionna.rt as rt |
| 10 | +from sionna.rt.radio_materials.itu import itu_material |
| 11 | +from sionna.rt.scene import Scene, load_scene |
| 12 | +from sionna.rt import PathSolver |
| 13 | + |
| 14 | + |
| 15 | +def add_example_radio_devices(scene: Scene): |
| 16 | + # Note: hardcoded for `box_two_screens.xml` as an example. |
| 17 | + scene.add(rt.Transmitter("tr-1", position=[-3.0, 0.0, 1.5])) |
| 18 | + scene.add(rt.Receiver("rc-1", position=[3.0, 0.0, 1.5])) |
| 19 | + scene.add( |
| 20 | + rt.Receiver( |
| 21 | + "rc-2", position=[1.0, -2.0, 3.5], color=(0.9, 0.9, 0.2), display_radius=0.9 |
| 22 | + ) |
| 23 | + ) |
| 24 | + |
| 25 | + scene.rx_array = rt.PlanarArray( |
| 26 | + num_rows=1, num_cols=1, pattern="tr38901", polarization="VH" |
| 27 | + ) |
| 28 | + scene.tx_array = rt.PlanarArray( |
| 29 | + num_rows=1, num_cols=1, pattern="tr38901", polarization="VH" |
| 30 | + ) |
| 31 | + |
| 32 | + |
| 33 | +def get_example_paths(scene: Scene): |
| 34 | + # Ray tracing parameters |
| 35 | + num_samples_per_src = int(1e6) |
| 36 | + max_num_paths = int(1e7) |
| 37 | + max_depth = 3 |
| 38 | + |
| 39 | + solver = PathSolver() |
| 40 | + paths = solver( |
| 41 | + scene, |
| 42 | + max_depth=max_depth, |
| 43 | + max_num_paths_per_src=max_num_paths, |
| 44 | + samples_per_src=num_samples_per_src, |
| 45 | + ) |
| 46 | + |
| 47 | + return paths |
| 48 | + |
| 49 | + |
| 50 | +def test01_preview_with_paths(): |
| 51 | + scene = load_scene(rt.scene.box_two_screens) |
| 52 | + |
| 53 | + eta_r, sigma = itu_material("metal", 3e9) # ITU material evaluated at 3GHz |
| 54 | + for sh in scene.mi_scene.shapes(): |
| 55 | + material = sh.bsdf() |
| 56 | + material.relative_permittivity = eta_r |
| 57 | + material.conductivity = sigma |
| 58 | + material.scattering_coefficient = 0.01 |
| 59 | + material.xpd_coefficient = 0.2 |
| 60 | + |
| 61 | + add_example_radio_devices(scene) |
| 62 | + paths = get_example_paths(scene) |
| 63 | + |
| 64 | + scene.preview(paths=paths) |
| 65 | + |
| 66 | + |
| 67 | +def test02_preview_with_paths_but_no_valid_path(): |
| 68 | + scene = load_scene(rt.scene.box_two_screens) |
| 69 | + |
| 70 | + eta_r, sigma = itu_material("metal", 3e9) # ITU material evaluated at 3GHz |
| 71 | + for sh in scene.mi_scene.shapes(): |
| 72 | + material = sh.bsdf() |
| 73 | + material.relative_permittivity = eta_r |
| 74 | + material.conductivity = sigma |
| 75 | + material.scattering_coefficient = 0.01 |
| 76 | + material.xpd_coefficient = 0.2 |
| 77 | + |
| 78 | + add_example_radio_devices(scene) |
| 79 | + paths = get_example_paths(scene) |
| 80 | + |
| 81 | + # No valid path |
| 82 | + paths._valid = dr.zeros(mi.TensorXb, paths.valid.shape) |
| 83 | + |
| 84 | + # Should not raise ValueError: need at least one array to concatenate |
| 85 | + scene.preview(paths=paths) |
0 commit comments