Vinno3DVisual.cs 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. using System.Collections.Generic;
  2. using System.IO;
  3. namespace fis.Vid.Visuals
  4. {
  5. public class Vinno3DVisual:VinnoVisual
  6. {
  7. /// <summary>
  8. /// Gets the tissue 3d areas for this visual.
  9. /// </summary>
  10. public IList<VinnoTissue3DArea> Tissue3DAreas { get; }
  11. public Vinno3DVisual()
  12. {
  13. VisualType = VinnoVisualType.V3D;
  14. Tissue3DAreas = new List<VinnoTissue3DArea>();
  15. }
  16. public override byte[] ToBytes()
  17. {
  18. var baseData = base.ToBytes();
  19. byte[] result;
  20. using (var stream = new MemoryStream())
  21. {
  22. stream.Write(baseData, 0, baseData.Length);
  23. var writer = new VinnoStreamWriter(stream);
  24. writer.WriteByte((byte)Tissue3DAreas.Count);
  25. foreach (var tissue3DArea in Tissue3DAreas)
  26. {
  27. writer.WriteBytes(tissue3DArea.ToBytes());
  28. }
  29. result = stream.ToArray();
  30. }
  31. return result;
  32. }
  33. public new static VinnoVisual FromBytes(byte[] bytes)
  34. {
  35. Vinno3DVisual result = null;
  36. using (var stream = new MemoryStream(bytes))
  37. {
  38. stream.Position = 0;
  39. var reader = new VinnoStreamReader(stream);
  40. var visualType = (VinnoVisualType)reader.ReadByte();
  41. var displayMode = (VinnoDisplayMode)reader.ReadByte();
  42. if (visualType == VinnoVisualType.V3D)
  43. {
  44. var indicator = (VinnoVisualIndicator)reader.ReadByte();
  45. result = new Vinno3DVisual {Indicator = indicator};
  46. var activeModeType = (VinnoModeType)reader.ReadByte();
  47. var modeCount = reader.ReadByte();
  48. var modes = new List<VinnoMode>();
  49. for (int i = 0; i < modeCount; i++)
  50. {
  51. var mode = VinnoMode.FromBytes(reader.ReadBytes());
  52. modes.Add(mode);
  53. }
  54. foreach (var mode in modes)
  55. {
  56. result.Modes.Add(mode);
  57. }
  58. result.ActiveModeType = activeModeType;
  59. var tissue3DAreaCount = reader.ReadByte();
  60. var tissue3DAreas = new List<VinnoTissue3DArea>();
  61. for (int i = 0; i < tissue3DAreaCount; i++)
  62. {
  63. var tissue3DArea = VinnoTissue3DArea.FromBytes(reader.ReadBytes());
  64. tissue3DAreas.Add(tissue3DArea);
  65. }
  66. foreach (var tissue3DArea in tissue3DAreas)
  67. {
  68. result.Tissue3DAreas.Add(tissue3DArea);
  69. }
  70. result.DisplayMode = displayMode;
  71. }
  72. }
  73. return result;
  74. }
  75. }
  76. }