General

get_public_fields

airgen.utils.general.get_public_fields(obj)

Get all public fields of an object (not starting with _).

Arguments
obj
Object

The object to retrieve fields from.

Returns
List[str]
List[str]

List[str]

list_to_2d_float_array

airgen.utils.general.list_to_2d_float_array(flst, width, height)

Convert a list of floats to a 2D array.

Arguments
flst
List[float]

List of float values.

width
int

The width of the array.

height
int

The height of the array.

Returns
np.ndarray
np.ndarray

A NumPy array with dtype=np.float32 and shape (height, width).

string_to_float_array

airgen.utils.general.string_to_float_array(bstr)

Convert a string to a float array.

Arguments
bstr
str | bytes

The string or bytes to convert.

Returns
np.ndarray
np.ndarray

np.ndarray

string_to_uint8_array

airgen.utils.general.string_to_uint8_array(bstr)

Convert a string to a uint8 array.

Arguments
bstr
str | bytes

The string or bytes to convert.

Returns
np.ndarray
np.ndarray

A NumPy array with dtype=uint8.

to_dict

airgen.utils.general.to_dict(obj)

Convert an object to a dictionary of its public fields.

Arguments
obj
Object

The object to convert.

Returns
Dict[str, Any]
Dict[str, Any]

Dict[str, Any]

to_str

airgen.utils.general.to_str(obj)

Convert an object to a string of its public fields.

Arguments
obj
Object

The object to convert.

Returns
str
str

str

vector3d2list

airgen.utils.general.vector3d2list(vector3d)

Turn an AirGen Vector3r into a list of three floats.

Arguments
vector3d
Vector3r

The 3D vector to convert.

Returns
List[float]
List[float]

List[float]

wait_key

airgen.utils.general.wait_key(message="")

Wait for a key press on the console and return it.

Arguments
message
str, optional

message to display while waiting.

write_file

airgen.utils.general.write_file(filename, bstr)

Write binary data to a file. Used for writing compressed PNG images.

Arguments
filename
str

The name of the file.

bstr
bytes

The binary data to write.

Sensor

imagetype2request

airgen.utils.sensor.imagetype2request(camera_name, image_type)

Helper function to create an uncompressed AirGen ImageRequest for a given image type.

Arguments
camera_name
Literal["front_center", "bottom_center"]

The name of the camera.

image_type
ImageType

The type of image to capture.

responses2images

airgen.utils.sensor.responses2images(responses, dtype=None)

Convert AirGen image responses to NumPy arrays.

Arguments
responses
List[ImageResponse]

The image responses to convert.

dtype
Optional[Any]

The data type for the resulting NumPy arrays.

Returns
Dict[str, np.ndarray]
Dict[str, np.ndarray]

A dictionary with keys corresponding to camera names and values as the images.

image: For ImageType.Scene, ImageType.DepthVis, ImageType.OpticalFlowVis, image data is RGB image, numpy array with dtype=np.uint8, shape=(height, width, 3)

For ImageType.DepthPerspective, ImageType.DepthPlanar, ImageType.DisparityNormalized, image data is depth image in meters, numpy array with dtype=np.float32, shape=(height, width, 1)

For ImageType.Segmentation, image data is array of objects’ SegmentationIDs, numpy array with dtype=np.uint8, shape=(height, width, 1)

For ImageType.SurfaceNormals, image data is array of unit vector (normalized length), numpy array with dtype=np.float32, shape=(height, width, 3)

For ImageType.OpticalFlow, image data is array of displacements in x,y directions, numpy array with dtype=np.float32, shape=(height, width, 2)

For ImageType.Infrared, image data is array of infrared values (object’s SegmentationID for now), numpy array with dtype=np.uint8, shape=(height, width, 1)

camera parameters: width (int): image width

height (int): image height

fov (float): camera field of view in degrees

camera_position (List[float]): camera position (x,y,z) in airgen (NED frame)

camera_orientation_euler_pry (List[float]): camera orientation (pitch, roll, yaw) in degrees

camera_orientation_quat_wxyz (List[float]): camera orientation (w,x,y,z) in quaternion format

Mechanics

cameracoord2worldcoord

airgen.utils.mechanics.cameracoord2worldcoord(camera_coord, camera_params)

Given AirGen camera parameters, transform a camera coordinate back to AirGen world coordinates.

Arguments
camera_coord
List[float]

A coordinate (x, y, z).

camera_params
dict

Camera parameters.

Returns
np.ndarray
np.ndarray

np.ndarray

homo_coord_to_nonhome_coord

airgen.utils.mechanics.homo_coord_to_nonhome_coord(home_coord)

Turn homogeneous coordinates into non-homogeneous coordinates by factoring out the last dimension.

Arguments
home_coord
ivy.Array

An array of shape (..., n).

Returns
ivy.Array
ivy.Array

An array of shape (..., n-1).

imagecoord2direction

airgen.utils.mechanics.imagecoord2direction(pixelcoord, camera_param)

Given camera parameters (position, pose, and FOV) and pixel coordinates, return the 3D direction of the pixel relative to the camera.

Arguments
pixelcoord
Tuple[float, float]

Coordinate of the pixel in the image in xy format.

camera_param
Dict[str, Any]

Camera parameters.

Returns
Tuple[float, float, float]
Tuple[float, float, float]

Normalized unit directional vector (x, y, z).

imagecoord2orientation

airgen.utils.mechanics.imagecoord2orientation(pixelcoord, camera_param)

Given camera parameters (position, pose, and FOV) and pixel coordinates, return the 3D direction of the pixel relative to the camera, represented in yaw and pitch (absolute degrees).

Arguments
pixelcoord
Tuple[float, float]

Coordinate of the pixel in the image in xy format.

camera_param
Dict[str, Any]

Camera parameters.

Returns
Tuple[float, float, float]
Tuple[float, float, float]

Target pitch, roll, yaw in radians.

imagecoord2pose

airgen.utils.mechanics.imagecoord2pose(pixelcoord, point_depth, camera_param)

Convert pixel coordinates to 3D coordinates.

Arguments
pixelcoord
Tuple[float, float]

Coordinate of the pixel in the image in xy format.

point_depth
float

Depth of the point.

camera_param
Dict[str, Any]

Camera parameters.

Returns
Tuple[float, float, float]
Tuple[float, float, float]

Target coordinate in (x, y, z) and orientation (pitch, roll, yaw) in radians.

pose2vector

airgen.utils.mechanics.pose2vector(pitch, roll, yaw)

Transform a target direction represented in (pitch, roll, yaw) in radians into a directional vector.

Arguments
pitch
float

Pitch angle in radians.

roll
float

Roll angle in radians.

yaw
float

Yaw angle in radians.

Returns
Tuple[float, float, float]
Tuple[float, float, float]

Unit directional vector (x, y, z).

quat_wxyz_to_xyzw

airgen.utils.mechanics.quat_wxyz_to_xyzw(quat_wxyz)

Transform a quaternion (represented by a list of floats) from wxyz format to xyzw format.

Arguments
quat_wxyz
List[float]

A quaternion in wxyz format.

Returns
np.ndarray
np.ndarray

A quaternion in xyzw format.

rotate_xy

airgen.utils.mechanics.rotate_xy(vec, theta)

Rotate the xy component of a 3D vector by theta (in degrees) counterclockwise in the xy plane.

Assume the orientation:

^ y
|
|
|______> x
Arguments
vec
np.ndarray

A vector of shape (3,).

theta
float

Rotation angle in degrees.

Returns
np.ndarray
np.ndarray

Rotated vector of shape (3,).

to_eularian_angles

airgen.utils.mechanics.to_eularian_angles(q)

Transform a quaternion into Euler angles.

Arguments
q
Quaternionr

A quaternion in wxyz format.

Returns
Tuple[float, float, float]
Tuple[float, float, float]

Euler angles (pitch, roll, yaw) in radians.

vec2eulerangles

airgen.utils.mechanics.vec2eulerangles(vec)

Transform an AirGen directional vector into Euler angles.

Arguments
vec
np.ndarray

A directional vector of shape (N, 3).

Returns
np.ndarray
np.ndarray

np.ndarray: Euler angles of shape (N, 3) where each row is (pitch, roll, yaw) in degrees.

Vision

The vision subsection of AirGen utilities provides essential functions for handling camera parameters and generating point clouds from depth images.

build_camera

airgen.utils.vision.build_camera(camera_params)

Given AirGen camera parameters, this function builds the inverse extrinsic matrix and the camera intrinsic matrix.

Arguments
camera_params
dict

AirGen camera parameters.

Returns
Tuple[ivy.Array, ivy.Array]
Tuple[ivy.Array, ivy.Array]

Tuple of: Inverse Extrinsic Matrix, Intrinsic Matrix

build_camera_intrinsic

airgen.utils.vision.build_camera_intrinsic(camera_params)

Constructs the camera intrinsic matrix using AirGen camera parameters.

Arguments
camera_params
dict

AirGen camera parameters.

Returns
ivy.Array
ivy.Array

ivy.Array

build_camera_inv_extrinsic

airgen.utils.vision.build_camera_inv_extrinsic(camera_params)

Generates the inverse extrinsic matrix for the camera based on its parameters.

Arguments
camera_params
dict

AirGen camera parameters.

Returns
ivy.Array
ivy.Array

Inverse Extrinsic Matrix

camera_unproject_depth

airgen.utils.vision.camera_unproject_depth(depth, cam_inv_ext_mat, cam_inv_calib_mat)

Generates a point cloud from a depth image (Depth Perspective).

Arguments
depth
np.ndarray

Depth image of shape (H, W, 1).

cam_inv_ext_mat
ivy.Array

Inverse of camera extrinsic matrix.

cam_inv_calib_mat
ivy.Array

Inverse of camera intrinsic matrix.

Returns
np.ndarray
np.ndarray

Point cloud of shape (N, 3).

depth2pointcloud

airgen.utils.vision.depth2pointcloud(depth, camera_param, mask=None)

Generates a point cloud from a depth image.

Arguments
depth
np.ndarray

Depth image of shape (H, W, 1).

camera_param
dict

Camera parameters containing field of view, height, width, and pose.

mask
Optional[np.ndarray]

Boolean mask where 1 indicates the object of interest (H, W, 1). Defaults to None.

Returns
np.ndarray
np.ndarray

Point cloud in AirGen world coordinates of shape (N, 3).

Trajectory

The trajectory subsection of AirGen utilities focuses on waypoint-based path planning and trajectory generation.

Waypoint

airgen.utils.trajectory.Waypoint(x, y, z, yaw, time)

Stores a waypoint with positional and timing information.

Arguments
x, y, z

Position in the world frame.

yaw

Euler angle of the waypoint.

time

Time at which the waypoint is to be reached.

calc_time

airgen.utils.trajectory.calc_time(start, end)

Calculates a fitting time for the trajectory between two waypoints.

Arguments
start
Waypoint

Starting waypoint.

end
Waypoint

Ending waypoint.

fit_min_snap_trajectory

airgen.utils.trajectory.fit_min_snap_trajectory(waypoint_arr, isJoint=True)

Starting point for trajectory generation by transforming an array of arrays into an array of waypoints.

Arguments
waypoint_arr
array of arrays

Input waypoints.

isJoint
bool

Indicates whether to calculate joint operations. Defaults to True.

joint

airgen.utils.trajectory.joint(waypoints)

Calculates a trajectory using joint operations.

Arguments
waypoints
array of Waypoints

Waypoints to be connected by joint operations.

separate

airgen.utils.trajectory.separate(waypoints)

Calculates a trajectory using separate operations.

Arguments
waypoints
array of Waypoints

Waypoints to be processed individually.

Visualize

The visualize subsection of AirGen utilities provides methods to log camera data and images from AirGen to Rerun for real-time visualization.

rr_camera_capture_logger

airgen.utils.visualize.rr_camera_capture_logger(rr_space_view_name)

Given a view space name (entity_path in Rerun), returns a function that logs camera data (pose and capture in AirGen’s 3D world coordinate) to that view space.

Arguments
rr_space_view_name
str

Name of the view space (entity_path) in Rerun.

Returns

A callable function that logs camera data to the specified view space.

  • Usage:
trajectory_logger = rr_camera_capture_logger("airgen_world")
trajectory_logger(image, camera_params, camera_name)

rr_log_airgen_image

airgen.utils.visualize.rr_log_airgen_image(entity_path, image_type, image, image_name="")

Logs images from AirGen to Rerun.

Arguments
entity_path
str

Path to the entity in Rerun.

image_type
ImageType

Type of image to log.

image
np.ndarray

Image data.

image_name
str, optional

Name of the image (default is an empty string).

Raises
ValueError

If image_type is not supported.

Was this page helpful?