Landscape
1# coding: utf-8 2from OpticalProperty import OpticalProperties, OpticalItem 3from Terrain import Terrain 4from SceneObjects import SceneObjects, SceneObject 5from Element import Element 6from LandscapeUtility import LandscapeUtility 7 8 9class Landscape(Element): 10 """ 11 Landscape represents the geometrical and spectral properties of the scene. 12 It contains scene objects, instances, optical properties, temperature properties 13 """ 14 def __init__(self): 15 super().__init__() 16 # forest 17 self.__scene_objects = SceneObjects() 18 19 # terrain 20 self.__terrain = Terrain() 21 22 # optical properties 23 self.__optical_properties = OpticalProperties() 24 25 # temperature 26 self.__temperature_properties = {} 27 28 # others 29 self.__extra_scene = "" 30 31 def init_landscape_from_json(self, json_object): 32 # forest 33 scene_objects = SceneObjects() 34 scene_objects.set_sim(self.get_sim()) 35 scene_objects.init_objects_from_json(json_object) 36 self.__scene_objects = scene_objects 37 38 # terrain 39 terrain = Terrain() 40 terrain.set_sim(self.get_sim()) 41 terrain.init_terrain_from_json(json_object) 42 self.__terrain = terrain 43 44 # optical properties 45 ops = OpticalProperties() 46 ops.init_ops_from_json(json_object) 47 self.__optical_properties = ops 48 49 # temperature 50 self.__temperature_properties = json_object["scene"]["temperature_properties"] 51 52 # others 53 self.__extra_scene = json_object["scene"]["extra_scene"] 54 55 return self 56 57 def get_objects(self) -> {}: 58 """ 59 Get Scene objects 60 :return: 61 """ 62 return self.__scene_objects.get_objects() 63 64 def get_object(self, obj_name): 65 """ 66 Get individual object given the object name 67 :param obj_name: object to be queried 68 :return: 69 """ 70 return self.__scene_objects.get_object(obj_name) 71 72 def get_instances(self): 73 """ 74 Get the instances of objects defined within the scene 75 :return: 76 """ 77 return self.__scene_objects.get_instances() 78 79 def set_obj_cache(self, obj_cache: bool): 80 """ 81 Whether the obj file are cached during the simulation. If you want to modify obj structures 82 without changing obj name, you must **not** to cache the obj, because the cache are based on names only 83 :param obj_cache: true or false to cache obj 84 :return: 85 """ 86 self.__scene_objects.cache_OBJ_file = obj_cache 87 88 def convert_obj_to_binary(self, convert_obj_to_binary): 89 """ 90 Whether convert the obj file to a binary representation to accelerate the loading of the scene 91 :param convert_obj_to_binary: true of false 92 :return: 93 """ 94 self.__scene_objects.ConvertOBJToBinaryFile = convert_obj_to_binary 95 96 def to_json_object(self, sim, sensor): 97 json_obj = {"forest": self.__scene_objects.to_json_object(), 98 "terrain": self.__terrain.to_json_object(), 99 "optical_properties": self.__optical_properties.to_json_object(sensor.get_spectral_bands(), sim.get_scene_helper().less_install_root_path), 100 "temperature_properties": self.__temperature_properties, 101 "extra_scene": self.__extra_scene} 102 return json_obj 103 104 def add_op_item(self, op_item: OpticalItem): 105 """ 106 The Optical Item representing leaf reflectance/transmittance, prospect, fluospect, etc. 107 :param op_item: an object of OpticalItem 108 :return: 109 """ 110 self.__optical_properties.add_optical_item(op_item) 111 112 def get_op_item(self, op_name) -> OpticalItem: 113 """ 114 Get an optical Item with a name 115 :param op_name: the optical item name to get 116 :return: 117 """ 118 return self.__optical_properties.get_optical_item(op_name) 119 120 def get_all_op_items(self): 121 """ 122 Get a list of OpticalItem that have been added to the landscape 123 :return: 124 """ 125 return self.__optical_properties.optical_properties 126 127 def add_object(self, scene_object: SceneObject, override_file=True, translate_to_origin="no"): 128 """ 129 Add an object to the scene 130 :param scene_object: an object of the SceneObject 131 :param override_file: If the obj files are overwrited 132 :param translate_to_origin: whether to translate the obj to the (0,0,0) coordinate 133 :return: 134 """ 135 self.__scene_objects.add_object(scene_object, override_file, translate_to_origin) 136 137 def place_object(self, obj_name, x=50.0, y=50.0, z=0.0, rotate=0.0, 138 rotate_axis_x=None, rotate_axis_y=None, rotate_axis_z=None, 139 scale_extent_x=None, scale_extent_y=None, scale_extent_z=None 140 ): 141 """ 142 Place the object to the scene 143 :param obj_name: 144 :param x: 145 :param y: 146 :param z: 147 :param rotate: 148 :param rotate_axis_x: 149 :param rotate_axis_y: 150 :param rotate_axis_z: 151 :param scale_extent_x: 152 :param scale_extent_y: 153 :param scale_extent_z: 154 :return: 155 """ 156 self.__scene_objects.place_object_to(obj_name, x, y, z, rotate, rotate_axis_x, rotate_axis_y, rotate_axis_z, 157 scale_extent_x, scale_extent_y, scale_extent_z) 158 159 def set_terrain_op(self, op_name): 160 self.__terrain.optical = op_name 161 162 def get_terrain(self): 163 return self.__terrain 164 165 def get_optical_properties(self): 166 return self.__optical_properties 167 168 def clear_objects(self): 169 self.__scene_objects.get_objects().clear() 170 171 def clear_instances(self): 172 self.__scene_objects.get_instances().clear() 173 174 def clear_landscape_elements(self): 175 self.__scene_objects.get_objects().clear() 176 self.__scene_objects.get_instances().clear() 177 178 def prepare_for_ui(self): 179 self.__scene_objects.calculate_object_bounding_box() 180 181 def get_object_bounds(self): 182 return self.__scene_objects.read_object_bounding_box() 183 184 # 情况自定义的 optical properties 185 def clear_user_defined_optical_properties(self): 186 for op in self.__optical_properties.optical_properties: 187 if op.get_op_name() not in ["birch_branch", "dark_soil_mollisol", "birch_leaf_green"]: 188 self.__optical_properties.optical_properties.remove(op) 189 # self.__optical_properties.optical_properties = \ 190 # [OpticalItem("birch_branch", "0.105,0.476;0.000,0.000;0.000,0.000", 0), 191 # OpticalItem("dark_soil_mollisol", "0.188,0.351;0.000,0.000;0.000,0.000", 0), 192 # OpticalItem("birch_leaf_green", "0.058,0.472;0.058,0.472;0.000,0.000", 0)] 193 194 def clear_all_optical_properties(self): 195 self.__optical_properties.optical_properties.clear() 196 197 def compute_scene_lai(self, exclude_object_outside=False, ignore_list=None): 198 land_scape_utility = LandscapeUtility(self) 199 return land_scape_utility.compute_scene_lai(exclude_object_outside, ignore_list) 200 201 def compute_lai3d(self, out_path, rows, cols, layers, compute_width=-1, compute_height=-1, ignore_list=None): 202 land_scape_utility = LandscapeUtility(self) 203 land_scape_utility.compute_lai3d(out_path, rows, cols, layers, compute_width, compute_height, ignore_list) 204 205 def compute_chm(self, out_path, resolution=2, ignore_list=None): 206 land_scape_utility = LandscapeUtility(self) 207 return land_scape_utility.compute_chm(out_path, resolution, ignore_list) 208 209 def compute_crown_radius(self, out_file, out_mask_img_file=None, mask_img_resolution=0.5): 210 land_scape_utility = LandscapeUtility(self) 211 return land_scape_utility.compute_crown_radius(out_file, out_mask_img_file, mask_img_resolution) 212 213 def compute_crown_boundary(self, out_file, out_mask_img_file=None, mask_img_resolution=0.5): 214 land_scape_utility = LandscapeUtility(self) 215 return land_scape_utility.compute_crown_boundary(out_file, out_mask_img_file, mask_img_resolution)
10class Landscape(Element): 11 """ 12 Landscape represents the geometrical and spectral properties of the scene. 13 It contains scene objects, instances, optical properties, temperature properties 14 """ 15 def __init__(self): 16 super().__init__() 17 # forest 18 self.__scene_objects = SceneObjects() 19 20 # terrain 21 self.__terrain = Terrain() 22 23 # optical properties 24 self.__optical_properties = OpticalProperties() 25 26 # temperature 27 self.__temperature_properties = {} 28 29 # others 30 self.__extra_scene = "" 31 32 def init_landscape_from_json(self, json_object): 33 # forest 34 scene_objects = SceneObjects() 35 scene_objects.set_sim(self.get_sim()) 36 scene_objects.init_objects_from_json(json_object) 37 self.__scene_objects = scene_objects 38 39 # terrain 40 terrain = Terrain() 41 terrain.set_sim(self.get_sim()) 42 terrain.init_terrain_from_json(json_object) 43 self.__terrain = terrain 44 45 # optical properties 46 ops = OpticalProperties() 47 ops.init_ops_from_json(json_object) 48 self.__optical_properties = ops 49 50 # temperature 51 self.__temperature_properties = json_object["scene"]["temperature_properties"] 52 53 # others 54 self.__extra_scene = json_object["scene"]["extra_scene"] 55 56 return self 57 58 def get_objects(self) -> {}: 59 """ 60 Get Scene objects 61 :return: 62 """ 63 return self.__scene_objects.get_objects() 64 65 def get_object(self, obj_name): 66 """ 67 Get individual object given the object name 68 :param obj_name: object to be queried 69 :return: 70 """ 71 return self.__scene_objects.get_object(obj_name) 72 73 def get_instances(self): 74 """ 75 Get the instances of objects defined within the scene 76 :return: 77 """ 78 return self.__scene_objects.get_instances() 79 80 def set_obj_cache(self, obj_cache: bool): 81 """ 82 Whether the obj file are cached during the simulation. If you want to modify obj structures 83 without changing obj name, you must **not** to cache the obj, because the cache are based on names only 84 :param obj_cache: true or false to cache obj 85 :return: 86 """ 87 self.__scene_objects.cache_OBJ_file = obj_cache 88 89 def convert_obj_to_binary(self, convert_obj_to_binary): 90 """ 91 Whether convert the obj file to a binary representation to accelerate the loading of the scene 92 :param convert_obj_to_binary: true of false 93 :return: 94 """ 95 self.__scene_objects.ConvertOBJToBinaryFile = convert_obj_to_binary 96 97 def to_json_object(self, sim, sensor): 98 json_obj = {"forest": self.__scene_objects.to_json_object(), 99 "terrain": self.__terrain.to_json_object(), 100 "optical_properties": self.__optical_properties.to_json_object(sensor.get_spectral_bands(), sim.get_scene_helper().less_install_root_path), 101 "temperature_properties": self.__temperature_properties, 102 "extra_scene": self.__extra_scene} 103 return json_obj 104 105 def add_op_item(self, op_item: OpticalItem): 106 """ 107 The Optical Item representing leaf reflectance/transmittance, prospect, fluospect, etc. 108 :param op_item: an object of OpticalItem 109 :return: 110 """ 111 self.__optical_properties.add_optical_item(op_item) 112 113 def get_op_item(self, op_name) -> OpticalItem: 114 """ 115 Get an optical Item with a name 116 :param op_name: the optical item name to get 117 :return: 118 """ 119 return self.__optical_properties.get_optical_item(op_name) 120 121 def get_all_op_items(self): 122 """ 123 Get a list of OpticalItem that have been added to the landscape 124 :return: 125 """ 126 return self.__optical_properties.optical_properties 127 128 def add_object(self, scene_object: SceneObject, override_file=True, translate_to_origin="no"): 129 """ 130 Add an object to the scene 131 :param scene_object: an object of the SceneObject 132 :param override_file: If the obj files are overwrited 133 :param translate_to_origin: whether to translate the obj to the (0,0,0) coordinate 134 :return: 135 """ 136 self.__scene_objects.add_object(scene_object, override_file, translate_to_origin) 137 138 def place_object(self, obj_name, x=50.0, y=50.0, z=0.0, rotate=0.0, 139 rotate_axis_x=None, rotate_axis_y=None, rotate_axis_z=None, 140 scale_extent_x=None, scale_extent_y=None, scale_extent_z=None 141 ): 142 """ 143 Place the object to the scene 144 :param obj_name: 145 :param x: 146 :param y: 147 :param z: 148 :param rotate: 149 :param rotate_axis_x: 150 :param rotate_axis_y: 151 :param rotate_axis_z: 152 :param scale_extent_x: 153 :param scale_extent_y: 154 :param scale_extent_z: 155 :return: 156 """ 157 self.__scene_objects.place_object_to(obj_name, x, y, z, rotate, rotate_axis_x, rotate_axis_y, rotate_axis_z, 158 scale_extent_x, scale_extent_y, scale_extent_z) 159 160 def set_terrain_op(self, op_name): 161 self.__terrain.optical = op_name 162 163 def get_terrain(self): 164 return self.__terrain 165 166 def get_optical_properties(self): 167 return self.__optical_properties 168 169 def clear_objects(self): 170 self.__scene_objects.get_objects().clear() 171 172 def clear_instances(self): 173 self.__scene_objects.get_instances().clear() 174 175 def clear_landscape_elements(self): 176 self.__scene_objects.get_objects().clear() 177 self.__scene_objects.get_instances().clear() 178 179 def prepare_for_ui(self): 180 self.__scene_objects.calculate_object_bounding_box() 181 182 def get_object_bounds(self): 183 return self.__scene_objects.read_object_bounding_box() 184 185 # 情况自定义的 optical properties 186 def clear_user_defined_optical_properties(self): 187 for op in self.__optical_properties.optical_properties: 188 if op.get_op_name() not in ["birch_branch", "dark_soil_mollisol", "birch_leaf_green"]: 189 self.__optical_properties.optical_properties.remove(op) 190 # self.__optical_properties.optical_properties = \ 191 # [OpticalItem("birch_branch", "0.105,0.476;0.000,0.000;0.000,0.000", 0), 192 # OpticalItem("dark_soil_mollisol", "0.188,0.351;0.000,0.000;0.000,0.000", 0), 193 # OpticalItem("birch_leaf_green", "0.058,0.472;0.058,0.472;0.000,0.000", 0)] 194 195 def clear_all_optical_properties(self): 196 self.__optical_properties.optical_properties.clear() 197 198 def compute_scene_lai(self, exclude_object_outside=False, ignore_list=None): 199 land_scape_utility = LandscapeUtility(self) 200 return land_scape_utility.compute_scene_lai(exclude_object_outside, ignore_list) 201 202 def compute_lai3d(self, out_path, rows, cols, layers, compute_width=-1, compute_height=-1, ignore_list=None): 203 land_scape_utility = LandscapeUtility(self) 204 land_scape_utility.compute_lai3d(out_path, rows, cols, layers, compute_width, compute_height, ignore_list) 205 206 def compute_chm(self, out_path, resolution=2, ignore_list=None): 207 land_scape_utility = LandscapeUtility(self) 208 return land_scape_utility.compute_chm(out_path, resolution, ignore_list) 209 210 def compute_crown_radius(self, out_file, out_mask_img_file=None, mask_img_resolution=0.5): 211 land_scape_utility = LandscapeUtility(self) 212 return land_scape_utility.compute_crown_radius(out_file, out_mask_img_file, mask_img_resolution) 213 214 def compute_crown_boundary(self, out_file, out_mask_img_file=None, mask_img_resolution=0.5): 215 land_scape_utility = LandscapeUtility(self) 216 return land_scape_utility.compute_crown_boundary(out_file, out_mask_img_file, mask_img_resolution)
Landscape represents the geometrical and spectral properties of the scene. It contains scene objects, instances, optical properties, temperature properties
32 def init_landscape_from_json(self, json_object): 33 # forest 34 scene_objects = SceneObjects() 35 scene_objects.set_sim(self.get_sim()) 36 scene_objects.init_objects_from_json(json_object) 37 self.__scene_objects = scene_objects 38 39 # terrain 40 terrain = Terrain() 41 terrain.set_sim(self.get_sim()) 42 terrain.init_terrain_from_json(json_object) 43 self.__terrain = terrain 44 45 # optical properties 46 ops = OpticalProperties() 47 ops.init_ops_from_json(json_object) 48 self.__optical_properties = ops 49 50 # temperature 51 self.__temperature_properties = json_object["scene"]["temperature_properties"] 52 53 # others 54 self.__extra_scene = json_object["scene"]["extra_scene"] 55 56 return self
58 def get_objects(self) -> {}: 59 """ 60 Get Scene objects 61 :return: 62 """ 63 return self.__scene_objects.get_objects()
Get Scene objects
Returns
65 def get_object(self, obj_name): 66 """ 67 Get individual object given the object name 68 :param obj_name: object to be queried 69 :return: 70 """ 71 return self.__scene_objects.get_object(obj_name)
Get individual object given the object name
Parameters
- obj_name: object to be queried
Returns
73 def get_instances(self): 74 """ 75 Get the instances of objects defined within the scene 76 :return: 77 """ 78 return self.__scene_objects.get_instances()
Get the instances of objects defined within the scene
Returns
80 def set_obj_cache(self, obj_cache: bool): 81 """ 82 Whether the obj file are cached during the simulation. If you want to modify obj structures 83 without changing obj name, you must **not** to cache the obj, because the cache are based on names only 84 :param obj_cache: true or false to cache obj 85 :return: 86 """ 87 self.__scene_objects.cache_OBJ_file = obj_cache
Whether the obj file are cached during the simulation. If you want to modify obj structures without changing obj name, you must not to cache the obj, because the cache are based on names only
Parameters
- obj_cache: true or false to cache obj
Returns
89 def convert_obj_to_binary(self, convert_obj_to_binary): 90 """ 91 Whether convert the obj file to a binary representation to accelerate the loading of the scene 92 :param convert_obj_to_binary: true of false 93 :return: 94 """ 95 self.__scene_objects.ConvertOBJToBinaryFile = convert_obj_to_binary
Whether convert the obj file to a binary representation to accelerate the loading of the scene
Parameters
- convert_obj_to_binary: true of false
Returns
97 def to_json_object(self, sim, sensor): 98 json_obj = {"forest": self.__scene_objects.to_json_object(), 99 "terrain": self.__terrain.to_json_object(), 100 "optical_properties": self.__optical_properties.to_json_object(sensor.get_spectral_bands(), sim.get_scene_helper().less_install_root_path), 101 "temperature_properties": self.__temperature_properties, 102 "extra_scene": self.__extra_scene} 103 return json_obj
105 def add_op_item(self, op_item: OpticalItem): 106 """ 107 The Optical Item representing leaf reflectance/transmittance, prospect, fluospect, etc. 108 :param op_item: an object of OpticalItem 109 :return: 110 """ 111 self.__optical_properties.add_optical_item(op_item)
The Optical Item representing leaf reflectance/transmittance, prospect, fluospect, etc.
Parameters
- op_item: an object of OpticalItem
Returns
113 def get_op_item(self, op_name) -> OpticalItem: 114 """ 115 Get an optical Item with a name 116 :param op_name: the optical item name to get 117 :return: 118 """ 119 return self.__optical_properties.get_optical_item(op_name)
Get an optical Item with a name
Parameters
- op_name: the optical item name to get
Returns
121 def get_all_op_items(self): 122 """ 123 Get a list of OpticalItem that have been added to the landscape 124 :return: 125 """ 126 return self.__optical_properties.optical_properties
Get a list of OpticalItem that have been added to the landscape
Returns
128 def add_object(self, scene_object: SceneObject, override_file=True, translate_to_origin="no"): 129 """ 130 Add an object to the scene 131 :param scene_object: an object of the SceneObject 132 :param override_file: If the obj files are overwrited 133 :param translate_to_origin: whether to translate the obj to the (0,0,0) coordinate 134 :return: 135 """ 136 self.__scene_objects.add_object(scene_object, override_file, translate_to_origin)
Add an object to the scene
Parameters
- scene_object: an object of the SceneObject
- override_file: If the obj files are overwrited
- translate_to_origin: whether to translate the obj to the (0,0,0) coordinate
Returns
138 def place_object(self, obj_name, x=50.0, y=50.0, z=0.0, rotate=0.0, 139 rotate_axis_x=None, rotate_axis_y=None, rotate_axis_z=None, 140 scale_extent_x=None, scale_extent_y=None, scale_extent_z=None 141 ): 142 """ 143 Place the object to the scene 144 :param obj_name: 145 :param x: 146 :param y: 147 :param z: 148 :param rotate: 149 :param rotate_axis_x: 150 :param rotate_axis_y: 151 :param rotate_axis_z: 152 :param scale_extent_x: 153 :param scale_extent_y: 154 :param scale_extent_z: 155 :return: 156 """ 157 self.__scene_objects.place_object_to(obj_name, x, y, z, rotate, rotate_axis_x, rotate_axis_y, rotate_axis_z, 158 scale_extent_x, scale_extent_y, scale_extent_z)
Place the object to the scene
Parameters
- obj_name:
- x:
- y:
- z:
- rotate:
- rotate_axis_x:
- rotate_axis_y:
- rotate_axis_z:
- scale_extent_x:
- scale_extent_y:
- scale_extent_z:
Returns
186 def clear_user_defined_optical_properties(self): 187 for op in self.__optical_properties.optical_properties: 188 if op.get_op_name() not in ["birch_branch", "dark_soil_mollisol", "birch_leaf_green"]: 189 self.__optical_properties.optical_properties.remove(op) 190 # self.__optical_properties.optical_properties = \ 191 # [OpticalItem("birch_branch", "0.105,0.476;0.000,0.000;0.000,0.000", 0), 192 # OpticalItem("dark_soil_mollisol", "0.188,0.351;0.000,0.000;0.000,0.000", 0), 193 # OpticalItem("birch_leaf_green", "0.058,0.472;0.058,0.472;0.000,0.000", 0)]
Inherited Members
- Element.Element
- set_sim
- get_sim