Ejemplo n.º 1
0
        public AppModel()
        {
            var initialTime = DateTime.Now;

            JustTicks = new PeriodicTimer2(TickInterval, () => GetNextJustTicks(initialTime), 1)
                        .ToGetOnly(GetJustTicks(initialTime));
        }
Ejemplo n.º 2
0
        public AppModel()
        {
            var kinect = new AsyncKinectManager();

            kinect.SensorConnected
            .Subscribe(sensor =>
            {
                sensor.SkeletonStream.EnableWithDefaultSmoothing();

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

            var skeletonData = Observable.Interval(FramesInterval)
                               .Select(_ => kinect.Sensor.Value.GetSkeletonData(FramesInterval))
                               .ToGetOnly(null);

            PositionText = skeletonData
                           .Select(GetPosition)
                           .Select(p => p.HasValue ? SkeletonPointToString(p.Value) : "")
                           .ToGetOnly("");
        }
Ejemplo n.º 3
0
        public AppModel()
        {
            var kinect = new AsyncKinectManager();

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

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

            Observable.Interval(FramesInterval)
            .Select(_ => kinect.Sensor.Value.GetDepthData(FramesInterval))
            .Where(d => d != null)
            .Select(ToBitmapData)
            .ObserveOn(SynchronizationContext.Current)
            .Subscribe(d => DepthBitmapInfo.WritePixels(DepthBitmap.Value, d));
        }
Ejemplo n.º 4
0
 public AppModel()
 {
     ProgressValue = Observable.Interval(TimeSpan.FromSeconds(0.03))
                     .Select(n => n % 120)
                     .Select(n => n / 100.0)
                     .Select(v => v < 1.0 ? v : 1.0)
                     .ToGetOnly(0.0);
 }
Ejemplo n.º 5
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());
        }
Ejemplo n.º 6
0
        public static IGetOnlyProperty <TResult> SelectToGetOnly <TSource, TResult>(this IGetOnlyProperty <TSource> source, Func <TSource, TResult> selector, bool notifiesUnchanged)
        {
            if (source == null)
            {
                throw new ArgumentNullException("source");
            }
            if (selector == null)
            {
                throw new ArgumentNullException("selector");
            }

            return(new FollowingGetOnlyProperty <TResult>(source.Select(selector), selector(source.Value), notifiesUnchanged));
        }
Ejemplo n.º 7
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);
        }
Ejemplo n.º 8
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++);
        }
Ejemplo n.º 9
0
        public AppModel()
        {
            IsAvailable = Observable.FromEventPattern <IsAvailableChangedEventArgs>(Sensor, "IsAvailableChanged")
                          .Select(_ => _.EventArgs.IsAvailable)
                          .ToGetOnly(false);

            ColorBitmap = IsAvailable
                          .ObserveOn(SynchronizationContext.Current)
                          .Select(b => b ? ColorBitmapInfo.CreateBitmap() : null)
                          .ToGetOnly(null);

            var colorReader = Sensor.ColorFrameSource.OpenReader();

            Sensor.Open();

            Observable.Interval(FramesInterval)
            .Select(_ => colorReader.GetColorBgraData())
            .Where(d => d != null)
            .ObserveOn(SynchronizationContext.Current)
            .Subscribe(d => ColorBitmapInfo.WritePixels(ColorBitmap.Value, d));
        }
Ejemplo n.º 10
0
        public AppModel()
        {
            var index = -1;

            Position = StaticEventProcessor.Message
                       .Select(m => (dynamic)JsonConvert.DeserializeObject(m))
                       .Where(o => o.index > index)
                       .Do(o => index = o.index)
                       .Select(o => (string)o.position)
                       .Select(Point.Parse)
                       .ToGetOnly(default(Point));

            var hostName                 = string.Format("Host-{0:yyyyMMdd-HHmmss}", DateTime.Now);
            var eventHubName             = "sakapon-event-201508";
            var eventHubConnectionString = ConfigurationManager.AppSettings["Microsoft.ServiceBus.ConnectionString"];
            var storageConnectionString  = ConfigurationManager.AppSettings["StorageConnection"];

            // Receives an event once for one consumer group.
            // EventHubConsumerGroup.DefaultGroupName is "$Default".
            var host = new EventProcessorHost(hostName, eventHubName, EventHubConsumerGroup.DefaultGroupName, eventHubConnectionString, storageConnectionString);

            host.RegisterEventProcessorAsync <StaticEventProcessor>();
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Notifies the property to update the value, for each element.
        /// </summary>
        /// <typeparam name="TSource">The type of the source.</typeparam>
        /// <typeparam name="TProperty">The type of the property.</typeparam>
        /// <param name="source">The source sequence of elements.</param>
        /// <param name="property">The get-only property.</param>
        /// <returns>An <see cref="IDisposable"/> object used to unsubscribe from the source sequence.</returns>
        public static IDisposable Subscribe <TSource, TProperty>(this IObservable <TSource> source, IGetOnlyProperty <TProperty> property)
        {
            if (source == null)
            {
                throw new ArgumentNullException("source");
            }
            if (property == null)
            {
                throw new ArgumentNullException("property");
            }

            return(source.Subscribe(o => property.OnNext()));
        }
Ejemplo n.º 12
0
 /// <summary>
 /// Creates an instance of IObservable-based get-only property from the predecessor get-only property.
 /// </summary>
 /// <typeparam name="TSource">The type of the source property.</typeparam>
 /// <typeparam name="TResult">The type of the property.</typeparam>
 /// <param name="source">The source property.</param>
 /// <param name="selector">The transform function.</param>
 /// <returns>An <see cref="IGetOnlyProperty&lt;TResult&gt;"/> object.</returns>
 public static IGetOnlyProperty <TResult> SelectToGetOnly <TSource, TResult>(this IGetOnlyProperty <TSource> source, Func <TSource, TResult> selector)
 {
     return(SelectToGetOnly(source, selector, false));
 }
Ejemplo n.º 13
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);
            });
        }
Ejemplo n.º 14
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);
        }