Skip to content

Commit

Permalink
Merge branch 'main' into jan/prepare-code-examples
Browse files Browse the repository at this point in the history
  • Loading branch information
jprochazk committed Mar 13, 2024
2 parents ef37d3b + 25bb0f6 commit ef23e0b
Show file tree
Hide file tree
Showing 51 changed files with 915 additions and 748 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/re_data_store/src/store_read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,7 @@ impl DataStore {

/// Sort all unsorted indices in the store.
pub fn sort_indices_if_needed(&self) {
re_tracing::profile_function!();
for index in self.tables.values() {
index.sort_indices_if_needed();
}
Expand Down
43 changes: 41 additions & 2 deletions crates/re_entity_db/src/entity_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ use re_data_store::{
DataStore, DataStoreConfig, GarbageCollectionOptions, StoreEvent, StoreSubscriber,
};
use re_log_types::{
ApplicationId, DataCell, DataRow, DataTable, EntityPath, EntityPathHash, LogMsg, RowId,
SetStoreInfo, StoreId, StoreInfo, StoreKind, TimePoint, Timeline,
ApplicationId, DataCell, DataRow, DataTable, DataTableResult, EntityPath, EntityPathHash,
LogMsg, RowId, SetStoreInfo, StoreId, StoreInfo, StoreKind, TimePoint, TimeRange, TimeRangeF,
Timeline,
};
use re_types_core::{components::InstanceKey, Archetype, Loggable};

Expand Down Expand Up @@ -510,6 +511,44 @@ impl EntityDb {
self.store_info()
.map(|info| (info.application_id.0.as_str(), info.started))
}

/// Export the contents of the current database to a sequence of messages.
///
/// If `time_selection` is specified, then only data for that specific timeline over that
/// specific time range will be accounted for.
pub fn to_messages(
&self,
time_selection: Option<(Timeline, TimeRangeF)>,
) -> DataTableResult<Vec<LogMsg>> {
re_tracing::profile_function!();

self.store().sort_indices_if_needed();

let set_store_info_msg = self
.store_info_msg()
.map(|msg| LogMsg::SetStoreInfo(msg.clone()));

let time_filter = time_selection.map(|(timeline, range)| {
(
timeline,
TimeRange::new(range.min.floor(), range.max.ceil()),
)
});

let data_messages = self.store().to_data_tables(time_filter).map(|table| {
table
.to_arrow_msg()
.map(|msg| LogMsg::ArrowMsg(self.store_id().clone(), msg))
});

let messages: Result<Vec<_>, _> = set_store_info_msg
.map(re_log_types::DataTableResult::Ok)
.into_iter()
.chain(data_messages)
.collect();

messages
}
}

// ----------------------------------------------------------------------------
Expand Down
18 changes: 11 additions & 7 deletions crates/re_log_encoding/src/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ impl<W: std::io::Write> Encoder<W> {
}

pub fn append(&mut self, message: &LogMsg) -> Result<(), EncodeError> {
re_tracing::profile_function!();

self.uncompressed.clear();
rmp_serde::encode::write_named(&mut self.uncompressed, message)?;

Expand Down Expand Up @@ -119,21 +121,23 @@ pub fn encode<'a>(
messages: impl Iterator<Item = &'a LogMsg>,
write: &mut impl std::io::Write,
) -> Result<(), EncodeError> {
re_tracing::profile_function!();
let mut encoder = Encoder::new(options, write)?;
for message in messages {
encoder.append(message)?;
}
Ok(())
}

pub fn encode_owned(
pub fn encode_as_bytes<'a>(
options: EncodingOptions,
messages: impl Iterator<Item = LogMsg>,
write: impl std::io::Write,
) -> Result<(), EncodeError> {
let mut encoder = Encoder::new(options, write)?;
messages: impl Iterator<Item = &'a LogMsg>,
) -> Result<Vec<u8>, EncodeError> {
re_tracing::profile_function!();
let mut bytes: Vec<u8> = vec![];
let mut encoder = Encoder::new(options, &mut bytes)?;
for message in messages {
encoder.append(&message)?;
encoder.append(message)?;
}
Ok(())
Ok(bytes)
}
3 changes: 0 additions & 3 deletions crates/re_log_encoding/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#[cfg(feature = "decoder")]
pub mod decoder;
#[cfg(feature = "encoder")]
#[cfg(not(target_arch = "wasm32"))] // we do no yet support encoding LogMsgs in the browser
pub mod encoder;

#[cfg(feature = "encoder")]
Expand Down Expand Up @@ -121,7 +120,6 @@ impl FileHeader {
pub const SIZE: usize = 12;

#[cfg(feature = "encoder")]
#[cfg(not(target_arch = "wasm32"))] // we do no yet support encoding LogMsgs in the browser
pub fn encode(&self, write: &mut impl std::io::Write) -> Result<(), encoder::EncodeError> {
write
.write_all(&self.magic)
Expand Down Expand Up @@ -165,7 +163,6 @@ impl MessageHeader {
pub const SIZE: usize = 8;

#[cfg(feature = "encoder")]
#[cfg(not(target_arch = "wasm32"))] // we do no yet support encoding LogMsgs in the browser
pub fn encode(&self, write: &mut impl std::io::Write) -> Result<(), encoder::EncodeError> {
write
.write_all(&self.compressed_len.to_le_bytes())
Expand Down
16 changes: 12 additions & 4 deletions crates/re_space_view/src/space_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ use re_types::{
use re_types_core::archetypes::Clear;
use re_types_core::Archetype as _;
use re_viewer_context::{
blueprint_timepoint_for_writes, DataResult, DynSpaceViewClass, PerSystemEntities,
PropertyOverrides, SpaceViewClassIdentifier, SpaceViewId, SpaceViewState, StoreContext,
blueprint_timepoint_for_writes, DataResult, PerSystemEntities, PropertyOverrides,
SpaceViewClass, SpaceViewClassIdentifier, SpaceViewId, SpaceViewState, StoreContext,
SystemCommand, SystemCommandSender as _, SystemExecutionOutput, ViewQuery, ViewerContext,
};

Expand Down Expand Up @@ -337,7 +337,7 @@ impl SpaceViewBlueprint {
pub fn class<'a>(
&self,
space_view_class_registry: &'a re_viewer_context::SpaceViewClassRegistry,
) -> &'a dyn DynSpaceViewClass {
) -> &'a dyn SpaceViewClass {
space_view_class_registry.get_class_or_log_error(&self.class_identifier)
}

Expand Down Expand Up @@ -391,7 +391,15 @@ impl SpaceViewBlueprint {
.unwrap_or_default();

ui.scope(|ui| {
class.ui(ctx, ui, view_state, &props, query, system_output);
class
.ui(ctx, ui, view_state, &props, query, system_output)
.unwrap_or_else(|err| {
re_log::error!(
"Error in Space View UI (class: {}, display name: {}): {err}",
self.class_identifier,
class.display_name(),
);
});
});
}

Expand Down
6 changes: 2 additions & 4 deletions crates/re_space_view/src/visualizable.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
use re_entity_db::EntityDb;
use re_log_types::EntityPath;
use re_viewer_context::{
ApplicableEntities, DynSpaceViewClass, PerVisualizer, VisualizableEntities,
};
use re_viewer_context::{ApplicableEntities, PerVisualizer, SpaceViewClass, VisualizableEntities};

/// Determines the set of visible entities for a given space view.
// TODO(andreas): This should be part of the SpaceView's (non-blueprint) state.
Expand All @@ -11,7 +9,7 @@ pub fn determine_visualizable_entities(
applicable_entities_per_visualizer: &PerVisualizer<ApplicableEntities>,
entity_db: &EntityDb,
visualizers: &re_viewer_context::VisualizerCollection,
class: &dyn DynSpaceViewClass,
class: &dyn SpaceViewClass,
space_origin: &EntityPath,
) -> PerVisualizer<VisualizableEntities> {
re_tracing::profile_function!();
Expand Down
27 changes: 18 additions & 9 deletions crates/re_space_view_bar_chart/src/space_view_class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ use re_log_types::EntityPath;
use re_space_view::{controls, suggest_space_view_for_each_entity};
use re_types::datatypes::TensorBuffer;
use re_viewer_context::{
auto_color, SpaceViewClass, SpaceViewClassRegistryError, SpaceViewId,
SpaceViewSystemExecutionError, ViewQuery, ViewerContext,
auto_color, SpaceViewClass, SpaceViewClassIdentifier, SpaceViewClassRegistryError, SpaceViewId,
SpaceViewState, SpaceViewSystemExecutionError, ViewQuery, ViewerContext,
};

use super::visualizer_system::BarChartVisualizerSystem;
Expand All @@ -14,15 +14,22 @@ use super::visualizer_system::BarChartVisualizerSystem;
pub struct BarChartSpaceView;

impl SpaceViewClass for BarChartSpaceView {
type State = ();
fn identifier() -> SpaceViewClassIdentifier {
"Bar Chart".into()
}

const IDENTIFIER: &'static str = "Bar Chart";
const DISPLAY_NAME: &'static str = "Bar Chart";
fn display_name(&self) -> &'static str {
"Bar Chart"
}

fn icon(&self) -> &'static re_ui::Icon {
&re_ui::icons::SPACE_VIEW_HISTOGRAM
}

fn new_state(&self) -> Box<dyn SpaceViewState> {
Box::<()>::default()
}

fn help_text(&self, re_ui: &re_ui::ReUi) -> egui::WidgetText {
let mut layout = re_ui::LayoutJobBuilder::new(re_ui);

Expand Down Expand Up @@ -55,7 +62,7 @@ impl SpaceViewClass for BarChartSpaceView {
system_registry.register_visualizer::<BarChartVisualizerSystem>()
}

fn preferred_tile_aspect_ratio(&self, _state: &Self::State) -> Option<f32> {
fn preferred_tile_aspect_ratio(&self, _state: &dyn SpaceViewState) -> Option<f32> {
None
}

Expand All @@ -75,11 +82,11 @@ impl SpaceViewClass for BarChartSpaceView {
&self,
ctx: &ViewerContext<'_>,
ui: &mut egui::Ui,
_state: &mut Self::State,
_state: &mut dyn SpaceViewState,
_space_origin: &EntityPath,
_space_view_id: SpaceViewId,
root_entity_properties: &mut EntityProperties,
) {
) -> Result<(), SpaceViewSystemExecutionError> {
ctx.re_ui
.selection_grid(ui, "bar_chart_selection_ui")
.show(ui, |ui| {
Expand Down Expand Up @@ -128,13 +135,15 @@ impl SpaceViewClass for BarChartSpaceView {
});
ui.end_row();
});

Ok(())
}

fn ui(
&self,
ctx: &ViewerContext<'_>,
ui: &mut egui::Ui,
_state: &mut Self::State,
_state: &mut dyn SpaceViewState,
root_entity_properties: &EntityProperties,
query: &ViewQuery<'_>,
system_output: re_viewer_context::SystemExecutionOutput,
Expand Down
32 changes: 14 additions & 18 deletions crates/re_space_view_dataframe/src/space_view_class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ use re_entity_db::{EntityProperties, InstancePath};
use re_log_types::{EntityPath, Timeline};
use re_query::get_component_with_instances;
use re_viewer_context::{
SpaceViewClass, SpaceViewClassRegistryError, SpaceViewId, SpaceViewSystemExecutionError,
SystemExecutionOutput, UiVerbosity, ViewQuery, ViewerContext,
SpaceViewClass, SpaceViewClassIdentifier, SpaceViewClassRegistryError, SpaceViewState,
SpaceViewSystemExecutionError, SystemExecutionOutput, UiVerbosity, ViewQuery, ViewerContext,
};

use crate::visualizer_system::EmptySystem;
Expand All @@ -18,10 +18,13 @@ use crate::visualizer_system::EmptySystem;
pub struct DataframeSpaceView;

impl SpaceViewClass for DataframeSpaceView {
type State = ();
fn identifier() -> SpaceViewClassIdentifier {
"Dataframe".into()
}

const IDENTIFIER: &'static str = "Dataframe";
const DISPLAY_NAME: &'static str = "Dataframe";
fn display_name(&self) -> &'static str {
"Dataframe"
}

fn icon(&self) -> &'static re_ui::Icon {
//TODO(ab): fix that icon
Expand All @@ -44,7 +47,11 @@ impl SpaceViewClass for DataframeSpaceView {
system_registry.register_visualizer::<EmptySystem>()
}

fn preferred_tile_aspect_ratio(&self, _state: &Self::State) -> Option<f32> {
fn new_state(&self) -> Box<dyn SpaceViewState> {
Box::<()>::default()
}

fn preferred_tile_aspect_ratio(&self, _state: &dyn SpaceViewState) -> Option<f32> {
None
}

Expand All @@ -60,22 +67,11 @@ impl SpaceViewClass for DataframeSpaceView {
Default::default()
}

fn selection_ui(
&self,
_ctx: &ViewerContext<'_>,
_ui: &mut egui::Ui,
_state: &mut Self::State,
_space_origin: &EntityPath,
_space_view_id: SpaceViewId,
_root_entity_properties: &mut EntityProperties,
) {
}

fn ui(
&self,
ctx: &ViewerContext<'_>,
ui: &mut egui::Ui,
_state: &mut Self::State,
_state: &mut dyn SpaceViewState,
_root_entity_properties: &EntityProperties,
query: &ViewQuery<'_>,
_system_output: SystemExecutionOutput,
Expand Down

0 comments on commit ef23e0b

Please sign in to comment.