< Summary - ReFlex - Library

Information
Class: ReFlex.Sensor.EmulatorModule.ImageBasedEmulatorCamera
Assembly: ReFlex.Sensor.EmulatorModule
File(s): D:\a\reflex\reflex\library\src\Sensor\EmulatorModule\ImageBasedEmulatorCamera.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 68
Coverable lines: 68
Total lines: 138
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 18
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.cctor()100%210%
get_Id()100%210%
get_ModelDescription()100%210%
get_CameraType()100%210%
get_State()0%620%
get_StreamParameter()100%210%
.ctor(...)100%210%
EnableStream(...)0%2040%
GetPossibleConfigurations()100%210%
Initialize()100%210%
StartStream()0%620%
StopStream()0%620%
Update(...)0%7280%

File(s)

D:\a\reflex\reflex\library\src\Sensor\EmulatorModule\ImageBasedEmulatorCamera.cs

#LineLine coverage
 1using System;
 2using System.Collections.Generic;
 3using System.Linq;
 4using NLog;
 5using ReFlex.Core.Common.Components;
 6using ReFlex.Core.Common.Util;
 7using ReFlex.Core.Networking.Util;
 8using ReFlex.Core.Tracking.Interfaces;
 9using ReFlex.Core.Tracking.Util;
 10
 11namespace ReFlex.Sensor.EmulatorModule
 12{
 13    public class ImageBasedEmulatorCamera : IDepthCamera
 14    {
 15        #region Fields
 16
 017        private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
 18        private readonly string _address;
 19
 20        private bool _isStarted;
 21        private StreamParameter _selectedConfig;
 22        private EmulatedPointCloud _pointCloud;
 23
 24        #endregion
 25        #region Properties
 26
 027        public string Id => _address;
 28
 029        public string ModelDescription => $"Image-Based Emulator [{_address}]";
 30
 031        public CameraType CameraType => CameraType.Emulator;
 32
 33        public DepthCameraState State
 34        {
 35            get
 036            {
 037                return _isStarted ? DepthCameraState.Streaming : DepthCameraState.Connected;
 038            }
 39        }
 40
 041        public StreamParameter StreamParameter { get; private set; }
 42
 43        #endregion
 44
 45        #region Events
 46
 47        public event EventHandler<DepthCameraState> StateChanged;
 48        public event EventHandler<DepthCameraFrame> FrameReady;
 49        public event EventHandler<ImageByteArray> DepthImageReady;
 50
 51        #endregion
 52
 53        #region Constructor
 54
 055        public ImageBasedEmulatorCamera(string address)
 056        {
 057            _address = address;
 058        }
 59
 60        #endregion
 61
 62        public void EnableStream(StreamParameter parameter)
 063        {
 064            _selectedConfig = GetPossibleConfigurations().FirstOrDefault(item => item.Width == parameter.Width && item.H
 65
 066            var param = new EmulatorParameters
 067            {
 068                HeightInMeters = 1.6f,
 069                WidthInMeters = 2.4f,
 070                MaxDepthInMeter = 2.1f,
 071                MinDepthInMeter = 0.8f,
 072                PlaneDistanceInMeter = 1.45f,
 073                Radius = (int)(parameter.Width * 0.4)
 074            };
 75
 076            StreamParameter = parameter;
 77
 078            _pointCloud = new EmulatedPointCloud(param);
 079            _pointCloud.InitializePointCloud(parameter);
 080        }
 81
 82        public IList<StreamParameter> GetPossibleConfigurations()
 083        {
 084            var configs = new List<StreamParameter>
 085            {
 086                new StreamParameter(50, 50, 30),
 087                new StreamParameter(64, 36, 30),
 088                new StreamParameter(64, 48, 30),
 089                new StreamParameter(100, 100, 30),
 090                new StreamParameter(128, 72, 30),
 091                new StreamParameter(128, 96, 30),
 092                new StreamParameter(640, 480, 30),
 093                new StreamParameter(800, 600, 30),
 094                new StreamParameter(1920, 1080, 30),
 095                new StreamParameter(2560, 1440, 30)
 096            };
 97
 098            return configs;
 099        }
 100
 101        public void Initialize()
 0102        {
 0103            throw new NotImplementedException();
 104        }
 105
 106        public void StartStream()
 0107        {
 0108            _isStarted = true;
 0109            StateChanged?.Invoke(this, State);
 0110        }
 111
 112        public void StopStream()
 0113        {
 0114            _isStarted = false;
 0115            StateChanged?.Invoke(this, State);
 0116        }
 117
 118        public void Update(byte[] data)
 0119        {
 0120            if (_isStarted && _selectedConfig != null)
 0121            {
 0122                var args = new ImageByteArray(
 0123                    data,
 0124                    _selectedConfig.Width,
 0125                    _selectedConfig.Height,
 0126                    3,
 0127                    1);
 128
 0129                _pointCloud.Reset();
 0130                _pointCloud.UpdateFromGreyScaleImage(args);
 131
 0132                DepthImageReady?.Invoke(this, args);
 0133                FrameReady?.Invoke(this, new DepthCameraFrame { Depth = _pointCloud.Points });
 0134            }
 135
 0136        }
 137    }
 138}