Пример #1
0
        void OnSelected(object sender, EventArgs e)
        {
            var index = _list.IndexOf((IndexItem)sender);

            SelectedPosition?.Invoke(this, new SelectedPositionChangedEventArgs(index));
            UpdateSelectedIndex(index);
        }
Пример #2
0
        void OnSelected(object?sender, EventArgs e)
        {
            if (sender == null)
            {
                return;
            }
            int index = _list.IndexOf((IndexItem)sender);

            SelectedPosition?.Invoke(this, new SelectedPositionChangedEventArgs(index));
            UpdateSelectedIndex(index);
        }
Пример #3
0
        public AppModel()
        {
            var kinect = new AsyncKinectManager();

            ColorBitmap = kinect.Sensor
                          .ObserveOn(SynchronizationContext.Current)
                          .Select(sensor => sensor != null ? ColorBitmapInfo.CreateBitmap() : null)
                          .ToGetOnly(null);
            kinect.SensorConnected
            .Subscribe(sensor =>
            {
                sensor.ColorStream.Enable(ColorBitmapInfo.Format);
                sensor.DepthStream.Enable(DepthBitmapInfo.Format);

                try
                {
                    sensor.Start();
                }
                catch (Exception ex)
                {
                    // センサーが他のプロセスに既に使用されている場合に発生します。
                    Debug.WriteLine(ex);
                }
            });
            kinect.SensorDisconnected
            .Subscribe(sensor => sensor.Stop());
            kinect.Initialize();

            var frameData = Observable.Interval(FramesInterval)
                            .Select(_ => new
            {
                Sensor    = kinect.Sensor.Value,
                ColorData = kinect.Sensor.Value.GetColorData(FramesInterval),
                DepthData = kinect.Sensor.Value.GetDepthData(FramesInterval),
            })
                            .ToGetOnly(null);

            frameData
            .Where(_ => _.ColorData != null)
            .ObserveOn(SynchronizationContext.Current)
            .Subscribe(_ => ColorBitmapInfo.WritePixels(ColorBitmap.Value, _.ColorData));

            var colorDepthMap = frameData
                                .Where(_ => _.DepthData != null)
                                .Select(_ =>
            {
                var map = new DepthImagePoint[ColorBitmapInfo.PixelsCount];
                _.Sensor.CoordinateMapper.MapColorFrameToDepthFrame(ColorBitmapInfo.Format, DepthBitmapInfo.Format, _.DepthData, map);
                return(map);
            })
                                .ToGetOnly(new DepthImagePoint[ColorBitmapInfo.PixelsCount]);

            SelectedPosition = ObservableProperty.CreateSettable(new Point(ColorBitmapInfo.Width / 2, ColorBitmapInfo.Height / 2));

            SelectedDepth = ObservableProperty.CreateGetOnly(() =>
            {
                var depth = colorDepthMap.Value[PositionToPixelIndex(SelectedPosition.Value)].Depth;
                return(depth > 0 ? depth : default(int?));
            });
            colorDepthMap.Subscribe(SelectedDepth);
            SelectedPosition.Subscribe(SelectedDepth);
        }