diff --git a/Sources/Lib/ColorImageStream.cs b/Sources/Lib/ColorImageStream.cs
index 3a8a3f0..8bdd2a2 100644
--- a/Sources/Lib/ColorImageStream.cs
+++ b/Sources/Lib/ColorImageStream.cs
@@ -1,4 +1,5 @@
using Microsoft.Kinect;
+using System.ComponentModel;
using System.Windows;
using System.Windows.Media;
using System.Windows.Media.Imaging;
@@ -8,9 +9,20 @@ namespace Lib
public class ColorImageStream : KinectStream
{
private ColorFrameReader reader;
- public ColorImageStream(KinectSensor sensor) : base(sensor)
+ public ColorFrameReader Reader {
+ get {
+ return reader;
+ }
+ set
+ {
+ reader = value;
+ }
+ }
+ public ColorImageStream() : base()
{
- reader = sensor.ColorFrameSource.OpenReader();
+ var frameDescription = KinectManager.Sensor.ColorFrameSource.CreateFrameDescription(ColorImageFormat.Bgra);
+ this.Bitmap = new WriteableBitmap(frameDescription.Width, frameDescription.Height, 96.0, 96.0, PixelFormats.Bgr32, null);
+ reader = KinectManager.Sensor.ColorFrameSource.OpenReader();
reader.FrameArrived += Reader_FrameArrived;
}
diff --git a/Sources/Lib/KinectManager.cs b/Sources/Lib/KinectManager.cs
index f57ca47..bf9ce2b 100644
--- a/Sources/Lib/KinectManager.cs
+++ b/Sources/Lib/KinectManager.cs
@@ -6,24 +6,18 @@ namespace Lib
{
public class KinectManager : INotifyPropertyChanged
{
- private KinectStream currentStream;
- public KinectStream CurrentStream
- {
- get { return currentStream; }
+ private KinectSensor sensor;
+ public KinectSensor Sensor {
+ get {
+ return sensor;
+ }
set
{
- if (currentStream != value)
- {
- if (currentStream != null)
- {
- currentStream.Stop();
- }
- currentStream = value;
- currentStream.Start();
- OnPropertyChanged(nameof(CurrentStream));
- }
+ sensor = value;
+ OnPropertyChanged(nameof(Sensor));
}
}
+
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void OnPropertyChanged(string propertyName)
{
@@ -32,48 +26,38 @@ namespace Lib
public KinectManager()
{
- CurrentStream = new ColorImageStream(KinectSensor.GetDefault());
+ sensor = KinectSensor.GetDefault();
}
-
- public void ChangeToColorStream()
- {
- CurrentStream = new ColorImageStream(KinectSensor.GetDefault());
- }
- //public void ChangeToDepthStream()
- //{
- // KinectSensor sensor = KinectSensor.GetDefault();
- // CurrentStream = new DepthImageStream(sensor);
- //}
- //public void ChangeToInfraredStream()
- //{
- // KinectSensor sensor = KinectSensor.GetDefault();
- // CurrentStream = new InfraredImageStream(sensor);
- //}
public void StartSensor()
{
- currentStream.Start();
+ if (sensor != null) {
+ sensor.Open();
+ }
}
public void StopSensor()
{
- currentStream.Stop();
+ if (sensor != null)
+ {
+ sensor.Close();
+ }
}
public bool Status
{
- get { return currentStream.Sensor != null && currentStream.Sensor.IsAvailable; }
+ get { return Sensor != null && Sensor.IsAvailable; }
}
public string StatusText
{
get
{
- if (currentStream.Sensor == null)
+ if (Sensor == null)
{
return "Kinect n'est pas connecté";
}
- else if (!currentStream.Sensor.IsOpen)
+ else if (!Sensor.IsOpen)
{
return "Kinect n'est pas ouvert";
}
- else if (currentStream.Sensor.IsAvailable)
+ else if (Sensor.IsAvailable)
{
return "Kinect est disponible";
}
diff --git a/Sources/Lib/KinectStream.cs b/Sources/Lib/KinectStream.cs
index c88c8eb..61d2fdf 100644
--- a/Sources/Lib/KinectStream.cs
+++ b/Sources/Lib/KinectStream.cs
@@ -12,7 +12,7 @@ namespace Lib
{
public abstract class KinectStream : INotifyPropertyChanged
{
- public KinectSensor Sensor { get; protected set; }
+ public KinectManager KinectManager { get; private set; }
private WriteableBitmap bitmap;
public WriteableBitmap Bitmap
{
@@ -33,26 +33,19 @@ namespace Lib
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
-
- public KinectStream(KinectSensor sensor)
+ public KinectStream()
{
- Sensor = sensor;
- var frameDescription = sensor.ColorFrameSource.CreateFrameDescription(ColorImageFormat.Bgra);
- Bitmap = new WriteableBitmap(frameDescription.Width, frameDescription.Height, 96.0, 96.0, PixelFormats.Bgr32, null);
+ KinectManager = new KinectManager();
}
public virtual void Start()
{
- if (Sensor != null) {
- Sensor.Open();
- }
+ KinectManager.StartSensor();
}
public virtual void Stop()
{
- if (Sensor != null) {
- Sensor.Close();
- }
+ KinectManager.StopSensor();
}
}
}
diff --git a/Sources/WpfApp/MainWindow.xaml b/Sources/WpfApp/MainWindow.xaml
index 709437d..2418690 100644
--- a/Sources/WpfApp/MainWindow.xaml
+++ b/Sources/WpfApp/MainWindow.xaml
@@ -26,6 +26,6 @@
-
+
\ No newline at end of file
diff --git a/Sources/WpfApp/MainWindow.xaml.cs b/Sources/WpfApp/MainWindow.xaml.cs
index 7854ad6..3672720 100644
--- a/Sources/WpfApp/MainWindow.xaml.cs
+++ b/Sources/WpfApp/MainWindow.xaml.cs
@@ -23,29 +23,26 @@ namespace WpfApp
///
public partial class MainWindow : Window
{
- private KinectManager _kinectManager;
- public KinectManager kinectManager
+ private KinectStream _kinectStream;
+ public KinectStream KinectStream
{
- get { return _kinectManager; }
- set { _kinectManager = value; }
+ get { return _kinectStream; }
+ set { _kinectStream = value; }
}
public MainWindow()
{
InitializeComponent();
- kinectManager = new KinectManager();
- Debug.WriteLine(kinectManager.StatusText);
- kinectManager.ChangeToColorStream();
- Debug.WriteLine(kinectManager.StatusText);
- kinectManager.StartSensor();
- Debug.WriteLine(kinectManager.CurrentStream.Bitmap);
- Debug.WriteLine(kinectManager.StatusText);
- DataContext = this;
+ this.DataContext = this;
+ KinectStream = new ColorImageStream();
+ Debug.WriteLine(KinectStream.KinectManager.StatusText);
+ KinectStream.Start();
+ Debug.WriteLine(KinectStream.KinectManager.StatusText);
}
private void MainWindow_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
- Debug.WriteLine(kinectManager.StatusText);
- kinectManager.StopSensor();
+ Debug.WriteLine(KinectStream.KinectManager.StatusText);
+ KinectStream.Stop();
}
}
}