< Summary - ReFlex - Library

Information
Class: ReFlex.Core.Interactivity.Components.SingleInteractionObserver
Assembly: ReFlex.Core.Interactivity
File(s): D:\a\reflex\reflex\library\src\Core\Interactivity\Components\SingleInteractionObserver.cs
Line coverage
90%
Covered lines: 38
Uncovered lines: 4
Coverable lines: 42
Total lines: 115
Line coverage: 90.4%
Branch coverage
91%
Covered branches: 11
Total branches: 12
Branch coverage: 91.6%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor()100%11100%
get_Type()100%210%
get_PointCloud()100%11100%
get_VectorField()100%210%
SelectSmoothedInteractions(...)100%11100%
CheckInitialState()100%22100%
Analyze(...)100%11100%
FindGlobalExtreme(...)90%101090.9%

File(s)

D:\a\reflex\reflex\library\src\Core\Interactivity\Components\SingleInteractionObserver.cs

#LineLine coverage
 1using System;
 2using System.Collections.Generic;
 3using System.Diagnostics;
 4using System.Linq;
 5using System.Threading.Tasks;
 6using ReFlex.Core.Common.Components;
 7using ReFlex.Core.Common.Util;
 8using ReFlex.Core.Interactivity.Interfaces;
 9using Math = System.Math;
 10
 11namespace ReFlex.Core.Interactivity.Components
 12{
 13    /// <summary>
 14    /// Observes a depthimage and reports single touch interactions.
 15    /// </summary>
 16    /// <seealso cref="IInteractionObserver" />
 17    /// <inheritdoc />
 18    /// <seealso cref="T:ReFlex.Core.Interactivity.Interfaces.IInteractionObserver" />
 19    public class SingleInteractionObserver : InteractionObserverBase
 20    {
 621        private readonly Stopwatch _stopWatch = new();
 22
 23        #region Properties
 24
 25        /// <summary>
 26        /// Gets the type.
 27        /// </summary>
 28        /// <value>
 29        /// The type.
 30        /// </value>
 031        public override ObserverType Type => ObserverType.SingleTouch;
 32
 33        /// <summary>
 34        /// Gets or sets the source.
 35        /// </summary>
 36        /// <value>
 37        /// The source.
 38        /// </value>
 2439        public override PointCloud3 PointCloud { get; set; }
 40
 41        /// <inheritdoc />
 42        /// <summary>
 43        /// Gets or sets the vector field.
 44        /// </summary>
 45        /// <value>
 46        /// The vector field.
 47        /// </value>
 048        public override VectorField2 VectorField { get; set; }
 49
 50        #endregion
 51
 52        protected override IEnumerable<Interaction> SelectSmoothedInteractions(IEnumerable<Interaction> interactions)
 1053            => interactions.OrderByDescending(item => item.Time)
 654                .ThenByDescending(item => item.TouchId)
 455                .Take(1);
 56
 57        protected override Task<ProcessingResult> CheckInitialState()
 658        {
 659          return Task.FromResult(PointCloud == null
 660            ? new ProcessingResult(ProcessServiceStatus.Error)
 661            : new ProcessingResult(ProcessServiceStatus.Available)
 662          );
 663        }
 64
 65
 66        protected override Task<Tuple<IEnumerable<Interaction>, ProcessPerformance>> Analyze(
 67          ProcessPerformance performance)
 468        {
 469          var extreme = FindGlobalExtreme(PointCloud, Distance);
 470          var result = new List<Interaction>() { new Interaction(extreme, InteractionType.None, 1) };
 471          var perfItem = new ProcessPerformance();
 472          perfItem.Preparation = TimeSpan.Zero;
 73
 474          return Task.FromResult(new Tuple<IEnumerable<Interaction>, ProcessPerformance>(result, perfItem));
 475        }
 76
 77        /// <summary>
 78        /// Finds the global extreme.
 79        /// </summary>
 80        /// <param name="source">The source.</param>
 81        /// <param name="averageDepth">The average depth.</param>
 82        /// <returns></returns>
 83        public static Point3 FindGlobalExtreme(PointCloud3 source, float averageDepth)
 484        {
 485            var candidate = new Point3(0, 0, averageDepth);
 86
 487            if (source == null)
 088                return candidate;
 89
 490            var candidates = source.AsJaggedArray();
 91
 40892            for (var x = 0; x < source.SizeX; ++x)
 20093            {
 1240094                for (var y = 0; y < source.SizeY; ++y)
 600095                {
 600096                    var curr = candidates[x][y];
 97
 600098                    if (!curr.IsValid)
 099                        continue;
 100
 6000101                    if (!(Math.Abs(curr.Z - averageDepth)
 6000102                          >= Math.Abs(candidate.Z - averageDepth)))
 3256103                        continue;
 104
 2744105                    candidate.X = x;
 2744106                    candidate.Y = y;
 2744107                    candidate.Z = candidates[x][y].Z;
 2744108                }
 200109            }
 110
 4111            return candidate;
 4112        }
 113    }
 114
 115}