Skip to content

Commit

Permalink
Gradient for samples, release readiness
Browse files Browse the repository at this point in the history
  • Loading branch information
basyniae committed Oct 26, 2024
1 parent bccff16 commit d7e156d
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 22 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ The math library has been made global, so that for example `sqrt(5)` can be type
An invalid code field will have a red background.
To indicate that the code field has run successfully, the background will turn green.

### Sampling

Todo

## Scope

The process of voxelization is that of approximating of particular shape by voxels, via a particular heuristic, implemented by a particular algorithm.
Expand Down
17 changes: 8 additions & 9 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,11 +191,11 @@ impl App {
blocks_all_layers_generate_once: false,
blocks_all_layers_is_outdated: false,
single_radius: true,
layers_enabled: true, // debug: make default false
layers_enabled: false,
lock_stack_size: false,

// Code mode
code_enabled: true, // debug: make default false
code_enabled: false,
parameters_current_layer_sample_once: true, // on startup, get the parameters from the current configuration
parameters_current_layer_sample_auto: false, // (Can only be turned off/on when sampling is enabled)
parameters_current_layer_is_outdated: false,
Expand All @@ -205,7 +205,7 @@ impl App {
parameters_all_layers_is_outdated: false,

// Sampling
sampling_enabled: true, // debug: make default false
sampling_enabled: false,
only_sample_half_of_bottom_layer: false, // todo: think about defaults
only_sample_half_of_top_layer: false,
nr_samples_per_layer: 1,
Expand Down Expand Up @@ -254,7 +254,7 @@ impl eframe::App for App {
egui::collapsing_header::CollapsingState::load_with_default_open(
ui.ctx(),
id,
false, //debug: default true
true,
)
.show_header(ui, |ui| {
ui.label(egui::RichText::new("Parameters").strong().size(15.0));
Expand Down Expand Up @@ -317,7 +317,7 @@ impl eframe::App for App {
egui::collapsing_header::CollapsingState::load_with_default_open(
ui.ctx(),
id,
true, //debug: set default to false (this is for testing)
false,
)
.show_header(ui, |ui| {
if ui
Expand Down Expand Up @@ -354,16 +354,13 @@ impl eframe::App for App {
}
)
));

// debug: remove label
ui.label(format!("Sampling points: {:?}", self.stack_sampling_points))
});

let id = ui.make_persistent_id("viewport_options_collapsable");
egui::collapsing_header::CollapsingState::load_with_default_open(
ui.ctx(),
id,
false, //debug: true
true,
)
.show_header(ui, |ui| {
ui.label(egui::RichText::new("Viewport").strong().size(15.0));
Expand Down Expand Up @@ -421,6 +418,8 @@ impl eframe::App for App {
&mut self.sampling_points_compute_once,
self.sampling_points_compute_auto,
&mut self.sampling_points_is_outdated,
&mut self.parameters_current_layer_is_outdated,
&mut self.parameters_all_layers_is_outdated,
self.layer_lowest,
self.layer_highest,
);
Expand Down
24 changes: 24 additions & 0 deletions src/app/colors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ pub const COLOR_LIME: Color32 = Color32::from_rgb(0, 255, 47);
// "Active object" color (lime)
pub const COLOR_DARK_GREEN: Color32 = Color32::from_rgb(6, 137, 30);
// Slightly decreased HSL saturation, decreased saturation from Lime
pub const COLOR_DARK_BLUE: Color32 = Color32::from_rgb(23, 143, 176);
pub const COLOR_LIGHT_BLUE: Color32 = Color32::from_rgb(0, 217, 255);
// "Object selected" color (light blue)
pub const COLOR_ORANGE: Color32 = Color32::from_rgb(255, 133, 0);
Expand All @@ -27,3 +28,26 @@ pub const COLOR_X_AXIS: Color32 = Color32::from_rgb(123, 34, 34);
// x-axis color (red)
pub const COLOR_Y_AXIS: Color32 = Color32::from_rgb(44, 107, 44);
// y-axis color (green)

/// convex combination in RGB
pub fn linear_gradient(color_a: Color32, color_b: Color32, t: f64) -> Color32 {
if t < 0.0 {
color_a
} else if t > 1.0 {
color_b
} else {
Color32::from_rgb(
((1.0 - t) * color_a.r() as f64 + t * color_b.r() as f64) as u8,
((1.0 - t) * color_a.g() as f64 + t * color_b.g() as f64) as u8,
((1.0 - t) * color_a.b() as f64 + t * color_b.b() as f64) as u8,
)
}
}

pub fn bilinear_gradient(color_a: Color32, color_b: Color32, color_c: Color32, t: f64) -> Color32 {
if t < 0.5 {
linear_gradient(color_a, color_b, 2.0 * t)
} else {
linear_gradient(color_b, color_c, 2.0 * t - 1.0)
}
}
1 change: 0 additions & 1 deletion src/app/ui_options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ pub fn ui_options(
// Select algorithm
egui::ComboBox::from_label("Algorithm")
.selected_text(format!("{:}", current_layer_config.algorithm))
// TODO: change formatting to text
// TODO: easily change algorithm for all layers
.show_ui(ui, |ui| {
ui.selectable_value(
Expand Down
27 changes: 15 additions & 12 deletions src/app/ui_viewport.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::app::colors::{
COLOR_BACKGROUND, COLOR_DARK_GREEN, COLOR_DARK_ORANGE, COLOR_FACE, COLOR_LIGHT_BLUE,
COLOR_LIME, COLOR_MUTED_ORANGE, COLOR_ORANGE, COLOR_PURPLE, COLOR_WIRE, COLOR_X_AXIS,
COLOR_YELLOW, COLOR_Y_AXIS,
linear_gradient, COLOR_BACKGROUND, COLOR_DARK_BLUE, COLOR_DARK_GREEN, COLOR_DARK_ORANGE,
COLOR_FACE, COLOR_LIGHT_BLUE, COLOR_LIME, COLOR_MUTED_ORANGE, COLOR_ORANGE, COLOR_PURPLE,
COLOR_WIRE, COLOR_X_AXIS, COLOR_YELLOW, COLOR_Y_AXIS,
};
use crate::app::data_structures::blocks::Blocks;
use crate::app::data_structures::layer_config::LayerConfig;
Expand Down Expand Up @@ -144,19 +144,22 @@ pub fn ui_viewport(
}

// Plot onion skinned samples
// todo: gradient for onionskin
if sampling_enabled {
for sampled_parameter in sampled_parameters.parameters.iter() {
for i in 0..sampled_parameters.nr_samples {
plot_ui.line(
plotting::superellipse_at_coords(
sampled_parameter[0],
sampled_parameter[1],
sampled_parameter[2],
sampled_parameter[3],
sampled_parameter[4],
sampled_parameter[5],
sampled_parameters.parameters[i][0],
sampled_parameters.parameters[i][1],
sampled_parameters.parameters[i][2],
sampled_parameters.parameters[i][3],
sampled_parameters.parameters[i][4],
sampled_parameters.parameters[i][5],
)
.color(COLOR_DARK_GREEN),
.color(linear_gradient(
COLOR_DARK_GREEN,
COLOR_DARK_BLUE,
i as f64 / (sampled_parameters.nr_samples as f64 - 1.0),
)),
);
}
}
Expand Down
7 changes: 7 additions & 0 deletions src/app/update_logic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ pub fn sampling_points_update(
sampling_points_compute_auto: bool,
sampling_points_is_outdated: &mut bool,

parameters_current_layer_is_outdated: &mut bool,
parameters_all_layers_is_outdated_is_outdated: &mut bool,

layer_lowest: isize,
layer_highest: isize,
) {
Expand All @@ -30,6 +33,10 @@ pub fn sampling_points_update(
*sampling_points_compute_once = false;
*sampling_points_is_outdated = false;

// if the sampling points have changed the parameters become outdated
*parameters_current_layer_is_outdated = true;
*parameters_all_layers_is_outdated_is_outdated = true;

*stack_sampling_points = crate::app::sampling::determine_sampling_points(
sample_distribute_method,
layer_lowest,
Expand Down

0 comments on commit d7e156d

Please sign in to comment.