123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498 |
- 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;
- }
- }
- }
|