Skip to content

Commit

Permalink
formatter
Browse files Browse the repository at this point in the history
  • Loading branch information
pascal-roth committed Nov 18, 2024
1 parent aad3d09 commit d0517f6
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,9 @@ def _point_filter_wall_closeness(
heights = heights[without_wall]
return ray_origins, heights

def _point_filter_semantic_cost(self, ray_origins: torch.Tensor, heights: torch.Tensor) -> tuple[torch.Tensor, torch.Tensor]:
def _point_filter_semantic_cost(
self, ray_origins: torch.Tensor, heights: torch.Tensor
) -> tuple[torch.Tensor, torch.Tensor]:
# raycast vertically down and get the corresponding face id
ray_directions = torch.zeros((ray_origins.shape[0], 3), dtype=torch.float32, device=self.device)
ray_directions[:, 2] = -1.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@

import cv2
import numpy as np
import torch
import omni.isaac.lab.utils.math as math_utils
import torch
from omni.isaac.lab.markers import VisualizationMarkers
from omni.isaac.lab.markers.config import GREEN_ARROW_X_MARKER_CFG
from omni.isaac.lab.scene import InteractiveScene
Expand Down Expand Up @@ -78,7 +78,9 @@ def sample_viewpoints(self, nbr_viewpoints: int, seed: int = 1) -> torch.Tensor:
while sample_locations_count < nbr_viewpoints:
# get samples
sample_idx = self.terrain_analyser.samples[:, 0] == curr_point_idx
sample_idx_select = torch.randperm(sample_idx.sum())[:min(nbr_samples_per_point, nbr_viewpoints - sample_locations_count)]
sample_idx_select = torch.randperm(sample_idx.sum())[
: min(nbr_samples_per_point, nbr_viewpoints - sample_locations_count)
]
sample_locations[
sample_locations_count : sample_locations_count + sample_idx_select.shape[0]
] = self.terrain_analyser.samples[sample_idx][sample_idx_select, :2]
Expand Down Expand Up @@ -165,7 +167,11 @@ def render_viewpoints(self, samples: torch.Tensor):
np.savetxt(os.path.join(filedir, "intrinsics.txt"), intrinsics.reshape(-1, 12), delimiter=",")

# save camera poses (format: x y z qx qy qz qw instead of x y z qw qx qy qz)
np.savetxt(os.path.join(filedir, "camera_extrinsic.txt"), samples[:, [0, 1, 2, 4, 5, 6, 3]].cpu().numpy(), delimiter=",")
np.savetxt(
os.path.join(filedir, "camera_extrinsic.txt"),
samples[:, [0, 1, 2, 4, 5, 6, 3]].cpu().numpy(),
delimiter=",",
)

# save images
samples = samples.to(self.scene.device)
Expand Down Expand Up @@ -217,12 +223,14 @@ def render_viewpoints(self, samples: torch.Tensor):
# might not start from 0 as well as some data ids might not be present in the label ids
unique_data_ids = np.unique(image_data_np)
unique_data_ids.sort()
mapping = np.zeros((max(unique_data_ids.max() + 1, max(info.keys()) + 1), 3), dtype=np.uint8)
mapping = np.zeros(
(max(unique_data_ids.max() + 1, max(info.keys()) + 1), 3), dtype=np.uint8
)
mapping[list(info.keys())] = np.array(list(info.values()), dtype=np.uint8)
output = mapping[image_data_np[idx].squeeze(-1)]
else:
output = image_data_np[idx]

assert cv2.imwrite(
os.path.join(filedir, "semantics", f"{image_idx[cam_idx]}".zfill(4) + ".png"),
cv2.cvtColor(output.astype(np.uint8), cv2.COLOR_RGB2BGR),
Expand All @@ -233,8 +241,11 @@ def render_viewpoints(self, samples: torch.Tensor):
os.path.join(filedir, "depth", f"{image_idx[cam_idx]}".zfill(4) + ".png"),
np.uint16(image_data_np[idx] * self.cfg.depth_scale),
)
# save as npy
np.save(os.path.join(filedir, "depth", f"{image_idx[cam_idx]}".zfill(4) + ".npy"), image_data_np[idx] * self.cfg.depth_scale)
# save as npy
np.save(
os.path.join(filedir, "depth", f"{image_idx[cam_idx]}".zfill(4) + ".npy"),
image_data_np[idx] * self.cfg.depth_scale,
)

image_idx[cam_idx] += 1

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,9 @@ def _add_semantics(self):
# assign class to mesh in ISAAC
def recursive_semUpdate(prim, sem_class_name: str, update_submesh: bool) -> bool:
# Necessary for Park Mesh
if prim.GetName() == "HierarchicalInstancedStaticMesh" or prim.GetTypeName() == "Mesh": # or "FoliageInstancedStaticMeshComponent" in prim.GetName():
if (
prim.GetName() == "HierarchicalInstancedStaticMesh" or prim.GetTypeName() == "Mesh"
): # or "FoliageInstancedStaticMeshComponent" in prim.GetName():
add_update_semantics(prim, sem_class_name)
update_submesh = True
children = prim.GetChildren()
Expand Down
2 changes: 1 addition & 1 deletion omniverse/standalone/data_collect.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def main():
cfg.terrain_analysis.dim_limiter_prim = "Road_Sidewalk"
elif args_cli.scene == "warehouse":
scene_cfg = WarehouseTerrainSceneCfg(args_cli.num_envs, env_spacing=1.0)
# overwrite semantic cost mapping
# overwrite semantic cost mapping
cfg.terrain_analysis.semantic_cost_mapping = CarlaSemanticCostMapping()
# limit space to be within the road network
cfg.terrain_analysis.dim_limiter_prim = "Section" # name of the meshes of the walls
Expand Down
8 changes: 4 additions & 4 deletions viplanner/config/costmap_cfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,13 +158,13 @@ class GeneralCostMapConfig:
# smoothing parameters
sigma_smooth: float = 3.0
# cost map expansion
x_min: Optional[float] = None # -8.05
x_min: Optional[float] = None
# [m] if None, the minimum of the point cloud is used None (carla town01: -8.05 matterport: None)
y_min: Optional[float] = None # -8.05
y_min: Optional[float] = None
# [m] if None, the minimum of the point cloud is used None (carla town01: -8.05 matterport: None)
x_max: Optional[float] = None # 346.22
x_max: Optional[float] = None
# [m] if None, the maximum of the point cloud is used None (carla town01: 346.22 matterport: None)
y_max: Optional[float] = None # 336.65
y_max: Optional[float] = None
# [m] if None, the maximum of the point cloud is used None (carla town01: 336.65 matterport: None)


Expand Down
2 changes: 1 addition & 1 deletion viplanner/depth_reconstruct.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class DepthReconstruction:
- semantics (optional)
- xxxx.png (images should be named with 4 digits, e.g. 0000.png, 0001.png, etc., RGB images)
In the case that the semantic and depth images have an offset in their position (as typical on some robotic platforms),
In the case that the semantic and depth images have an offset in their position (as typical on some robotic platforms),
define a sem_suffic and depth_suffix in ReconstructionCfg to differentiate between the two with the following structure:
- env_name
Expand Down

0 comments on commit d0517f6

Please sign in to comment.