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++); }
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); }