Frame

Struct Frame 

Source
pub struct Frame { /* private fields */ }
Expand description

Represents a coordinate frame in a Cartesian tree structure.

Each frame can have one parent and multiple children. The frame stores its transformation (position and orientation) relative to its parent.

Root frames (created via Frame::new_origin) have no parent and use the identity transform.

Implementations§

Source§

impl Frame

Source

pub fn new_origin(name: impl Into<String>) -> Self

Creates a new root frame (origin) with the given name.

The origin has no parent and uses the identity transform.

§Arguments
  • name: The name of the root frame.
§Example
use cartesian_tree::Frame;

let origin = Frame::new_origin("world");
Source

pub fn name(&self) -> String

Returns the name of the frame.

Source

pub fn transform_to_parent(&self) -> Result<Isometry3<f64>, CartesianTreeError>

Returns the transformation from this frame to its parent frame.

§Returns
  • Ok(Isometry3<f64>) if the frame has a parent.
  • Err(String) if the frame has no parent.
Source

pub fn update_transform<O>( &self, position: Vector3<f64>, orientation: O, ) -> Result<(), CartesianTreeError>
where O: IntoOrientation,

Updates the frame’s transformation relative to its parent.

This method modifies the frame’s position and orientation relative to its parent frame. It fails if the frame is a root frame (i.e., has no parent).

§Arguments
  • position: A 3D vector representing the new translational offset from the parent.
  • orientation: An orientation convertible into a unit quaternion for new orientational offset from the parent.
§Returns
  • Ok(()) if the transformation was updated successfully.
  • Err(String) if the frame has no parent.
§Example
use cartesian_tree::Frame;
use nalgebra::{Vector3, UnitQuaternion};

let root = Frame::new_origin("root");
let child = root
    .add_child("camera", Vector3::new(0.0, 0.0, 1.0), UnitQuaternion::identity())
    .unwrap();
child.update_transform(Vector3::new(1.0, 0.0, 0.0), UnitQuaternion::identity())
    .unwrap();
Source

pub fn add_child<O>( &self, name: impl Into<String>, position: Vector3<f64>, orientation: O, ) -> Result<Frame, CartesianTreeError>
where O: IntoOrientation,

Adds a new child frame to the current frame.

The child is positioned and oriented relative to this frame.

Returns an error if a child with the same name already exists.

§Arguments
  • name: The name of the new child frame.
  • position: A 3D vector representing the translational offset from the parent.
  • orientation: An orientation convertible into a unit quaternion.
§Returns
  • Ok(Rc<Frame>) the newly added child frame.
  • Err(String) if a child with the same name already exists.
§Example
use cartesian_tree::Frame;
use nalgebra::{Vector3, UnitQuaternion};

let root = Frame::new_origin("base");
let child = root
    .add_child("camera", Vector3::new(0.0, 0.0, 1.0), UnitQuaternion::identity())
    .unwrap();
Source

pub fn calibrate_child<O>( &self, name: impl Into<String>, desired_position: Vector3<f64>, desired_orientation: O, reference_pose: &Pose, ) -> Result<Frame, CartesianTreeError>
where O: IntoOrientation,

Adds a new child frame calibrated such that a reference pose, when expressed in the new frame, matches the desired position and orientation.

§Arguments
  • name: The name of the new child frame.
  • desired_position: The desired position of the reference pose in the new frame.
  • desired_orientation: The desired orientation of the reference pose in the new frame.
  • reference_pose: The existing pose (in some frame A) used as the calibration reference.
§Returns
  • Ok(Frame) the new child frame if successful.
  • Err(CartesianTreeError) if the reference frame is invalid, no common ancestor exists, or a child name conflict occurs.
§Example
use cartesian_tree::Frame;
use nalgebra::{Vector3, UnitQuaternion};

let root = Frame::new_origin("root");
let reference_pose = root.add_pose(Vector3::new(1.0, 0.0, 0.0), UnitQuaternion::identity());
let calibrated_child = root.calibrate_child(
    "calibrated",
    Vector3::zeros(),
    UnitQuaternion::identity(),
    &reference_pose,
).unwrap();
Source

pub fn add_pose<O>(&self, position: Vector3<f64>, orientation: O) -> Pose
where O: IntoOrientation,

Adds a pose to the current frame.

§Arguments
  • position: The translational part of the pose.
  • orientation: The orientational part of the pose.
§Returns
  • The newly added pose.
§Example
use cartesian_tree::Frame;
use nalgebra::{Vector3, UnitQuaternion};

let frame = Frame::new_origin("base");
let pose = frame.add_pose(Vector3::new(0.5, 0.0, 0.0), UnitQuaternion::identity());
Source

pub fn to_json(&self) -> Result<String, CartesianTreeError>

Serializes the frame tree to a JSON string.

This recursively serializes the hierarchy starting from this frame (ideally the root). Transforms for root frames are set to identity.

§Returns
  • Ok(String) the pretty-printed JSON.
  • Err(CartesianTreeError) on serialization failure.
Source

pub fn apply_config(&self, json: &str) -> Result<(), CartesianTreeError>

Applies a JSON config to this frame tree by updating matching transforms.

Deserializes the JSON to a temporary structure, then recursively updates transforms where names match (partial apply; ignores unmatched nodes in config). Skips updating root frames (identity assumed) - assumes this frame is the root.

§Arguments
  • json: The JSON string to apply.
§Returns
  • Ok(()) if applied successfully (even if partial).
  • Err(CartesianTreeError) on deserialization or mismatch (e.g., root names differ).

Trait Implementations§

Source§

impl Clone for Frame

Source§

fn clone(&self) -> Frame

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Frame

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl HasChildren for Frame

Source§

type Node = Frame

Source§

fn children(&self) -> Vec<Frame>

Returns all children.
Source§

impl HasParent for Frame

Source§

type Node = Frame

Source§

fn parent(&self) -> Option<Self::Node>

Returns the parent of this node, if it exists.
Source§

impl NodeEquality for Frame

Source§

fn is_same(&self, other: &Self) -> bool

Whether this node is the same as another.

Auto Trait Implementations§

§

impl Freeze for Frame

§

impl !RefUnwindSafe for Frame

§

impl !Send for Frame

§

impl !Sync for Frame

§

impl Unpin for Frame

§

impl !UnwindSafe for Frame

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> Walking for T
where T: HasParent<Node = T> + NodeEquality + Clone,

Source§

fn depth(&self) -> usize

Gets the depth of this node in comparison to the root. Read more
Source§

fn walk_up(&self, steps: usize) -> Option<Self>

Walks up the tree by a given number of steps. Read more
Source§

fn root(&self) -> Self

Finds the root of this node. Read more
Source§

fn lca_with(&self, other: &Self) -> Option<Self>

Finds the lowest common ancestor with another Node. Read more