Skip to content
esc
Start typing to search the docs
Navigate Open

Entities and Components

Data model

The core of Rerun's data model is inspired by the ideas of the Entity Component System (ECS) architecture pattern. In short, an ECS is a composition-oriented framework in which entities represent generic objects while components describe data associated with those entities.

  • Entities are the "things" that you log with the rr.log() function. They are represented by the entity path string which is passed as first argument.
  • Components, however, are what contains the data that is associated with those "things". For example, position, color, pixel data, etc.

Entities are like folders, and components are like files.

Additionally, Rerun has two more concepts:

  • Archetypes are named sets of semantically related components. Points2D, for example, is positions, colors, and radii. In the Rerun SDKs, archetypes take the form of builder objects that create such a set for you. The archetype name is stored with each component, and the Viewer uses it to choose how to show the data by default. See Archetypes.
  • Encodings are regular data structures that components occasionally rely on when fundamental data types (float, uint32, etc.) are not sufficient.

Logging and viewing data

All the data that you log within Rerun is mapped to the concepts of entities and components. For example, consider the case of logging a point:

rr.log("my_point", rr.Points2D([32.7, 45.9], colors=[255, 0, 0]))

This statement uses the rr.Points2D archetype. Internally, this archetype builds a set of, in this case, two components:

  • Points2D:positions of type Position2D
  • Points2D:colors of type Color. Then, the rr.log() function records these two components and associates them with the "my_point" entity.

Later, a 2D view looks for the entities it can draw. It finds the "my_point" entity, because Points2D:positions has the datatype that the Points2D visualizer needs. Both components are tagged with the Points2D archetype (via metadata attached to the components), so the Viewer selects the Points2D visualizer by default. That visualizer then reads Points2D:colors from the same entity.

See the Types reference for a list of archetypes, components, and encodings.

Adding custom data

Although both the SDKs' archetype objects and the view are based on the same archetype definition, they both operate on arbitrary collections of components. Neither the SDKs nor the Viewer enforce or require that an entity should contain a specific set of components. The Rerun Viewer will display any data in a generic form, but its views will only work on sets of components it can make sense of.

Your entity could have any number of additional components as well. This isn't a problem. Any components that aren't relevant to the scene that the view is drawing are safely ignored. Also, Rerun even allows you to log your own set of components, bypassing archetypes altogether.

In Python, the rr.AnyValues helper object can be used to log custom component(s) to the same entity as an archetype:

"""Log extra values with a `Points2D`."""

import rerun as rr
import rerun.blueprint as rrb

rr.init("rerun_example_extra_values", spawn=True)

rr.log(
    "extra_values",
    rr.Points2D([[-1, -1], [-1, 1], [1, -1], [1, 1]]),
    rr.AnyValues(
        confidence=[0.3, 0.4, 0.5, 0.6],
    ),
)

# Set view bounds:
rr.send_blueprint(
    rrb.Spatial2DView(
        visual_bounds=rrb.VisualBounds2D(
            x_range=[-1.5, 1.5], y_range=[-1.5, 1.5]
        )
    )
)

It can also be used to log an entirely custom set of components:

"""Log arbitrary data."""

import rerun as rr

rr.init("rerun_example_any_values", spawn=True)

rr.log(
    "any_values",
    rr
    .AnyValues(
        # Using arbitrary Arrow data.
        homepage="https://www.rerun.io",
        repository="https://github.com/rerun-io/rerun",
    )
    # Using Rerun's builtin components.
    .with_component_override(
        "confidence", rr.components.ScalarBatch._COMPONENT_TYPE, [1.2, 3.4, 5.6]
    )
    .with_component_override(
        "description", rr.components.TextBatch._COMPONENT_TYPE, "Bla bla bla…"
    ),
)

For more complex use-cases, custom objects implementing the rr.AsComponents protocol can be used. For Rust, the rerun::AsComponents trait must be implemented:

"""Shows how to implement custom archetypes and components."""

from __future__ import annotations

import argparse
from typing import Any

import numpy as np
import numpy.typing as npt
import pyarrow as pa

import rerun as rr


class ConfidenceBatch(rr.ComponentBatchMixin):  # type: ignore[misc]
    """A batch of confidence data."""

    def __init__(self: Any, confidence: npt.ArrayLike) -> None:
        self.confidence = confidence

    def as_arrow_array(self) -> pa.Array:
        """The arrow batch representing the custom component."""
        return pa.array(self.confidence, type=pa.float32())


class CustomPoints3D(rr.AsComponents):  # type: ignore[misc]
    """A custom archetype extending the builtin `Points3D` with extra data."""

    def __init__(
        self: Any, positions: npt.ArrayLike, confidences: npt.ArrayLike
    ) -> None:
        self.points3d = rr.Points3D(positions)
        self.confidences = ConfidenceBatch(confidences).described(
            rr.ComponentDescriptor(
                "user.CustomPoints3D:confidences",
                archetype="user.CustomPoints3D",
                component_type="user.Confidence",
            )
        )

    def as_component_batches(self) -> list[rr.DescribedComponentBatch]:
        return [
            # The components from Points3D
            *self.points3d.as_component_batches(),
            # Custom confidence data
            self.confidences,
        ]


def log_custom_data() -> None:
    lin = np.linspace(-5, 5, 3)
    z, y, x = np.meshgrid(lin, lin, lin, indexing="ij")
    point_grid = np.vstack([x.flatten(), y.flatten(), z.flatten()]).T

    rr.log(
        "left/my_confident_point_cloud",
        CustomPoints3D(
            positions=point_grid,
            confidences=[42],
        ),
    )

    rr.log(
        "right/my_polarized_point_cloud",
        CustomPoints3D(
            positions=point_grid, confidences=np.arange(0, len(point_grid))
        ),
    )


def main() -> None:
    parser = argparse.ArgumentParser(
        description="Logs rich data using the Rerun SDK."
    )
    rr.script_add_args(parser)
    args = parser.parse_args()

    rr.script_setup(args, "rerun_example_custom_data")
    log_custom_data()
    rr.script_teardown(args)


if __name__ == "__main__":
    main()

Empty entities

An entity without components is nothing more than an identity (represented by its entity path). It contains no data, and has no type. When you log a piece of data, all that you are doing is setting the values of one or more components associated with that entity.

ECS systems

There is a third concept we haven't touched on: systems are processes which operate on the entities based on the components they possess. You can only write your own systems in Rust Viewer code. Views use a variety of systems under the hood. For more information see the Extend the Viewer in Rust section.