object.py (3310B)
1 # 2 # SPDX-FileCopyrightText: Copyright (c) 2021-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. 3 # SPDX-License-Identifier: Apache-2.0 4 # 5 """ 6 Abstract Base class for cameras, radios, and scene objects. 7 """ 8 9 from abc import ABC 10 from abc import abstractmethod 11 12 13 class Object(ABC): 14 # pylint: disable=line-too-long 15 r"""Object(name) 16 17 Baseclass for implementing items that are part of the scene. 18 19 Input 20 ----- 21 name : str 22 Name of the object 23 24 position : [3], float 25 Position :math:`(x,y,z)` as three-dimensional vector. 26 Defaults to `None`, in which case the position is not set at init. 27 28 orientation : [3], float | None 29 Orientation :math:`(\alpha, \beta, \gamma)` specified 30 through three angles corresponding to a 3D rotation 31 as defined in :eq:`rotation`. 32 This parameter is ignored if ``look_at`` is not `None`. 33 34 look_at : [3], float | :class:`sionna.rt.Object` | None 35 A position or the instance of an :class:`~sionna.rt.Object` to 36 point toward to. 37 """ 38 39 # The following names are reserved and therefore cannot be used by objects 40 RESERVED_NAMES = ('preview',) 41 42 def __init__(self, name, position=None, orientation=None, 43 look_at=None, **kwargs): 44 45 # Set the name 46 if not isinstance(name, str): 47 raise TypeError("`name` must be a string") 48 if name in Object.RESERVED_NAMES: 49 msg = f"Cannot use name '{name}' as it is reserved." 50 raise ValueError(msg) 51 self._name = name 52 53 # Scene 54 self._scene = None 55 56 if position is not None: 57 self.position = position 58 59 if look_at is None: 60 if orientation is not None: 61 self.orientation = orientation 62 else: 63 self.look_at(look_at) 64 65 super().__init__(**kwargs) 66 67 @property 68 def name(self): 69 """ 70 str (read-only) : Name 71 """ 72 return self._name 73 74 @property 75 @abstractmethod 76 def position(self): 77 """ 78 [3], tf.float : Get/set the position 79 """ 80 pass 81 82 @position.setter 83 @abstractmethod 84 def position(self, new_position): 85 pass 86 87 @property 88 @abstractmethod 89 def orientation(self): 90 """ 91 [3], tf.float : Get/set the orientation 92 """ 93 pass 94 95 @orientation.setter 96 @abstractmethod 97 def orientation(self, new_orient): 98 pass 99 100 @abstractmethod 101 def look_at(self, target): 102 # pylint: disable=line-too-long 103 r""" 104 Sets the orientation so that the x-axis points toward an 105 ``Object``. 106 107 Input 108 ----- 109 target : [3], float | :class:`sionna.rt.Object` | str 110 A position or the name or instance of an 111 :class:`sionna.rt.Object` in the scene to point toward to 112 """ 113 pass 114 115 ############################################## 116 # Internal methods. 117 # Should not be appear in the end user 118 # documentation 119 ############################################## 120 121 @property 122 def scene(self): 123 """ 124 :class:`~sionna.rt.Scene` : Get/set the scene 125 """ 126 return self._scene 127 128 @scene.setter 129 def scene(self, scene): 130 self._scene = scene