File tree Expand file tree Collapse file tree 14 files changed +226
-98
lines changed
tests/assets/rrd/snippets/howto Expand file tree Collapse file tree 14 files changed +226
-98
lines changed Original file line number Diff line number Diff line change @@ -111,9 +111,12 @@ impl McapChunkDecoder {
111
111
112
112
let channel = msg. channel . as_ref ( ) ;
113
113
let channel_id = ChannelId ( channel. id ) ;
114
+ let log_time_cell = crate :: util:: TimestampCell :: guess_from_nanos ( msg. log_time , "log_time" ) ;
115
+ let publish_time_cell =
116
+ crate :: util:: TimestampCell :: guess_from_nanos ( msg. publish_time , "publish_time" ) ;
114
117
let timepoint = re_chunk:: TimePoint :: from ( [
115
- ( "log_time" , crate :: util :: guess_epoch ( msg . log_time ) ) ,
116
- ( "publish_time" , crate :: util :: guess_epoch ( msg . publish_time ) ) ,
118
+ ( "log_time" , log_time_cell . into_time_cell ( ) ) ,
119
+ ( "publish_time" , publish_time_cell . into_time_cell ( ) ) ,
117
120
] ) ;
118
121
119
122
if let Some ( ( ctx, parser) ) = self . parsers . get_mut ( & channel_id) {
Original file line number Diff line number Diff line change @@ -6,6 +6,8 @@ use re_chunk::{
6
6
} ;
7
7
use re_log_types:: TimeCell ;
8
8
9
+ use crate :: util:: TimestampCell ;
10
+
9
11
/// Trait for parsing MCAP messages of a specific schema into Rerun chunks.
10
12
///
11
13
/// This trait defines the interface for converting MCAP messages into Rerun's internal
@@ -104,6 +106,22 @@ impl ParserContext {
104
106
self
105
107
}
106
108
109
+ /// Add a timestamp to the timeline using the provided timestamp cell.
110
+ ///
111
+ /// The timeline name and [`TimeCell`] are automatically determined from the timestamp cell.
112
+ /// For Unix epochs, creates a timestamp cell. For custom epochs, creates a duration cell.
113
+ pub fn add_timestamp_cell ( & mut self , timestamp_cell : TimestampCell ) -> & mut Self {
114
+ let timeline_name = TimelineName :: from ( timestamp_cell. timeline_name ( ) ) ;
115
+ let cell = timestamp_cell. into_time_cell ( ) ;
116
+
117
+ self . timelines
118
+ . entry ( timeline_name)
119
+ . or_insert_with ( || TimeColumn :: builder ( Timeline :: new ( timeline_name, cell. typ ) ) )
120
+ . with_row ( cell. value ) ;
121
+
122
+ self
123
+ }
124
+
107
125
/// Consume this context and build all timelines into [`TimeColumn`]s.
108
126
pub fn build_timelines ( self ) -> IntMap < TimelineName , TimeColumn > {
109
127
self . timelines
Original file line number Diff line number Diff line change @@ -8,14 +8,11 @@ use re_types::{
8
8
datatypes:: Rgba32 ,
9
9
} ;
10
10
11
- use crate :: {
12
- parsers:: {
13
- cdr,
14
- decode:: { MessageParser , ParserContext } ,
15
- ros2msg:: definitions:: rcl_interfaces:: { self , LogLevel } ,
16
- util:: fixed_size_list_builder,
17
- } ,
18
- util:: guess_epoch,
11
+ use crate :: parsers:: {
12
+ cdr,
13
+ decode:: { MessageParser , ParserContext } ,
14
+ ros2msg:: definitions:: rcl_interfaces:: { self , LogLevel } ,
15
+ util:: fixed_size_list_builder,
19
16
} ;
20
17
21
18
/// Plugin that parses `rcl_interfaces/msg/Log` messages.
@@ -81,7 +78,10 @@ impl MessageParser for LogMessageParser {
81
78
. context ( "Failed to decode `rcl_interfaces::Log` message from CDR data" ) ?;
82
79
83
80
// add the sensor timestamp to the context, `log_time` and `publish_time` are added automatically
84
- ctx. add_time_cell ( "timestamp" , guess_epoch ( stamp. as_nanos ( ) as u64 ) ) ;
81
+ ctx. add_timestamp_cell ( crate :: util:: TimestampCell :: guess_from_nanos (
82
+ stamp. as_nanos ( ) as u64 ,
83
+ msg. channel . topic . clone ( ) ,
84
+ ) ) ;
85
85
86
86
self . text_entries . push ( format ! ( "[{name}] {log_msg}" ) ) ;
87
87
self . levels . push ( level. to_string ( ) ) ;
Original file line number Diff line number Diff line change @@ -84,10 +84,10 @@ impl<T: ScalarExtractor> MessageParser for ScalarMessageParser<T> {
84
84
} ) ?;
85
85
86
86
// Add the sensor timestamp to the context, `log_time` and `publish_time` are added automatically
87
- ctx. add_time_cell (
88
- "timestamp" ,
89
- crate :: util :: guess_epoch ( message . header ( ) . stamp . as_nanos ( ) as u64 ) ,
90
- ) ;
87
+ ctx. add_timestamp_cell ( crate :: util :: TimestampCell :: guess_from_nanos (
88
+ message . header ( ) . stamp . as_nanos ( ) as u64 ,
89
+ msg . channel . topic . clone ( ) ,
90
+ ) ) ;
91
91
92
92
let scalar_values = message. extract_scalars ( ) ;
93
93
Original file line number Diff line number Diff line change @@ -96,10 +96,10 @@ impl MessageParser for CameraInfoMessageParser {
96
96
} = cdr:: try_decode_message :: < sensor_msgs:: CameraInfo > ( & msg. data ) ?;
97
97
98
98
// add the sensor timestamp to the context, `log_time` and `publish_time` are added automatically
99
- ctx. add_time_cell (
100
- "timestamp" ,
101
- crate :: util :: guess_epoch ( header . stamp . as_nanos ( ) as u64 ) ,
102
- ) ;
99
+ ctx. add_timestamp_cell ( crate :: util :: TimestampCell :: guess_from_nanos (
100
+ header . stamp . as_nanos ( ) as u64 ,
101
+ msg . channel . topic . clone ( ) ,
102
+ ) ) ;
103
103
104
104
self . distortion_models
105
105
. values ( )
Original file line number Diff line number Diff line change @@ -10,9 +10,12 @@ use re_types::{
10
10
reflection:: ComponentDescriptorExt as _,
11
11
} ;
12
12
13
- use crate :: parsers:: {
14
- cdr,
15
- decode:: { MessageParser , ParserContext } ,
13
+ use crate :: {
14
+ parsers:: {
15
+ cdr,
16
+ decode:: { MessageParser , ParserContext } ,
17
+ } ,
18
+ util:: TimestampCell ,
16
19
} ;
17
20
18
21
/// Plugin that parses `sensor_msgs/msg/CompressedImage` messages.
@@ -47,10 +50,10 @@ impl MessageParser for CompressedImageMessageParser {
47
50
} = cdr:: try_decode_message :: < sensor_msgs:: CompressedImage < ' _ > > ( & msg. data ) ?;
48
51
49
52
// add the sensor timestamp to the context, `log_time` and `publish_time` are added automatically
50
- ctx. add_time_cell (
51
- "timestamp" ,
52
- crate :: util :: guess_epoch ( header . stamp . as_nanos ( ) as u64 ) ,
53
- ) ;
53
+ ctx. add_timestamp_cell ( TimestampCell :: guess_from_nanos (
54
+ header . stamp . as_nanos ( ) as u64 ,
55
+ msg . channel . topic . clone ( ) ,
56
+ ) ) ;
54
57
55
58
self . blobs . push ( data. into_owned ( ) ) ;
56
59
Original file line number Diff line number Diff line change @@ -72,10 +72,10 @@ impl MessageParser for ImageMessageParser {
72
72
. context ( "Failed to decode sensor_msgs::Image message from CDR data" ) ?;
73
73
74
74
// add the sensor timestamp to the context, `log_time` and `publish_time` are added automatically
75
- ctx. add_time_cell (
76
- "timestamp" ,
77
- crate :: util :: guess_epoch ( header . stamp . as_nanos ( ) as u64 ) ,
78
- ) ;
75
+ ctx. add_timestamp_cell ( crate :: util :: TimestampCell :: guess_from_nanos (
76
+ header . stamp . as_nanos ( ) as u64 ,
77
+ msg . channel . topic . clone ( ) ,
78
+ ) ) ;
79
79
80
80
let dimensions = [ width, height] ;
81
81
let img_format = decode_image_format ( & encoding, dimensions)
Original file line number Diff line number Diff line change @@ -72,10 +72,10 @@ impl MessageParser for ImuMessageParser {
72
72
. map_err ( |err| Error :: Other ( anyhow:: anyhow!( err) ) ) ?;
73
73
74
74
// add the sensor timestamp to the context, `log_time` and `publish_time` are added automatically
75
- ctx. add_time_cell (
76
- "timestamp" ,
77
- crate :: util :: guess_epoch ( imu . header . stamp . as_nanos ( ) as u64 ) ,
78
- ) ;
75
+ ctx. add_timestamp_cell ( crate :: util :: TimestampCell :: guess_from_nanos (
76
+ imu . header . stamp . as_nanos ( ) as u64 ,
77
+ msg . channel . topic . clone ( ) ,
78
+ ) ) ;
79
79
80
80
self . orientation . values ( ) . append_slice ( & [
81
81
imu. orientation . x ,
Original file line number Diff line number Diff line change @@ -45,10 +45,10 @@ impl MessageParser for JointStateMessageParser {
45
45
. map_err ( |err| Error :: Other ( anyhow:: anyhow!( err) ) ) ?;
46
46
47
47
// add the sensor timestamp to the context, `log_time` and `publish_time` are added automatically
48
- ctx. add_time_cell (
49
- "timestamp" ,
50
- crate :: util :: guess_epoch ( header . stamp . as_nanos ( ) as u64 ) ,
51
- ) ;
48
+ ctx. add_timestamp_cell ( crate :: util :: TimestampCell :: guess_from_nanos (
49
+ header . stamp . as_nanos ( ) as u64 ,
50
+ msg . channel . topic . clone ( ) ,
51
+ ) ) ;
52
52
53
53
for name in & name {
54
54
self . joint_names . values ( ) . append_value ( name) ;
Original file line number Diff line number Diff line change @@ -39,10 +39,10 @@ impl MessageParser for MagneticFieldMessageParser {
39
39
. map_err ( |err| Error :: Other ( anyhow:: anyhow!( err) ) ) ?;
40
40
41
41
// add the sensor timestamp to the context, `log_time` and `publish_time` are added automatically
42
- ctx. add_time_cell (
43
- "timestamp" ,
44
- crate :: util :: guess_epoch ( magnetic_field . header . stamp . as_nanos ( ) as u64 ) ,
45
- ) ;
42
+ ctx. add_timestamp_cell ( crate :: util :: TimestampCell :: guess_from_nanos (
43
+ magnetic_field . header . stamp . as_nanos ( ) as u64 ,
44
+ msg . channel . topic . clone ( ) ,
45
+ ) ) ;
46
46
47
47
// Convert magnetic field vector to Vector3D and store
48
48
self . vectors . push ( Vec3D ( [
You can’t perform that action at this time.
0 commit comments