Skip to content

Commit

Permalink
chunkified text-log view with multi-timeline display
Browse files Browse the repository at this point in the history
  • Loading branch information
teh-cmc committed Aug 2, 2024
1 parent a5e6461 commit 3137c4a
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 48 deletions.
3 changes: 2 additions & 1 deletion Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5065,12 +5065,13 @@ version = "0.18.0-alpha.1+dev"
dependencies = [
"egui",
"egui_extras",
"itertools 0.13.0",
"re_chunk_store",
"re_data_ui",
"re_entity_db",
"re_log",
"re_log_types",
"re_query",
"re_query2",
"re_renderer",
"re_space_view",
"re_tracing",
Expand Down
3 changes: 2 additions & 1 deletion crates/viewer/re_space_view_text_log/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ re_data_ui.workspace = true
re_entity_db.workspace = true
re_log_types.workspace = true
re_log.workspace = true
re_query.workspace = true
re_query2.workspace = true
re_renderer.workspace = true
re_space_view.workspace = true
re_tracing.workspace = true
Expand All @@ -34,3 +34,4 @@ re_viewer_context.workspace = true

egui_extras.workspace = true
egui.workspace = true
itertools.workspace = true
28 changes: 10 additions & 18 deletions crates/viewer/re_space_view_text_log/src/space_view_class.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::collections::BTreeMap;

use re_data_ui::item_ui;
use re_log_types::{EntityPath, TimePoint, Timeline};
use re_log_types::{EntityPath, Timeline};
use re_types::View;
use re_types::{components::TextLogLevel, SpaceViewClassIdentifier};
use re_ui::UiExt as _;
Expand Down Expand Up @@ -279,20 +279,12 @@ fn table_ui(
entries: &[&Entry],
scroll_to_row: Option<usize>,
) {
let timelines = vec![*ctx.rec_cfg.time_ctrl.read().timeline()];

// TODO(#6611): This regressed because adding a metadata registry in the store is an antipattern.
//
// We'll bring back the multi-timeline display once we get rid of the native cache and start
// exposing chunks directly instead.
// Since chunks embed the data for all associated timelines, there'll be no extra work needed
// to get that information out.
// let timelines = state
// .filters
// .col_timelines
// .iter()
// .filter_map(|(timeline, visible)| visible.then_some(timeline))
// .collect::<Vec<_>>();
let timelines = state
.filters
.col_timelines
.iter()
.filter_map(|(timeline, visible)| visible.then_some(timeline))
.collect::<Vec<_>>();

use egui_extras::Column;

Expand Down Expand Up @@ -366,17 +358,17 @@ fn table_ui(
let entry = &entries[row.index()];

// timeline(s)
let timepoint: TimePoint = [(global_timeline, entry.time)].into();
for timeline in &timelines {
row.col(|ui| {
let row_time = timepoint
let row_time = entry
.timepoint
.get(timeline)
.copied()
.unwrap_or(re_log_types::TimeInt::STATIC);
item_ui::time_button(ctx, ui, timeline, row_time);

if let Some(global_time) = global_time {
if timeline == &global_timeline {
if *timeline == &global_timeline {
#[allow(clippy::comparison_chain)]
if global_time < row_time {
// We've past the global time - it is thus above this row.
Expand Down
65 changes: 37 additions & 28 deletions crates/viewer/re_space_view_text_log/src/visualizer_system.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
use itertools::izip;
use re_chunk_store::ResolvedTimeRange;
use re_chunk_store::RowId;
use re_entity_db::EntityPath;
use re_log_types::TimeInt;
use re_query::{clamped_zip_1x2, range_zip_1x2};
use re_space_view::{range_with_blueprint_resolved_data, RangeResultsExt};
use re_log_types::TimePoint;
use re_query2::{clamped_zip_1x2, range_zip_1x2};
use re_space_view::{range_with_blueprint_resolved_data2, RangeResultsExt2};
use re_types::{
archetypes::TextLog,
components::{Color, Text, TextLogLevel},
Expand All @@ -19,6 +21,7 @@ pub struct Entry {
pub row_id: RowId,
pub entity_path: EntityPath,
pub time: TimeInt,
pub timepoint: TimePoint,
pub color: Option<Color>,
pub body: Text,
pub level: Option<TextLogLevel>,
Expand Down Expand Up @@ -53,13 +56,7 @@ impl VisualizerSystem for TextLogSystem {
re_chunk_store::RangeQuery::new(view_query.timeline, ResolvedTimeRange::EVERYTHING);

for data_result in view_query.iter_visible_data_results(ctx, Self::identifier()) {
if let Err(err) = self.process_entity(ctx, &query, data_result) {
re_log::error_once!(
"Error visualizing text logs for {:?}: {:?}",
data_result.entity_path,
err
);
}
self.process_entity(ctx, &query, data_result);
}

{
Expand All @@ -86,36 +83,49 @@ impl TextLogSystem {
ctx: &ViewContext<'_>,
query: &re_chunk_store::RangeQuery,
data_result: &re_viewer_context::DataResult,
) -> Result<(), SpaceViewSystemExecutionError> {
) {
re_tracing::profile_function!();
let resolver = ctx.recording().resolver();

let results = range_with_blueprint_resolved_data(
let results = range_with_blueprint_resolved_data2(
ctx,
None,
query,
data_result,
[Text::name(), TextLogLevel::name(), Color::name()],
);

let Some(all_texts) = results
.get_required_component_dense::<Text>(resolver)
.transpose()?
else {
return Ok(());
let Some(all_text_chunks) = results.get_required_chunks(&Text::name()) else {
return;
};

let all_levels = results.get_or_empty_dense::<TextLogLevel>(resolver)?;
let all_colors = results.get_or_empty_dense::<Color>(resolver)?;
// TODO(cmc): It would be more efficient (both space and compute) to do this lazily as
// we're rendering the table by indexing back into the original chunk etc.
// Let's keep it simple for now, until we have data suggested we need the extra perf.
let all_timepoints = all_text_chunks
.iter()
.flat_map(|chunk| chunk.iter_component_timepoints(&Text::name()));

let timeline = query.timeline();
let all_texts = results.iter_as(timeline, Text::name());
let all_levels = results.iter_as(timeline, TextLogLevel::name());
let all_colors = results.iter_as(timeline, Color::name());

let all_frames = range_zip_1x2(
all_texts.range_indexed(),
all_levels.range_indexed(),
all_colors.range_indexed(),
all_texts.string(),
all_levels.component(),
all_colors.primitive::<u32>(),
);

for (&(data_time, row_id), bodies, levels, colors) in all_frames {
let levels = levels.unwrap_or(&[]).iter().cloned().map(Some);
let colors = colors.unwrap_or(&[]).iter().copied().map(Some);
let all_frames = izip!(all_timepoints, all_frames);

for (timepoint, ((data_time, row_id), bodies, levels, colors)) in all_frames {
let levels = levels.as_deref().unwrap_or(&[]).iter().cloned().map(Some);
let colors = colors
.unwrap_or(&[])
.iter()
.copied()
.map(Into::into)
.map(Some);

let level_default_fn = || None;
let color_default_fn = || None;
Expand All @@ -128,14 +138,13 @@ impl TextLogSystem {
row_id,
entity_path: data_result.entity_path.clone(),
time: data_time,
timepoint: timepoint.clone(),
color,
body: text.clone(),
body: text.clone().into(),
level,
});
}
}

Ok(())
}
}

Expand Down

0 comments on commit 3137c4a

Please sign in to comment.