pub trait Transformable {
// Required method
fn transform(&mut self, transform: &Transform) -> Result<(), TransformError>;
}Expand description
A trait for types that can be transformed between different coordinate frames.
This trait provides functionality to apply spatial transformations to objects, typically used in robotics and computer vision applications. The transformations follow the common robotics convention where transforms are considered from child to parent frame (e.g., from sensor frame to base frame, or from base frame to map frame).
§Frame Convention
In robotics, it’s common to transform data from sensor reference frames “up” to base or map reference frames. For example:
- A camera’s data might need to be transformed from the camera frame to the robot’s base frame
- LiDAR points might need to be transformed from the LiDAR frame to the map frame
This trait follows this convention, where transforms are applied from child frame to parent frame. The child frame is typically the more specific/local frame (e.g., a sensor frame), while the parent frame is typically the more general/global frame (e.g., map or world frame).
§Examples
use transforms::{
geometry::{Point, Quaternion, Transform, Transformable, Vector3},
time::Timestamp,
};
let mut point = Point {
position: Vector3::new(1.0, 0.0, 0.0),
orientation: Quaternion::identity(),
timestamp: Timestamp::now(),
frame: "camera".into(),
};
let transform = Transform {
translation: Vector3::new(0.0, 1.0, 0.0),
rotation: Quaternion::identity(),
timestamp: point.timestamp,
parent: "base".into(),
child: "camera".into(),
};
// Transform the point from camera frame to base frame
point
.transform(&transform)
.expect("Failed to transform point");§Errors
Returns TransformError if:
- The frames are incompatible (transform’s child frame doesn’t match the object’s frame)
- The timestamps don’t match
- Other transform-specific errors occur
Required Methods§
Implementors§
impl Transformable for Point
The Transformable trait defines an interface for objects that can be transformed
using a Transform. Implementors of this trait can apply a transformation to
themselves, modifying their position and orientation.
Below is an example of how to implement the Transformable trait for a Point.
§Examples
use transforms::{
geometry::{Point, Quaternion, Vector3},
time::Timestamp,
Transform, Transformable,
};
let position = Vector3 {
x: 1.0,
y: 2.0,
z: 3.0,
};
let orientation = Quaternion {
w: 1.0,
x: 0.0,
y: 0.0,
z: 0.0,
};
let timestamp = Timestamp { nanoseconds: 0 };
let frame = String::from("b");
let mut point = Point {
position,
orientation,
timestamp,
frame,
};
let transform = Transform {
translation: Vector3 {
x: 2.0,
y: 0.0,
z: 0.0,
},
rotation: Quaternion {
w: 1.0,
x: 0.0,
y: 0.0,
z: 0.0,
},
timestamp: Timestamp { nanoseconds: 0 },
parent: "a".into(),
child: "b".into(),
};
let r = point.transform(&transform);
assert!(r.is_ok());
assert_eq!(point.position.x, 3.0);