Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Barebone examples and slightly friendlier show() for Rust #1153

Merged
merged 27 commits into from
Feb 9, 2023

Conversation

teh-cmc
Copy link
Member

@teh-cmc teh-cmc commented Feb 8, 2023

What the title says.

Most barebone python:

import numpy as np
import rerun as rr

SIZE = 10

rr.spawn()

x, y, z = np.meshgrid(np.linspace(-5, 5, SIZE), np.linspace(-5, 5, SIZE), np.linspace(-5, 5, SIZE))
positions = np.array(list(zip(x.reshape(-1), y.reshape(-1), z.reshape(-1))))

r, g, b = np.meshgrid(np.linspace(0, 255, SIZE), np.linspace(0, 255, SIZE), np.linspace(0, 255, SIZE))
colors = np.array(list(zip(r.reshape(-1), g.reshape(-1), b.reshape(-1))), dtype=np.uint8)

rr.log_points("my_points", positions=positions, colors=colors)

Most barebone rust (hiding helpers, we won't show them in the doc page):

use rerun::external::glam;
use rerun::{ColorRGBA, MsgSender, Point3D, Session};

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let mut session = Session::new();

    let points = grid(glam::Vec3::splat(-5.0), glam::Vec3::splat(5.0), 10)
        .map(Point3D::from)
        .collect::<Vec<_>>();
    let colors = grid(glam::Vec3::ZERO, glam::Vec3::splat(255.0), 10)
        .map(|v| ColorRGBA::from([v.x as u8, v.y as u8, v.z as u8, 255]))
        .collect::<Vec<_>>();

    MsgSender::new("my_point")
        .with_component(&points)?
        .with_component(&colors)?
        .send(&mut session)?;

    session.show()?;

    Ok(())
}

Copy link
Member

@emilk emilk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think these examples are too minimal. Is there really any point to them (pun intended)?

I prefer examples/hello_world/main.py (though it should maybe be renamed to minimal).

If you don't want a dependency on an image or image crate, then perhaps we should log at least a semi-interesting point cloud. All our examples should be interesting in some way imho.

examples/minimal/main.py Outdated Show resolved Hide resolved
crates/re_sdk/src/session.rs Show resolved Hide resolved
@teh-cmc
Copy link
Member Author

teh-cmc commented Feb 9, 2023

Update: we decided to drop hello_world in favor of minimal, and update minimal to log @jleibs' fancy color-cube rather than a less fancy single point 🥲 (we won't use the demo library though, minimal must be self contained!).

The idea here is that minimal is what we will show on the For {Python/Rust} Users} pages in the docs.

https://rerunio.slack.com/archives/C041NHU952S/p1675933683218999

commit 640a1c6
Author: Clement Rey <cr.rey.clement@gmail.com>
Date:   Thu Feb 9 11:18:52 2023 +0100

    addressed PR comments

commit e495477
Merge: ad3940a 025dbe3
Author: Clement Rey <cr.rey.clement@gmail.com>
Date:   Thu Feb 9 11:15:40 2023 +0100

    Merge remote-tracking branch 'origin/main' into cmc/rerun_is_the_sdk

commit 025dbe3
Author: Andreas Reich <andreas@rerun.io>
Date:   Thu Feb 9 11:06:12 2023 +0100

    Fix incorrectly logged warnings on paths missing from the entity tree. (#1147)

    Reasoning detailed in the code comments.
    Took the opportunity to do a clarifying rename.

commit e7139d2
Author: Emil Ernerfeldt <emil@rerun.io>
Date:   Thu Feb 9 10:45:21 2023 +0100

    Replace `nb_things` with `num_things` (#1162)

    * Replace `nb_things` with `num_things`

    Also adds a lint against it.

    Motivation: https://twitter.com/ernerfeldt/status/1622620902297837572

    I went with `num_` here because it was the smaller change.

    * Add tests to lint.py

    * py-format

    * merge fix

    * chmod fix

commit d5b822c
Author: Emil Ernerfeldt <emil@rerun.io>
Date:   Thu Feb 9 09:52:55 2023 +0100

    Update some crates in anticipation of egui 0.21 (#1154)

    * Make sure we never depend on cmake

    * Update to pollster 0.3

    * Remove text-to-speech-related dependencies

    They shouldn't be needed, since we don't use tts

    * Use workspace versions of egui and eframe

    * use eframe 0.20.1 in Cargo.toml

    * Update eframe/egui and wasm-bindgen

    * downgrade toml crate to avoid duplicate crate

    * document deny.toml

    * Update to wasm-bindgen-cli v0.2.84 everywhere

    * Publish new ci_docker image with wasm-bindgen-cli 0.2.84

    * Better comment in deny.toml

    * Remove some unused crates found with cargo udeps

    * build fix (re-add unindent crate)

commit 9f1452d
Author: Emil Ernerfeldt <emil@rerun.io>
Date:   Thu Feb 9 09:51:55 2023 +0100

    Improve the dev docs and top-level README.md (#1133)

    * Create a BUILD.md and CODE_STYLE.md

    * Move docs about how to build docs to BUILD.md

    * Improve example docs

    * Remove `python -m rerun` instructions (`rerun` should work just as well)

    * Explain justfile

    * Explain taplo.toml

    * Create dummy ARCHITECTURE.md and interlink all dev-docs

    * Start filling out ARCHITECTURE.md

    * Strip down README.md to its minimum

    * Document some of the major technologies

    * "Wasm" should not be written as WASM

    * Add a section about immediate mode

    * Add link to benchmarks

    * Fix link in TODO

    * Add list of shortcomings

    * a short section about the native viewer

    Co-authored-by: Jeremy Leibs <jeremy@rerun.io>

    * Improve the buisness model section

    Co-authored-by: Nikolaus West <niko@grapic.co>

    * User feedback

    * Unrelated code cleanup

    ---------

    Co-authored-by: Jeremy Leibs <jeremy@rerun.io>
    Co-authored-by: Nikolaus West <niko@grapic.co>
Base automatically changed from cmc/rerun_is_the_sdk to main February 9, 2023 10:32
commit 9108c86
Author: Clement Rey <cr.rey.clement@gmail.com>
Date:   Thu Feb 9 11:32:39 2023 +0100

    The main `rerun` crate is now the public facing SDK (#1151)

    * main rerun crate now exposes the SDK

    * the sdk shall never depend directly on eframe

    * SDK crate is now mostly for internal use -> re_sdk

    * make sdk feature on by default

    * how did that guy get in

    * using new feature flag for optional dep thing

    * grabbing the SDK through 'rerun' implies access to the viewer

    * fmt

    * carrying glam aaaallll the way

    * addressed PR comments

commit 025dbe3
Author: Andreas Reich <andreas@rerun.io>
Date:   Thu Feb 9 11:06:12 2023 +0100

    Fix incorrectly logged warnings on paths missing from the entity tree. (#1147)

    Reasoning detailed in the code comments.
    Took the opportunity to do a clarifying rename.

commit e7139d2
Author: Emil Ernerfeldt <emil@rerun.io>
Date:   Thu Feb 9 10:45:21 2023 +0100

    Replace `nb_things` with `num_things` (#1162)

    * Replace `nb_things` with `num_things`

    Also adds a lint against it.

    Motivation: https://twitter.com/ernerfeldt/status/1622620902297837572

    I went with `num_` here because it was the smaller change.

    * Add tests to lint.py

    * py-format

    * merge fix

    * chmod fix

commit d5b822c
Author: Emil Ernerfeldt <emil@rerun.io>
Date:   Thu Feb 9 09:52:55 2023 +0100

    Update some crates in anticipation of egui 0.21 (#1154)

    * Make sure we never depend on cmake

    * Update to pollster 0.3

    * Remove text-to-speech-related dependencies

    They shouldn't be needed, since we don't use tts

    * Use workspace versions of egui and eframe

    * use eframe 0.20.1 in Cargo.toml

    * Update eframe/egui and wasm-bindgen

    * downgrade toml crate to avoid duplicate crate

    * document deny.toml

    * Update to wasm-bindgen-cli v0.2.84 everywhere

    * Publish new ci_docker image with wasm-bindgen-cli 0.2.84

    * Better comment in deny.toml

    * Remove some unused crates found with cargo udeps

    * build fix (re-add unindent crate)

commit 9f1452d
Author: Emil Ernerfeldt <emil@rerun.io>
Date:   Thu Feb 9 09:51:55 2023 +0100

    Improve the dev docs and top-level README.md (#1133)

    * Create a BUILD.md and CODE_STYLE.md

    * Move docs about how to build docs to BUILD.md

    * Improve example docs

    * Remove `python -m rerun` instructions (`rerun` should work just as well)

    * Explain justfile

    * Explain taplo.toml

    * Create dummy ARCHITECTURE.md and interlink all dev-docs

    * Start filling out ARCHITECTURE.md

    * Strip down README.md to its minimum

    * Document some of the major technologies

    * "Wasm" should not be written as WASM

    * Add a section about immediate mode

    * Add link to benchmarks

    * Fix link in TODO

    * Add list of shortcomings

    * a short section about the native viewer

    Co-authored-by: Jeremy Leibs <jeremy@rerun.io>

    * Improve the buisness model section

    Co-authored-by: Nikolaus West <niko@grapic.co>

    * User feedback

    * Unrelated code cleanup

    ---------

    Co-authored-by: Jeremy Leibs <jeremy@rerun.io>
    Co-authored-by: Nikolaus West <niko@grapic.co>
@teh-cmc teh-cmc requested a review from emilk February 9, 2023 11:23
examples/minimal/src/main.rs Outdated Show resolved Hide resolved
//! Demonstrates the most barebone usage of the Rerun SDK.

use rerun::external::glam;
use rerun::{ColorRGBA, MsgSender, Point3D, Session};
Copy link
Member

@emilk emilk Feb 9, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we should put components in a separate module?

Suggested change
use rerun::{ColorRGBA, MsgSender, Point3D, Session};
use rerun::{MsgSender, Session, components::{ColorRGBA, Point3D}};

This makes it more clear what you can use as a component. Right now it reads a bit "magic"

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmm, actually I keep splitting things up between message-stuff, time-stuff, init-stuff, component-stuff every time I import all of this otherwise it's just too messy to digest... so yeah we might as well make modules I guess. In another PR tho.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will also give some much-needed structure to the docs of rerun:

image

@teh-cmc teh-cmc merged commit 0904dc1 into main Feb 9, 2023
@teh-cmc teh-cmc deleted the cmc/barebone_usage branch February 9, 2023 15:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants