From d06ab36c111f0672e4322892851a20cff4a3a01b Mon Sep 17 00:00:00 2001 From: AntoineRichard Date: Tue, 10 Sep 2024 01:30:25 +0200 Subject: [PATCH] baby cleaning --- test_collider.py | 129 ------ test_instancers.py | 176 --------- visual_terrain_stack_alignment_test.py | 158 -------- visual_terrain_stack_alignment_test_im.py | 196 ---------- visual_terrain_stack_demo.py | 390 ------------------- visual_terrain_stack_demo_test_instancers.py | 165 -------- 6 files changed, 1214 deletions(-) delete mode 100644 test_collider.py delete mode 100644 test_instancers.py delete mode 100644 visual_terrain_stack_alignment_test.py delete mode 100644 visual_terrain_stack_alignment_test_im.py delete mode 100644 visual_terrain_stack_demo.py delete mode 100644 visual_terrain_stack_demo_test_instancers.py diff --git a/test_collider.py b/test_collider.py deleted file mode 100644 index 2c6ada8..0000000 --- a/test_collider.py +++ /dev/null @@ -1,129 +0,0 @@ -import omni -import copy -import math -import os - -from omni.isaac.kit import SimulationApp - - -cfg = { - "headless": False, -} -simulation_app = SimulationApp(cfg) - -CBCfg_D = { - "resolution": 0.05, - "block_size": 50, - "collider_path": "/World/colliders", - "collider_mode": "meshSimplification", - "visible": True, - "profiling": True, -} - -CMCfg_D = { - "collider_resolution": 0.05, - "block_size": 50, - "cache_size": 10, - "build_colliders_n_meters_ahead": 4, - "collider_path": "/World/colliders", - "collider_builder_conf": CBCfg_D, - "profiling": True, -} - -PSMCfg_D = { - "gravity": (0, 0, -1.62), - "dt": 0.1666, - "enable_ccd": True, - "enable_stabilization": False, -} - - -if __name__ == "__main__": - from omni.isaac.core import World - from omni.usd import get_context - from pxr import UsdLux, UsdGeom, Gf, UsdShade - - import numpy as np - - from src.terrain_management.large_scale_terrain.collider_manager import ColliderManager, ColliderManagerConf - from src.configurations.physics_confs import PhysicsSceneConf - from src.physics.physics_scene import PhysicsSceneManager - from src.terrain_management.large_scale_terrain.pxr_utils import set_xform_ops, add_collider, make_rigid - - def is_map_done(): - return True - - def bindMaterial(stage, mtl_prim_path, prim_path): - mtl_prim = stage.GetPrimAtPath(mtl_prim_path) - prim = stage.GetPrimAtPath(prim_path) - shade = UsdShade.Material(mtl_prim) - UsdShade.MaterialBindingAPI(prim).Bind(shade, UsdShade.Tokens.strongerThanDescendants) - - world = World(stage_units_in_meters=1.0) - PSMCfg = PhysicsSceneConf(**PSMCfg_D) - print(PSMCfg.physics_scene_args) - PSM = PhysicsSceneManager(PSMCfg) - - stage = get_context().get_stage() - asset_path = os.path.join(os.getcwd(), "assets") - - # Let there be light - light = UsdLux.DistantLight.Define(stage, "/World/sun") - light.CreateIntensityAttr(3000.0) - set_xform_ops(light.GetPrim(), orient=Gf.Quatd(0.76, (0.65, 0, 0))) - - # Create a sphere - sphere = UsdGeom.Sphere.Define(stage, "/World/sphere") - add_collider(stage, sphere.GetPath(), mode="boundingSphere") - make_rigid(stage, sphere.GetPath()) - - map = np.load("assets/Terrains/SouthPole/LM1_final_adj_5mpp_surf/dem.npy") * 0.1 / 5.0 - - for i in range(100): - world.step(render=True) - - CM_Cfg = ColliderManagerConf(**CMCfg_D) - source_resolution = 0.1 - CM = ColliderManager(CM_Cfg, map, map.shape, (map.shape[0] * 0.1 / 2, map.shape[1] * 0.1 / 2), source_resolution) - - C = 0 - R = 100 - max_displacement = 1.0 / 120 - acquisition_rate = 1 - perimeter = 2 * np.pi * R - rotation_rate = int(perimeter / max_displacement) - spiral_rate = 0.0 / rotation_rate - theta = np.linspace(0, 2 * np.pi, rotation_rate) - i = 0 - i2 = 1.0 - - x = C + i2 * R * math.cos(theta[i]) - y = C + i2 * R * math.sin(theta[i]) - - initial_position = (0, 0) - - timeline = omni.timeline.get_timeline_interface() - # timeline.play() - - last_position = initial_position - CM.build() - CM.update(initial_position) - set_xform_ops(sphere.GetPrim(), translate=Gf.Vec3d(0, 0, 20)) - - while True: - x = sphere.GetPrim().GetAttribute("xformOp:translate").Get()[0] - y = sphere.GetPrim().GetAttribute("xformOp:translate").Get()[1] - - dist = math.sqrt((last_position[0] - x) ** 2 + (last_position[1] - y) ** 2) - if dist > 2.0: - last_position = (x, y) - xu = int(x) - yu = int(y) - CM.update((x, y)) - world.step(render=True) - - i += 1 - i = i % theta.shape[0] - - timeline.stop() - simulation_app.close() diff --git a/test_instancers.py b/test_instancers.py deleted file mode 100644 index 7a2bebd..0000000 --- a/test_instancers.py +++ /dev/null @@ -1,176 +0,0 @@ -import omni -import copy -import math -import os - -from omni.isaac.kit import SimulationApp - -cfg = { - "headless": False, -} -simulation_app = SimulationApp(cfg) - -RDBCfg_D = { - "block_size": 50, - "max_blocks": int(1e7), - "save_to_disk": False, - "write_to_disk_interval": 1000, -} -RSCfg_1_D = { - "block_size": 50, - "rock_dist_cfg": { - "position_distribution": { - "name": "thomas_point_process", - "parent_density": 0.04, - "child_density": 100, - "sigma": 3.0, - "seed": 42, - }, - "scale_distribution": { - "name": "uniform", - "min": 0.02, - "max": 0.05, - "seed": 42, - }, - "seed": 42, - }, -} -RSCfg_2_D = { - "block_size": 50, - "rock_dist_cfg": { - "position_distribution": { - "name": "thomas_point_process", - "parent_density": 0.01, - "child_density": 25, - "sigma": 3.0, - "seed": 42, - }, - "scale_distribution": { - "name": "uniform", - "min": 0.05, - "max": 0.2, - "seed": 42, - }, - "seed": 43, - }, -} -RGCfg_1_D = { - "rock_sampler_cfg": RSCfg_1_D, - "rock_assets_folder": "assets/USD_Assets/rocks/small_rocks_v2", - "instancer_name": "very_small_rock_instancer", - "seed": 42, - "block_span": 1, - "block_size": 50, -} -RGCfg_2_D = { - "rock_sampler_cfg": RSCfg_2_D, - "rock_assets_folder": "assets/USD_Assets/rocks/small_rocks_v2", - "instancer_name": "large_rock_instancer", - "seed": 42, - "block_span": 2, - "block_size": 50, - "semantic_label": "rock", - "collider_mode": "meshSimplification", - "add_colliders": True, -} -RMCfg_D = { - "rock_gen_cfgs": [RGCfg_1_D, RGCfg_2_D], - "instancers_path": "/World/rock_instancers", - "seed": 42, - "block_size": 50, - "rock_dbs_cfg": RDBCfg_D, - "profiling": True, -} - -if __name__ == "__main__": - from omni.isaac.core import World - from omni.usd import get_context - from pxr import UsdLux, UsdGeom, Gf, UsdShade - - from WorldBuilders.pxr_utils import setDefaultOps, addDefaultOps - import numpy as np - - from src.terrain_management.large_scale_terrain.rock_manager import ( - RockManagerConf, - RockManager, - ) - from src.terrain_management.large_scale_terrain.rock_distribution import mock_call - from src.terrain_management.large_scale_terrain.utils import ScopedTimer - - def is_map_done(): - return True - - def bindMaterial(stage, mtl_prim_path, prim_path): - mtl_prim = stage.GetPrimAtPath(mtl_prim_path) - prim = stage.GetPrimAtPath(prim_path) - shade = UsdShade.Material(mtl_prim) - UsdShade.MaterialBindingAPI(prim).Bind(shade, UsdShade.Tokens.strongerThanDescendants) - - world = World(stage_units_in_meters=1.0) - stage = get_context().get_stage() - asset_path = os.path.join(os.getcwd(), "assets") - - # Let there be light - light = UsdLux.DistantLight.Define(stage, "/World/sun") - light.CreateIntensityAttr(3000.0) - addDefaultOps(light.GetPrim()) - setDefaultOps(light.GetPrim(), (0, 0, 0), (0.65, 0, 0, 0.76), (1, 1, 1)) - - # Add sphere - sphere = UsdGeom.Sphere.Define(stage, "/World/sphere") - addDefaultOps(sphere.GetPrim()) - setDefaultOps(sphere.GetPrim(), (0, 0, 0), (0, 0, 0, 1), (1, 1, 1)) - - C = 0 - R = 500 * 5 - max_displacement = 2.0 / 30 - acquisition_rate = 1 - perimeter = 2 * np.pi * R - rotation_rate = int(perimeter / max_displacement) - spiral_rate = 0.0 / rotation_rate - theta = np.linspace(0, 2 * np.pi, rotation_rate) - i = 0 - i2 = 1.0 - print(rotation_rate) - - x = C + i2 * R * math.cos(theta[i]) - y = C + i2 * R * math.sin(theta[i]) - - initial_position = (x, y) - - rm_settings = RockManagerConf(**RMCfg_D) - RM = RockManager(rm_settings, mock_call, is_map_done) - RM.build() - RM.sample((0, 0)) - - timeline = omni.timeline.get_timeline_interface() - timeline.play() - - i3 = 0 - target = R * 2 * math.pi / max_displacement / acquisition_rate - target = target / 8 - target += 10 - Q_camera4 = None - while True: - x_new = C + i2 * R * math.cos(theta[i]) - y_new = C + i2 * R * math.sin(theta[i]) - x_delta = x_new - x - y_delta = y_new - y - coords = (x_delta, y_delta) - - # Move sphere - setDefaultOps(sphere.GetPrim(), (x_delta, y_delta, 0), (0, 0, 0, 1), (1, 1, 1)) - - RM.sample(coords) - with ScopedTimer("env_step", active=True): - world.step(render=True) - i = (i + 1) % rotation_rate - # if i % acquisition_rate == 0: - # try: - # AL.record() - # i3 += 1 - # except Exception as e: - # print(e) - # i2 += spiral_rate - timeline.stop() - simulation_app.close() diff --git a/visual_terrain_stack_alignment_test.py b/visual_terrain_stack_alignment_test.py deleted file mode 100644 index ecedd6d..0000000 --- a/visual_terrain_stack_alignment_test.py +++ /dev/null @@ -1,158 +0,0 @@ -import omni -import math -from omni.isaac.kit import SimulationApp - -simulation_app = SimulationApp({"headless": False}) -HRDEMCfg_D = { - "num_blocks": 4, - "block_size": 500, - "pad_size": 50.0, - "max_blocks": int(1e7), - "seed": 42, - "resolution": 0.05, - "z_scale": 1.0, - "source_resolution": 5.0, - "resolution": 0.5, - "interpolation_padding": 2, - "generate_craters": False, -} -CWMCfg_D = { - "num_workers": 8, - "input_queue_size": 400, - "output_queue_size": 16, - "worker_queue_size": 2, -} -IWMCfg_D = { - "num_workers": 1, - "input_queue_size": 400, - "output_queue_size": 30, - "worker_queue_size": 200, -} -CraterDBCfg_D = { - "block_size": 50, - "max_blocks": 7, - "save_to_disk": False, - "write_to_disk_interval": 100, -} -CGCfg_D = { - "profiles_path": "assets/Terrains/crater_spline_profiles.pkl", - "min_xy_ratio": 0.85, - "max_xy_ratio": 1.0, - "random_rotation": True, - "seed": 42, - "num_unique_profiles": 10000, -} -CDDCfg_D = { - "densities": [0.025, 0.05, 0.5], - "radius": [[1.5, 2.5], [0.75, 1.5], [0.25, 0.5]], - "num_repeat": 1, - "seed": 42, -} -CraterSamplerCfg_D = { - "block_size": 50, - "crater_gen_cfg": CGCfg_D, - "crater_dist_cfg": CDDCfg_D, -} -CraterBuilderCfg_D = { - "block_size": 50, - "pad_size": 10.0, - "resolution": 0.5, - "z_scale": 1.0, -} -ICfg = { - "source_resolution": 5.0, - "target_resolution": 0.5, - "source_padding": 2, - "method": "bicubic", -} -HRDEMGenCfg_D = { - "high_res_dem_cfg": HRDEMCfg_D, - "crater_db_cfg": CraterDBCfg_D, - "crater_sampler_cfg": CraterSamplerCfg_D, - "crater_builder_cfg": CraterBuilderCfg_D, - "interpolator_cfg": ICfg, - "crater_worker_manager_cfg": CWMCfg_D, - "interpolator_worker_manager_cfg": IWMCfg_D, -} - -MMCfg_D = { - "folder_path": "assets/Terrains/SouthPole", - "lr_dem_name": "crater", -} - -NGCMMCfg_D = { - "num_texels_per_level": 256, - "target_res": 0.1, - "fine_interpolation_method": "bilinear", - "coarse_interpolation_method": "bilinear", - "fine_acceleration_mode": "hybrid", - "coarse_acceleration_mode": "hybrid", -} - -LSTMCfg_D = { - "map_name": "NPD_final_adj_5mpp_surf", - "pixel_coordinates": (0, 0), - "ll_coordinates": (0, 0), - "meters_coordinates": (0, 0), - "coordinate_format": "meters", - "visual_mesh_update_threshold": 2.0, -} - -if __name__ == "__main__": - from omni.isaac.core import World - from omni.usd import get_context - from pxr import UsdLux - from WorldBuilders.pxr_utils import setDefaultOps, addDefaultOps - import numpy as np - - from src.terrain_management.large_scale_terrain.map_manager import MapManagerCfg, MapManager - from src.terrain_management.large_scale_terrain.high_resolution_DEM_generator import HighResDEMGenCfg - - from src.terrain_management.large_scale_terrain_manager import ( - NestedGeometricClipMapManagerCfg, - LargeScaleTerrainManagerCfg, - LargeScaleTerrainManager, - ) - - world = World(stage_units_in_meters=1.0) - stage = get_context().get_stage() - - # Let there be light - light = UsdLux.DistantLight.Define(stage, "/sun") - light.CreateIntensityAttr(3000.0) - addDefaultOps(light.GetPrim()) - setDefaultOps(light.GetPrim(), (0, 0, 0), (0.383, 0, 0, 0.924), (1, 1, 1)) - - C = 20000 * 5 - R = 500 * 5 - max_displacement = 2.0 / 30 - perimeter = 2 * np.pi * R - rotation_rate = int(perimeter / max_displacement) - spiral_rate = 0.0 / rotation_rate - theta = np.linspace(0, 2 * np.pi, rotation_rate) - print(rotation_rate) - - hrdem_settings = HighResDEMGenCfg(**HRDEMGenCfg_D) - mm_settings = MapManagerCfg(**MMCfg_D) - ngcmm_settings = NestedGeometricClipMapManagerCfg(**NGCMMCfg_D) - lstm_settings = LargeScaleTerrainManagerCfg(**LSTMCfg_D) - - LSTM = LargeScaleTerrainManager( - lstm_settings, ngcmm_settings, hrdem_settings, mm_settings - ) - - LSTM.build() - #LSTM.update_visual_mesh((0, 0)) - - i = 0 - i2 = 1.0 - while True: - # GCM.updateGeoClipmap( - # np.array( - # [C + i2 * R * math.cos(theta[i]), C + i2 * R * math.sin(theta[i]), 0] - # ), - # np.array([i2 * R * math.cos(theta[i]), i2 * R * math.sin(theta[i]), 0]), - # ) - world.step(render=True) - # i = (i + 1) % rotation_rate - # i2 += spiral_rate diff --git a/visual_terrain_stack_alignment_test_im.py b/visual_terrain_stack_alignment_test_im.py deleted file mode 100644 index e1202ce..0000000 --- a/visual_terrain_stack_alignment_test_im.py +++ /dev/null @@ -1,196 +0,0 @@ -# import omni -# import math -# from omni.isaac.kit import SimulationApp - -# simulation_app = SimulationApp({"headless": False}) -HRDEMCfg_D = { - "num_blocks": 4, - "block_size": 50, - "pad_size": 10.0, - "max_blocks": int(1e7), - "seed": 42, - "resolution": 0.05, - "z_scale": 1.0, - "source_resolution": 5.0, - "resolution": 0.025, - "interpolation_padding": 2, - "generate_craters": True, -} -CWMCfg_D = { - "num_workers": 8, - "input_queue_size": 400, - "output_queue_size": 30, -} -IWMCfg_D = { - "num_workers": 1, - "input_queue_size": 400, - "output_queue_size": 30, -} -CraterDBCfg_D = { - "block_size": 50, - "max_blocks": 7, - "save_to_disk": False, - "write_to_disk_interval": 100, -} -CGCfg_D = { - "profiles_path": "assets/Terrains/crater_spline_profiles.pkl", - "min_xy_ratio": 0.85, - "max_xy_ratio": 1.0, - "random_rotation": True, - "seed": 42, - "num_unique_profiles": 10000, -} -CDDCfg_D = { - "densities": [0.025, 0.05, 0.5], - "radius": [[1.5, 2.5], [0.75, 1.5], [0.25, 0.5]], - "num_repeat": 1, - "seed": 42, -} -CraterSamplerCfg_D = { - "block_size": 50, - "crater_gen_cfg": CGCfg_D, - "crater_dist_cfg": CDDCfg_D, -} -CraterBuilderCfg_D = { - "block_size": 50, - "pad_size": 10.0, - "resolution": 0.025, - "z_scale": 1.0, -} -ICfg = { - "source_resolution": 5.0, - "target_resolution": 0.025, - "source_padding": 2, - "method": "bicubic", -} -HRDEMGenCfg_D = { - "high_res_dem_cfg": HRDEMCfg_D, - "crater_db_cfg": CraterDBCfg_D, - "crater_sampler_cfg": CraterSamplerCfg_D, - "crater_builder_cfg": CraterBuilderCfg_D, - "interpolator_cfg": ICfg, - "crater_worker_manager_cfg": CWMCfg_D, - "interpolator_worker_manager_cfg": IWMCfg_D, -} - -MMCfg_D = { - "folder_path": "assets/Terrains/debug", - "hrdem_settings": HRDEMGenCfg_D, -} - -NGCMMCfg_D = { - "num_texels_per_level": 256, - "target_res": 0.1, - "fine_interpolation_method": "bilinear", - "coarse_interpolation_method": "bilinear", - "fine_acceleration_mode": "hybrid", - "coarse_acceleration_mode": "hybrid", -} - -LSTMCfg_D = { - "map_name": "NPD_final_adj_5mpp_surf", - "pixel_coordinates": (0, 0), - "ll_coordinates": (0, 0), - "meters_coordinates": (0, 0), - "coordinate_format": "meters", - "visual_mesh_update_threshold": 2.0, -} - -if __name__ == "__main__": - # from omni.isaac.core import World - # from omni.usd import get_context - # from pxr import UsdLux - # from WorldBuilders.pxr_utils import setDefaultOps, addDefaultOps - import numpy as np - - from src.terrain_management.large_scale_terrain.map_manager import ( - MapManagerConf, - MapManager, - ) - from src.terrain_management.large_scale_terrain.high_resolution_DEM_generator import ( - HighResDEMGenConf, - ) - - # from src.terrain_management.large_scale_terrain_manager import ( - # NestedGeometricClipMapManagerCfg, - # LargeScaleTerrainManagerCfg, - # LargeScaleTerrainManager, - # ) - - # world = World(stage_units_in_meters=1.0) - # stage = get_context().get_stage() - - # Let there be light - # light = UsdLux.DistantLight.Define(stage, "/sun") - # light.CreateIntensityAttr(3000.0) - # addDefaultOps(light.GetPrim()) - # setDefaultOps(light.GetPrim(), (0, 0, 0), (0.383, 0, 0, 0.924), (1, 1, 1)) - - C = 20000 * 5 - R = 500 * 5 - max_displacement = 2.0 / 30 - perimeter = 2 * np.pi * R - rotation_rate = int(perimeter / max_displacement) - spiral_rate = 0.0 / rotation_rate - theta = np.linspace(0, 2 * np.pi, rotation_rate) - print(rotation_rate) - - mm_settings = MapManagerConf(**MMCfg_D) - # ngcmm_settings = NestedGeometricClipMapManagerCfg(**NGCMMCfg_D) - # lstm_settings = LargeScaleTerrainManagerCfg(**LSTMCfg_D) - - from matplotlib import pyplot as plt - import matplotlib.colors as mcolors - import cv2 - - MM = MapManager(mm_settings) - MM.load_lr_dem_by_name("normals") - MM.initialize_hr_dem((0, 0)) - np.save("hr_dem.npy", MM.get_hr_dem()) - norm = mcolors.Normalize(vmin=MM.lr_dem.min(), vmax=MM.lr_dem.max()) - hr_rs = cv2.resize(MM.hr_dem_gen.high_res_dem, (0, 0), fx=0.1, fy=0.1, interpolation=cv2.INTER_AREA) - MM.update_hr_dem((50, 0)) - MM.update_hr_dem((0, 50)) - MM.update_hr_dem((-50, 0)) - MM.update_hr_dem((0, -50)) - MM.update_hr_dem((50, 50)) - MM.update_hr_dem((-50, 50)) - MM.update_hr_dem((50, -50)) - MM.update_hr_dem((-50, -50)) - MM.hr_dem_gen.shutdown() - - lr_shape = MM.get_lr_dem_shape() - x = lr_shape[0] // 2 + 50 - y = lr_shape[1] // 2 + 50 - plt.figure() - plt.imshow(hr_rs, cmap="terrain", norm=norm) - plt.figure() - plt.imshow(MM.lr_dem, cmap="terrain", norm=norm) - # plt.figure() - # plt.imshow( - # MM.lr_dem[x - 550 : x + 550, y - 550 : y + 550], cmap="terrain", norm=norm - # ) - # diff = hr_rs - MM.lr_dem[x - 550 : x + 550, y - 550 : y + 550] - # plt.figure() - # plt.imshow(diff, cmap="jet") - plt.show() - - # LSTM = LargeScaleTerrainManager( - # lstm_settings, ngcmm_settings, hrdem_settings, mm_settings - # ) - - # LSTM.build() - # LSTM.update_visual_mesh((0, 0)) - - # i = 0 - # i2 = 1.0 - # while True: - # GCM.updateGeoClipmap( - # np.array( - # [C + i2 * R * math.cos(theta[i]), C + i2 * R * math.sin(theta[i]), 0] - # ), - # np.array([i2 * R * math.cos(theta[i]), i2 * R * math.sin(theta[i]), 0]), - # ) - # world.step(render=True) - # i = (i + 1) % rotation_rate - # i2 += spiral_rate diff --git a/visual_terrain_stack_demo.py b/visual_terrain_stack_demo.py deleted file mode 100644 index efc664d..0000000 --- a/visual_terrain_stack_demo.py +++ /dev/null @@ -1,390 +0,0 @@ -import omni -import copy -import math -import os - -import numpy as np -from omni.isaac.kit import SimulationApp -from scipy.spatial.transform import Rotation as SSTR - - -def EMAquat(q1, q2, alpha): - dot = q1[0] * q2[0] + q1[1] * q2[1] + q1[2] * q2[2] + q1[3] * q2[3] - if dot < 0: - alpha2 = -alpha - else: - alpha2 = copy.copy(alpha) - x = q1[0] * (1 - alpha2) + q2[0] * alpha2 - y = q1[1] * (1 - alpha2) + q2[1] * alpha2 - z = q1[2] * (1 - alpha2) + q2[2] * alpha2 - w = q1[3] * (1 - alpha2) + q2[3] * alpha2 - s = math.sqrt(x * x + y * y + z * z + w * w) - return x / s, y / s, z / s, w / s - - -cfg = { - "renderer": "PathTracing", - "headless": True, - "samples_per_pixel_per_frame": 32, - "max_bounces": 6, - "max_specular_transmission_bounces": 6, - "max_volume_bounces": 4, - "subdiv_refinement_level": 0, -} -# cfg = { -# "headless": False, -# } -simulation_app = SimulationApp(cfg) - - -RSCfg_1_D = { - "block_size": 50, - "seed": 42, - "rock_dist_cfg": { - "position_distribution": { - "name": "thomas_point_process", - "parent_density": 0.04, - "child_density": 100, - "sigma": 3.0, - "seed": 42, - }, - "scale_distribution": { - "name": "uniform", - "min": 0.02, - "max": 0.05, - "seed": 43, - }, - }, -} -RSCfg_2_D = { - "block_size": 50, - "seed": 42, - "rock_dist_cfg": { - "position_distribution": { - "name": "thomas_point_process", - "parent_density": 0.01, - "child_density": 25, - "sigma": 3.0, - "seed": 44, - }, - "scale_distribution": { - "name": "uniform", - "min": 0.05, - "max": 0.2, - "seed": 45, - }, - }, -} -RGCfg_1_D = { - "rock_sampler_cfg": RSCfg_1_D, - "rock_assets_folder": "assets/USD_Assets/rocks/small_rocks_v4", - "instancer_name": "very_small_rock_instancer", - "seed": 46, - "block_span": 1, - "add_colliders": False, - "texture_name": "seaside_rock_2k", - "texture_path": "assets/Textures/seaside_rock_2k.mdl", -} -RGCfg_2_D = { - "rock_sampler_cfg": RSCfg_2_D, - "rock_assets_folder": "assets/USD_Assets/rocks/small_rocks_v4", - "instancer_name": "small_rock_instancer", - "seed": 47, - "block_span": 2, - "add_colliders": False, - "collider_mode": "none", - "semantic_label": "small_rock", - "texture_name": "seaside_rock_2k", - "texture_path": "assets/Textures/seaside_rock_2k.mdl", -} -LSTCfg_D = { - "seed": 42, - "crater_gen_seed": None, - "crater_gen_distribution_seed": None, - "crater_gen_metadata_seed": None, - "rock_gen_main_seed": None, - "profiling": True, - "update_every_n_meters": 2.0, - "z_scale": 1.0, - "block_size": 50, - "dbs_max_elements": 10000000, - "dbs_save_to_disk": False, - "dbs_write_interval": 1000, - "hr_dem_resolution": 0.025, - "hr_dem_generate_craters": True, - "hr_dem_num_blocks": 4, - "crater_gen_densities": [0.025, 0.05, 0.5], - "crater_gen_radius": [[1.5, 2.5], [0.75, 1.5], [0.25, 0.5]], - "crater_gen_profiles_path": "assets/Terrains/crater_spline_profiles.pkl", - "crater_gen_padding": 10.0, - "crater_gen_min_xy_ratio": 0.85, - "crater_gen_max_xy_ratio": 1.0, - "crater_gen_random_rotation": True, - "crater_gen_num_unique_profiles": 10000, - "num_workers_craters": 8, - "num_workers_interpolation": 1, - "input_queue_size": 400, - "output_queue_size": 30, - "hrdem_interpolation_method": "bicubic", - "hrdem_interpolator_name": "PIL", - "hrdem_interpolator_padding": 2, - "lr_dem_folder_path": "assets/Terrains/SouthPole", - "lr_dem_name": "Site20_final_adj_5mpp_surf", - "starting_position": (0, 0), - "geo_cm_num_texels_per_level": 384, - "geo_cm_target_res": 0.02, - "geo_cm_fine_interpolation_method": "bilinear", - "geo_cm_coarse_interpolation_method": "bicubic", - "geo_cm_fine_acceleration_mode": "hybrid", - "geo_cm_coarse_acceleration_mode": "gpu", - "geo_cm_semantic_label": "terrain", - "geo_cm_texture_name": "LunarRegolith8k", - "geo_cm_texture_path": "assets/Textures/LunarRegolith8k.mdl", - "geo_cm_apply_smooth_shading": False, - "terrain_collider_enabled": True, - "terrain_collider_resolution": 0.05, - "terrain_collider_cache_size": 10, - "terrain_collider_building_threshold": 4.0, - "rock_gen_cfgs": [ - RGCfg_1_D, - RGCfg_2_D, - ], -} - - -if __name__ == "__main__": - from omni.isaac.core import World - from omni.usd import get_context - from pxr import UsdLux, UsdGeom, Gf, UsdShade, Vt, Sdf, Usd - - from src.terrain_management.large_scale_terrain.pxr_utils import set_xform_ops - from src.terrain_management.large_scale_terrain.utils import ScopedTimer - from src.configurations.large_scale_terrain_confs import LargeScaleTerrainConf - from src.terrain_management.large_scale_terrain_manager import ( - LargeScaleTerrainManager, - ) - from src.labeling.auto_label import AutonomousLabeling - from src.configurations.auto_labeling_confs import AutoLabelingConf - from omni.isaac.sensor import Camera - - def buildRealSenseRGB(stage, camera_path): - rs_d455 = stage.DefinePrim(camera_path, "Xform") - set_xform_ops(rs_d455, Gf.Vec3d(0, 0, 0), Gf.Quatd(1, (0, 0, 0)), Gf.Vec3d(1, 1, 1)) - # Mono - camera_mono = UsdGeom.Camera.Define(stage, camera_path + "/mono") - camera_mono.GetClippingRangeAttr().Set(Gf.Vec2f(0.01, 100000)) - camera_mono.GetFocalLengthAttr().Set(1.93) - camera_mono.GetFocusDistanceAttr().Set(0.0) - camera_mono.GetFStopAttr().Set(0.0) - camera_mono.GetHorizontalApertureAttr().Set(3.896) - camera_mono.GetVerticalApertureAttr().Set(2.453) - camera_mono_prim = camera_mono.GetPrim() - set_xform_ops(camera_mono_prim, Gf.Vec3d(0, -0.0115, 0), Gf.Quatd(0.5, (0.5, -0.5, -0.5)), Gf.Vec3d(1, 1, 1)) - # Left - camera_left = UsdGeom.Camera.Define(stage, camera_path + "/left") - camera_left.GetClippingRangeAttr().Set(Gf.Vec2f(0.01, 100000)) - camera_left.GetFocalLengthAttr().Set(1.93) - camera_left.GetFocusDistanceAttr().Set(0.0) - camera_left.GetFStopAttr().Set(0.0) - camera_left.GetHorizontalApertureAttr().Set(3.896) - camera_left.GetVerticalApertureAttr().Set(2.453) - camera_left_prim = camera_left.GetPrim() - set_xform_ops(camera_left_prim, Gf.Vec3d(0, 0.0475, 0), Gf.Quatd(0.5, (0.5, -0.5, -0.5)), Gf.Vec3d(1, 1, 1)) - # Right - camera_right = UsdGeom.Camera.Define(stage, camera_path + "/right") - camera_right.GetClippingRangeAttr().Set(Gf.Vec2f(0.01, 100000)) - camera_right.GetFocalLengthAttr().Set(1.93) - camera_right.GetFocusDistanceAttr().Set(0.0) - camera_right.GetFStopAttr().Set(0.0) - camera_right.GetHorizontalApertureAttr().Set(3.896) - camera_right.GetVerticalApertureAttr().Set(2.453) - camera_right_prim = camera_right.GetPrim() - set_xform_ops(camera_right_prim, Gf.Vec3d(0, -0.0475, 0), Gf.Quatd(0.5, (0.5, -0.5, -0.5)), Gf.Vec3d(1, 1, 1)) - # Depth - camera_depth = UsdGeom.Camera.Define(stage, camera_path + "/depth") - camera_depth.GetClippingRangeAttr().Set(Gf.Vec2f(0.01, 100000)) - camera_depth.GetFocalLengthAttr().Set(1.93) - camera_depth.GetFocusDistanceAttr().Set(0.0) - camera_depth.GetFStopAttr().Set(0.0) - camera_depth.GetHorizontalApertureAttr().Set(3.896) - camera_depth.GetVerticalApertureAttr().Set(2.453) - camera_depth_prim = camera_depth.GetPrim() - set_xform_ops(camera_depth_prim, Gf.Vec3d(0, 0, 0), Gf.Quatd(0.5, (0.5, -0.5, -0.5)), Gf.Vec3d(1, 1, 1)) - return rs_d455 - - # attr = camera.GetPrim().CreateAttribute("cameraProjectionType", Sdf.ValueTypeNames.Token) - # if attr.GetMetadata("allowedTokens") is None: - # attr.SetMetadata( - # "allowedTokens", - # [ - # "pinhole", - # "fisheyeOrthographic", - # "fisheyeEquidistant", - # "fisheyeEquisolid", - # "fisheyePolynomial", - # "fisheyeSpherical", - # "fisheyeKannalaBrandtK3", - # "fisheyeRadTanThinPrism", - # "omniDirectionalStereo", - # ], - # ) - # properties = [ - # "fthetaPolyA", - # "fthetaPolyB", - # "fthetaPolyC", - # "fthetaPolyD", - # "fthetaPolyE", - # "fthetaCx", - # "fthetaCy", - # "fthetaWidth", - # "fthetaHeight", - # "fthetaMaxFov", - # ] - # for property_name in properties: - # if camera.GetPrim().GetAttribute(property_name).Get() is None: - # camera.GetPrim().CreateAttribute(property_name, Sdf.ValueTypeNames.Float) - - # camera.GetPrim().GetAttribute("cameraProjectionType").Set(Vt.Token("pinhole")) - # camera.GetPrim().GetAttribute("fthetaMaxFov").Set(98.0) - # return camera - - world = World(stage_units_in_meters=1.0) - stage = get_context().get_stage() - asset_path = os.path.join(os.getcwd(), "assets") - - # Let there be light - light = UsdLux.DistantLight.Define(stage, "/World/sun") - light.CreateIntensityAttr(1000.0) - set_xform_ops(light.GetPrim(), Gf.Vec3d(0, 0, 0), Gf.Quatd(0.76, (0.65, 0, 0)), Gf.Vec3d(1, 1, 1)) - - camera = buildRealSenseRGB(stage, "/World/camera") - - left_light = UsdLux.DiskLight.Define(stage, "/World/camera/left_light") - left_light.CreateRadiusAttr(0.05) - left_light.CreateIntensityAttr(10000000.0) - left_light.CreateColorAttr(Gf.Vec3f(0.87, 0.97, 0.97)) - left_shaping_api = UsdLux.ShapingAPI(left_light.GetPrim()) - left_shaping_api.CreateShapingIesFileAttr().Set(asset_path + "/Textures/RobotProjector.ies") - left_shaping_api.CreateShapingIesNormalizeAttr().Set(True) - set_xform_ops( - left_light.GetPrim(), - Gf.Vec3d(0, 0.5, 0), - Gf.Quatd(0.5, (0.5, -0.5, -0.5)), - Gf.Vec3d(1, 1, 1), - ) - right_light = UsdLux.DiskLight.Define(stage, "/World/camera/right_light") - right_light.CreateRadiusAttr(0.05) - right_light.CreateIntensityAttr(10000000.0) - right_light.CreateColorAttr(Gf.Vec3f(0.87, 0.97, 0.97)) - right_shaping_api = UsdLux.ShapingAPI(right_light.GetPrim()) - right_shaping_api.CreateShapingIesFileAttr().Set(asset_path + "/Textures/RobotProjector.ies") - right_shaping_api.CreateShapingIesNormalizeAttr().Set(True) - set_xform_ops( - right_light.GetPrim(), - Gf.Vec3d(0.0, -0.5, 0), - Gf.Quatd(0.5, (0.5, -0.5, -0.5)), - Gf.Vec3d(1, 1, 1), - ) - - C = 0 - R = 800 - render_substeps = 2 - max_displacement = 2.0 / 30 - acquisition_rate = 15 - perimeter = 2 * np.pi * R - rotation_rate = int(perimeter / max_displacement) - spiral_rate = 0.0 / rotation_rate - theta = np.linspace(0, 2 * np.pi, rotation_rate) - i = 0 - i2 = 1.0 - - x = C + i2 * R * math.cos(theta[i]) - y = C + i2 * R * math.sin(theta[i]) - - initial_position = (x, y) - - LSTCfg_D["starting_position"] = initial_position - - AL_Cfg_D = { - "num_images": 10000000, - "prim_path": "/World", - "camera_names": ["mono", "left", "right", "depth"], - "camera_resolutions": [(1280, 720), (1280, 720), (1280, 720), (1280, 720)], - "data_dir": "data", - "annotators_list": [["rgb", "pose"], ["ir", "pose"], ["ir", "pose"], ["depth", "pose"]], - "image_formats": ["png", "png", "png", "png"], - "annot_formats": ["json", "json", "json", "json"], - "element_per_folder": 10000000, - "save_intrinsics": True, - } - # Prime the world - for i in range(100): - world.step(render=True) - - ALCFG = AutoLabelingConf(**AL_Cfg_D) - AL = AutonomousLabeling(ALCFG) - AL.load() - - lstm_settings = LargeScaleTerrainConf(**LSTCfg_D) - LSTM = LargeScaleTerrainManager(lstm_settings) - - LSTM.build() - height = LSTM.get_height_global(initial_position) - - timeline = omni.timeline.get_timeline_interface() - timeline.play() - - i3 = 0 - target = R * 2 * math.pi / max_displacement / acquisition_rate - target += 10 - Q_camera = None - - for _ in range(100): - world.step(render=True) - - print("Starting simulation") - while target > i3: - x_new = C + i2 * R * math.cos(theta[i]) - y_new = C + i2 * R * math.sin(theta[i]) - x_delta = x_new - x - y_delta = y_new - y - coords = (x_delta, y_delta) - - normal_vector = LSTM.get_normal_local(coords) - heading_vector = np.array([np.cos(theta[i]), np.sin(theta[i]), 0]) - heading_vector = heading_vector / np.linalg.norm(heading_vector) - heading_vector = np.cross(normal_vector, heading_vector) - heading_vector = heading_vector / np.linalg.norm(heading_vector) - heading_vector_2 = np.cross(normal_vector, heading_vector) - RNorm = np.array([heading_vector, heading_vector_2, normal_vector]).T - - RM = SSTR.from_matrix(RNorm) - if Q_camera is None: - Q_camera = RM.as_quat() - else: - Q_camera = EMAquat(Q_camera, RM.as_quat(), 0.0333) - - set_xform_ops( - camera.GetPrim(), - Gf.Vec3d(x_delta, y_delta, LSTM.get_height_local(coords) + 0.5), - Gf.Quatd(Q_camera[-1], (Q_camera[0], Q_camera[1], Q_camera[2])), - Gf.Vec3d(1, 1, 1), - ) - - with ScopedTimer("update_visual_mesh", active=False): - update, coords = LSTM.update_visual_mesh(coords) - - i = (i + 1) % rotation_rate - if i % acquisition_rate == 0: - for _ in range(render_substeps): - with ScopedTimer("env_step", active=False): - world.step(render=True) - try: - AL.record() - i3 += 1 - except Exception as e: - print(e) - # i2 += spiral_rate - timeline.stop() - LSTM.map_manager.hr_dem_gen.shutdown() - simulation_app.close() diff --git a/visual_terrain_stack_demo_test_instancers.py b/visual_terrain_stack_demo_test_instancers.py deleted file mode 100644 index 9f9d83f..0000000 --- a/visual_terrain_stack_demo_test_instancers.py +++ /dev/null @@ -1,165 +0,0 @@ -import omni -import copy -import math -import os - -import numpy as np -from omni.isaac.kit import SimulationApp - - -cfg = { - "headless": False, -} -simulation_app = SimulationApp(cfg) - -RDBCfg_D = { - "block_size": 50, - "max_blocks": int(1e7), - "save_to_disk": False, - "write_to_disk_interval": 1000, -} -RSCfg_1_D = { - "block_size": 50, - "rock_dist_cfg": { - "position_distribution": { - "name": "thomas_point_process", - "parent_density": 0.04, - "child_density": 100, - "sigma": 3, - "seed": 42, - }, - "scale_distribution": { - "name": "uniform", - "min": 0.02, - "max": 0.05, - "seed": 42, - }, - "seed": 42, - "num_rock_id": 23, - }, -} -RSCfg_2_D = { - "block_size": 50, - "rock_dist_cfg": { - "position_distribution": { - "name": "thomas_point_process", - "parent_density": 0.01, - "child_density": 25, - "sigma": 3, - "seed": 42, - }, - "scale_distribution": { - "name": "uniform", - "min": 0.05, - "max": 0.2, - "seed": 42, - }, - "seed": 43, - "num_rock_id": 23, - }, -} -RGCfg_1_D = { - "rock_db_cfg": RDBCfg_D, - "rock_sampler_cfg": RSCfg_1_D, - "rock_assets_folder": "assets/USD_Assets/rocks/small_v2", - "instancer_name": "very_small_rock_instancer", - "seed": 42, - "block_span": 0, - "block_size": 50, -} -RGCfg_2_D = { - "rock_db_cfg": RDBCfg_D, - "rock_sampler_cfg": RSCfg_2_D, - "rock_assets_folder": "assets/USD_Assets/rocks/small_v2", - "instancer_name": "large_rock_instancer", - "seed": 42, - "block_span": 1, - "block_size": 50, -} -RMCfg_D = { - "rock_gen_cfgs": [RGCfg_1_D, RGCfg_2_D], - "instancers_path": "/World/rock_instancers", - "seed": 42, - "block_size": 50, -} - - -if __name__ == "__main__": - from omni.isaac.core import World - from omni.usd import get_context - from pxr import UsdLux, UsdGeom, Gf, UsdShade, Vt, Sdf, Usd - - from WorldBuilders.pxr_utils import setDefaultOps, addDefaultOps - - def is_map_done(): - return True - - from src.terrain_management.large_scale_terrain.rock_distribution import ( - mock_call, - ) - from src.terrain_management.large_scale_terrain.rock_manager import ( - RockManagerCfg, - RockManager, - ) - - world = World(stage_units_in_meters=1.0) - stage = get_context().get_stage() - asset_path = os.path.join(os.getcwd(), "assets") - - # Let there be light - light = UsdLux.DistantLight.Define(stage, "/World/sun") - light.CreateIntensityAttr(3000.0) - addDefaultOps(light.GetPrim()) - setDefaultOps(light.GetPrim(), (0, 0, 0), (0.65, 0, 0, 0.76), (1, 1, 1)) - - C = 0 - R = 100 * 5 - max_displacement = 2.0 / 30 - acquisition_rate = 1 - perimeter = 2 * np.pi * R - rotation_rate = int(perimeter / max_displacement) - spiral_rate = 0.0 / rotation_rate - theta = np.linspace(0, 2 * np.pi, rotation_rate) - i = 0 - i2 = 1.0 - - x = C + i2 * R * math.cos(theta[i]) - y = C + i2 * R * math.sin(theta[i]) - - initial_position = (x, y) - - # Prime the world - for i in range(100): - world.step(render=True) - - rm_settings = RockManagerCfg(**RMCfg_D) - - timeline = omni.timeline.get_timeline_interface() - timeline.play() - - i3 = 0 - target = R * 2 * math.pi / max_displacement / acquisition_rate - target = target / 8 - target += 10 - Q_camera = None - update_done = False - rock_manager = RockManager(rm_settings, mock_call, is_map_done) - rock_manager.build() - - for i in range(100): - world.step(render=True) - print("Starting simulation") - while target > i3: - x_new = C + i2 * R * math.cos(theta[i]) - y_new = C + i2 * R * math.sin(theta[i]) - x_delta = x_new - x - y_delta = y_new - y - coords = (x_delta, y_delta) - - world.step(render=True) - - rock_manager.sample(coords) - i = (i + 1) % rotation_rate - - timeline.stop() - simulation_app.close()