-
Notifications
You must be signed in to change notification settings - Fork 385
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Example of how to embed the Rerun Viewer inside your own GUI (+ ergon…
…omic improvements) (#2250) Closes #2243 Add an example showing how to wrap the Rerun Viewer in your own GUI, using [`eframe`](https://github.com/emilk/egui/tree/master/crates/eframe) and [`egui`](https://github.com/emilk/egui). This example can be useful for anyone who wants to extend the viewer with their own controls and widgets. The example shows how to read from the data store. Analytics are supported but is an opt-in feature in the example `Cargo.toml`. I created a `re_crash_handler` crate so that the example can get useful info on panics and signals, and have them sent to rerun if they enable analytics. Only works on `main` (not on 0.6.0). ![image](https://github.com/rerun-io/rerun/assets/1148717/cbbad63e-9b18-4e54-bafe-b6ffd723f63e) * [ ] Top-level docs at https://www.rerun.io/docs * [x] I have read and agree to [Contributor Guide](https://github.com/rerun-io/rerun/blob/main/CONTRIBUTING.md) and the [Code of Conduct](https://github.com/rerun-io/rerun/blob/main/CODE_OF_CONDUCT.md) * [x] I've included a screenshot or gif (if applicable) <!-- This line will get updated when the PR build summary job finishes. --> PR Build Summary: https://build.rerun.io/pr/2250 --------- Co-authored-by: Andreas Reich <[email protected]>
- Loading branch information
Showing
40 changed files
with
664 additions
and
187 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
[package] | ||
name = "re_crash_handler" | ||
authors.workspace = true | ||
description = "Detect panics and signals, logging them and optionally sending them to analytics." | ||
edition.workspace = true | ||
homepage.workspace = true | ||
include.workspace = true | ||
license.workspace = true | ||
publish = true | ||
readme = "README.md" | ||
repository.workspace = true | ||
rust-version.workspace = true | ||
version.workspace = true | ||
|
||
[package.metadata.docs.rs] | ||
all-features = true | ||
|
||
|
||
[features] | ||
default = ["analytics"] | ||
|
||
## Send analytics to Rerun on crashes | ||
analytics = ["dep:re_analytics"] | ||
|
||
[dependencies] | ||
re_build_info.workspace = true | ||
|
||
itertools.workspace = true | ||
parking_lot.workspace = true | ||
|
||
# Optional dependencies: | ||
re_analytics = { workspace = true, optional = true } | ||
|
||
# Native dependencies: | ||
[target.'cfg(not(target_arch = "wasm32"))'.dependencies] | ||
backtrace = "0.3" | ||
|
||
# Native unix dependencies: | ||
[target.'cfg(not(any(target_arch = "wasm32", target_os = "windows")))'.dependencies] | ||
libc = "0.2" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# re_crash_handler | ||
|
||
Part of the [`rerun`](https://github.com/rerun-io/rerun) family of crates. | ||
|
||
[![Latest version](https://img.shields.io/crates/v/re_crash_handler.svg)](https://crates.io/crates/re_crash_handler) | ||
[![Documentation](https://docs.rs/re_crash_handler/badge.svg)](https://docs.rs/re_crash_handler) | ||
![MIT](https://img.shields.io/badge/license-MIT-blue.svg) | ||
![Apache](https://img.shields.io/badge/license-Apache-blue.svg) | ||
|
||
Detect and handle signals, panics, and other crashes, making sure to log them and optionally send them off to analytics. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
use re_arrow_store::LatestAtQuery; | ||
use re_log_types::{ | ||
DataRow, DeserializableComponent, EntityPath, RowId, SerializableComponent, TimePoint, Timeline, | ||
}; | ||
|
||
use crate::LogDb; | ||
|
||
// ---------------------------------------------------------------------------- | ||
|
||
/// Get the latest value for a given [`re_log_types::Component`]. | ||
/// | ||
/// This assumes that the row we get from the store only contains a single instance for this | ||
/// component; it will log a warning otherwise. | ||
/// | ||
/// This should only be used for "mono-components" such as `Transform` and `Tensor`. | ||
pub fn query_latest_single<C: DeserializableComponent>( | ||
data_store: &re_arrow_store::DataStore, | ||
entity_path: &EntityPath, | ||
query: &LatestAtQuery, | ||
) -> Option<C> | ||
where | ||
for<'b> &'b C::ArrayType: IntoIterator, | ||
{ | ||
crate::profile_function!(); | ||
|
||
// Although it would be nice to use the `re_query` helpers for this, we would need to move | ||
// this out of re_data_store to avoid a circular dep. Since we don't need to do a join for | ||
// single components this is easy enough. | ||
|
||
let (_, cells) = data_store.latest_at(query, entity_path, C::name(), &[C::name()])?; | ||
let cell = cells.get(0)?.as_ref()?; | ||
|
||
let mut iter = cell.try_to_native::<C>().ok()?; | ||
|
||
let component = iter.next(); | ||
|
||
if iter.next().is_some() { | ||
re_log::warn_once!("Unexpected batch for {} at: {}", C::name(), entity_path); | ||
} | ||
|
||
component | ||
} | ||
|
||
/// Get the latest value for a given [`re_log_types::Component`] assuming it is timeless. | ||
/// | ||
/// This assumes that the row we get from the store only contains a single instance for this | ||
/// component; it will log a warning otherwise. | ||
pub fn query_timeless_single<C: DeserializableComponent>( | ||
data_store: &re_arrow_store::DataStore, | ||
entity_path: &EntityPath, | ||
) -> Option<C> | ||
where | ||
for<'b> &'b C::ArrayType: IntoIterator, | ||
{ | ||
let query = re_arrow_store::LatestAtQuery::latest(Timeline::default()); | ||
query_latest_single(data_store, entity_path, &query) | ||
} | ||
|
||
// ---------------------------------------------------------------------------- | ||
|
||
/// Store a single value for a given [`re_log_types::Component`]. | ||
pub fn store_one_component<C: SerializableComponent>( | ||
log_db: &mut LogDb, | ||
entity_path: &EntityPath, | ||
timepoint: &TimePoint, | ||
component: C, | ||
) { | ||
let mut row = DataRow::from_cells1( | ||
RowId::random(), | ||
entity_path.clone(), | ||
timepoint.clone(), | ||
1, | ||
[component].as_slice(), | ||
); | ||
row.compute_all_size_bytes(); | ||
|
||
match log_db.entity_db.try_add_data_row(&row) { | ||
Ok(()) => {} | ||
Err(err) => { | ||
re_log::warn_once!( | ||
"Failed to store component {}.{}: {err}", | ||
entity_path, | ||
C::name(), | ||
); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.