Scene
1# coding: utf-8 2import json 3from Landscape import Landscape 4from Sensor import SensorOrthographic, SensorPerspective, SensorFisheye, SensorPhotonTracing, SensorLiDAR 5from Illumination import Illumination 6from Observation import ObservationOrthographic, ObservationPerspective, ObservationPhotonTracing, ObservationFisheye 7from AdvancedParams import AdvancedParams 8from Element import Element 9from typing import Union 10 11 12class Scene(Element): 13 """ 14 The Scene class that represents the virtual scene, containing landscape, illumination, 15 observation, sensor, and advanced parameters 16 """ 17 18 def __init__(self, sim=None): 19 super().__init__() 20 self.__sensor = SensorOrthographic() 21 # self.__lidarSensor = None 22 self.__landscape = Landscape() 23 self.__illumination = Illumination() 24 self.__observation = ObservationOrthographic() 25 self.__advanced_params = AdvancedParams() 26 self.set_sim(sim) 27 28 def set_sensor(self, sensor: Union[SensorOrthographic, SensorPerspective, SensorFisheye, SensorPhotonTracing, SensorLiDAR]): 29 """ 30 Set the sensor for simulation 31 :param sensor: Sensor of different types 32 :return: 33 """ 34 self.__sensor = sensor 35 self.__sensor.set_sim(self.get_sim()) 36 if isinstance(self.__sensor, SensorLiDAR): 37 self.__sensor.get_scanning_device().set_sim(self.get_sim()) 38 # correct atmosphere skl according to number of bands 39 new_len = len(self.__sensor.get_spectral_bands().split(",")) 40 ill = self.get_sim().get_scene().get_illumination() 41 ats_skl = ill.get_ats_percentage() 42 arr = ats_skl.split(",") 43 old_len = len(arr) 44 if new_len >= old_len: 45 for i in range(0, new_len - old_len): 46 arr.append("0.0") 47 else: 48 arr = arr[0:new_len] 49 ill.set_ats_percentage(','.join(arr)) 50 51 # compute bounding box when virtual plane is enabled 52 if self.__sensor.get_virtualPlane() is not None: 53 self.get_sim().prepare_for_ui() 54 55 def get_sensor(self): 56 """ 57 Return the current sensor 58 :return: 59 """ 60 return self.__sensor 61 62 def with_lidar_sensor(self): 63 """ 64 Whether the scene is configured with a LiDAR sensor 65 :return: 66 """ 67 if isinstance(self.__sensor, SensorLiDAR): 68 return True 69 else: 70 return False 71 72 def set_landscape(self, landscape: Landscape): 73 """ 74 Set the landscape for the scene 75 :param landscape: 76 :return: 77 """ 78 self.__landscape = landscape 79 self.__landscape.set_sim(self.get_sim()) 80 81 def get_landscape(self): 82 """ 83 Get the landscape 84 :return: 85 """ 86 return self.__landscape 87 88 def set_illumination(self, illumination: Illumination): 89 """ 90 Set the illumination for the scene 91 :param illumination: 92 :return: 93 """ 94 self.__illumination = illumination 95 self.__illumination.set_sim(self.get_sim()) 96 97 def get_illumination(self): 98 """ 99 Get the current illumination 100 :return: 101 """ 102 return self.__illumination 103 104 def set_observation(self, observation: Union[ObservationOrthographic, ObservationPerspective, ObservationPhotonTracing, ObservationFisheye]): 105 """ 106 Set observation 107 :param observation: 108 :return: 109 """ 110 self.__observation = observation 111 self.__observation.set_sim(self.get_sim()) 112 113 def get_observation(self): 114 """ 115 Get the observation 116 :return: 117 """ 118 return self.__observation 119 120 def set_advanced_params(self, advanced_params: AdvancedParams): 121 """ 122 Set the advanced parameter 123 :param advanced_params: 124 :return: 125 """ 126 self.__advanced_params = advanced_params 127 128 def get_advanced_params(self): 129 """ 130 Get the advanced parameter 131 :return: 132 """ 133 return self.__advanced_params 134 135 def to_json_object(self, sim): 136 """ 137 Save scene to json string 138 :param sim: the simulation 139 :return: 140 """ 141 json_object = {"Advanced": self.__advanced_params.to_json_object(), 142 "illumination": self.__illumination.to_json_object(), 143 "observation": self.__observation.to_json_object(), 144 "sensor": self.__sensor.to_json_object(), 145 "scene": self.__landscape.to_json_object(sim, self.__sensor)} 146 return json_object 147 148 def write_scene(self, json_file_path): 149 """ 150 Write the scene to file 151 :param json_file_path: 152 :return: 153 """ 154 f_out = open(json_file_path, "w") 155 json.dump(self.to_json_object(self.get_sim()), f_out, indent=2) 156 f_out.close()
class
Scene(Element.Element):
13class Scene(Element): 14 """ 15 The Scene class that represents the virtual scene, containing landscape, illumination, 16 observation, sensor, and advanced parameters 17 """ 18 19 def __init__(self, sim=None): 20 super().__init__() 21 self.__sensor = SensorOrthographic() 22 # self.__lidarSensor = None 23 self.__landscape = Landscape() 24 self.__illumination = Illumination() 25 self.__observation = ObservationOrthographic() 26 self.__advanced_params = AdvancedParams() 27 self.set_sim(sim) 28 29 def set_sensor(self, sensor: Union[SensorOrthographic, SensorPerspective, SensorFisheye, SensorPhotonTracing, SensorLiDAR]): 30 """ 31 Set the sensor for simulation 32 :param sensor: Sensor of different types 33 :return: 34 """ 35 self.__sensor = sensor 36 self.__sensor.set_sim(self.get_sim()) 37 if isinstance(self.__sensor, SensorLiDAR): 38 self.__sensor.get_scanning_device().set_sim(self.get_sim()) 39 # correct atmosphere skl according to number of bands 40 new_len = len(self.__sensor.get_spectral_bands().split(",")) 41 ill = self.get_sim().get_scene().get_illumination() 42 ats_skl = ill.get_ats_percentage() 43 arr = ats_skl.split(",") 44 old_len = len(arr) 45 if new_len >= old_len: 46 for i in range(0, new_len - old_len): 47 arr.append("0.0") 48 else: 49 arr = arr[0:new_len] 50 ill.set_ats_percentage(','.join(arr)) 51 52 # compute bounding box when virtual plane is enabled 53 if self.__sensor.get_virtualPlane() is not None: 54 self.get_sim().prepare_for_ui() 55 56 def get_sensor(self): 57 """ 58 Return the current sensor 59 :return: 60 """ 61 return self.__sensor 62 63 def with_lidar_sensor(self): 64 """ 65 Whether the scene is configured with a LiDAR sensor 66 :return: 67 """ 68 if isinstance(self.__sensor, SensorLiDAR): 69 return True 70 else: 71 return False 72 73 def set_landscape(self, landscape: Landscape): 74 """ 75 Set the landscape for the scene 76 :param landscape: 77 :return: 78 """ 79 self.__landscape = landscape 80 self.__landscape.set_sim(self.get_sim()) 81 82 def get_landscape(self): 83 """ 84 Get the landscape 85 :return: 86 """ 87 return self.__landscape 88 89 def set_illumination(self, illumination: Illumination): 90 """ 91 Set the illumination for the scene 92 :param illumination: 93 :return: 94 """ 95 self.__illumination = illumination 96 self.__illumination.set_sim(self.get_sim()) 97 98 def get_illumination(self): 99 """ 100 Get the current illumination 101 :return: 102 """ 103 return self.__illumination 104 105 def set_observation(self, observation: Union[ObservationOrthographic, ObservationPerspective, ObservationPhotonTracing, ObservationFisheye]): 106 """ 107 Set observation 108 :param observation: 109 :return: 110 """ 111 self.__observation = observation 112 self.__observation.set_sim(self.get_sim()) 113 114 def get_observation(self): 115 """ 116 Get the observation 117 :return: 118 """ 119 return self.__observation 120 121 def set_advanced_params(self, advanced_params: AdvancedParams): 122 """ 123 Set the advanced parameter 124 :param advanced_params: 125 :return: 126 """ 127 self.__advanced_params = advanced_params 128 129 def get_advanced_params(self): 130 """ 131 Get the advanced parameter 132 :return: 133 """ 134 return self.__advanced_params 135 136 def to_json_object(self, sim): 137 """ 138 Save scene to json string 139 :param sim: the simulation 140 :return: 141 """ 142 json_object = {"Advanced": self.__advanced_params.to_json_object(), 143 "illumination": self.__illumination.to_json_object(), 144 "observation": self.__observation.to_json_object(), 145 "sensor": self.__sensor.to_json_object(), 146 "scene": self.__landscape.to_json_object(sim, self.__sensor)} 147 return json_object 148 149 def write_scene(self, json_file_path): 150 """ 151 Write the scene to file 152 :param json_file_path: 153 :return: 154 """ 155 f_out = open(json_file_path, "w") 156 json.dump(self.to_json_object(self.get_sim()), f_out, indent=2) 157 f_out.close()
The Scene class that represents the virtual scene, containing landscape, illumination, observation, sensor, and advanced parameters
Scene(sim=None)
19 def __init__(self, sim=None): 20 super().__init__() 21 self.__sensor = SensorOrthographic() 22 # self.__lidarSensor = None 23 self.__landscape = Landscape() 24 self.__illumination = Illumination() 25 self.__observation = ObservationOrthographic() 26 self.__advanced_params = AdvancedParams() 27 self.set_sim(sim)
def
set_sensor( self, sensor: Union[Sensor.SensorOrthographic, Sensor.SensorPerspective, Sensor.SensorFisheye, Sensor.SensorPhotonTracing, Sensor.SensorLiDAR]):
29 def set_sensor(self, sensor: Union[SensorOrthographic, SensorPerspective, SensorFisheye, SensorPhotonTracing, SensorLiDAR]): 30 """ 31 Set the sensor for simulation 32 :param sensor: Sensor of different types 33 :return: 34 """ 35 self.__sensor = sensor 36 self.__sensor.set_sim(self.get_sim()) 37 if isinstance(self.__sensor, SensorLiDAR): 38 self.__sensor.get_scanning_device().set_sim(self.get_sim()) 39 # correct atmosphere skl according to number of bands 40 new_len = len(self.__sensor.get_spectral_bands().split(",")) 41 ill = self.get_sim().get_scene().get_illumination() 42 ats_skl = ill.get_ats_percentage() 43 arr = ats_skl.split(",") 44 old_len = len(arr) 45 if new_len >= old_len: 46 for i in range(0, new_len - old_len): 47 arr.append("0.0") 48 else: 49 arr = arr[0:new_len] 50 ill.set_ats_percentage(','.join(arr)) 51 52 # compute bounding box when virtual plane is enabled 53 if self.__sensor.get_virtualPlane() is not None: 54 self.get_sim().prepare_for_ui()
Set the sensor for simulation
Parameters
- sensor: Sensor of different types
Returns
def
get_sensor(self):
56 def get_sensor(self): 57 """ 58 Return the current sensor 59 :return: 60 """ 61 return self.__sensor
Return the current sensor
Returns
def
with_lidar_sensor(self):
63 def with_lidar_sensor(self): 64 """ 65 Whether the scene is configured with a LiDAR sensor 66 :return: 67 """ 68 if isinstance(self.__sensor, SensorLiDAR): 69 return True 70 else: 71 return False
Whether the scene is configured with a LiDAR sensor
Returns
73 def set_landscape(self, landscape: Landscape): 74 """ 75 Set the landscape for the scene 76 :param landscape: 77 :return: 78 """ 79 self.__landscape = landscape 80 self.__landscape.set_sim(self.get_sim())
Set the landscape for the scene
Parameters
- landscape:
Returns
def
get_landscape(self):
82 def get_landscape(self): 83 """ 84 Get the landscape 85 :return: 86 """ 87 return self.__landscape
Get the landscape
Returns
89 def set_illumination(self, illumination: Illumination): 90 """ 91 Set the illumination for the scene 92 :param illumination: 93 :return: 94 """ 95 self.__illumination = illumination 96 self.__illumination.set_sim(self.get_sim())
Set the illumination for the scene
Parameters
- illumination:
Returns
def
get_illumination(self):
98 def get_illumination(self): 99 """ 100 Get the current illumination 101 :return: 102 """ 103 return self.__illumination
Get the current illumination
Returns
def
set_observation( self, observation: Union[Observation.ObservationOrthographic, Observation.ObservationPerspective, Observation.ObservationPhotonTracing, Observation.ObservationFisheye]):
105 def set_observation(self, observation: Union[ObservationOrthographic, ObservationPerspective, ObservationPhotonTracing, ObservationFisheye]): 106 """ 107 Set observation 108 :param observation: 109 :return: 110 """ 111 self.__observation = observation 112 self.__observation.set_sim(self.get_sim())
Set observation
Parameters
- observation:
Returns
def
get_observation(self):
114 def get_observation(self): 115 """ 116 Get the observation 117 :return: 118 """ 119 return self.__observation
Get the observation
Returns
121 def set_advanced_params(self, advanced_params: AdvancedParams): 122 """ 123 Set the advanced parameter 124 :param advanced_params: 125 :return: 126 """ 127 self.__advanced_params = advanced_params
Set the advanced parameter
Parameters
- advanced_params:
Returns
def
get_advanced_params(self):
129 def get_advanced_params(self): 130 """ 131 Get the advanced parameter 132 :return: 133 """ 134 return self.__advanced_params
Get the advanced parameter
Returns
def
to_json_object(self, sim):
136 def to_json_object(self, sim): 137 """ 138 Save scene to json string 139 :param sim: the simulation 140 :return: 141 """ 142 json_object = {"Advanced": self.__advanced_params.to_json_object(), 143 "illumination": self.__illumination.to_json_object(), 144 "observation": self.__observation.to_json_object(), 145 "sensor": self.__sensor.to_json_object(), 146 "scene": self.__landscape.to_json_object(sim, self.__sensor)} 147 return json_object
Save scene to json string
Parameters
- sim: the simulation
Returns
def
write_scene(self, json_file_path):
149 def write_scene(self, json_file_path): 150 """ 151 Write the scene to file 152 :param json_file_path: 153 :return: 154 """ 155 f_out = open(json_file_path, "w") 156 json.dump(self.to_json_object(self.get_sim()), f_out, indent=2) 157 f_out.close()
Write the scene to file
Parameters
- json_file_path:
Returns
Inherited Members
- Element.Element
- set_sim
- get_sim