using System; using System.IO; namespace fis.Vid.Visuals { public enum PhysicalCoordinateType { Tissue = 0, TimeMotion, ConvexTissue, LinearTissue, ConvexTVTissue, LinearTVTissue, Doppler, TissueTimeMotion, MAM, PWV } public abstract class VinnoPhysicalCoordinate { public PhysicalCoordinateType Type { get; protected set; } public virtual byte[] ToBytes() { byte[] result; using (var stream = new MemoryStream()) { var writer = new VinnoStreamWriter(stream); writer.WriteByte((byte)Type); result = stream.ToArray(); } return result; } public static VinnoPhysicalCoordinate FromBytes(byte[] bytes) { VinnoPhysicalCoordinate physicalCoordinate = null; using (var stream = new MemoryStream(bytes)) { stream.Position = 0; var reader = new VinnoStreamReader(stream); var type = (PhysicalCoordinateType) reader.ReadByte(); switch (type) { case PhysicalCoordinateType.ConvexTissue: physicalCoordinate = VinnoConvexTissuePhysicalCoordinate.FromBytes(bytes); break; case PhysicalCoordinateType.LinearTissue: physicalCoordinate = VinnoLinearTissuePhysicalCoordinate.FromBytes(bytes); break; case PhysicalCoordinateType.ConvexTVTissue: physicalCoordinate = VinnoConvexTVTissuePhysicalCoordinate.FromBytes(bytes); break; case PhysicalCoordinateType.LinearTVTissue: physicalCoordinate = VinnoLinearTVTissuePhysicalCoordinate.FromBytes(bytes); break; case PhysicalCoordinateType.Doppler: physicalCoordinate = VinnoDopplerPhysicalCoordinate.FromBytes(bytes); break; case PhysicalCoordinateType.TissueTimeMotion: physicalCoordinate = VinnoTissueTimeMotionPhysicalCoordinate.FromBytes(bytes); break; case PhysicalCoordinateType.MAM: physicalCoordinate = VinnoMAMPhysicalCoordinate.FromBytes(bytes); break; case PhysicalCoordinateType.PWV: physicalCoordinate = VinnoPWVPhysicalCoordinate.FromBytes(bytes); break; } } return physicalCoordinate; } } public abstract class VinnoTissuePhysicalCoordinate : VinnoPhysicalCoordinate { public double DepthEnd { get; } public double DepthStart { get; } public double Width { get; } public double BeamPosition { get; } protected VinnoTissuePhysicalCoordinate(double depthEnd, double depthStart, double width, double beamPosition) { Type = PhysicalCoordinateType.Tissue; BeamPosition = beamPosition; Width = width; DepthStart = depthStart; DepthEnd = depthEnd; } public override byte[] ToBytes() { byte[] result; using (var stream = new MemoryStream()) { var baseData = base.ToBytes(); stream.Write(baseData, 0, baseData.Length); stream.Position = stream.Length; var writer = new VinnoStreamWriter(stream); writer.WriteDouble(DepthStart); writer.WriteDouble(DepthEnd); writer.WriteDouble(Width); writer.WriteDouble(BeamPosition); result = stream.ToArray(); } return result; } } public abstract class VinnoTimeMotionPhysicalCoordinate : VinnoPhysicalCoordinate { public double SweepSpeed { get; } public double Max { get; } public double Min { get; } protected VinnoTimeMotionPhysicalCoordinate(double sweepSpeed, double max, double min) { Type = PhysicalCoordinateType.TimeMotion; Min = min; Max = max; SweepSpeed = sweepSpeed; } public override byte[] ToBytes() { byte[] result; using (var stream = new MemoryStream()) { var baseData = base.ToBytes(); stream.Write(baseData, 0, baseData.Length); stream.Position = stream.Length; var writer = new VinnoStreamWriter(stream); writer.WriteDouble(Min); writer.WriteDouble(Max); writer.WriteDouble(SweepSpeed); result = stream.ToArray(); } return result; } } public class VinnoConvexTissuePhysicalCoordinate : VinnoTissuePhysicalCoordinate { public double ZeroRadius { get; private set; } public VinnoConvexTissuePhysicalCoordinate(double depthEnd, double depthStart, double width, double beamPosition, double zeroRadius) : base(depthEnd, depthStart, width, beamPosition) { Type = PhysicalCoordinateType.ConvexTissue; ZeroRadius = zeroRadius; } public override byte[] ToBytes() { byte[] result; using (var stream = new MemoryStream()) { var baseData = base.ToBytes(); stream.Write(baseData, 0, baseData.Length); stream.Position = stream.Length; var writer = new VinnoStreamWriter(stream); writer.WriteDouble(ZeroRadius); result = stream.ToArray(); } return result; } public new static VinnoPhysicalCoordinate FromBytes(byte[] bytes) { VinnoPhysicalCoordinate result; using (var stream = new MemoryStream(bytes)) { stream.Position = 0; var reader = new VinnoStreamReader(stream); var type = (PhysicalCoordinateType)reader.ReadByte(); if (type != PhysicalCoordinateType.ConvexTissue) { throw new InvalidCastException( $"Type not matched, target type:{PhysicalCoordinateType.ConvexTissue}, source type:{type}"); } var depthStart = reader.ReadDouble(); var depthEnd = reader.ReadDouble(); var width = reader.ReadDouble(); var beamPosition = reader.ReadDouble(); var zeroRadius = reader.ReadDouble(); result = new VinnoConvexTissuePhysicalCoordinate(depthEnd,depthStart,width,beamPosition,zeroRadius); } return result; } } public class VinnoLinearTissuePhysicalCoordinate : VinnoTissuePhysicalCoordinate { public double Steer { get; } public VinnoLinearTissuePhysicalCoordinate(double depthEnd, double depthStart, double width, double beamPosition, double steer) : base(depthEnd, depthStart, width, beamPosition) { Type = PhysicalCoordinateType.LinearTissue; Steer = steer; } public override byte[] ToBytes() { byte[] result; using (var stream = new MemoryStream()) { var baseData = base.ToBytes(); stream.Write(baseData, 0, baseData.Length); stream.Position = stream.Length; var writer = new VinnoStreamWriter(stream); writer.WriteDouble(Steer); result = stream.ToArray(); } return result; } public new static VinnoPhysicalCoordinate FromBytes(byte[] bytes) { VinnoPhysicalCoordinate result; using (var stream = new MemoryStream(bytes)) { stream.Position = 0; var reader = new VinnoStreamReader(stream); var type = (PhysicalCoordinateType)reader.ReadByte(); if (type != PhysicalCoordinateType.LinearTissue) { throw new InvalidCastException($"Type not matched, target type:{PhysicalCoordinateType.LinearTissue}, source type:{type}"); } var depthStart = reader.ReadDouble(); var depthEnd = reader.ReadDouble(); var width = reader.ReadDouble(); var beamPosition = reader.ReadDouble(); var steer = reader.ReadDouble(); result = new VinnoLinearTissuePhysicalCoordinate(depthEnd, depthStart, width, beamPosition, steer); } return result; } } public class VinnoConvexTVTissuePhysicalCoordinate : VinnoConvexTissuePhysicalCoordinate { public double OriginalZeroRadius { get; private set; } public double OriginalRocx { get; private set; } public VinnoConvexTVTissuePhysicalCoordinate(double depthEnd, double depthStart, double width, double beamPosition, double zeroRadius, double originalZeroRadius, double originalRocx) : base(depthEnd, depthStart, width, beamPosition, zeroRadius) { Type = PhysicalCoordinateType.ConvexTVTissue; OriginalRocx = originalRocx; OriginalZeroRadius = originalZeroRadius; } public override byte[] ToBytes() { byte[] result; using (var stream = new MemoryStream()) { var baseData = base.ToBytes(); stream.Write(baseData, 0, baseData.Length); stream.Position = stream.Length; var writer = new VinnoStreamWriter(stream); writer.WriteDouble(OriginalZeroRadius); writer.WriteDouble(OriginalRocx); result = stream.ToArray(); } return result; } public new static VinnoPhysicalCoordinate FromBytes(byte[] bytes) { VinnoPhysicalCoordinate result; using (var stream = new MemoryStream(bytes)) { stream.Position = 0; var reader = new VinnoStreamReader(stream); var type = (PhysicalCoordinateType)reader.ReadByte(); if (type != PhysicalCoordinateType.ConvexTVTissue) { throw new InvalidCastException($"Type not matched, target type:{PhysicalCoordinateType.ConvexTVTissue}, source type:{type}"); } var depthStart = reader.ReadDouble(); var depthEnd = reader.ReadDouble(); var width = reader.ReadDouble(); var beamPosition = reader.ReadDouble(); var zeroRadius = reader.ReadDouble(); var originalZeroRadius = reader.ReadDouble(); var originalRocx = reader.ReadDouble(); result = new VinnoConvexTVTissuePhysicalCoordinate(depthEnd, depthStart, width, beamPosition, zeroRadius,originalZeroRadius,originalRocx); } return result; } } public class VinnoLinearTVTissuePhysicalCoordinate : VinnoConvexTissuePhysicalCoordinate { public VinnoLinearTVTissuePhysicalCoordinate(double depthEnd, double depthStart, double width, double beamPosition, double zeroRadius) : base(depthEnd, depthStart, width, beamPosition, zeroRadius) { Type = PhysicalCoordinateType.LinearTVTissue; } public new static VinnoPhysicalCoordinate FromBytes(byte[] bytes) { VinnoPhysicalCoordinate result; using (var stream = new MemoryStream(bytes)) { stream.Position = 0; var reader = new VinnoStreamReader(stream); var type = (PhysicalCoordinateType)reader.ReadByte(); if (type != PhysicalCoordinateType.LinearTVTissue) { throw new InvalidCastException( $"Type not matched, target type:{PhysicalCoordinateType.LinearTVTissue}, source type:{type}"); } var depthStart = reader.ReadDouble(); var depthEnd = reader.ReadDouble(); var width = reader.ReadDouble(); var beamPosition = reader.ReadDouble(); var zeroRadius = reader.ReadDouble(); result = new VinnoLinearTVTissuePhysicalCoordinate(depthEnd, depthStart, width, beamPosition, zeroRadius); } return result; } } public class VinnoDopplerPhysicalCoordinate : VinnoTimeMotionPhysicalCoordinate { public double BaseLine { get; } public VinnoDopplerPhysicalCoordinate(double sweepSpeed, double max, double min, double baseLine) : base(sweepSpeed, max, min) { Type = PhysicalCoordinateType.Doppler; BaseLine = baseLine; } public override byte[] ToBytes() { byte[] result; using (var stream = new MemoryStream()) { var baseData = base.ToBytes(); stream.Write(baseData, 0, baseData.Length); stream.Position = stream.Length; var writer = new VinnoStreamWriter(stream); writer.WriteDouble(BaseLine); result = stream.ToArray(); } return result; } public new static VinnoPhysicalCoordinate FromBytes(byte[] bytes) { VinnoPhysicalCoordinate result; using (var stream = new MemoryStream(bytes)) { stream.Position = 0; var reader = new VinnoStreamReader(stream); var type = (PhysicalCoordinateType)reader.ReadByte(); if (type != PhysicalCoordinateType.Doppler) { throw new InvalidCastException($"Type not matched, target type:{PhysicalCoordinateType.Doppler}, source type:{type}"); } var min = reader.ReadDouble(); var max = reader.ReadDouble(); var sweepSpeed = reader.ReadDouble(); var baseLine = reader.ReadDouble(); result = new VinnoDopplerPhysicalCoordinate(sweepSpeed, max, min, baseLine); } return result; } } public class VinnoTissueTimeMotionPhysicalCoordinate : VinnoTimeMotionPhysicalCoordinate { public double DepthStart { get; } public double DepthEnd { get; } public VinnoTissueTimeMotionPhysicalCoordinate(double sweepSpeed, double max, double min, double depthStart, double depthEnd) : base(sweepSpeed, max, min) { Type = PhysicalCoordinateType.TissueTimeMotion; DepthEnd = depthEnd; DepthStart = depthStart; } public override byte[] ToBytes() { byte[] result; using (var stream = new MemoryStream()) { var baseData = base.ToBytes(); stream.Write(baseData, 0, baseData.Length); stream.Position = stream.Length; var writer = new VinnoStreamWriter(stream); writer.WriteDouble(DepthStart); writer.WriteDouble(DepthEnd); result = stream.ToArray(); } return result; } public new static VinnoPhysicalCoordinate FromBytes(byte[] bytes) { VinnoPhysicalCoordinate result; using (var stream = new MemoryStream(bytes)) { stream.Position = 0; var reader = new VinnoStreamReader(stream); var type = (PhysicalCoordinateType)reader.ReadByte(); if (type != PhysicalCoordinateType.TissueTimeMotion) { throw new InvalidCastException( $"Type not matched, target type:{PhysicalCoordinateType.TissueTimeMotion}, source type:{type}"); } var min = reader.ReadDouble(); var max = reader.ReadDouble(); var sweepSpeed = reader.ReadDouble(); var depthStart = reader.ReadDouble(); var depthEnd = reader.ReadDouble(); result = new VinnoTissueTimeMotionPhysicalCoordinate(sweepSpeed, max, min, depthStart,depthEnd); } return result; } } public class VinnoMAMPhysicalCoordinate : VinnoTissueTimeMotionPhysicalCoordinate { public VinnoMAMPhysicalCoordinate(double sweepSpeed, double max, double min, double depthStart, double depthEnd) : base(sweepSpeed, max, min, depthStart, depthEnd) { Type = PhysicalCoordinateType.MAM; } public new static VinnoPhysicalCoordinate FromBytes(byte[] bytes) { VinnoPhysicalCoordinate result; using (var stream = new MemoryStream(bytes)) { stream.Position = 0; var reader = new VinnoStreamReader(stream); var type = (PhysicalCoordinateType)reader.ReadByte(); if (type != PhysicalCoordinateType.MAM) { throw new InvalidCastException($"Type not matched, target type:{PhysicalCoordinateType.MAM}, source type:{type}"); } var min = reader.ReadDouble(); var max = reader.ReadDouble(); var sweepSpeed = reader.ReadDouble(); var depthStart = reader.ReadDouble(); var depthEnd = reader.ReadDouble(); result = new VinnoMAMPhysicalCoordinate(sweepSpeed, max, min, depthStart, depthEnd); } return result; } } public class VinnoPWVPhysicalCoordinate : VinnoTissueTimeMotionPhysicalCoordinate { public VinnoPWVPhysicalCoordinate(double sweepSpeed, double max, double min, double depthStart, double depthEnd) : base(sweepSpeed, max, min, depthStart, depthEnd) { Type = PhysicalCoordinateType.PWV; } public new static VinnoPhysicalCoordinate FromBytes(byte[] bytes) { VinnoPhysicalCoordinate result; using (var stream = new MemoryStream(bytes)) { stream.Position = 0; var reader = new VinnoStreamReader(stream); var type = (PhysicalCoordinateType)reader.ReadByte(); if (type != PhysicalCoordinateType.PWV) { throw new InvalidCastException($"Type not matched, target type:{PhysicalCoordinateType.PWV}, source type:{type}"); } var min = reader.ReadDouble(); var max = reader.ReadDouble(); var sweepSpeed = reader.ReadDouble(); var depthStart = reader.ReadDouble(); var depthEnd = reader.ReadDouble(); result = new VinnoPWVPhysicalCoordinate(sweepSpeed, max, min, depthStart, depthEnd); } return result; } } }