Getting the bounding box of the grey floor in warehouse USD in Isaac Sim

How can I programmatically get the bounding box of the complete grey floor (not just a couple tiles as shown in selection) using Python code?

I intend to use this bounding box so that when I am spawning random objects they are not spawn outside of the factory.

def main():
    # Open the environment in a new stage
    print(f"Loading Stage {ENV_URL}")
    open_stage(prefix_with_isaac_asset_server(ENV_URL))

    # Create a custom scope for newly added prims
    stage = get_current_stage()
    
     # Get the height of the pallet
    bb_cache = create_bbox_cache()
    curr_spawn_height = bb_cache.ComputeLocalBound(pallet_prim).GetRange().GetSize()[2] * 1.1
    print("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$")
    print('pallet get size: ', bb_cache.ComputeLocalBound(pallet_prim).GetRange().GetSize())

^ also, in above code, does bb_cache.ComputeLocalBound(pallet_prim).GetRange().GetSize() give me the bounding box of the pallet? For example, these are the numbers I got for pallet get size:

pallet get size: (1.213234950604253, 1.0028731312705617, 0.21111953263462624)

I was trying to use same to get the bounding box of the floor in the warehouse but I don’t know how to use a regular expression or better method to find the prim that belongs to the complete floor in the stage.

Please note that in the offline code, warehouse USD is my stage.

Hi @mona.jalal

What about using the compute_combined_aabb function for computing a combined AABB for a given a list of prim paths (in your case: floor tiles)

import omni.usd

import omni.isaac.core.utils.bounds as bounds_utils
import omni.isaac.core.utils.prims as prims_utils

stage = omni.usd.get_context().get_stage()
prims = [x.GetPath() for x in stage.Traverse() if "SM_floor" in x.GetName() and prims_utils.get_prim_type_name(x.GetPath()) == "Xform"]

bb_cache = bounds_utils.create_bbox_cache()
combined_range_arr = bounds_utils.compute_combined_aabb(bb_cache, prim_paths=prims)
print(combined_range_arr)

Another possible solution could be to add some objects (small visual spheres, e.g.) to specific positions (opposite corners, e.g.) to determine a working volume from the readings of their positions as show in the image

1 Like

Hi Toni,

Thanks a lot for your response.


def main():
    # Open the environment in a new stage
    print(f"Loading Stage {ENV_URL}")
    open_stage(prefix_with_isaac_asset_server(ENV_URL))

    # Create a custom scope for newly added prims
    stage = get_current_stage()
    
    floor_prims = [x.GetPath() for x in stage.Traverse() if "SM_floor" in x.GetName() and prims_utils.get_prim_type_name(x.GetPath()) == "Xform"]

    bb_cache = bounds_utils.create_bbox_cache()
    combined_range_arr = bounds_utils.compute_combined_aabb(bb_cache, prim_paths=floor_prims)
    print('combined_range_arr: ', combined_range_arr)

Why is it outputting 6 numbers instead of 4 numbers for the bounding box?

combined_range_arr:  [-2.80000155e+01 -2.34000366e+01 -8.58306866e-08  8.00001977e+00
  3.05999996e+01  1.43051144e-07]

I need this for

    `position=(random.uniform(-20, -2), random.uniform(-1, 3), 0)`

Also is it giving me the AABB for the rectangle or for the cube?

So, I need this information for forklift_prim because sometimes it is spawn outside of the warehouse. So need to figure what numbers to replace -20 and -2 programmatically for a stage where I randomize my objects.

    # Spawn a custom forklift at a random pose
    forklift_prim = prims.create_prim(
        prim_path=f"{SCOPE_NAME}/Custom_Forklift",
        position=(random.uniform(-20, -2), random.uniform(-1, 3), 0),
        orientation=euler_angles_to_quat([0, 0, random.uniform(0, math.pi)]),
        #orientation = np.array(euler_angles_to_quat([45, -60, 180], degrees=True)),
        #orientation=euler_angles_to_quat([random.uniform(0, math.pi), random.uniform(0, math.pi), random.uniform(0, math.pi)]),
        #orientation=euler_angles_to_quat(np.array([0, 90, 0], degrees=True)),
        #orientation=np.array(euler_angles_to_quat([0, 90, 0], degrees=True)),
        usd_path=CUSTOM_FORKLIFT_URL,
        semantic_label="Forklift",
    )

Hi Toni,

based on the numbers I got, does the following sound correct to you?

    # position=(random.uniform(-20, -2), random.uniform(-1, 3), 0),
    position = (random.uniform(-25, 7), random.uniform(-23, 28), 0),

I have:


combined_range_arr:  [-2.80000155e+01 -2.34000366e+01 -8.58306866e-08  8.00001977e+00
  3.05999996e+01  1.43051144e-07]

@toni.sm it seems what I have is wrong since stuff or the camera is being spawn out of the warehouse and shows the black stuff as the photo below

Hi @mona.jalal

According to the compute_combined_aabb documentation, the return value is NumPy array with the combined bounding box for input prims: [min x, min y, min z, max x, max y, max z]


According to the documentation, then something like the following code should make sense.
use the margin variable to control the distance from bounding box limits

margin = 0.5
min_x, min_y, min_z, max_x, max_y, max_z = combined_range_arr
position = (np.random.uniform(min_x + margin, max_x - margin),  # x
            np.random.uniform(min_y + margin, max_y - margin),  # y
            0)                                                  # z

Keep in mind that the margin should be larger than the radius of the sphere that encapsulates the object, to prevent the object from going out of the box.

1 Like

Hi @mona.jalal

I notice that some floor tiles in full_warehouse.usd file fall outside the warehouse walls. You need to take this into account for this scenario

d

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.