Skip to content

Commit

Permalink
viewer in its own crate + intensity image tweaks (#18)
Browse files Browse the repository at this point in the history
Co-authored-by: strasdat <strasdat@localhost.localdomain>
  • Loading branch information
strasdat and strasdat authored May 26, 2024
1 parent bf3bb66 commit ab2316e
Show file tree
Hide file tree
Showing 43 changed files with 2,239 additions and 1,811 deletions.
54 changes: 28 additions & 26 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ members = [
"crates/sophus_image",
"crates/sophus_sensor",
"crates/sophus_opt",
"crates/sophus_viewer",
]
resolver = "2"

Expand All @@ -20,46 +21,47 @@ include = [
keywords = ["robotics", "optimization"]
license = "MIT OR Apache-2.0"
repository = "https://github.com/farm-ng/sophus-rs/"
version = "0.4.0"
version = "0.6.0"

[workspace.dependencies]
sophus = {path = "crates/sophus", version = "0.4.0"}
sophus_core = {path = "crates/sophus_core", version = "0.4.0"}
sophus_image = {path = "crates/sophus_image", version = "0.4.0"}
sophus_lie = {path = "crates/sophus_lie", version = "0.4.0"}
sophus_opt = {path = "crates/sophus_opt", version = "0.4.0"}
sophus_pyo3 = {path = "crates/sophus_pyo3", version = "0.4.0"}
sophus_sensor = {path = "crates/sophus_sensor", version = "0.4.0"}
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"}

approx = "0.5.1"
as-any = "0.3.1"
assertables = "7.0.1"
async-trait = "0.1.77"
bytemuck = {version = "1.14.0", features = ["derive"]}
concat-arrays = "0.1.2"
dyn-clone = "1.0.16"
eframe = {version = "0.26", features = ["wgpu"]}
egui_extras = "0.26"
approx = "0.5"
as-any = "0.3"
assertables = "7.0"
async-trait = "0.1"
bytemuck = {version = "1.14", features = ["derive"]}
concat-arrays = "0.1"
dyn-clone = "1.0"
eframe = {version = "0.27", features = ["wgpu"]}
egui_extras = "0.27"
env_logger = "0.11"
faer = "0.18"
hollywood = "0.5.0"
hollywood = {version = "0.7.0"}
image = {version = "0.25", features = [
"jpeg",
"png",
"tiff",
]}
log = "0.4.14"
log = "0.4"
nalgebra = {version = "0.32", features = ["rand"]}
ndarray = {version = "0.15.4", features = ["approx-0_5"]}
num-traits = "0.2.15"
ndarray = {version = "0.15", features = ["approx-0_5"]}
num-traits = "0.2"
numpy = "0.21"
png = "0.17.11"
rand = "0.8.5"
sleef = "0.3.2"
png = "0.17"
rand = "0.8"
sleef = "0.3"
tokio = {version = "1", features = ["full"]}
typenum = {version = "1.17.0", features = ["const-generics"]}
typenum = {version = "1.17", features = ["const-generics"]}
wgpu = "0.19"
winit = {version = "0.29", features = ["android-native-activity"]}
winit = {version = "0.30", features = ["android-native-activity"]}

[profile.release]
debug = 1
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# sophus-rs

highly experimental... use at your own risk
This library is in an early development stage - hence API is highly unstable.

Sophus-rs currently requires rust nightly. The only nightly feature it uses is `portable-simd`.
It is the intention to move to rust stable once `portable-simd` is stabilized. There is no current
plan to depend on other nightly features.
1 change: 1 addition & 0 deletions crates/sophus/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ sophus_lie.workspace = true
sophus_opt.workspace = true
sophus_pyo3.workspace = true
sophus_sensor.workspace = true
sophus_viewer.workspace = true

approx.workspace = true
assertables.workspace = true
Expand Down
31 changes: 19 additions & 12 deletions crates/sophus/examples/pose_graph.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
use hollywood::actors::egui::EguiActor;
use hollywood::actors::egui::Stream;
pub use hollywood::compute::Context;
pub use hollywood::core::*;
use hollywood::macros::*;
use hollywood::prelude::*;
use sophus::opt::example_problems::pose_circle::PoseCircleProblem;
use sophus::prelude::*;
use sophus::viewer::actor::run_viewer_on_main_thread;
Expand All @@ -20,18 +18,26 @@ use sophus_sensor::camera_enum::perspective_camera::PerspectiveCameraEnum;
use sophus_sensor::dyn_camera::DynCamera;
use sophus_sensor::KannalaBrandtCamera;

#[actor(ContentGeneratorMessage)]
#[actor(ContentGeneratorMessage, NullInRequestMessage)]
type ContentGenerator = Actor<
NullProp,
ContentGeneratorInbound,
NullInRequests,
ContentGeneratorState,
ContentGeneratorOutbound,
NullRequest,
NullOutRequests,
>;

/// Inbound message for the ContentGenerator actor.
#[derive(Clone, Debug)]
#[actor_inputs(ContentGeneratorInbound, {NullProp, ContentGeneratorState, ContentGeneratorOutbound, NullRequest})]
#[actor_inputs(
ContentGeneratorInbound,
{
NullProp,
ContentGeneratorState,
ContentGeneratorOutbound,
NullOutRequests,
NullInRequestMessage})]
pub enum ContentGeneratorMessage {
/// in seconds
ClockTick(f64),
Expand Down Expand Up @@ -86,14 +92,14 @@ fn make_axes(world_from_local_poses: Vec<Isometry2<f64, 1>>) -> Vec<Line3> {
lines
}

impl OnMessage for ContentGeneratorMessage {
impl HasOnMessage for ContentGeneratorMessage {
/// Process the inbound time_stamp message.
fn on_message(
self,
_prop: &Self::Prop,
_state: &mut Self::State,
outbound: &Self::OutboundHub,
_request: &NullRequest,
_request: &NullOutRequests,
) {
match &self {
ContentGeneratorMessage::ClockTick(_time_in_seconds) => {
Expand All @@ -116,7 +122,7 @@ impl OnMessage for ContentGeneratorMessage {
}
}

impl InboundMessageNew<f64> for ContentGeneratorMessage {
impl IsInboundMessageNew<f64> for ContentGeneratorMessage {
fn new(_inbound_name: String, msg: f64) -> Self {
ContentGeneratorMessage::ClockTick(msg)
}
Expand Down Expand Up @@ -147,7 +153,7 @@ pub async fn run_viewer_example() {
let mut builder = ViewerBuilder::from_config(ViewerConfig { camera });

// Pipeline configuration
let pipeline = hollywood::compute::Context::configure(&mut |context| {
let pipeline = Hollywood::configure(&mut |context| {
// Actor creation:
// 1. Periodic timer to drive the simulation
let mut timer = hollywood::actors::Periodic::new_with_period(context, 0.01);
Expand All @@ -158,8 +164,9 @@ pub async fn run_viewer_example() {
ContentGeneratorState::default(),
);
// 3. The viewer actor
let mut viewer =
EguiActor::<Vec<Renderable>, (), Isometry3<f64, 1>>::from_builder(context, &builder);
let mut viewer = EguiActor::<Vec<Renderable>, (), Isometry3<f64, 1>, (), ()>::from_builder(
context, &builder,
);

// Pipeline connections:
timer
Expand Down
54 changes: 30 additions & 24 deletions crates/sophus/examples/viewer_ex.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
use hollywood::actors::egui::EguiActor;
use hollywood::actors::egui::Stream;
pub use hollywood::compute::Context;
use hollywood::core::request::ReplyMessage;
use hollywood::core::request::RequestChannel;
pub use hollywood::core::request::RequestHub;
pub use hollywood::core::*;
use hollywood::macros::*;
use hollywood::prelude::*;
use nalgebra::SVector;
use sophus::image::arc_image::ArcImage4F32;
use sophus::image::ImageSize;
Expand All @@ -21,37 +16,47 @@ use sophus_core::linalg::VecF64;
use sophus_lie::Isometry3;
use sophus_sensor::DynCamera;

#[actor(ContentGeneratorMessage)]
#[actor(ContentGeneratorMessage, NullInRequestMessage)]
type ContentGenerator = Actor<
NullProp,
ContentGeneratorInbound,
NullInRequests,
ContentGeneratorState,
ContentGeneratorOutbound,
ContentGeneratorRequest,
ContentGeneratorOutRequest,
>;

/// Inbound message for the ContentGenerator actor.
#[derive(Clone, Debug)]
#[actor_inputs(ContentGeneratorInbound, {NullProp, ContentGeneratorState, ContentGeneratorOutbound, ContentGeneratorRequest})]
#[actor_inputs(
ContentGeneratorInbound,
{
NullProp,
ContentGeneratorState,
ContentGeneratorOutbound,
ContentGeneratorOutRequest,
NullInRequestMessage
})]
pub enum ContentGeneratorMessage {
/// in seconds
ClockTick(f64),
SceneFromCamera(ReplyMessage<Isometry3<f64, 1>>),
}

/// Request of the simulation actor.
pub struct ContentGeneratorRequest {
pub struct ContentGeneratorOutRequest {
/// Check time-stamp of receiver
pub scene_from_camera_request: RequestChannel<(), Isometry3<f64, 1>, ContentGeneratorMessage>,
pub scene_from_camera_request:
OutRequestChannel<(), Isometry3<f64, 1>, ContentGeneratorMessage>,
}

impl RequestHub<ContentGeneratorMessage> for ContentGeneratorRequest {
impl IsOutRequestHub<ContentGeneratorMessage> for ContentGeneratorOutRequest {
fn from_parent_and_sender(
actor_name: &str,
sender: &tokio::sync::mpsc::Sender<ContentGeneratorMessage>,
sender: &tokio::sync::mpsc::UnboundedSender<ContentGeneratorMessage>,
) -> Self {
Self {
scene_from_camera_request: RequestChannel::new(
scene_from_camera_request: OutRequestChannel::new(
actor_name.to_owned(),
"scene_from_camera_request",
sender,
Expand All @@ -60,7 +65,7 @@ impl RequestHub<ContentGeneratorMessage> for ContentGeneratorRequest {
}
}

impl Activate for ContentGeneratorRequest {
impl HasActivate for ContentGeneratorOutRequest {
fn extract(&mut self) -> Self {
Self {
scene_from_camera_request: self.scene_from_camera_request.extract(),
Expand Down Expand Up @@ -104,14 +109,14 @@ pub struct ContentGeneratorOutbound {
pub packets: OutboundChannel<Stream<Vec<Renderable>>>,
}

impl OnMessage for ContentGeneratorMessage {
impl HasOnMessage for ContentGeneratorMessage {
/// Process the inbound time_stamp message.
fn on_message(
self,
_prop: &Self::Prop,
state: &mut Self::State,
outbound: &Self::OutboundHub,
request: &ContentGeneratorRequest,
request: &ContentGeneratorOutRequest,
) {
match &self {
ContentGeneratorMessage::ClockTick(_time_in_seconds) => {
Expand Down Expand Up @@ -414,13 +419,13 @@ impl OnMessage for ContentGeneratorMessage {
}
}

impl InboundMessageNew<f64> for ContentGeneratorMessage {
impl IsInboundMessageNew<f64> for ContentGeneratorMessage {
fn new(_inbound_name: String, msg: f64) -> Self {
ContentGeneratorMessage::ClockTick(msg)
}
}

impl InboundMessageNew<ReplyMessage<Isometry3<f64, 1>>> for ContentGeneratorMessage {
impl IsInboundMessageNew<ReplyMessage<Isometry3<f64, 1>>> for ContentGeneratorMessage {
fn new(_inbound_name: String, scene_from_camera: ReplyMessage<Isometry3<f64, 1>>) -> Self {
ContentGeneratorMessage::SceneFromCamera(scene_from_camera)
}
Expand Down Expand Up @@ -449,7 +454,7 @@ pub async fn run_viewer_example() {
let mut builder = ViewerBuilder::from_config(ViewerConfig { camera });

// Pipeline configuration
let pipeline = hollywood::compute::Context::configure(&mut |context| {
let pipeline = Hollywood::configure(&mut |context| {
// Actor creation:
// 1. Periodic timer to drive the simulation
let mut timer = hollywood::actors::Periodic::new_with_period(context, 0.01);
Expand All @@ -465,8 +470,9 @@ pub async fn run_viewer_example() {
},
);
// 3. The viewer actor
let mut viewer =
EguiActor::<Vec<Renderable>, (), Isometry3<f64, 1>>::from_builder(context, &builder);
let mut viewer = EguiActor::<Vec<Renderable>, (), Isometry3<f64, 1>, (), ()>::from_builder(
context, &builder,
);

// Pipeline connections:
timer
Expand All @@ -478,9 +484,9 @@ pub async fn run_viewer_example() {
.packets
.connect(context, &mut viewer.inbound.stream);
content_generator
.request
.out_requests
.scene_from_camera_request
.connect(context, &mut viewer.inbound.request);
.connect(context, &mut viewer.in_requests.request);
});

// The cancel_requester is used to cancel the pipeline.
Expand Down
4 changes: 2 additions & 2 deletions crates/sophus/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ pub use sophus_image as image;
pub use sophus_lie as lie;
pub use sophus_opt as opt;
pub use sophus_sensor as sensor;

pub mod viewer;
pub use sophus_viewer as viewer;

pub use hollywood;
pub use nalgebra;

pub mod prelude {
pub use crate::core::prelude::*;
Expand Down
Loading

0 comments on commit ab2316e

Please sign in to comment.