| | | 1 | | using System; |
| | | 2 | | using System.Collections.Generic; |
| | | 3 | | using System.Diagnostics; |
| | | 4 | | using System.Threading.Tasks; |
| | | 5 | | using ReFlex.Core.Common.Components; |
| | | 6 | | using ReFlex.Core.Common.Util; |
| | | 7 | | using ReFlex.Core.Interactivity.Interfaces; |
| | | 8 | | |
| | | 9 | | namespace ReFlex.Core.Interactivity.Components; |
| | | 10 | | |
| | | 11 | | public class RemoteInteractionProcessor : InteractionObserverBase |
| | | 12 | | { |
| | | 13 | | private readonly IRemoteInteractionProcessorService _service; |
| | | 14 | | |
| | 52 | 15 | | public RemoteInteractionProcessor(IRemoteInteractionProcessorService service) => _service = service; |
| | | 16 | | |
| | 0 | 17 | | public override ObserverType Type => ObserverType.Remote; |
| | 100 | 18 | | public override PointCloud3 PointCloud { get; set; } |
| | 4 | 19 | | public override VectorField2 VectorField { get; set; } |
| | | 20 | | |
| | | 21 | | protected override async Task<ProcessingResult> CheckInitialState() |
| | 26 | 22 | | { |
| | 28 | 23 | | if (PointCloud == null) return new ProcessingResult(ProcessServiceStatus.Error); |
| | 26 | 24 | | if (_service.IsBusy) return new ProcessingResult(ProcessServiceStatus.Skipped); |
| | 22 | 25 | | if (!_service.IsConnected && !await _service.Connect()) |
| | 2 | 26 | | return new ProcessingResult(ProcessServiceStatus.Error); |
| | 20 | 27 | | return new ProcessingResult(_service.IsBusy ? ProcessServiceStatus.Skipped : ProcessServiceStatus.Available); |
| | 26 | 28 | | } |
| | | 29 | | |
| | | 30 | | protected override async Task<Tuple<IEnumerable<Interaction>, ProcessPerformance>> Analyze(ProcessPerformance perfor |
| | 20 | 31 | | { |
| | 20 | 32 | | var timer = MeasurePerformance ? Stopwatch.StartNew() : null; |
| | 20 | 33 | | var result = await _service.Update(PointCloud, Distance, performance, MeasurePerformance); |
| | 20 | 34 | | if (timer != null && result.Item2.RemoteTimingsMs != null) |
| | 2 | 35 | | result.Item2.RemoteTimingsMs["client_remote_total"] = timer.Elapsed.TotalMilliseconds; |
| | 20 | 36 | | return result; |
| | 20 | 37 | | } |
| | | 38 | | |
| | | 39 | | protected override Task ReportPerformance(ProcessPerformance performance) |
| | 2 | 40 | | { |
| | 2 | 41 | | if (performance.RemoteTimingsMs == null) return Task.CompletedTask; |
| | 2 | 42 | | performance.RemoteTimingsMs["client_depth_conversion"] = performance.ConvertDepthValue.TotalMilliseconds; |
| | 2 | 43 | | performance.RemoteTimingsMs["client_extremum_classification"] = performance.ComputeExtremumType.TotalMillisecond |
| | 2 | 44 | | performance.RemoteTimingsMs["client_smoothing"] = performance.Smoothing.TotalMilliseconds; |
| | 2 | 45 | | return _service.ReportPerformance(performance); |
| | 2 | 46 | | } |
| | | 47 | | } |