Utils¶
-
vista.utils.misc.
agent2poly
(agent: vista.entities.agents.Car.Car, ref_dynamics: Optional[vista.entities.agents.Dynamics.StateDynamics] = None) → shapely.geometry.geo.box[source]¶ Convert Agent object to polygon w.r.t. a reference dynamics.
- Parameters
agent (Car) – An agent with valid dynamics (pose and vehicle state).
ref_dynamics (StateDynamics) – A reference dynamics for computing the polygon representation of the agent. Default set to None that uses human dynamics of the agent.
- Returns
A polygon that describes the agent.
- Return type
Box
-
vista.utils.misc.
merge_dict
(dict1: Dict, dict2: Dict) → Dict[source]¶ Merge two dict, where dict1 has higher priority.
- Parameters
dict1 (Dict) – The first dictionary.
dict2 (Dict) – The second dictionary.
- Returns
The merged dictionary.
- Return type
Dict
-
vista.utils.misc.
fetch_agent_info
(agent: vista.entities.agents.Car.Car) → Dict[str, Any][source]¶ Get info from agent class.
- Parameters
agent (Car) – The agent to be extracted information from.
- Returns
A dictionary contains various information of the agent.
- Return type
Dict
-
vista.utils.misc.
img2flow
(img: numpy.ndarray, mag_minmax: Union[List, Tuple, numpy.ndarray], flow_size: Optional[Union[List, Tuple, numpy.ndarray]] = None) → numpy.ndarray[source]¶ Convert HSV-encoded flow image to optical flow.
- Parameters
img (np.ndarray) – An image with channel order BGR.
mag_minmax (Vec) – The minmum and maximum when normalizing the flow magnitude to [0,1].
flow_size (Vec) – Size of the output flow array. If set, resize the image before converting to flow; default to
None
.
- Returns
A HxWx2 array with the two channels as magnitude and the angle of the flow.
- Return type
np.ndarray
-
vista.utils.misc.
biinterp
(I0: numpy.ndarray, I1: numpy.ndarray, F_0_1: numpy.ndarray, F_1_0: numpy.ndarray, ts: float, t0: float, t1: float) → numpy.ndarray[source]¶ Interpolate frame with bidirectional flow.
- Parameters
I0 (np.ndarray) – A RGB image at time t0.
I1 (np.ndarray) – A RGB image at time t1.
F_0_1 (np.ndarray) – The flow from time t0 to t1.
F_1_0 (np.ndarray) – The flow from time t1 to t0.
ts (float) – The timestamp to be interpolated to.
t0 (float) – The timestamp of I0.
t1 (float) – The timestamp of I1.
- Returns
An interpolated RGB image at time ts.
- Return type
np.ndarray
-
vista.utils.misc.
flow_backwarp
(img: numpy.ndarray, flow: numpy.ndarray, use_pytorch: Optional[bool] = False) → numpy.ndarray[source]¶ Warp image based on optical flow.
- Parameters
img (np.ndarray) – An image to be warped.
flow (np.ndarray) – Optical flow to warp the image.
use_pytorch (bool) – Whether to use pytorch for warping; default to
False
.
- Returns
A warped image.
- Return type
np.ndarray
Helper functions for spatial transformation. Follow right handed (OpenGL) coordinate system.
-
vista.utils.transform.
rot2mat
(rot: Union[numpy.ndarray, List[Any], Tuple[Any]], seq: Optional[str] = 'xyz') → numpy.ndarray[source]¶ Convert euler vector (with sequence order) to rotation matrix.
- Parameters
rot (Vec) – A 3-dimensional rotation vector in Euler angle.
seq (str) – The order of the rotation vector, e.g.,
xzy
; default toxyz
.
- Returns
A rotation matrix equivalent to the given rotation vector.
- Return type
np.ndarray
-
vista.utils.transform.
vec2mat
(trans: Union[numpy.ndarray, List[Any], Tuple[Any]], rot: Union[numpy.ndarray, List[Any], Tuple[Any]]) → numpy.ndarray[source]¶ Convert translation and rotation vector to transformation matrix.
- Parameters
trans (Vec) – A 3-dimensional translation vector.
rot (Vec) – A 3-dimensional rotation vector.
- Returns
A 4-by-4 transformation matrix in SE(3).
- Return type
np.ndarray
-
vista.utils.transform.
euler2quat
(euler: Union[numpy.ndarray, List[Any], Tuple[Any]], seq: Optional[str] = 'xyz', degrees: Optional[bool] = False) → Union[numpy.ndarray, List[Any], Tuple[Any]][source]¶ Convert Euler rotation to quaternion.
- Parameters
euler (Vec) – A 3-dimensional rotation vector in Euler angle.
seq (str) – The order of the rotation vector, e.g.,
xzy
; default toxyz
.
- Returns
A 4-dimensional vector that describes a quaternion.
- Return type
Vec
-
vista.utils.transform.
quat2euler
(quat: Union[numpy.ndarray, List[Any], Tuple[Any]], seq: Optional[str] = 'xyz', degrees: Optional[bool] = False) → Union[numpy.ndarray, List[Any], Tuple[Any]][source]¶ Convert quaternion to Euler rotation.
- Parameters
quat (Vec) – A 4-dimensional vector that describes a quaternion.
seq (str) – The order of the output Euler rotation vector; default to
xyz
.degrees (bool) – Whether to convert the output rotation to degrees instead of radians; default to
False
.
- Returns
A 3-dimensional rotation vector in Euler angle.
- Return type
Vec
-
vista.utils.transform.
latlongyaw2vec
(latlongyaw: Union[numpy.ndarray, List[Any], Tuple[Any]]) → Tuple[Union[numpy.ndarray, List[Any], Tuple[Any]], Union[numpy.ndarray, List[Any], Tuple[Any]]][source]¶ Convert lateral, longitudinal, yaw compoenents to translational and rotational vectors. Note that the longitudinal component will be negated to follow right-handed OpenGL coordinate system.
- Parameters
latlongyaw (Vec) – A 3-dimensional vector with entries as lateral shift, longitudinal shift, and yaw difference.
- Returns
Return a tuple (
Vec_a
,Vec_b
), whereVec_a
is a 3-dimensional translation vector andVec_b
is a 3-dimensional rotation vector in Euler anglexyz
.
-
vista.utils.transform.
vec2latlongyaw
(trans: Union[numpy.ndarray, List[Any], Tuple[Any]], rot: Union[numpy.ndarray, List[Any], Tuple[Any]]) → Union[numpy.ndarray, List[Any], Tuple[Any]][source]¶ Convert translational and rotational vectors to lateral, longitudinal, yaw compoenents. Note that the y translational component will be negated to follow right-handed OpenGL coordinate system.
- Parameters
trans (Vec) – A 3-dimensional translation vector.
rot (Vec) – A 3-dimensional Euler rotation vector.
- Returns
- A 3-dimensional vector with entries as lateral shift,
longitudinal shift, and yaw difference.
- Return type
Vec
-
vista.utils.transform.
compute_relative_latlongyaw
(latlongyaw: Union[numpy.ndarray, List[Any], Tuple[Any]], latlongyaw_ref: Union[numpy.ndarray, List[Any], Tuple[Any]]) → Union[numpy.ndarray, List[Any], Tuple[Any]][source]¶ Compute relative lateral, longitudinal, yaw compoenents.
- Parameters
latlongyaw (Vec) – A 3-dimensional vector with lateral, longitudinal, and yaw component.
latlongyaw_ref (Vec) – A reference 3-dimensional vector with lateral, longitudinal, and yaw component.
- Returns
- A 3-dimensional vector that describe relative lateral,
longitudinal shift and yaw difference between the given two vectors.
- Return type
Vec
-
vista.utils.transform.
SE3_inv
(T_in: numpy.ndarray) → numpy.ndarray[source]¶ More efficient matrix inversion for SE(3).
- Parameters
T_in (np.ndarray) – a 4-by-4 transformation matrix in SE(3).
- Returns
The inverse of
T_in
.- Return type
np.ndarray
-
vista.utils.transform.
mat2vec
(mat: numpy.ndarray, seq: Optional[str] = 'xyz', degrees: Optional[bool] = False) → Tuple[Union[numpy.ndarray, List[Any], Tuple[Any]], Union[numpy.ndarray, List[Any], Tuple[Any]]][source]¶ Convert transformation matrix to translational and rotational vectors.
- Parameters
mat (np.ndarray) – A 4-by-4 transformation matrix in SE(3).
seq (str) – The order of the output Euler rotation vector; default to
xyz
.degrees (bool) – Whether to convert the output rotation to degrees instead of radians; default to
False
.
- Returns
Return a tuple (
Vec_a
,Vec_b
), whereVec_a
is a 3-dimensional translation vector andVec_b
is a 3-dimensional rotation vector in Euler anglexyz
.
-
vista.utils.transform.
pi2pi
(angle: float) → float[source]¶ Make sure angle is within -pi to pi.
- Parameters
angle (float) – Input angle in radians.
- Returns
Output angle that is within range [-pi, pi]
- Return type
float
Logging utilities of the simulator.
-
class
vista.utils.logging.
CustomFormatter
(fmt=None, datefmt=None, style='%', validate=True)[source]¶ A custom logger class inherited from python logging module. It basically define a custom formatting as
<time>::<level>::<module>::<msg>
with colored text (DEBUG
: cyan,INFO
: regular,WARNING
: yellow,ERROR
: bold red,CRITICAL
: underlined bold red). Otherwise, it can be used as if using regular python logging.Example Usage:
>>> from vista.utils import logging >>> logging.setLevel(logging.ERROR) >>> logging.debug('This is a debug message.') >>> logging.warning('This is a warning message.')
-
format
(record)[source]¶ Format the specified record as text.
The record’s attribute dictionary is used as the operand to a string formatting operation which yields the returned string. Before formatting the dictionary, a couple of preparatory steps are carried out. The message attribute of the record is computed using LogRecord.getMessage(). If the formatting string uses the time (as determined by a call to usesTime(), formatTime() is called to format the event time. If there is exception information, it is formatted using formatException() and appended to the message.
-