Skip to content

Commit

Permalink
feat: 2d views and other viewer tweaks (#19)
Browse files Browse the repository at this point in the history
  • Loading branch information
strasdat authored Jun 3, 2024
1 parent ab2316e commit 237ee0a
Show file tree
Hide file tree
Showing 40 changed files with 2,347 additions and 1,222 deletions.
21 changes: 11 additions & 10 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,17 @@ include = [
keywords = ["robotics", "optimization"]
license = "MIT OR Apache-2.0"
repository = "https://github.com/farm-ng/sophus-rs/"
version = "0.6.0"
version = "0.6.1"

[workspace.dependencies]
sophus = {path = "crates/sophus", version = "0.6.0"}
sophus_core = {path = "crates/sophus_core", version = "0.6.0"}
sophus_image = {path = "crates/sophus_image", version = "0.6.0"}
sophus_lie = {path = "crates/sophus_lie", version = "0.6.0"}
sophus_opt = {path = "crates/sophus_opt", version = "0.6.0"}
sophus_pyo3 = {path = "crates/sophus_pyo3", version = "0.6.0"}
sophus_sensor = {path = "crates/sophus_sensor", version = "0.6.0"}
sophus_viewer = {path = "crates/sophus_viewer", version = "0.6.0"}
sophus = {path = "crates/sophus", version = "0.6.1"}
sophus_core = {path = "crates/sophus_core", version = "0.6.1"}
sophus_image = {path = "crates/sophus_image", version = "0.6.1"}
sophus_lie = {path = "crates/sophus_lie", version = "0.6.1"}
sophus_opt = {path = "crates/sophus_opt", version = "0.6.1"}
sophus_pyo3 = {path = "crates/sophus_pyo3", version = "0.6.1"}
sophus_sensor = {path = "crates/sophus_sensor", version = "0.6.1"}
sophus_viewer = {path = "crates/sophus_viewer", version = "0.6.1"}

approx = "0.5"
as-any = "0.3"
Expand All @@ -43,13 +43,14 @@ dyn-clone = "1.0"
eframe = {version = "0.27", features = ["wgpu"]}
egui_extras = "0.27"
env_logger = "0.11"
faer = "0.18"
faer = "0.19"
hollywood = {version = "0.7.0"}
image = {version = "0.25", features = [
"jpeg",
"png",
"tiff",
]}
linked-hash-map = "0.5"
log = "0.4"
nalgebra = {version = "0.32", features = ["rand"]}
ndarray = {version = "0.15", features = ["approx-0_5"]}
Expand Down
79 changes: 48 additions & 31 deletions crates/sophus/examples/pose_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,22 @@ use sophus::viewer::actor::run_viewer_on_main_thread;
use sophus::viewer::actor::ViewerBuilder;
use sophus::viewer::actor::ViewerCamera;
use sophus::viewer::actor::ViewerConfig;
use sophus::viewer::renderable::*;
use sophus::viewer::scene_renderer::interaction::WgpuClippingPlanes;
use sophus::viewer::SimpleViewer;
use sophus::viewer::renderables::*;
use sophus_core::linalg::VecF64;
use sophus_image::ImageSize;
use sophus_lie::Isometry2;
use sophus_lie::Isometry3;
use sophus_sensor::camera_enum::perspective_camera::PerspectiveCameraEnum;
use sophus_sensor::dyn_camera::DynCamera;
use sophus_sensor::KannalaBrandtCamera;
use sophus_viewer::interactions::WgpuClippingPlanes;
use sophus_viewer::simple_viewer::SimpleViewer;

use crate::color::Color;
use crate::renderable3d::Line3;
use crate::renderable3d::Lines3;
use crate::renderable3d::Renderable3d;
use crate::renderable3d::View3dPacket;

#[actor(ContentGeneratorMessage, NullInRequestMessage)]
type ContentGenerator = Actor<
Expand Down Expand Up @@ -50,7 +56,7 @@ pub struct ContentGeneratorState {}
#[actor_outputs]
pub struct ContentGeneratorOutbound {
/// curves
pub packets: OutboundChannel<Stream<Vec<Renderable>>>,
pub packets: OutboundChannel<Stream<Packets>>,
}

fn make_axes(world_from_local_poses: Vec<Isometry2<f64, 1>>) -> Vec<Line3> {
Expand Down Expand Up @@ -105,18 +111,50 @@ impl HasOnMessage for ContentGeneratorMessage {
ContentGeneratorMessage::ClockTick(_time_in_seconds) => {
let pose_graph = PoseCircleProblem::new(25);

let renderables = vec![
Renderable::Lines3(Lines3 {
// Camera / view pose parameters
let intrinsics = KannalaBrandtCamera::<f64, 1>::new(
&VecF64::<8>::from_array([600.0, 600.0, 320.0, 240.0, 0.0, 0.0, 0.0, 0.0]),
ImageSize {
width: 640,
height: 480,
},
);
let scene_from_camera = Isometry3::from_t(&VecF64::<3>::new(0.0, 0.0, -50.0));
let clipping_planes = WgpuClippingPlanes {
near: 0.1,
far: 1000.0,
};

let initial_camera = ViewerCamera {
intrinsics: DynCamera::<f64, 1>::from_model(
PerspectiveCameraEnum::KannalaBrandt(intrinsics),
),
clipping_planes,
scene_from_camera,
};

let mut packet = View3dPacket {
view_label: "view0".to_owned(),
renderables3d: vec![],
initial_camera,
};

packet.renderables3d = vec![
Renderable3d::Lines3(Lines3 {
name: "true".into(),
lines: make_axes(pose_graph.true_world_from_robot.clone()),
}),
Renderable::Lines3(Lines3 {
Renderable3d::Lines3(Lines3 {
name: "est".into(),
lines: make_axes(pose_graph.est_world_from_robot.clone()),
}),
];

outbound.packets.send(Stream { msg: renderables });
outbound.packets.send(Stream {
msg: Packets {
packets: vec![Packet::View3d(packet)],
},
});
}
}
}
Expand All @@ -129,28 +167,7 @@ impl IsInboundMessageNew<f64> for ContentGeneratorMessage {
}

pub async fn run_viewer_example() {
// Camera / view pose parameters
let intrinsics = KannalaBrandtCamera::<f64, 1>::new(
&VecF64::<8>::from_array([600.0, 600.0, 320.0, 240.0, 0.0, 0.0, 0.0, 0.0]),
ImageSize {
width: 640,
height: 480,
},
);
let scene_from_camera = Isometry3::from_t(&VecF64::<3>::new(0.0, 0.0, -50.0));
let clipping_planes = WgpuClippingPlanes {
near: 0.1,
far: 1000.0,
};
let camera = ViewerCamera {
intrinsics: DynCamera::<f64, 1>::from_model(PerspectiveCameraEnum::KannalaBrandt(
intrinsics,
)),
clipping_planes,
scene_from_camera,
};

let mut builder = ViewerBuilder::from_config(ViewerConfig { camera });
let mut builder = ViewerBuilder::from_config(ViewerConfig {});

// Pipeline configuration
let pipeline = Hollywood::configure(&mut |context| {
Expand All @@ -164,7 +181,7 @@ pub async fn run_viewer_example() {
ContentGeneratorState::default(),
);
// 3. The viewer actor
let mut viewer = EguiActor::<Vec<Renderable>, (), Isometry3<f64, 1>, (), ()>::from_builder(
let mut viewer = EguiActor::<Packets, String, Isometry3<f64, 1>, (), ()>::from_builder(
context, &builder,
);

Expand Down
Loading

0 comments on commit 237ee0a

Please sign in to comment.