示例#1
0
        public AppModel()
        {
            // ストレージへの接続は非同期処理です。
            OutputCsvs        = ObservableProperty.CreateSettable(new string[0]);
            SelectedOutputCsv = ObservableProperty.CreateSettable <string>(null);
            Clusters          = SelectedOutputCsv.Select(GetColorClusters).ToGetOnly(null);

            OutputCsvs.Select(cs => cs.FirstOrDefault()).Subscribe(SelectedOutputCsv);

            Task.Run(() => OutputCsvs.Value = GetOutputCsvs());
        }
示例#2
0
        public AsyncKinectManager()
        {
            _Sensor = ObservableProperty.CreateSettable <KinectSensor>(null);
            Sensor  = _Sensor.ToGetOnlyMask();

            SensorDisconnected = _Sensor
                                 .Select(s => _sensorCache)
                                 .Where(s => s != null)
                                 .ToGetOnly(null, true);
            SensorConnected = _Sensor
                              .Do(s => _sensorCache = s)
                              .Where(s => s != null)
                              .ToGetOnly(null, true);
        }
示例#3
0
        public AppModel()
        {
            Position = ObservableProperty.CreateSettable(new Point());

            var client = EventHubClient.Create("sakapon-event-201508");

            var index = 0;

            Position
            .Select(p => new { index = index++, position = p.ToString() })
            .Select(o => JsonConvert.SerializeObject(o))
            .Do(m => Debug.WriteLine("Sending message. {0}", new[] { m }))
            .Select(m => new EventData(Encoding.UTF8.GetBytes(m)))
            .Subscribe(d => client.SendAsync(d));
        }
示例#4
0
        public AppModel()
        {
            var timer  = Observable.Interval(TimeSpan.FromSeconds(1)).Select(_ => DateTime.Now);
            var random = new Random();

            FirstName = ObservableProperty.CreateSettable("Jiro");
            LastName  = ObservableProperty.CreateSettable("Mita");
            FullName  = ObservableProperty.CreateGetOnly(() => string.Format("{0} {1}", FirstName.Value, LastName.Value));
            FirstName.Merge(LastName).Subscribe(FullName);
            Message     = FirstName.SelectToGetOnly(name => string.Format("Hello, {0}!", name));
            CurrentTime = timer.ToGetOnly(DateTime.Now);

            // 初期値をランダムに設定する場合。
            //RandomNumber = CurrentTime.SelectToGetOnly(_ => random.Next(0, 3), true);
            RandomNumber = timer.Select(_ => random.Next(0, 3)).ToGetOnly(0, true);
            _Count       = ObservableProperty.CreateSettable(0);
            Count        = _Count.ToGetOnlyMask();
            RandomNumber.Subscribe(_ => _Count.Value++);
        }
 static StaticEventProcessor()
 {
     Message = ObservableProperty.CreateSettable <string>(null);
 }
示例#6
0
        public AppModel()
        {
            SwitchDevice  = ObservableProperty.CreateSettable <object>(null, true);
            ReverseBitmap = ObservableProperty.CreateSettable <object>(null, true);

            VideoBitmap = ObservableProperty.CreateSettable <BitmapFrame>(null);
            IsRunning   = ObservableProperty.CreateSettable(false);

            var oldNewIndexes = SwitchDevice
                                .Select(_ => new
            {
                OldValue = SelectedDeviceIndex.Value,
                NewValue = (SelectedDeviceIndex.Value + 1) % _devices.Length
            })
                                .ToGetOnly(null);

            SelectedDeviceIndex = oldNewIndexes
                                  .Select(_ => _.NewValue)
                                  .ToGetOnly(0);

            BitmapScaleX = ReverseBitmap
                           .Select(_ => - 1 * BitmapScaleX.Value)
                           .ToGetOnly(-1);

            _devices = new FilterInfoCollection(FilterCategory.VideoInputDevice)
                       .Cast <FilterInfo>()
                       .Select(f => new VideoCaptureDevice(f.MonikerString))
                       .Do(d => d.VideoResolution = GetResolution(d.VideoCapabilities))
                       .ToArray();
            if (_devices.Length == 0)
            {
                return;
            }

            IsRunning
            //.Throttle(TimeSpan.FromMilliseconds(200))
            .ObserveOn(Scheduler.Default)
            .Subscribe(b =>
            {
                if (b)
                {
                    StartDevice(SelectedDeviceIndex.Value);
                }
                else
                {
                    StopDevice(SelectedDeviceIndex.Value);
                }
            });

            oldNewIndexes
            .Where(_ => IsRunning.Value)
            //.Throttle(TimeSpan.FromMilliseconds(200))
            .ObserveOn(Scheduler.Default)
            .Subscribe(_ =>
            {
                StopDevice(_.OldValue);
                // 連続してデバイスを操作すると失敗することがあるため、待機します。
                Thread.Sleep(200);
                StartDevice(_.NewValue);
            });
        }
示例#7
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);
        }