< Summary - ReFlex - Library

Information
Class: PointCloud.Benchmark.Benchmarks.Interactivity.ObserverComparisonSetup
Assembly: ReFlex.PointCloud.Benchmark
File(s): D:\a\reflex\reflex\test\Library\Performance\PointCloud.Benchmark\Benchmarks\Interactivity\ObserverComparison.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 18
Coverable lines: 18
Total lines: 123
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 6
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
Configure(...)0%4260%

File(s)

D:\a\reflex\reflex\test\Library\Performance\PointCloud.Benchmark\Benchmarks\Interactivity\ObserverComparison.cs

#LineLine coverage
 1using BenchmarkDotNet.Attributes;
 2using ReFlex.Core.Common.Components;
 3using ReFlex.Core.Common.Util;
 4using ReFlex.Core.Interactivity.Interfaces;
 5using ReFlex.Core.Interactivity.Util;
 6using LegacyObserver = PointCloud.Benchmark.Interactivity.MultiInteractionObserver;
 7using CurrentObserver = ReFlex.Core.Interactivity.Components.MultiInteractionObserver;
 8
 9namespace PointCloud.Benchmark.Benchmarks.Interactivity;
 10
 11// Adapters expose the base-class stages without including the different detectors.
 12public sealed class LegacyObserverAdapter : LegacyObserver
 13{
 14    public ExtremumDescription Classify(int x, int y) => ComputeExtremumType(PointCloud.AsJaggedArray(), x, y);
 15    public InteractionFrame Smooth(IList<Interaction> contacts) => ComputeSmoothingValue(contacts);
 16}
 17
 18public sealed class CurrentObserverAdapter : CurrentObserver
 19{
 20    public ExtremumDescription Classify(int x, int y) => ComputeExtremumType(PointCloud.AsJaggedArray(), x, y);
 21    public InteractionFrame Smooth(IList<Interaction> contacts) => ComputeSmoothingValue(contacts);
 22}
 23
 24public static class ObserverComparisonSetup
 25{
 26    public static void Configure(IInteractionObserver observer)
 027    {
 028        var cloud = new PointCloud3(640, 480);
 029        foreach (var point in cloud.AsArray()) point.Z = 1.45f;
 030        for (var i = 0; i < 20; i++) cloud[40 + i * 28, 240].Z = i % 2 == 0 ? 1.3f : 1.6f;
 031        observer.PointCloud = cloud;
 032        observer.Distance = 1.45f;
 033        observer.ExtremumTypeCheckRadius = 12;
 034        observer.ExtremumTypeCheckNumSamples = 16;
 035        observer.ExtremumTypeCheckFittingPercentage = .75f;
 036        observer.InteractionHistorySize = 25;
 037        observer.NumSmoothingFrames = 25;
 038        observer.FilterType = FilterType.MovingAverage;
 039        observer.ContactRetentionSeconds = 1;
 040        observer.TouchMergeDistance2D = 64;
 041        observer.MaxConfidence = 30;
 042        observer.DepthScale = 100;
 043        observer.UseVelocityPrediction = false;
 044    }
 45}
 46
 47[MemoryDiagnoser]
 48public class ObserverExtremumComparison
 49{
 50    private LegacyObserverAdapter _legacy = null!;
 51    private CurrentObserverAdapter _current = null!;
 52
 53    [Params(ExtremumTypeCheckMethod.FixedRadius, ExtremumTypeCheckMethod.StochasticStatic,
 54        ExtremumTypeCheckMethod.StochasticDynamic)]
 55    public ExtremumTypeCheckMethod Sampling { get; set; }
 56
 57    [GlobalSetup]
 58    public void Setup()
 59    {
 60        _legacy = new LegacyObserverAdapter();
 61        _current = new CurrentObserverAdapter();
 62        ObserverComparisonSetup.Configure(_legacy);
 63        ObserverComparisonSetup.Configure(_current);
 64        _legacy.ExtremumTypeCheckMethod = _current.ExtremumTypeCheckMethod = Sampling;
 65        for (var i = 0; i < 20; i++)
 66        {
 67            var expected = i % 2 == 0 ? ExtremumType.Minimum : ExtremumType.Maximum;
 68            if (_legacy.Classify(40 + i * 28, 240).Type != expected ||
 69                _current.Classify(40 + i * 28, 240).Type != expected)
 70                throw new InvalidOperationException("Classifier output differs from the reference scene.");
 71        }
 72    }
 73
 74    [Benchmark(Baseline = true)]
 75    public int BenchmarkCopy()
 76    {
 77        var count = 0;
 78        for (var i = 0; i < 20; i++) count += _legacy.Classify(40 + i * 28, 240).NumFittingPoints;
 79        return count;
 80    }
 81
 82    [Benchmark]
 83    public int Current()
 84    {
 85        var count = 0;
 86        for (var i = 0; i < 20; i++) count += _current.Classify(40 + i * 28, 240).NumFittingPoints;
 87        return count;
 88    }
 89}
 90
 91[MemoryDiagnoser]
 92public class ObserverSmoothingComparison
 93{
 94    private LegacyObserverAdapter _legacy = null!;
 95    private CurrentObserverAdapter _current = null!;
 96    private List<Interaction> _contacts = null!;
 97
 98    [GlobalSetup]
 99    public void Setup()
 100    {
 101        _legacy = new LegacyObserverAdapter();
 102        _current = new CurrentObserverAdapter();
 103        ObserverComparisonSetup.Configure(_legacy);
 104        ObserverComparisonSetup.Configure(_current);
 105        _contacts = Enumerable.Range(0, 20).Select(i => new Interaction
 106        {
 107            Position = new Point3(40 + i * 28, 240, -.5f),
 108            Type = InteractionType.Push,
 109            Confidence = 10
 110        }).ToList();
 111        for (var i = 0; i < 25; i++)
 112        {
 113            _legacy.Smooth(_contacts);
 114            _current.Smooth(_contacts);
 115        }
 116    }
 117
 118    [Benchmark(Baseline = true)]
 119    public InteractionFrame BenchmarkCopy() => _legacy.Smooth(_contacts);
 120
 121    [Benchmark]
 122    public InteractionFrame Current() => _current.Smooth(_contacts);
 123}