Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unity wrapper #2063

Merged
merged 9 commits into from
Jul 16, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 92 additions & 0 deletions wrappers/csharp/Intel.RealSense/Device.cs
Original file line number Diff line number Diff line change
Expand Up @@ -208,4 +208,96 @@ public string JsonConfiguration
}
}

public class PlaybackDevice : Device
{
internal PlaybackDevice(IntPtr dev) : base(dev)
{

}

public static PlaybackDevice FromDevice(Device dev)
{
object error;
if (NativeMethods.rs2_is_device_extendable_to(dev.m_instance, Extension.Playback, out error) == 0)
{
throw new ArgumentException("Device does not support Playback");
}

return new PlaybackDevice(dev.m_instance);
}

public void Pause()
{
object error;
NativeMethods.rs2_playback_device_pause(m_instance, out error);
}

public void Resume()
{
object error;
NativeMethods.rs2_playback_device_resume(m_instance, out error);
}

public PlaybackStatus Status
{
get
{
object error;
return NativeMethods.rs2_playback_device_get_current_status(m_instance, out error);
}
}

public ulong Duration
{
get
{
object error;
return NativeMethods.rs2_playback_get_duration(m_instance, out error);
}
}

public ulong Position
{
get
{
object error;
return NativeMethods.rs2_playback_get_position(m_instance, out error);
}
set
{
object error;
NativeMethods.rs2_playback_seek(m_instance, (long)value, out error);
}
}

public void Seek(long time)
{
object error;
NativeMethods.rs2_playback_seek(m_instance, time, out error);
}

public bool Realtime
{
get
{
object error;
return NativeMethods.rs2_playback_device_is_real_time(m_instance, out error) != 0;
}
set
{
object error;
NativeMethods.rs2_playback_device_set_real_time(m_instance, value ? 1 : 0, out error);
}
}

public float Speed
{
set
{
object error;
NativeMethods.rs2_playback_device_set_playback_speed(m_instance, value, out error);
}
}
}

}
4 changes: 2 additions & 2 deletions wrappers/csharp/Intel.RealSense/Frame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ public int Count
}
}

private IntPtr VertexData
public IntPtr VertexData
{
get
{
Expand Down Expand Up @@ -252,7 +252,7 @@ public void CopyTo(Vertex[] array)
}
}

private IntPtr TextureData
public IntPtr TextureData
{
get
{
Expand Down
56 changes: 33 additions & 23 deletions wrappers/csharp/Intel.RealSense/FrameSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
using System.Collections;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Linq;

namespace Intel.RealSense
{
public class FrameSet : IDisposable, IEnumerable<Frame>
{
internal HandleRef m_instance;
readonly int m_count;

public Frame AsFrame()
{
Expand Down Expand Up @@ -42,40 +42,37 @@ internal static Frame CreateFrame(IntPtr ptr)
return new Frame(ptr);
}

public T FirstOrDefault<T>(Stream stream) where T : Frame
{
foreach (Frame frame in this)
{
if (frame.Profile.Stream == stream)
return frame as T;
frame.Dispose();
}
return null;
}

public DepthFrame DepthFrame
{
get
{
foreach(var frame in this)
{
if (frame.Profile.Stream == Stream.Depth)
return frame as DepthFrame;
frame.Dispose();
}
return null;
return FirstOrDefault<DepthFrame>(Stream.Depth);
}
}

public VideoFrame ColorFrame
{
get
{
foreach (var frame in this)
{
if (frame.Profile.Stream == Stream.Color)
return frame as VideoFrame;
frame.Dispose();
}
return null;
return FirstOrDefault<VideoFrame>(Stream.Color);
}
}

public IEnumerator<Frame> GetEnumerator()
{
object error;

int deviceCount = NativeMethods.rs2_embedded_frames_count(m_instance.Handle, out error);
for (int i = 0; i < deviceCount; i++)
for (int i = 0; i < m_count; i++)
{
var ptr = NativeMethods.rs2_extract_frame(m_instance.Handle, i, out error);
yield return CreateFrame(ptr);
Expand All @@ -91,9 +88,7 @@ public int Count
{
get
{
object error;
int deviceCount = NativeMethods.rs2_embedded_frames_count(m_instance.Handle, out error);
return deviceCount;
return m_count;
}
}

Expand All @@ -107,9 +102,26 @@ public Frame this[int index]
}
}

public Frame this[Stream stream, int index = 0]
{
get
{
foreach (Frame frame in this)
{
var p = frame.Profile;
if (p.Stream == stream && p.Index == index)
return frame;
frame.Dispose();
}
return null;
}
}

internal FrameSet(IntPtr ptr)
{
m_instance = new HandleRef(this, ptr);
object error;
m_count = NativeMethods.rs2_embedded_frames_count(m_instance.Handle, out error);
}

#region IDisposable Support
Expand Down Expand Up @@ -154,10 +166,8 @@ public void Release()
NativeMethods.rs2_release_frame(m_instance.Handle);
m_instance = new HandleRef(this, IntPtr.Zero);
}

}


class FrameSetMarshaler : ICustomMarshaler
{
private static FrameSetMarshaler Instance;
Expand Down
8 changes: 6 additions & 2 deletions wrappers/csharp/Intel.RealSense/Pipeline.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
using System.Runtime.InteropServices;
using System.Linq;

namespace Intel.RealSense
{
Expand Down Expand Up @@ -138,7 +137,12 @@ public StreamProfileList Streams

public StreamProfile GetStream(Stream s, int index = -1)
{
return Streams.First(x => x.Stream == s && (index != -1 ? x.Index == index : true));
foreach(var x in Streams)
{
if (x.Stream == s && (index != -1 ? x.Index == index : true))
return x;
}
return null;
}

#region IDisposable Support
Expand Down
24 changes: 8 additions & 16 deletions wrappers/csharp/Intel.RealSense/Processing.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ public Colorizer()
{
object error;
m_instance = new HandleRef(this, NativeMethods.rs2_create_colorizer(out error));
queue = new FrameQueue();
NativeMethods.rs2_start_processing_queue(m_instance.Handle, queue.m_instance.Handle, out error);
}

Expand All @@ -79,7 +78,7 @@ public VideoFrame Colorize(VideoFrame original, FramesReleaser releaser = null)
return FramesReleaser.ScopedReturn(releaser, queue.WaitForFrame() as VideoFrame);
}

FrameQueue queue;
readonly FrameQueue queue = new FrameQueue(1);
}

public class Align : ProcessingBlock
Expand All @@ -88,7 +87,6 @@ public Align(Stream align_to)
{
object error;
m_instance = new HandleRef(this, NativeMethods.rs2_create_align(align_to, out error));
queue = new FrameQueue();
NativeMethods.rs2_start_processing_queue(m_instance.Handle, queue.m_instance.Handle, out error);
}

Expand All @@ -100,7 +98,7 @@ public FrameSet Process(FrameSet original, FramesReleaser releaser = null)
return FramesReleaser.ScopedReturn(releaser, queue.WaitForFrames() as FrameSet);
}

FrameQueue queue;
readonly FrameQueue queue = new FrameQueue(1);
}

public class DisparityTransform : ProcessingBlock
Expand All @@ -110,7 +108,6 @@ public DisparityTransform(bool transform_to_disparity = true)
object error;
byte transform_direction = transform_to_disparity ? (byte)1 : (byte)0;
m_instance = new HandleRef(this, NativeMethods.rs2_create_disparity_transform_block(transform_direction, out error));
queue = new FrameQueue();
NativeMethods.rs2_start_processing_queue(m_instance.Handle, queue.m_instance.Handle, out error);
}

Expand All @@ -122,7 +119,7 @@ public VideoFrame ApplyFilter(VideoFrame original, FramesReleaser releaser = nul
return FramesReleaser.ScopedReturn(releaser, queue.WaitForFrame() as VideoFrame);
}

FrameQueue queue;
readonly FrameQueue queue = new FrameQueue(1);
}

public class DecimationFilter : ProcessingBlock
Expand All @@ -131,7 +128,6 @@ public DecimationFilter()
{
object error;
m_instance = new HandleRef(this, NativeMethods.rs2_create_decimation_filter_block(out error));
queue = new FrameQueue();
NativeMethods.rs2_start_processing_queue(m_instance.Handle, queue.m_instance.Handle, out error);
}

Expand All @@ -143,7 +139,7 @@ public VideoFrame ApplyFilter(VideoFrame original, FramesReleaser releaser = nul
return FramesReleaser.ScopedReturn(releaser, queue.WaitForFrame() as VideoFrame);
}

FrameQueue queue;
readonly FrameQueue queue = new FrameQueue(1);
}

public class SpatialFilter : ProcessingBlock
Expand All @@ -152,7 +148,6 @@ public SpatialFilter()
{
object error;
m_instance = new HandleRef(this, NativeMethods.rs2_create_spatial_filter_block(out error));
queue = new FrameQueue();
NativeMethods.rs2_start_processing_queue(m_instance.Handle, queue.m_instance.Handle, out error);
}

Expand All @@ -164,7 +159,7 @@ public VideoFrame ApplyFilter(VideoFrame original, FramesReleaser releaser = nul
return FramesReleaser.ScopedReturn(releaser, queue.WaitForFrame() as VideoFrame);
}

FrameQueue queue;
readonly FrameQueue queue = new FrameQueue(1);
}

public class TemporalFilter : ProcessingBlock
Expand All @@ -173,7 +168,6 @@ public TemporalFilter()
{
object error;
m_instance = new HandleRef(this, NativeMethods.rs2_create_temporal_filter_block(out error));
queue = new FrameQueue();
NativeMethods.rs2_start_processing_queue(m_instance.Handle, queue.m_instance.Handle, out error);
}

Expand All @@ -185,7 +179,7 @@ public VideoFrame ApplyFilter(VideoFrame original, FramesReleaser releaser = nul
return FramesReleaser.ScopedReturn(releaser, queue.WaitForFrame() as VideoFrame);
}

FrameQueue queue;
readonly FrameQueue queue = new FrameQueue(1);
}

public class HoleFillingFilter : ProcessingBlock
Expand All @@ -194,7 +188,6 @@ public HoleFillingFilter()
{
object error;
m_instance = new HandleRef(this, NativeMethods.rs2_create_hole_filling_filter_block(out error));
queue = new FrameQueue();
NativeMethods.rs2_start_processing_queue(m_instance.Handle, queue.m_instance.Handle, out error);
}

Expand All @@ -206,18 +199,17 @@ public VideoFrame ApplyFilter(VideoFrame original)
return queue.WaitForFrame() as VideoFrame;
}

FrameQueue queue;
readonly FrameQueue queue = new FrameQueue(1);
}

public class PointCloud : ProcessingBlock
{
FrameQueue queue;
readonly FrameQueue queue = new FrameQueue(1);

public PointCloud()
{
object error;
m_instance = new HandleRef(this, NativeMethods.rs2_create_pointcloud(out error));
queue = new FrameQueue();
NativeMethods.rs2_start_processing_queue(m_instance.Handle, queue.m_instance.Handle, out error);
}

Expand Down
Loading