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

Component mappings

By default, each visualizer reads its input components from its own archetype — for example, the Points3D visualizer reads colors from Points3D:colors. Component mappings let you override this, redirecting any visualizer input to a different component on the same entity. This makes it possible to store multiple variants of the same data and switch between them per view.

To learn more about how visualizers are set up in general, also have a look at the concept page on customizing Views.

To log custom components, see Logging custom data.

The first example uses a point cloud with two color sets. The later sections use scalars to show nested data selectors and default values. For computing the colors, see Color a point cloud by height or intensity.

Full example

You can find the full example here:

Two 3D views of the same torus point cloud side by side: Height Colors in a red, white and blue map and Spin Colors in a rainbow map

How it works

Storing multiple component variants with custom archetypes

A standard archetype like Points3D assigns a fixed column name, as well as component type & archetype metainformation, to every component it logs (Points3D:colors, Points3D:positions, etc.). To store additional variants of a component on the same entity, log them as custom archetypes. The easiest way to do this is to use the DynamicArchetype utility.

# --- Log positions once, then each color set as a separate custom archetype ---
rr.log(
    "pointcloud",
    rr.Points3D(positions, radii=0.06),
    rr.DynamicArchetype(
        "HeightColors",
        components={"colors": rr.components.ColorBatch(height_rgba)},
    ),
    rr.DynamicArchetype(
        "SpinColors", components={"colors": rr.components.ColorBatch(spin_rgba)}
    ),
)

After this call, the entity's component list contains four components:

  • Points3D:positions, Points3D:radii — from the standard archetype
  • HeightColors:colors — the first custom variant
  • SpinColors:colors — the second custom variant

You can inspect this in the viewer by selecting the entity in the streams panel:

Selection panel for the /pointcloud entity listing HeightColors and SpinColors color components next to Points3D positions and radii

Configuring component mappings in blueprint

To make a visualizer read from an arbitrary source, we need to explicitly set the component mapping for a visualizer. The mapping specifies a target (the component the visualizer expects) and a source (the component to actually read from). Everything that isn't explicitly mapped keeps its default behavior.

# --- Blueprint: two side-by-side 3D views with different color mappings ---
blueprint = rrb.Blueprint(
    rrb.Horizontal(
        rrb.Spatial3DView(
            name="Height Colors",
            origin="/",
            overrides={
                "pointcloud": [
                    rr.Points3D.from_fields().visualizer(
                        mappings=[
                            VisualizerComponentMapping(
                                target="Points3D:colors",
                                source_kind=ComponentSourceKind.SourceComponent,
                                source_component="HeightColors:colors",
                            ),
                        ]
                    ),
                ],
            },
        ),
        rrb.Spatial3DView(
            name="Spin Colors",
            origin="/",
            overrides={
                "pointcloud": [
                    rr.Points3D.from_fields().visualizer(
                        mappings=[
                            VisualizerComponentMapping(
                                target="Points3D:colors",
                                source_kind=ComponentSourceKind.SourceComponent,
                                source_component="SpinColors:colors",
                            ),
                        ]
                    ),
                ],
            },
        ),
    ),
    collapse_panels=True,
)

rr.send_blueprint(blueprint)

In this example, each view overrides only the color source for the Points3D visualizer - positions, radii, and everything else are still read from their default sources automatically.

In the viewer you can access this in the visualizer settings, presented when selecting an entity in a view:

Source dropdown for the Points3D colors component, with SpinColors:colors selected over HeightColors:colors, View default and Add custom

Configuring component mappings in the UI

You can set up the same mappings interactively without writing any blueprint code:

  • Add two 3D views (or clone an existing one)
  • Select the entity in one of the views.
  • In the selection panel, find the visualizer section (e.g. Points3D).
  • Click on the component row you want to remap (e.g. colors) to expand the component mapping options.
  • Change the source from the default to the desired custom archetype component (e.g. HeightColors:colors).

Selectors for nested data

When your data lives inside an Arrow StructArray, use a selector to extract a specific field. Selectors use a jq-inspired syntax (e.g. .values to select the values field).

Data types are automatically cast when compatible. For example, Float32 data will be cast to Float64 as needed by the visualizer.

Here is how to create a nested StructArray:

def make_sigmoid_struct_array(steps: int) -> pa.StructArray:
    """Creates a StructArray with a `values` field containing sigmoid data.

    Note: We intentionally use float32 here to demonstrate that the data will
    be automatically cast to the correct type (float64) when resolved by the
    visualizer.
    """
    x = np.arange(steps, dtype=np.float32) / 10.0
    sigmoid_values = 1.0 / (1.0 + np.exp(-(x - 3.0)))
    return pa.StructArray.from_arrays(
        [pa.array(sigmoid_values, type=pa.float32())], names=["values"]
    )

The following remaps the Scalars:scalars input to read from custom:my_nested_scalar and selects the values field:

# Blue sigmoid:
# * source scalars from a nested struct using a selector to
#   extract the "values" field
# * set the name and an explicit blue color via overrides
rr.SeriesLines(
    names="sigmoid (nested)", colors=[0, 0, 255]
).visualizer(
    mappings=[
        VisualizerComponentMapping(
            target="Scalars:scalars",
            source_kind=ComponentSourceKind.SourceComponent,
            source_component="custom:my_nested_scalar",
            selector=".values",
        ),
    ]
),

Providing default values

You can also force a visualizer to use a specific source kind. Setting the source to Default makes the visualizer ignore any store data and use the view's default instead:

# Red sine:
# * set the name via an override
# * explicitly use the view's default for color
# * everything else uses the automatic component mappings,
#   so it will pick up scalars from the store.
rr.SeriesLines(names="sine (store)").visualizer(
    mappings=[
        VisualizerComponentMapping(
            target="SeriesLines:colors",
            source_kind=ComponentSourceKind.Default,
        ),
    ]
),