VinnoCarotid3DPhysicalData.cs 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. using System.Collections.Generic;
  2. using System.IO;
  3. using fis.Vid.Visuals;
  4. namespace fis.Vid
  5. {
  6. public class VinnoCarotid3DPhysicalData
  7. {
  8. /// <summary>
  9. /// Get cartid type.
  10. /// </summary>
  11. public CarotidType CarotidType { get; }
  12. /// <summary>
  13. /// Get vinno visual.
  14. /// </summary>
  15. public IList<VinnoVisual> VinnoVisuals { get; }
  16. /// <summary>
  17. /// Get vinno visual.
  18. /// </summary>
  19. public VinnoProbe VinnoProbe { get; }
  20. public VinnoCarotid3DPhysicalData(CarotidType carotidType, VinnoProbe vinnoProbe, IList<VinnoVisual> vinnoVisuals)
  21. {
  22. VinnoProbe = vinnoProbe;
  23. VinnoVisuals = vinnoVisuals;
  24. CarotidType = carotidType;
  25. }
  26. /// <summary>
  27. /// Convert to bytes.
  28. /// </summary>
  29. /// <returns>Bytes.</returns>
  30. public byte[] ToBytes()
  31. {
  32. using (var stream = new MemoryStream())
  33. {
  34. var writer = new VinnoStreamWriter(stream);
  35. writer.WriteByte((byte)CarotidType);
  36. writer.WriteBytes(VinnoProbe.ToBytes());
  37. writer.WriteByte((byte)VinnoVisuals.Count);
  38. foreach (var visual in VinnoVisuals)
  39. {
  40. writer.WriteBytes(visual.ToBytes());
  41. }
  42. return stream.ToArray();
  43. }
  44. }
  45. /// <summary>
  46. /// From bytes.
  47. /// </summary>
  48. /// <param name="bytes">bytes.</param>
  49. /// <returns>Instance of vinno carotid 3d physical data.</returns>
  50. public static VinnoCarotid3DPhysicalData FromBytes(byte[] bytes)
  51. {
  52. using (var stream = new MemoryStream(bytes))
  53. {
  54. stream.Position = 0;
  55. var reader = new VinnoStreamReader(stream);
  56. var carotidType = (CarotidType)reader.ReadByte();
  57. var probe = VinnoProbe.FromBytes(reader.ReadBytes());
  58. var visualCount = reader.ReadByte();
  59. var visuals = new List<VinnoVisual>();
  60. for (int i = 0; i < visualCount; i++)
  61. {
  62. var visual = VinnoVisual.FromBytes(reader.ReadBytes());
  63. visuals.Add(visual);
  64. }
  65. return new VinnoCarotid3DPhysicalData(carotidType, probe, visuals);
  66. }
  67. }
  68. }
  69. }