mirror of
https://github.com/storytold/artcraft.git
synced 2026-11-03 17:08:13 +00:00
This segfaults at runtime, but I think pieces are in place
This commit is contained in:
1 parent
a111e8653a
commit
5f6237d03e
5 files changed
+108
-19
No files matched your search
+29
-6
@@ -17,12 +17,14 @@ use glutin::window::WindowBuilder;
|
||||
use glutin::ContextBuilder;
|
||||
use std::mem::size_of;
|
||||
use std::ptr::null;
|
||||
use glium::framebuffer::ColorAttachment::Texture;
|
||||
//use glium::framebuffer::ColorAttachment::Texture;
|
||||
use std::sync::Arc;
|
||||
use sensor_control::CaptureProvider;
|
||||
use point_cloud;
|
||||
use point_cloud::point_cloud_compute_shader::PointCloudComputeShader;
|
||||
use point_cloud::point_cloud_renderer_shader::PointCloudRendererShader;
|
||||
use point_cloud::point_cloud_visualiser::PointCloudVisualizer;
|
||||
use point_cloud::viewer_image::ViewerImage;
|
||||
|
||||
//use shader::Shader;
|
||||
|
||||
@@ -107,7 +109,7 @@ static TEXTURE_CHECKERBOARD : [GLfloat; 12] = [
|
||||
1.0, 1.0, 1.0, 0.0, 0.0, 0.0,
|
||||
];
|
||||
|
||||
pub fn run(capture_provider: Arc<CaptureProvider>) {
|
||||
pub fn run(capture_provider: Arc<CaptureProvider>, calibration_data: k4a_sys::k4a_calibration_t) {
|
||||
let event_loop = EventLoop::new();
|
||||
let window = WindowBuilder::new();
|
||||
let gl_window = ContextBuilder::new()
|
||||
@@ -120,8 +122,18 @@ pub fn run(capture_provider: Arc<CaptureProvider>) {
|
||||
// Load the OpenGL function pointers
|
||||
gl::load_with(|symbol| gl_window.get_proc_address(symbol));
|
||||
|
||||
let compute_shader = PointCloudComputeShader::new();
|
||||
let render_shader = PointCloudRendererShader::new();
|
||||
// TODO
|
||||
// k4a::calibration calib = m_device.get_calibration(m_config.DepthMode, m_config.ColorResolution);
|
||||
|
||||
let mut visualizer = PointCloudVisualizer::new(false, calibration_data);
|
||||
// TODO - constructed in PointCloudWindow.
|
||||
/*
|
||||
// TODO GLenum initResult = m_pointCloudVisualizer.InitializeTexture(&m_texture);
|
||||
if (initResult != GL_NO_ERROR)
|
||||
{
|
||||
CheckVisualizationResult(PointCloudVisualizationResult::OpenGlError);
|
||||
}
|
||||
*/
|
||||
|
||||
// Create GLSL shaders
|
||||
let vs = compile_shader(VERTEX_SHADER_SRC, gl::VERTEX_SHADER);
|
||||
@@ -257,6 +269,14 @@ pub fn run(capture_provider: Arc<CaptureProvider>) {
|
||||
gl::Uniform3f(triangle_color_attr, 1.0, 0.0, 1.0);
|
||||
}
|
||||
|
||||
|
||||
let mut texture = ViewerImage::create(
|
||||
800,
|
||||
800,
|
||||
None,
|
||||
None
|
||||
).expect("ViewerImage texture creation should work");
|
||||
|
||||
event_loop.run(move |event, window, control_flow| {
|
||||
//*control_flow = ControlFlow::Wait;
|
||||
match event {
|
||||
@@ -297,7 +317,7 @@ pub fn run(capture_provider: Arc<CaptureProvider>) {
|
||||
|
||||
// TODO: This belongs in a worker thread with buffers on both producer and consumer.
|
||||
if let Some(capture) = capture_provider.get_capture() {
|
||||
if let Ok(image) = capture.get_color_image() {
|
||||
/*if let Ok(image) = capture.get_color_image() {
|
||||
let width = image.get_width_pixels() as i32;
|
||||
let height = image.get_height_pixels() as i32;
|
||||
println!("Size: {}x{}", width, height);
|
||||
@@ -332,7 +352,10 @@ pub fn run(capture_provider: Arc<CaptureProvider>) {
|
||||
);
|
||||
}
|
||||
gl_window.swap_buffers().unwrap();
|
||||
}
|
||||
}*/
|
||||
|
||||
visualizer.update_texture(&texture, &capture);
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
+56
-2
@@ -9,6 +9,7 @@ use k4a_sys;
|
||||
use k4a_sys_wrapper::ImageFormat::ColorMjpg;
|
||||
use glutin::platform::unix::x11::ffi::IconMaskHint;
|
||||
use std::ptr::null_mut;
|
||||
use std::mem::MaybeUninit;
|
||||
|
||||
pub fn device_get_installed_count() -> u32 {
|
||||
unsafe {
|
||||
@@ -136,8 +137,6 @@ impl Device {
|
||||
pub fn get_capture_buffered(&self, capture_buffer: &mut k4a_sys::k4a_capture_t, timeout_ms: i32)
|
||||
-> Result<(), GetCaptureError>
|
||||
{
|
||||
let timeout_millis = 1000;
|
||||
|
||||
let result = unsafe {
|
||||
k4a_sys::k4a_device_get_capture(self.device_pointer, capture_buffer, timeout_ms)
|
||||
};
|
||||
@@ -157,6 +156,50 @@ impl Device {
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Get the camera calibration for the entire Azure Kinect device.
|
||||
///
|
||||
/// The calibration represents the data needed to transform between the camera views and may be
|
||||
/// different for each operating depth_mode and color_resolution the device is configured to
|
||||
/// operate in.
|
||||
/// The calibration output is used as input to all calibration and transformation functions.
|
||||
pub fn get_calibration(&self,
|
||||
depth_mode: k4a_sys::k4a_depth_mode_t,
|
||||
color_resolution: k4a_sys::k4a_color_resolution_t)
|
||||
-> Result<k4a_sys::k4a_calibration_t, GetCalibrationError>
|
||||
{
|
||||
// TODO: Why isn't the way I've been using to init structures before still working?
|
||||
//let mut calibration_buffer: k4a_sys::k4a_calibration_t = ptr::null_mut();
|
||||
/*let mut calibration_buffer: k4a_sys::k4a_calibration_t = k4a_sys::k4a_calibration_t {
|
||||
color_camera_calibration: 0,
|
||||
color_resolution: 0,
|
||||
depth_camera_calibration: 0,
|
||||
depth_mode: 0,
|
||||
extrinsics: [0,0,0,0],
|
||||
};*/
|
||||
|
||||
unsafe {
|
||||
let mut calibration_buffer = MaybeUninit::uninit();
|
||||
let result = k4a_sys::k4a_device_get_calibration(
|
||||
self.device_pointer,
|
||||
depth_mode,
|
||||
color_resolution,
|
||||
calibration_buffer.as_mut_ptr(),
|
||||
);
|
||||
|
||||
match result {
|
||||
k4a_sys::k4a_result_t_K4A_RESULT_SUCCEEDED => { /* ok, continue */ },
|
||||
k4a_sys::k4a_result_t_K4A_RESULT_FAILED => {
|
||||
return Err(GetCalibrationError::FailedError);
|
||||
},
|
||||
_ => {
|
||||
return Err(GetCalibrationError::UnknownError(result));
|
||||
},
|
||||
}
|
||||
|
||||
Ok(calibration_buffer.assume_init())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Errors for GetCapture
|
||||
@@ -172,6 +215,14 @@ pub enum CaptureError {
|
||||
NullCapture,
|
||||
}
|
||||
|
||||
/// Errors for GetCalibration
|
||||
#[derive(Debug)]
|
||||
pub enum GetCalibrationError {
|
||||
FailedError,
|
||||
UnknownError(u32),
|
||||
}
|
||||
|
||||
|
||||
/// Adapted from k4a-sys. Represents a capture.
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Capture(pub k4a_sys::k4a_capture_t);
|
||||
@@ -231,6 +282,9 @@ impl Drop for Capture {
|
||||
/// https://users.rust-lang.org/t/solved-how-to-move-non-send-between-threads-or-an-alternative/19928/11
|
||||
unsafe impl Send for Capture{}
|
||||
|
||||
/// TODO: We also need to send device
|
||||
unsafe impl Send for Device{}
|
||||
|
||||
/// Adapted from k4a-sys. Represents an image within a capture.
|
||||
#[derive(Debug)]
|
||||
pub struct Image(pub k4a_sys::k4a_image_t);
|
||||
|
||||
+9
-2
@@ -62,11 +62,18 @@ pub mod sensor_control;
|
||||
pub mod point_cloud;
|
||||
|
||||
pub fn main() {
|
||||
let device = Device::open(0).expect("Device should open");
|
||||
|
||||
let depth_mode : k4a_sys::k4a_depth_mode_t = 2; //k4a_sys::K4A_DEPTH_MODE_NFOV_UNBINNED;
|
||||
let color_format: k4a_sys::k4a_color_resolution_t = 1; //k4a_sys::K4A_COLOR_RESOLUTION_720P;
|
||||
let calibration = device.get_calibration(depth_mode, color_format).unwrap();
|
||||
|
||||
let capture_provider = Arc::new(CaptureProvider::new());
|
||||
let capture_provider2= capture_provider.clone();
|
||||
thread::spawn(move || capture_thread(capture_provider));
|
||||
|
||||
thread::spawn(move || capture_thread(capture_provider, Some(device)));
|
||||
|
||||
//graphics_grr::run(capture_provider2).unwrap();
|
||||
//graphics_glium::run_glium();
|
||||
graphics_gl::run(capture_provider2);
|
||||
graphics_gl::run(capture_provider2, calibration);
|
||||
}
|
||||
@@ -79,7 +79,7 @@ impl ViewerImage {
|
||||
pub fn create(
|
||||
width: u32,
|
||||
height: u32,
|
||||
data: &[uint8_t],
|
||||
//data: &[uint8_t],
|
||||
format: Option<GLenum>,
|
||||
internal_format: Option<GLenum>) -> Result<Self>
|
||||
{
|
||||
@@ -105,9 +105,9 @@ impl ViewerImage {
|
||||
);
|
||||
}
|
||||
|
||||
unsafe {
|
||||
/*unsafe {
|
||||
viewer_image.update_texture(data)?;
|
||||
}
|
||||
}*/
|
||||
|
||||
if let Err(err) = gl_get_error() {
|
||||
return Err(ViewerImageError::OpenGlError(err));
|
||||
|
||||
+11
-6
@@ -70,12 +70,18 @@ impl CaptureProvider {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn capture_thread(capture_provider: Arc<CaptureProvider>) {
|
||||
let installed_devices = device_get_installed_count();
|
||||
println!("Installed devices: {}", installed_devices);
|
||||
pub fn capture_thread(capture_provider: Arc<CaptureProvider>, device: Option<Device>) {
|
||||
let device = match device {
|
||||
Some(device) => device,
|
||||
None => {
|
||||
let installed_devices = device_get_installed_count();
|
||||
println!("Installed devices: {}", installed_devices);
|
||||
|
||||
let device = Device::open(0).unwrap();
|
||||
println!("Device: {:?}", device);
|
||||
let device = Device::open(0).unwrap();
|
||||
println!("Device: {:?}", device);
|
||||
device
|
||||
},
|
||||
};
|
||||
|
||||
let serial_number = device.get_serial_number().unwrap();
|
||||
println!("Device: {:?}", serial_number);
|
||||
@@ -91,7 +97,6 @@ pub fn capture_thread(capture_provider: Arc<CaptureProvider>) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
pub fn capture_thread_to_texture(frame: Arc<Mutex<Option<TextureData2d>>>) {
|
||||
let installed_devices = device_get_installed_count();
|
||||
println!("Installed devices: {}", installed_devices);
|
||||
|
||||
Reference in new issue
Block a user