123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122 |
- using System.Collections.Generic;
- using System.Linq;
- namespace fis.Vid
- {
- /// <summary>
- /// Carotid scan direction
- /// </summary>
- public enum CarotidDirection
- {
- TopToBottom,
- BottomToTop
- }
- public enum CarotidType
- {
- Left,
- Right
- }
- public class VinnoCarotidExtendedData
- {
- private const string CarotidGroup = "Carotid";
- private const string ScanDistanceElement = "ScanDistance";
- private const string ScanTypeElement = "ScanType";
- private const string ScanDirectionElement = "ScanDirection";
- private readonly VidExtendedData _extendedData;
- /// <summary>
- /// Get CarotidType.
- /// </summary>
- public CarotidType CarotidType { get; }
-
- /// <summary>
- /// Get CarotidDirection
- /// </summary>
- public CarotidDirection CarotidDirection { get; }
- /// <summary>
- /// Get ScanDistance.
- /// </summary>
- public float ScanDistance { get; }
- public VinnoCarotidExtendedData(float scanDistance, CarotidType carotidType,CarotidDirection carotidDirection)
- {
- ScanDistance = scanDistance;
- CarotidType = carotidType;
- CarotidDirection = carotidDirection;
- var dic = new Dictionary<VidTag, IVidValue>
- {
- {new VidTag(CarotidGroup, ScanDistanceElement), new VidFloatValueElement(scanDistance)},
- {new VidTag(CarotidGroup, ScanTypeElement), new VidIntegerValueElement((int)carotidType)},
- {new VidTag(CarotidGroup, ScanDirectionElement), new VidIntegerValueElement((int)carotidDirection)}
- };
- _extendedData = new VidExtendedData(dic);
- }
- /// <summary>
- /// Object to bytes.
- /// </summary>
- /// <returns></returns>
- public byte[] ToBytes()
- {
- return _extendedData.ToBytes();
- }
- public static bool IsCarotid(byte[] bytes)
- {
- if (bytes != null)
- {
- var extendedData = VidExtendedData.FromBytes(bytes);
- if (extendedData != null)
- {
- var vidTags = extendedData.Data.Keys.Where(k => k.Group == CarotidGroup).ToList();
- if (vidTags.Count > 2)
- {
- return true;
- }
- }
- }
- return false;
- }
- /// <summary>
- /// Convert from bytes.
- /// </summary>
- /// <param name="bytes">bytes.</param>
- /// <returns>Instance of vinno carotid extended data.</returns>
- public static VinnoCarotidExtendedData FromBytes(byte[] bytes)
- {
- var extendedData = VidExtendedData.FromBytes(bytes);
- if (extendedData != null)
- {
- var vidTags = extendedData.Data.Keys.Where(k => k.Group == CarotidGroup).ToList();
- if (vidTags.Count > 2)
- {
- var scanDistanceTag = vidTags.FirstOrDefault(t => t.Element.Equals(ScanDistanceElement));
- var carotidTypeTag = vidTags.FirstOrDefault(t => t.Element.Equals(ScanTypeElement));
- var carotidDirectionTag = vidTags.FirstOrDefault(t => t.Element.Equals(ScanDirectionElement));
- if (scanDistanceTag == null || carotidTypeTag == null || carotidDirectionTag==null)
- {
- return null;
- }
- var scanDistance =extendedData.Data[scanDistanceTag];
- var carotidType = extendedData.Data[carotidTypeTag];
- var carotidDirection = extendedData.Data[carotidDirectionTag];
- if (scanDistance is VidFloatValueElement distance &&
- carotidType is VidIntegerValueElement scanType &&
- carotidDirection is VidIntegerValueElement direction)
- {
- return new VinnoCarotidExtendedData(distance.Value, (CarotidType)scanType.Value,(CarotidDirection)direction.Value);
- }
- }
- }
- return null;
- }
- }
- }
|