Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve raw value interpretation #31

Merged
merged 5 commits into from
Mar 13, 2025
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
3 changes: 2 additions & 1 deletion src/app_impl/load_delete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,9 @@ impl AppState {
}

pub(crate) fn add_map(&mut self, name: &String, meta: Meta, image_pyramid: Arc<ImagePyramid>) {
let use_interpretation = meta.value_interpretation.mode != value_interpretation::Mode::Raw;
let use_interpretation = meta.value_interpretation.explicit_mode;
if use_interpretation {
// This map has an explicitly specified value interpretation.
// We need to set this to not loose the values in the next frame.
self.options.tint_settings.active_tint_selection = Some(name.clone());
}
Expand Down
23 changes: 14 additions & 9 deletions src/texture_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,14 @@ impl TextureState {
}
}

pub fn update(&mut self, ui: &egui::Ui, request: &TextureRequest) {
let changed = self.desired_size != request.desired_rect.size()
fn changed(&self, request: &TextureRequest) -> bool {
self.desired_size != request.desired_rect.size()
|| self.desired_color_to_alpha != request.color_to_alpha
|| self.desired_thresholding != request.thresholding;
|| self.desired_thresholding != request.thresholding
}

if changed {
pub fn update(&mut self, ui: &egui::Ui, request: &TextureRequest) {
if self.changed(request) {
// Free the old texture if the size changed.
self.texture_handle = None;
}
Expand Down Expand Up @@ -78,14 +80,17 @@ impl TextureState {
}
}

fn changed_crop(&self, request: &RotatedCropRequest) -> bool {
if self.changed(&request.uncropped) {
return true;
}
return self.desired_uv != request.uv;
}

pub fn update_crop(&mut self, ui: &mut egui::Ui, request: &RotatedCropRequest) {
let desired_size = request.uncropped.desired_rect.size();

let mut unchanged = self.desired_size == desired_size && self.desired_uv == request.uv;
unchanged &= request.uncropped.color_to_alpha == self.desired_color_to_alpha;
unchanged &= self.desired_thresholding.unwrap_or_default()
== request.uncropped.thresholding.unwrap_or_default();
if unchanged {
if !self.changed_crop(request) {
return;
}
self.desired_size = desired_size;
Expand Down
11 changes: 9 additions & 2 deletions src/value_interpretation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ use crate::value_colormap::ColorMap;
#[serde(rename_all = "lowercase")]
pub enum Mode {
/// Raw mode: no interpretation.
#[default]
Raw,
/// Trinary mode: values are thresholded into free, occupied, unknown.
#[default]
Trinary,
/// Scale mode: values are scaled into a continuous range between free and occupied.
Scale,
Expand All @@ -54,6 +54,8 @@ pub struct ValueInterpretation {
pub occupied: f32,
pub negate: bool,
pub mode: Mode,
#[serde(default)]
pub explicit_mode: bool,
pub quirks: Quirks,
#[serde(default)]
pub colormap: ColorMap,
Expand All @@ -66,6 +68,7 @@ impl Default for ValueInterpretation {
occupied: MAP_SERVER_OCCUPIED_DEFAULT,
negate: false,
mode: Mode::default(),
explicit_mode: false,
quirks: Quirks::default(),
colormap: ColorMap::default(),
}
Expand All @@ -79,6 +82,7 @@ impl ValueInterpretation {
occupied,
negate,
mode: mode.unwrap_or_default(),
explicit_mode: mode.is_some(),
quirks: Quirks::default(),
colormap: ColorMap::default(),
}
Expand Down Expand Up @@ -113,8 +117,11 @@ impl ValueInterpretation {
pub fn apply(&self, img: &mut DynamicImage, original_has_alpha: bool) {
match self.mode {
Mode::Raw => {
map_colors_mut(img, |c| {
map_colors_mut(img, |mut c| {
// Only colormap without interpretation in raw mode.
if self.negate {
c[0] = 255 - c[0];
}
self.colormap.get().map(c[0])
});
}
Expand Down
12 changes: 12 additions & 0 deletions tests/sessions/value_interpretations_map_server.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,15 @@ free = 0.19599999487400055
occupied = 0.6499999761581421
negate = false
mode = "raw"
explicit_mode = true
quirks = "Ros1MapServer"

[maps."tests/maps/dummy_map_raw.yaml".meta.original_value_interpretation]
free = 0.19599999487400055
occupied = 0.6499999761581421
negate = false
mode = "raw"
explicit_mode = true
quirks = "Ros1MapServer"

[maps."tests/maps/dummy_map_raw.yaml".pose]
Expand Down Expand Up @@ -67,13 +69,15 @@ free = 0.19599999487400055
occupied = 0.6499999761581421
negate = true
mode = "raw"
explicit_mode = true
quirks = "Ros1MapServer"

[maps."tests/maps/dummy_map_raw_negate.yaml".meta.original_value_interpretation]
free = 0.19599999487400055
occupied = 0.6499999761581421
negate = true
mode = "raw"
explicit_mode = true
quirks = "Ros1MapServer"

[maps."tests/maps/dummy_map_raw_negate.yaml".pose]
Expand Down Expand Up @@ -113,13 +117,15 @@ free = 0.19599999487400055
occupied = 0.6499999761581421
negate = false
mode = "scale"
explicit_mode = true
quirks = "Ros1MapServer"

[maps."tests/maps/dummy_map_scale.yaml".meta.original_value_interpretation]
free = 0.19599999487400055
occupied = 0.6499999761581421
negate = false
mode = "scale"
explicit_mode = true
quirks = "Ros1MapServer"

[maps."tests/maps/dummy_map_scale.yaml".pose]
Expand Down Expand Up @@ -159,13 +165,15 @@ free = 0.19599999487400055
occupied = 0.6499999761581421
negate = true
mode = "scale"
explicit_mode = true
quirks = "Ros1MapServer"

[maps."tests/maps/dummy_map_scale_negate.yaml".meta.original_value_interpretation]
free = 0.19599999487400055
occupied = 0.6499999761581421
negate = true
mode = "scale"
explicit_mode = true
quirks = "Ros1MapServer"

[maps."tests/maps/dummy_map_scale_negate.yaml".pose]
Expand Down Expand Up @@ -205,13 +213,15 @@ free = 0.19599999487400055
occupied = 0.6499999761581421
negate = false
mode = "trinary"
explicit_mode = true
quirks = "Ros1MapServer"

[maps."tests/maps/dummy_map_trinary.yaml".meta.original_value_interpretation]
free = 0.19599999487400055
occupied = 0.6499999761581421
negate = false
mode = "trinary"
explicit_mode = true
quirks = "Ros1MapServer"

[maps."tests/maps/dummy_map_trinary.yaml".pose]
Expand Down Expand Up @@ -251,13 +261,15 @@ free = 0.19599999487400055
occupied = 0.6499999761581421
negate = true
mode = "trinary"
explicit_mode = true
quirks = "Ros1MapServer"

[maps."tests/maps/dummy_map_trinary_negate.yaml".meta.original_value_interpretation]
free = 0.19599999487400055
occupied = 0.6499999761581421
negate = true
mode = "trinary"
explicit_mode = true
quirks = "Ros1MapServer"

[maps."tests/maps/dummy_map_trinary_negate.yaml".pose]
Expand Down
12 changes: 12 additions & 0 deletions tests/sessions/value_interpretations_ros1_wiki.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,15 @@ free = 0.19599999487400055
occupied = 0.6499999761581421
negate = false
mode = "raw"
explicit_mode = true
quirks = "Ros1Wiki"

[maps."tests/maps/dummy_map_raw.yaml".meta.original_value_interpretation]
free = 0.19599999487400055
occupied = 0.6499999761581421
negate = false
mode = "raw"
explicit_mode = true
quirks = "Ros1Wiki"

[maps."tests/maps/dummy_map_raw.yaml".pose]
Expand Down Expand Up @@ -67,13 +69,15 @@ free = 0.19599999487400055
occupied = 0.6499999761581421
negate = true
mode = "raw"
explicit_mode = true
quirks = "Ros1Wiki"

[maps."tests/maps/dummy_map_raw_negate.yaml".meta.original_value_interpretation]
free = 0.19599999487400055
occupied = 0.6499999761581421
negate = true
mode = "raw"
explicit_mode = true
quirks = "Ros1Wiki"

[maps."tests/maps/dummy_map_raw_negate.yaml".pose]
Expand Down Expand Up @@ -113,13 +117,15 @@ free = 0.19599999487400055
occupied = 0.6499999761581421
negate = false
mode = "scale"
explicit_mode = true
quirks = "Ros1Wiki"

[maps."tests/maps/dummy_map_scale.yaml".meta.original_value_interpretation]
free = 0.19599999487400055
occupied = 0.6499999761581421
negate = false
mode = "scale"
explicit_mode = true
quirks = "Ros1Wiki"

[maps."tests/maps/dummy_map_scale.yaml".pose]
Expand Down Expand Up @@ -159,13 +165,15 @@ free = 0.19599999487400055
occupied = 0.6499999761581421
negate = true
mode = "scale"
explicit_mode = true
quirks = "Ros1Wiki"

[maps."tests/maps/dummy_map_scale_negate.yaml".meta.original_value_interpretation]
free = 0.19599999487400055
occupied = 0.6499999761581421
negate = true
mode = "scale"
explicit_mode = true
quirks = "Ros1Wiki"

[maps."tests/maps/dummy_map_scale_negate.yaml".pose]
Expand Down Expand Up @@ -205,13 +213,15 @@ free = 0.19599999487400055
occupied = 0.6499999761581421
negate = false
mode = "trinary"
explicit_mode = true
quirks = "Ros1Wiki"

[maps."tests/maps/dummy_map_trinary.yaml".meta.original_value_interpretation]
free = 0.19599999487400055
occupied = 0.6499999761581421
negate = false
mode = "trinary"
explicit_mode = true
quirks = "Ros1Wiki"

[maps."tests/maps/dummy_map_trinary.yaml".pose]
Expand Down Expand Up @@ -251,13 +261,15 @@ free = 0.19599999487400055
occupied = 0.6499999761581421
negate = true
mode = "trinary"
explicit_mode = true
quirks = "Ros1Wiki"

[maps."tests/maps/dummy_map_trinary_negate.yaml".meta.original_value_interpretation]
free = 0.19599999487400055
occupied = 0.6499999761581421
negate = true
mode = "trinary"
explicit_mode = true
quirks = "Ros1Wiki"

[maps."tests/maps/dummy_map_trinary_negate.yaml".pose]
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions tests/snapshots/value_colormap_rviz_costmap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions tests/snapshots/value_colormap_rviz_map.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions tests/snapshots/value_interpretations_map_server.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions tests/snapshots/value_interpretations_wiki.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.