Skip to content

Archetypes should implement as_components #3103

@nikolausWest

Description

@nikolausWest

To make it more ergonomic for users to log their own types that are translated into Rerun archetypes, we should introduce a protocol that all archetypes implement:

from typing import Iterable, Protocol

class ComponentsGroup(Protocol):  # TODO: find a better name than ComponentsGroup

    def as_components(self) -> Iterable[rerun.Component]:
        ...

We should then make sure that

rr.log("path", SomeArchetype(a, b=b, c=c))
# is equivalent to (and even implemented by)
rr.log_components("path", SomeArchetype(a, b=b, c=c).as_components())

That way, if a user already has a type MyPointCloud in their code, they can log it as

point_cloud = MyPointCloud(...)
rr.log("path", point_cloud)

By letting MyPointCloud implement as_components(). Could in the simplest case be

class MyPointCloud:
    ...
    def as_components(self) -> Iterable[rr.Component]:
        rertun rr.Points3D(self.positions, ...).as_components()

TODO:

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions