VinnoTissue3DArea.cs 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. using System.IO;
  2. namespace fis.Vid.Visuals
  3. {
  4. public enum VinnoAreaIndicator
  5. {
  6. Global = 0,
  7. A,
  8. B,
  9. C,
  10. ThreeD
  11. }
  12. public class VinnoTissue3DArea
  13. {
  14. public VinnoRect Bounds { get; }
  15. public double CmPerPixel { get; }
  16. public VinnoPoint GlobalOffset { get; }
  17. public VinnoAreaIndicator Indicator { get; }
  18. public VinnoTissue3DArea(VinnoRect bounds, double cmPerPixel, VinnoPoint globalOffset, VinnoAreaIndicator indicator)
  19. {
  20. Indicator = indicator;
  21. GlobalOffset = globalOffset;
  22. CmPerPixel = cmPerPixel;
  23. Bounds = bounds;
  24. }
  25. public byte[] ToBytes()
  26. {
  27. byte[] result;
  28. using (var stream = new MemoryStream())
  29. {
  30. var writer = new VinnoStreamWriter(stream);
  31. writer.WriteByte((byte)Indicator);
  32. writer.WriteDouble(CmPerPixel);
  33. writer.WriteDouble(GlobalOffset.X);
  34. writer.WriteDouble(GlobalOffset.Y);
  35. writer.WriteDouble(Bounds.Left);
  36. writer.WriteDouble(Bounds.Top);
  37. writer.WriteDouble(Bounds.Right);
  38. writer.WriteDouble(Bounds.Bottom);
  39. result = stream.ToArray();
  40. }
  41. return result;
  42. }
  43. public static VinnoTissue3DArea FromBytes(byte[] tissue3DAreaData)
  44. {
  45. VinnoTissue3DArea result;
  46. using (var stream = new MemoryStream(tissue3DAreaData))
  47. {
  48. var reader = new VinnoStreamReader(stream);
  49. var indicator = (VinnoAreaIndicator)reader.ReadByte();
  50. var cmPerPixel = reader.ReadDouble();
  51. var x = reader.ReadDouble();
  52. var y = reader.ReadDouble();
  53. var globalOffset = new VinnoPoint(x,y);
  54. var left = reader.ReadDouble();
  55. var top = reader.ReadDouble();
  56. var right = reader.ReadDouble();
  57. var bottom = reader.ReadDouble();
  58. var bounds = new VinnoRect(new VinnoPoint(left, top), new VinnoPoint(right, bottom));
  59. result = new VinnoTissue3DArea(bounds,cmPerPixel,globalOffset,indicator);
  60. }
  61. return result;
  62. }
  63. }
  64. }