pub struct Registry {
pub data: HashMap<String, Buffer>,
/* private fields */
}
Expand description
A registry for managing transforms between different frames. It can traverse the parent-child tree and calculate the final transform. It will interpolate between two entries if a time is requested that lies in between.
The Registry
struct provides methods to add and retrieve transforms
between frames, supporting both synchronous and asynchronous operations
depending on the feature flags.
§Examples
use std::time::Duration;
use transforms::{
geometry::{Quaternion, Transform, Vector3},
time::Timestamp,
Registry,
};
// Create a new registry with a max_age duration
let mut registry = Registry::new(Duration::from_secs(60));
let t1 = Timestamp::now();
let t2 = t1.clone();
// Define a transform from frame "a" to frame "b"
let t_a_b_1 = Transform {
translation: Vector3 {
x: 1.0,
y: 0.0,
z: 0.0,
},
rotation: Quaternion {
w: 1.0,
x: 0.0,
y: 0.0,
z: 0.0,
},
timestamp: t1,
parent: "a".into(),
child: "b".into(),
};
// For validation
let t_a_b_2 = t_a_b_1.clone();
// Add the transform to the registry
let result = registry.add_transform(t_a_b_1);
assert!(result.is_ok());
// Retrieve the transform from "a" to "b"
let result = registry.get_transform("a", "b", t2);
assert!(result.is_ok());
assert_eq!(result.unwrap(), t_a_b_2);
Fields§
§data: HashMap<String, Buffer>
Implementations§
Source§impl Registry
impl Registry
Sourcepub fn add_transform(&mut self, t: Transform) -> Result<(), BufferError>
pub fn add_transform(&mut self, t: Transform) -> Result<(), BufferError>
Adds a transform to the registry.
§Arguments
t
- The transform to add.
§Errors
Returns a BufferError
if the transform cannot be added.
§Examples
use std::time::Duration;
use transforms::{geometry::Transform, Registry};
let mut registry = Registry::new(Duration::from_secs(60));
let transform = Transform::identity();
let result = registry.add_transform(transform);
assert!(result.is_ok());
Sourcepub fn get_transform(
&mut self,
from: &str,
to: &str,
timestamp: Timestamp,
) -> Result<Transform, TransformError>
pub fn get_transform( &mut self, from: &str, to: &str, timestamp: Timestamp, ) -> Result<Transform, TransformError>
Retrieves a transform from the registry.
§Arguments
from
- The source frame.to
- The destination frame.timestamp
- The timestamp for which the transform is requested.
§Errors
Returns a TransformError
if the transform cannot be found.
§Examples
use std::time::Duration;
use transforms::{
geometry::{Quaternion, Transform, Vector3},
time::Timestamp,
Registry,
};
let mut registry = Registry::new(Duration::from_secs(60));
let t1 = Timestamp::zero();
let t2 = t1.clone();
// Define a transform from frame "a" to frame "b"
let t_a_b_1 = Transform {
translation: Vector3 {
x: 1.0,
y: 0.0,
z: 0.0,
},
rotation: Quaternion {
w: 1.0,
x: 0.0,
y: 0.0,
z: 0.0,
},
timestamp: t1,
parent: "a".into(),
child: "b".into(),
};
// For validation
let t_a_b_2 = t_a_b_1.clone();
let result = registry.add_transform(t_a_b_1);
assert!(result.is_ok());
let result = registry.get_transform("a", "b", t2);
assert!(result.is_ok());
assert_eq!(result.unwrap(), t_a_b_2);
Auto Trait Implementations§
impl Freeze for Registry
impl RefUnwindSafe for Registry
impl Send for Registry
impl Sync for Registry
impl Unpin for Registry
impl UnwindSafe for Registry
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more