Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2227,6 +2227,7 @@ name = "custom_callback"
version = "0.30.0-alpha.1+dev"
dependencies = [
"bincode",
"clap",
"mimalloc",
"parking_lot",
"rerun",
Expand Down
1 change: 1 addition & 0 deletions examples/rust/custom_callback/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ rerun = { path = "../../../crates/top/rerun", default-features = false, features
"server",
] }

clap = { workspace = true, features = ["derive"] }
bincode.workspace = true
mimalloc.workspace = true
parking_lot.workspace = true
Expand Down
48 changes: 43 additions & 5 deletions examples/rust/custom_callback/src/viewer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use std::cell::RefCell;
use std::rc::Rc;
use std::time::{Duration, Instant, SystemTime, UNIX_EPOCH};

use clap::Parser;
use custom_callback::interaction::{LcmPublisher, click_event_from_ms};
use rerun::external::{eframe, re_crash_handler, re_grpc_server, re_log, re_memory, re_viewer};

Expand All @@ -15,24 +16,61 @@ const LCM_CHANNEL: &str = "/clicked_point#geometry_msgs.PointStamped";
const CLICK_DEBOUNCE_MS: u64 = 100;
/// Maximum rapid clicks to log as warning
const RAPID_CLICK_THRESHOLD: usize = 5;
/// Default gRPC listen port (9877 to avoid conflict with stock Rerun on 9876)
const DEFAULT_PORT: u16 = 9877;

/// DimOS Interactive Viewer — a custom Rerun viewer with LCM click-to-navigate.
///
/// Accepts the same CLI flags as the stock `rerun` binary so it can be spawned
/// seamlessly via `rerun_bindings.spawn(executable_name="dimos-viewer")`.
#[derive(Parser, Debug)]
#[command(name = "dimos-viewer", version, about)]
struct Args {
/// The gRPC port to listen on for incoming SDK connections.
#[arg(long, default_value_t = DEFAULT_PORT)]
port: u16,

/// An upper limit on how much memory the viewer should use.
/// When this limit is reached, the oldest data will be dropped.
/// Examples: "75%", "16GB".
#[arg(long, default_value = "75%")]
memory_limit: String,

/// An upper limit on how much memory the gRPC server should use.
/// Examples: "1GiB", "50%".
#[arg(long, default_value = "1GiB")]
server_memory_limit: String,

/// Hide the Rerun welcome screen.
#[arg(long)]
hide_welcome_screen: bool,

/// Hint that data will arrive shortly (suppresses "waiting for data" message).
#[arg(long)]
expect_data_soon: bool,
}

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let args = Args::parse();

let main_thread_token = re_viewer::MainThreadToken::i_promise_i_am_on_the_main_thread();
re_log::setup_logging();
re_crash_handler::install_crash_handlers(re_viewer::build_info());

// Listen for gRPC connections from Rerun's logging SDKs.
let listen_addr = format!("0.0.0.0:{}", args.port);
re_log::info!("Listening for SDK connections on {listen_addr}");
let rx_log = re_grpc_server::spawn_with_recv(
"0.0.0.0:9877".parse()?,
listen_addr.parse()?,
Default::default(),
re_grpc_server::shutdown::never(),
);

// Create LCM publisher for click events
let lcm_publisher = LcmPublisher::new(LCM_CHANNEL.to_string())
.expect("Failed to create LCM publisher");
re_log::info!("LCM publisher created for channel: {}", LCM_CHANNEL);
re_log::info!("LCM publisher created for channel: {LCM_CHANNEL}");

// State for debouncing and rapid click detection
let last_click_time = Rc::new(RefCell::new(Instant::now()));
Expand Down Expand Up @@ -108,7 +146,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
);
}
Err(err) => {
re_log::error!("Failed to publish LCM click event: {:?}", err);
re_log::error!("Failed to publish LCM click event: {err:?}");
}
}
}
Expand All @@ -121,8 +159,8 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {

if !has_position && no_position_count > 0 {
re_log::trace!(
"Selection change without position data ({} items). This is normal for hover/keyboard navigation.",
no_position_count
"Selection change without position data ({no_position_count} items). \
This is normal for hover/keyboard navigation."
);
}
}
Expand Down
Loading