Skip to content

Commit

Permalink
Display of flowfield
Browse files Browse the repository at this point in the history
  • Loading branch information
Masterchef365 committed Jun 11, 2024
1 parent 734ce22 commit 7530a6a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use flowfield_nd::{sweep_pointcloud, FlowField, FluidSolver, PointCloud, SolverC
use rand::Rng;
use threegui::Vec3;

use crate::{projection::{generate_axes, AxisProjection}, visualization::{compute_n_grid, draw_n_grid, draw_pcld, random_pcld_uniform}};
use crate::{projection::{generate_axes, AxisProjection}, visualization::{compute_n_grid, draw_flowfield_interp, draw_n_grid, draw_pcld, random_pcld_uniform}};

/// We derive Deserialize/Serialize so we can persist app state on shutdown.
//#[derive(serde::Deserialize, serde::Serialize)]
Expand Down Expand Up @@ -146,6 +146,8 @@ impl eframe::App for DemoApp {
draw_n_grid(&self.grid, paint, Stroke::new(1., Color32::from_gray(90)));
}

draw_flowfield_interp(paint, &self.proj, self.sim.get_flow(), 3.);

draw_pcld(&self.pcld, &self.proj, paint, 1., Color32::from_gray(180));
})
});
Expand Down
22 changes: 22 additions & 0 deletions src/visualization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,28 @@ pub fn compute_n_grid(
out
}

pub fn draw_flowfield_interp(
paint: &Painter3D,
proj: &dyn Projection,
ff: &FlowField,
scale: f32,
) {
for cell in combos(0, ff.width() as i32 - 2, 1, ff.dims()) {
let mut pos: Vec<f32> = cell.iter().map(|c| *c as f32).collect();
let interp = ff.n_linear_interp(&pos, flowfield_nd::Boundary::Zero).unwrap();

pos.iter_mut().for_each(|p| *p += 0.5);
let a = proj.project(&pos);

pos.iter_mut().zip(interp).for_each(|(p, i)| *p += i * scale);
let b = proj.project(&pos);

let color = Color32::RED;
paint.circle_filled(a, 2., color);
paint.line(a, b, Stroke::new(1., color));
}
}

pub fn draw_n_grid(
buf: &[(Vec3, Vec3)],
paint: &Painter3D,
Expand Down

0 comments on commit 7530a6a

Please sign in to comment.